-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: filter config list by health on click of the config item
fix: fix issue with config summary
- Loading branch information
1 parent
a305327
commit 20fdbed
Showing
2 changed files
with
98 additions
and
69 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/components/Configs/ConfigSummary/Cells/ConfigSummaryHealthCells.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { ConfigSummary } from "@flanksource-ui/api/types/configs"; | ||
import { | ||
StatusInfo, | ||
StatusLine | ||
} from "@flanksource-ui/components/StatusLine/StatusLine"; | ||
import { CellContext } from "@tanstack/react-table"; | ||
import { useMemo } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { getConfigStatusColor } from "../ConfigSummaryList"; | ||
|
||
export function ConfigSummaryHealthCell({ | ||
getValue, | ||
row | ||
}: CellContext<ConfigSummary, any>) { | ||
const [searchParams] = useSearchParams(); | ||
|
||
const value = getValue<ConfigSummary["health"]>(); | ||
const type = row.original.type; | ||
const groupBy = searchParams.get("groupBy"); | ||
|
||
const urlBase = useMemo(() => { | ||
if (groupBy) { | ||
return `/catalogs?groupBy=${groupBy}&configType=${type}`; | ||
} | ||
return `/catalogs?configType=${type}`; | ||
}, [groupBy, type]); | ||
|
||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const statusLines = useMemo(() => { | ||
const data: StatusInfo[] = Object.entries(value ?? {}).map( | ||
([key, value]) => { | ||
return { | ||
label: value, | ||
url: `${urlBase}&health=${key}`, | ||
color: getConfigStatusColor({ | ||
[key]: value | ||
} as ConfigSummary["health"]) | ||
}; | ||
} | ||
); | ||
return data; | ||
}, [urlBase, value]); | ||
|
||
if (!value) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-row gap-1"> | ||
<StatusLine label="" statuses={statusLines} /> | ||
</div> | ||
); | ||
} | ||
|
||
export function ConfigSummaryHealthAggregateCell({ | ||
row | ||
}: CellContext<ConfigSummary, any>) { | ||
const value = row.subRows.reduce((acc, row) => { | ||
const health = row.original.health; | ||
if (health) { | ||
Object.entries(health).forEach(([key, value]) => { | ||
acc[key] = (acc[key] || 0) + value; | ||
}); | ||
} | ||
return acc; | ||
}, {} as Record<string, number>); | ||
|
||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const statusLines = useMemo(() => { | ||
const data: StatusInfo[] = Object.entries(value ?? {}).map( | ||
([key, value]) => { | ||
return { | ||
label: value.toString(), | ||
// @ts-ignore | ||
color: getConfigStatusColor({ | ||
[key]: value | ||
}) | ||
}; | ||
} | ||
); | ||
return data; | ||
}, [value]); | ||
|
||
if (!value) { | ||
return null; | ||
} | ||
return ( | ||
<div className="flex flex-row gap-1"> | ||
<StatusLine label="" statuses={statusLines} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters