Skip to content

Commit

Permalink
fix: Order Status Bar by color
Browse files Browse the repository at this point in the history
  • Loading branch information
frumie1984 authored and moshloop committed Sep 15, 2024
1 parent 0141252 commit 3de0082
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { CellContext } from "@tanstack/react-table";
import { useMemo } from "react";
import { useSearchParams } from "react-router-dom";
import { getConfigStatusColor } from "../ConfigSummaryList";
import { Count, CountBar } from "@flanksource-ui/ui/Icons/ChangeCount";
import {
Count,
CountBar,
OrderByColor
} from "@flanksource-ui/ui/Icons/ChangeCount";

export function ConfigSummaryHealthCell({
getValue,
Expand Down Expand Up @@ -48,7 +52,7 @@ export function ConfigSummaryHealthCell({
e.stopPropagation();
}}
>
<CountBar items={statusLines} barStyle="RAG" />
<CountBar items={OrderByColor(statusLines)} barStyle="RAG" />
</div>
);
}
Expand Down Expand Up @@ -84,5 +88,5 @@ export function ConfigSummaryHealthAggregateCell({
if (!value) {
return null;
}
return <CountBar items={statusLines} barStyle="RAG" />;
return <CountBar items={OrderByColor(statusLines)} barStyle="RAG" />;
}
18 changes: 18 additions & 0 deletions src/ui/Icons/ChangeCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ export default function ChangeCountIcon({ count }: { count: number }) {
);
}

export function OrderByColor(items: Count[]) {
const colorOrder = ["green", "red", "orange", "gray"];

return items.sort((a, b) => {
const colorA = a.color?.toLowerCase() || "";
const colorB = b.color?.toLowerCase() || "";

const indexA = colorOrder.findIndex((color) => colorA.includes(color));
const indexB = colorOrder.findIndex((color) => colorB.includes(color));

if (indexA === -1 && indexB === -1) return 0;
if (indexA === -1) return 1;
if (indexB === -1) return -1;

return indexA - indexB;
});
}

function num(count: number | string) {
let val = `${count}`;

Expand Down

0 comments on commit 3de0082

Please sign in to comment.