Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workflow] Add search in variable dropdown #8479

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const StyledHeader = styled.li`
border-top-right-radius: ${({ theme }) => theme.border.radius.sm};
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};

padding: ${({ theme }) => theme.spacing(1)};
padding: ${({ theme }) => theme.spacing(1)} 0;

user-select: none;
width: inherit;

&:hover {
background: ${({ theme, onClick }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import styled from '@emotion/styled';
type StyledDropdownButtonProps = {
isUnfolded: boolean;
isActive?: boolean;
transparentBackground?: boolean;
};

export const StyledDropdownButtonContainer = styled.div<StyledDropdownButtonProps>`
align-items: center;
background: ${({ theme, isUnfolded }) =>
isUnfolded ? theme.background.transparent.light : theme.background.primary};
background: ${({ theme, isUnfolded, transparentBackground }) =>
transparentBackground
? 'none'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: 'none' and 'transparent' used inconsistently between normal and hover states. Should use 'transparent' in both places for consistency.

: isUnfolded
? theme.background.transparent.light
: theme.background.primary};
border-radius: ${({ theme }) => theme.border.radius.sm};
color: ${({ isActive, theme }) =>
isActive ? theme.color.blue : theme.font.color.secondary};
Expand All @@ -22,9 +27,11 @@ export const StyledDropdownButtonContainer = styled.div<StyledDropdownButtonProp
user-select: none;

&:hover {
background: ${({ theme, isUnfolded }) =>
isUnfolded
? theme.background.transparent.medium
: theme.background.transparent.light};
background: ${({ theme, isUnfolded, transparentBackground }) =>
transparentBackground
? 'transparent'
: isUnfolded
? theme.background.transparent.medium
: theme.background.transparent.light};
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Editor } from '@tiptap/react';
import { useState } from 'react';
import { IconVariable } from 'twenty-ui';
import { IconVariablePlus } from 'twenty-ui';

const StyledDropdownVariableButtonContainer = styled(
StyledDropdownButtonContainer,
)`
background-color: ${({ theme }) => theme.background.transparent.lighter};
)<{ transparentBackground?: boolean }>`
background-color: ${({ theme, transparentBackground }) =>
transparentBackground
? 'transparent'
: theme.background.transparent.lighter};
color: ${({ theme }) => theme.font.color.tertiary};
padding: ${({ theme }) => theme.spacing(0)};
margin: ${({ theme }) => theme.spacing(2)};
padding: ${({ theme }) => theme.spacing(2)};
`;

const SearchVariablesDropdown = ({
Expand Down Expand Up @@ -65,12 +67,15 @@ const SearchVariablesDropdown = ({
scope: dropdownId,
}}
clickableComponent={
<StyledDropdownVariableButtonContainer isUnfolded={isDropdownOpen}>
<IconVariable size={theme.icon.size.sm} />
<StyledDropdownVariableButtonContainer
isUnfolded={isDropdownOpen}
transparentBackground
>
<IconVariablePlus size={theme.icon.size.sm} />
</StyledDropdownVariableButtonContainer>
}
dropdownComponents={
<DropdownMenuItemsContainer>
<DropdownMenuItemsContainer hasMaxHeight>
{selectedStep ? (
<SearchVariablesDropdownStepSubItem
step={selectedStep}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StepOutputSchema } from '@/workflow/search-variables/types/StepOutputSc
import { isObject } from '@sniptt/guards';
import { useState } from 'react';
import { IconChevronLeft, MenuItemSelect } from 'twenty-ui';
import { DropdownMenuSearchInput } from '@/ui/layout/dropdown/components/DropdownMenuSearchInput';

type SearchVariablesDropdownStepSubItemProps = {
step: StepOutputSchema;
Expand All @@ -16,6 +17,7 @@ const SearchVariablesDropdownStepSubItem = ({
onBack,
}: SearchVariablesDropdownStepSubItemProps) => {
const [currentPath, setCurrentPath] = useState<string[]>([]);
const [searchInputValue, setSearchInputValue] = useState('');

const getSelectedObject = () => {
let selected = step.outputSchema;
Expand All @@ -30,6 +32,7 @@ const SearchVariablesDropdownStepSubItem = ({

if (isObject(selectedObject[key])) {
setCurrentPath([...currentPath, key]);
setSearchInputValue('');
} else {
onSelect(`{{${step.id}.${[...currentPath, key].join('.')}}}`);
}
Expand All @@ -45,12 +48,25 @@ const SearchVariablesDropdownStepSubItem = ({

const headerLabel = currentPath.length === 0 ? step.name : currentPath.at(-1);

const options = Object.entries(getSelectedObject());

const filteredOptions = searchInputValue
? options.filter(([key]) =>
key.toLowerCase().includes(searchInputValue.toLowerCase()),
)
: options;
Comment on lines +53 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider debouncing the filter operation for better performance with large option sets


return (
<>
<DropdownMenuHeader StartIcon={IconChevronLeft} onClick={goBack}>
{headerLabel}
</DropdownMenuHeader>
{Object.entries(getSelectedObject()).map(([key, value]) => (
<DropdownMenuSearchInput
autoFocus
value={searchInputValue}
onChange={(event) => setSearchInputValue(event.target.value)}
/>
{filteredOptions.map(([key, value]) => (
<MenuItemSelect
key={key}
selected={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export {
IconUser,
IconUserCircle,
IconUsers,
IconVariable,
IconVariablePlus,
IconVideo,
IconWand,
IconWorld,
Expand Down
Loading