Skip to content

Commit

Permalink
feat: show only available change types in dropdown for config changes
Browse files Browse the repository at this point in the history
Fixes #1642
  • Loading branch information
mainawycliffe committed May 13, 2024
1 parent 9df0ce9 commit 10e3894
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
import {
ConfigChangesTypeItem,
getConfigsChangesTypesFilter
} from "@flanksource-ui/api/services/configs";
import { ChangeIcon } from "@flanksource-ui/components/Icon/ChangeIcon";
import TristateReactSelect, {
TriStateOptions
} from "@flanksource-ui/ui/Dropdowns/TristateReactSelect";
import { useQuery } from "@tanstack/react-query";
import { useCallback } from "react";
import { useMemo } from "react";
import { useSearchParams } from "react-router-dom";

type Props = {
onChange?: (value: string | undefined) => void;
searchParamKey?: string;
paramsToReset?: string[];
changeTypes?: Record<string, number>;
isLoading?: boolean;
};

export function ChangesTypesDropdown({
onChange = () => {},
searchParamKey = "changeType",
paramsToReset = []
changeTypes,
paramsToReset = [],
isLoading
}: Props) {
const [searchParams, setSearchParams] = useSearchParams();

const { isLoading, data: configTypeOptions } = useQuery(
["db", "changes_types"],
getConfigsChangesTypesFilter,
{
select: useCallback((data: ConfigChangesTypeItem[] | null) => {
return data?.map(
({ change_type }) =>
({
id: change_type,
label: change_type,
value: change_type,
icon: <ChangeIcon change={{ change_type: change_type }} />
} satisfies TriStateOptions)
);
}, [])
}
);
const configTypeOptions = useMemo(() => {
return changeTypes
? Object.entries(changeTypes).map(([change_type]) => {
return {
id: change_type,
label: change_type,
value: change_type,
icon: <ChangeIcon change={{ change_type: change_type }} />
} satisfies TriStateOptions;
})
: [];
}, [changeTypes]);

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

Expand Down
6 changes: 5 additions & 1 deletion src/pages/config/ConfigChangesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ export function ConfigChangesPage() {
<InfoMessage message={errorMessage} />
) : (
<>
<ConfigChangeFilters paramsToReset={["pageIndex", "pageSize"]} />
<ConfigChangeFilters
isLoading={isLoading}
changeTypes={data?.summary}
paramsToReset={["pageIndex", "pageSize"]}
/>
<ConfigChangeHistory
data={changes}
isLoading={isLoading}
Expand Down

0 comments on commit 10e3894

Please sign in to comment.