Skip to content

Commit

Permalink
Add search input in variables
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed Nov 13, 2024
1 parent 4104713 commit 04d8eb4
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader';
import { StepOutputSchema } from '@/workflow/search-variables/types/StepOutputSchema';
import { isObject } from '@sniptt/guards';
import { useState } from 'react';
import { useMemo, useState } from 'react';
import { IconChevronLeft, MenuItemSelect } from 'twenty-ui';
import { DropdownMenuSearchInput } from 'packages/twenty-front/src/modules/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 Down Expand Up @@ -45,12 +47,29 @@ const SearchVariablesDropdownStepSubItem = ({

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

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

const filteredOptions = useMemo(
() =>
searchInputValue
? options.filter(([key]) =>
key.toLowerCase().includes(searchInputValue.toLowerCase()),
)
: options,
[options, searchInputValue],
);

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

0 comments on commit 04d8eb4

Please sign in to comment.