8000 FE-575 | adds debounce and loading state for node start search (#21767) · arangodb/arangodb@6a8c799 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a8c799

Browse files
authored
FE-575 | adds debounce and loading state for node start search (#21767)
1 parent f222093 commit 6a8c799

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
devel
22
-----
33

4+
* FE-575: adds debounce and loading state for node start search.
5+
46
* Fix BTS-2086: Fixes missing reschedule of license checks on single-server
57
instances.
68

js/apps/system/_admin/aardvark/APP/react/src/views/graphV2/viewGraph/graphSettings/ParameterNodeStart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ const ParameterNodeStart = () => {
1010
const [inputValue, setInputValue] = useState<string>("");
1111

1212
const { values, onRemoveValue, onAddValue } = useSetupNodeStartValues();
13-
const { options } = useNodeStartOptions({ graphName, inputValue, values });
13+
const { options, isLoading: isLoadingOptions } = useNodeStartOptions({
14+
graphName,
15+
inputValue,
16+
values
17+
});
1418

1519
return (
1620
<>
1721
<FormLabel htmlFor="nodeStart">Start node</FormLabel>
1822
<MultiSelect
1923
noOptionsMessage={() => "No nodes found"}
2024
isClearable={false}
25+
isLoading={isLoadingOptions}
2126
styles={{
2227
container: baseStyles => {
2328
return { width: "240px", ...baseStyles };

js/apps/system/_admin/aardvark/APP/react/src/views/graphV2/viewGraph/graphSettings/useNodeStartOptions.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ const fetchOptions = async ({
5151
});
5252
};
5353

54+
const useDebouncedValue = (value: string, delay: number) => {
55+
const [debouncedValue, setDebouncedValue] = useState(value);
56+
useEffect(() => {
57+
const timeout = setTimeout(() => setDebouncedValue(value), delay);
58+
return () => clearTimeout(timeout);
59+
}, [value, delay]);
60+
return debouncedValue;
61+
};
5462
/**
5563
* Takes the graph name and
5664
* the input entered by the user,
@@ -70,6 +78,8 @@ export const useNodeStartOptions = ({
7078
inputValue: string;
7179
values: OptionType[];
7280
}) => {
81+
const [isLoading, setIsLoading] = useState(false);
82+
const debouncedInputValue = useDebouncedValue(inputValue, 500);
7383
const [vertexOptions, setVertexOptions] = useState<
7484
OptionType[] | undefined
7585
>();
@@ -90,18 +100,21 @@ export const useNodeStartOptions = ({
90100
};
91101
fetchGraphVertexCollection();
92102
}, [graphName]);
93-
103+
useEffect(() => {
104+
setIsLoading(true);
105+
}, [inputValue]);
94106
// loads options based on inputValue
95107
useEffect(() => {
96108
const loadVertexOptions = async () => {
97109
const vertexOptions = await fetchOptions({
98-
inputValue,
110+
inputValue: debouncedInputValue,
99111
collectionOptions,
100112
values
101113
});
102114
setVertexOptions(vertexOptions);
115+
setIsLoading(false);
103116
};
104117
loadVertexOptions();
105-
}, [inputValue, collectionOptions, values]);
106-
return { options: vertexOptions };
118+
}, [debouncedInputValue, collectionOptions, values]);
119+
return { options: vertexOptions, isLoading };
107120
};

0 commit comments

Comments
 (0)
0