|
1 |
| -import { |
2 |
| - ConfigChangesTypeItem, |
3 |
| - getConfigsChangesTypesFilter |
4 |
| -} from "@flanksource-ui/api/services/configs"; |
5 | 1 | import { ChangeIcon } from "@flanksource-ui/components/Icon/ChangeIcon";
|
6 | 2 | import TristateReactSelect, {
|
7 | 3 | TriStateOptions
|
8 | 4 | } from "@flanksource-ui/ui/Dropdowns/TristateReactSelect";
|
9 |
| -import { useQuery } from "@tanstack/react-query"; |
10 |
| -import { useCallback } from "react"; |
| 5 | +import { useMemo } from "react"; |
11 | 6 | import { useSearchParams } from "react-router-dom";
|
12 | 7 |
|
13 | 8 | type Props = {
|
14 | 9 | onChange?: (value: string | undefined) => void;
|
15 | 10 | searchParamKey?: string;
|
16 | 11 | paramsToReset?: string[];
|
| 12 | + changeTypes?: Record<string, number>; |
| 13 | + isLoading?: boolean; |
17 | 14 | };
|
18 | 15 |
|
19 | 16 | export function ChangesTypesDropdown({
|
20 | 17 | onChange = () => {},
|
21 | 18 | searchParamKey = "changeType",
|
22 |
| - paramsToReset = [] |
| 19 | + changeTypes, |
| 20 | + paramsToReset = [], |
| 21 | + isLoading |
23 | 22 | }: Props) {
|
24 | 23 | const [searchParams, setSearchParams] = useSearchParams();
|
25 | 24 |
|
26 |
| - const { isLoading, data: configTypeOptions } = useQuery( |
27 |
| - ["db", "changes_types"], |
28 |
| - getConfigsChangesTypesFilter, |
29 |
| - { |
30 |
| - select: useCallback((data: ConfigChangesTypeItem[] | null) => { |
31 |
| - return data?.map( |
32 |
| - ({ change_type }) => |
33 |
| - ({ |
34 |
| - id: change_type, |
35 |
| - label: change_type, |
36 |
| - value: change_type, |
37 |
| - icon: <ChangeIcon change={{ change_type: change_type }} /> |
38 |
| - } satisfies TriStateOptions) |
39 |
| - ); |
40 |
| - }, []) |
41 |
| - } |
42 |
| - ); |
| 25 | + const configTypeOptions = useMemo(() => { |
| 26 | + return changeTypes |
| 27 | + ? Object.entries(changeTypes).map(([change_type]) => { |
| 28 | + return { |
| 29 | + id: change_type, |
| 30 | + label: change_type, |
| 31 | + value: change_type, |
| 32 | + icon: <ChangeIcon change={{ change_type: change_type }} /> |
| 33 | + } satisfies TriStateOptions; |
| 34 | + }) |
| 35 | + : []; |
| 36 | + }, [changeTypes]); |
43 | 37 |
|
44 | 38 | const value = searchParams.get(searchParamKey) || undefined;
|
45 | 39 |
|
|
0 commit comments