Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 10e3894

Browse files
committedMay 13, 2024
feat: show only available change types in dropdown for config changes
Fixes #1642
1 parent 9df0ce9 commit 10e3894

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed
 

‎src/components/Configs/Changes/ConfigChangesFilters/ChangeTypesDropdown.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
1-
import {
2-
ConfigChangesTypeItem,
3-
getConfigsChangesTypesFilter
4-
} from "@flanksource-ui/api/services/configs";
51
import { ChangeIcon } from "@flanksource-ui/components/Icon/ChangeIcon";
62
import TristateReactSelect, {
73
TriStateOptions
84
} from "@flanksource-ui/ui/Dropdowns/TristateReactSelect";
9-
import { useQuery } from "@tanstack/react-query";
10-
import { useCallback } from "react";
5+
import { useMemo } from "react";
116
import { useSearchParams } from "react-router-dom";
127

138
type Props = {
149
onChange?: (value: string | undefined) => void;
1510
searchParamKey?: string;
1611
paramsToReset?: string[];
12+
changeTypes?: Record<string, number>;
13+
isLoading?: boolean;
1714
};
1815

1916
export function ChangesTypesDropdown({
2017
onChange = () => {},
2118
searchParamKey = "changeType",
22-
paramsToReset = []
19+
changeTypes,
20+
paramsToReset = [],
21+
isLoading
2322
}: Props) {
2423
const [searchParams, setSearchParams] = useSearchParams();
2524

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]);
4337

4438
const value = searchParams.get(searchParamKey) || undefined;
4539

‎src/pages/config/ConfigChangesPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ export function ConfigChangesPage() {
160160
<InfoMessage message={errorMessage} />
161161
) : (
162162
<>
163-
<ConfigChangeFilters paramsToReset={["pageIndex", "pageSize"]} />
163+
<ConfigChangeFilters
164+
isLoading={isLoading}
165+
changeTypes={data?.summary}
166+
paramsToReset={["pageIndex", "pageSize"]}
167+
/>
164168
<ConfigChangeHistory
165169
data={changes}
166170
isLoading={isLoading}

0 commit comments

Comments
 (0)
Please sign in to comment.