Skip to content

Commit

Permalink
fix: fix filter by health and status not working
Browse files Browse the repository at this point in the history
Fixes #2364
  • Loading branch information
mainawycliffe authored and moshloop committed Oct 22, 2024
1 parent be7719b commit d46e745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/api/query-hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tristateOutputToQueryFilterParam } from "@flanksource-ui/ui/Dropdowns/TristateReactSelect";
import { setTristateOutputToQueryFilterToURLSearchParam } from "@flanksource-ui/ui/Dropdowns/TristateReactSelect";
import { UseQueryOptions, useQuery } from "@tanstack/react-query";
import { isNull } from "lodash";
import { toastError } from "../../components/Toast/toast";
Expand Down Expand Up @@ -193,13 +193,11 @@ export function prepareConfigListQuery({
}

if (status && status !== "All") {
const statusParam = tristateOutputToQueryFilterParam(status, "status");
query.append("status", statusParam);
setTristateOutputToQueryFilterToURLSearchParam(query, status, "status");
}

if (health) {
const healthParam = tristateOutputToQueryFilterParam(health, "health");
query.append("health", healthParam);
setTristateOutputToQueryFilterToURLSearchParam(query, health, "health");
}

if (search) {
Expand Down
14 changes: 14 additions & 0 deletions src/ui/Dropdowns/TristateReactSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ export function tristateOutputToQueryFilterParam(
return `&${key}.filter=${paramValue}`;
}

export function setTristateOutputToQueryFilterToURLSearchParam(
searchParams: URLSearchParams,
param: string | undefined,
key: string
) {
if (param === undefined) {
return "";
}
const paramValue = tristateOutputToQueryParamValue(param);
if (paramValue) {
searchParams.set(`${key}.filter`, paramValue);
}
}

type TriStateToggleState = {
[key: string]: number;
};
Expand Down

0 comments on commit d46e745

Please sign in to comment.