Skip to content

Commit d44a41c

Browse files
ivaibhavmkart1ka
andauthored
feat: Add search functionality for variables in workflow (calcom#23191)
* Add search functionality for variables in workflow * feat: Add search functionality for variables in workflow - updated * fix failing test * fix UI of AddVariable * fix: clear stale input value * fix: locale * fix: locale * chore --------- Co-authored-by: Kartik Saini <41051387+kart1ka@users.noreply.github.com>
1 parent 4960c4b commit d44a41c

2 files changed

Lines changed: 54 additions & 19 deletions

File tree

apps/web/public/static/locales/en/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,5 +3583,7 @@
35833583
"you_have_one_team": "You have one team",
35843584
"consider_consolidating_one_team_org": "Consider setting up an organization to unify billing, admin tools, and analytics across your team.",
35853585
"consider_consolidating_multi_team_org": "Consider setting up an organization to unify billing, admin tools, and analytics across your teams.",
3586+
"search_variables": "Search variables",
3587+
"no_variables_found": "No variables found",
35863588
"ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
35873589
}

packages/ui/components/editor/plugins/AddVariablesDropdown.tsx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { useMemo, useState } from "react";
2+
13
import { useLocale } from "@calcom/lib/hooks/useLocale";
2-
import classNames from "@calcom/ui/classNames";
34

45
import { Dropdown, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../../dropdown";
56
import { Icon } from "../../icon";
@@ -14,9 +15,24 @@ interface IAddVariablesDropdown {
1415

1516
export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
1617
const { t } = useLocale();
18+
const [query, setQuery] = useState("");
19+
20+
const filteredVariables = useMemo(() => {
21+
const q = query.trim().toLowerCase();
22+
if (!q) return props.variables;
23+
return props.variables.filter((variable) => {
24+
const key = variable.toLowerCase();
25+
const name = t(`${variable}_variable`).toLowerCase();
26+
const info = t(`${variable}_info`).toLowerCase();
27+
return key.includes(q) || name.includes(q) || info.includes(q);
28+
});
29+
}, [props.variables, query, t]);
1730

1831
return (
19-
<Dropdown>
32+
<Dropdown
33+
onOpenChange={(open) => {
34+
if (!open) setQuery("");
35+
}}>
2036
<DropdownMenuTrigger aria-label="Add variable" className="focus:bg-muted pt-[6px]">
2137
<div className="items-center">
2238
{props.isTextEditor ? (
@@ -49,25 +65,42 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
4965
<div className="text-subtle mb-3 text-left text-xs font-medium uppercase tracking-wide">
5066
{t("add_dynamic_variables")}
5167
</div>
68+
<div className="mb-2 px-2">
69+
<input
70+
type="text"
71+
value={query}
72+
onChange={(e) => setQuery(e.target.value)}
73+
placeholder={t("search_variables")}
74+
aria-label={t("search_variables")}
75+
className="border-subtle bg-default focus:ring-brand-800 w-full rounded-md border px-3 py-2 text-sm outline-none focus:ring-1"
76+
/>
77+
</div>
5278
<div className="max-h-64 overflow-y-auto md:max-h-80">
53-
{props.variables.map((variable) => (
54-
<DropdownMenuItem key={variable} className="hover:ring-0">
55-
<button
56-
key={variable}
57-
type="button"
58-
className="hover:bg-muted w-full rounded-md px-3 py-2 text-left transition-colors"
59-
onClick={() => props.addVariable(t(`${variable}_variable`))}>
60-
<div className="flex flex-col space-y-1">
61-
<div className="text-default font-mono text-sm">
62-
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
79+
{filteredVariables.length === 0 ? (
80+
<div className="text-subtle px-4 py-2 text-center text-sm">{t("no_variables_found")}</div>
81+
) : (
82+
filteredVariables.map((variable) => (
83+
<DropdownMenuItem key={variable} className="hover:ring-0">
84+
<button
85+
key={variable}
86+
type="button"
87+
className="hover:bg-muted w-full rounded-md px-3 py-2 text-left transition-colors"
88+
onClick={() => {
89+
props.addVariable(t(`${variable}_variable`));
90+
setQuery("");
91+
}}>
92+
<div className="flex flex-col space-y-1">
93+
<div className="text-default font-mono text-sm">
94+
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
95+
</div>
96+
<div className="text-muted-foreground hidden text-xs sm:block">
97+
{t(`${variable}_info`)}
98+
</div>
6399
</div>
64-
<div className="text-muted-foreground hidden text-xs sm:block">
65-
{t(`${variable}_info`)}
66-
</div>
67-
</div>
68-
</button>
69-
</DropdownMenuItem>
70-
))}
100+
</button>
101+
</DropdownMenuItem>
102+
))
103+
)}
71104
</div>
72105
</div>
73106
</DropdownMenuContent>

0 commit comments

Comments
 (0)