Skip to content

Commit

Permalink
fix: filter config list by health on click of the config item
Browse files Browse the repository at this point in the history
fix: fix issue with config summary

chore: fix health filter link

fix: fix filters not working
  • Loading branch information
mainawycliffe authored and moshloop committed Jun 6, 2024
1 parent 2167f19 commit df14917
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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 `/catalog?groupBy=${groupBy}&configType=${type}`;
}
return `/catalog?configType=${type}`;
}, [groupBy, type]);

const statusLines = useMemo(() => {
const data: StatusInfo[] = Object.entries(value ?? {}).map(
([key, value]) => {
return {
label: value,
url: `${urlBase}&health=${key}:1`,
color: getConfigStatusColor({
[key]: value
} as ConfigSummary["health"])
};
}
);
return data;
}, [urlBase, value]);

if (!value) {
return null;
}

return (
<div
className="flex flex-row gap-1"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
>
<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>);

const statusLines = useMemo(() => {
const data: StatusInfo[] = Object.entries(value ?? {}).map(
([key, value]) => {
return {
label: value.toString(),
color: getConfigStatusColor({
[key]: value
} as ConfigSummary["health"])
};
}
);
return data;
}, [value]);

if (!value) {
return null;
}
return (
<div className="flex flex-row gap-1">
<StatusLine label="" statuses={statusLines} />
</div>
);
}
75 changes: 6 additions & 69 deletions src/components/Configs/ConfigSummary/ConfigSummaryList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { ConfigSummary } from "@flanksource-ui/api/types/configs";
import {
StatusInfo,
StatusLine
} from "@flanksource-ui/components/StatusLine/StatusLine";
import { Badge } from "@flanksource-ui/ui/Badge/Badge";
import { CountBadge } from "@flanksource-ui/ui/Badge/CountBadge";
import { DataTable } from "@flanksource-ui/ui/DataTable";
Expand All @@ -15,6 +11,10 @@ import ConfigListCostCell from "../ConfigList/Cells/ConfigListCostCell";
import ConfigListDateCell from "../ConfigList/Cells/ConfigListDateCell";
import ConfigsTypeIcon from "../ConfigsTypeIcon";
import ConfigInsightsIcon from "../Insights/ConfigInsightsIcon";
import {
ConfigSummaryHealthAggregateCell,
ConfigSummaryHealthCell
} from "./Cells/ConfigSummaryHealthCells";

export function getConfigStatusColor(health?: ConfigSummary["health"]) {
if (!health) {
Expand Down Expand Up @@ -111,71 +111,8 @@ const configSummaryColumns: ColumnDef<ConfigSummary, any>[] = [
accessorKey: "health",
minSize: 50,
maxSize: 100,
cell: ({ getValue }: CellContext<ConfigSummary, any>) => {
const value = getValue<ConfigSummary["health"]>();

// eslint-disable-next-line react-hooks/rules-of-hooks
const statusLines = useMemo(() => {
const data: StatusInfo[] = Object.entries(value ?? {}).map(
([key, value]) => {
return {
label: value,
// @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>
);
},
aggregatedCell: ({ 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>
);
}
cell: ConfigSummaryHealthCell,
aggregatedCell: ConfigSummaryHealthAggregateCell
},
{
header: "analysis",
Expand Down

0 comments on commit df14917

Please sign in to comment.