diff --git a/CHANGELOG.md b/CHANGELOG.md index eab6c232..1c32a6d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## v1.4.1 [TBD] _Bug Fixes_ +- Improve benchmark/detection summary chart width calculations. ([#945](https://github.com/turbot/powerpipe/issues/945)) - Fix filtering by false boolean values in tables. ([#946](https://github.com/turbot/powerpipe/issues/946)) ## v1.4.0 [2025-09-22] diff --git a/ui/dashboard/src/components/dashboards/grouping/CheckSummaryChart/index.tsx b/ui/dashboard/src/components/dashboards/grouping/CheckSummaryChart/index.tsx index d51e44ea..c3ac0b53 100644 --- a/ui/dashboard/src/components/dashboards/grouping/CheckSummaryChart/index.tsx +++ b/ui/dashboard/src/components/dashboards/grouping/CheckSummaryChart/index.tsx @@ -1,7 +1,8 @@ import IntegerDisplay from "../../../IntegerDisplay"; +import usePrevious from "@powerpipe/hooks/usePrevious"; import { CheckNodeStatus, CheckSummary } from "../common"; import { classNames } from "@powerpipe/utils/styles"; -import { ReactNode } from "react"; +import { ReactNode, useEffect, useRef, useState } from "react"; type ProgressBarGroupProps = { children: ReactNode; @@ -10,7 +11,7 @@ type ProgressBarGroupProps = { type ProgressBarProps = { className?: string; - percent: number; + width: number; }; type CheckSummaryChartProps = { @@ -34,7 +35,7 @@ type ProgressBarGroupTotalProps = { total: number; }; -const getWidth = (x, y) => { +const getWidth = (x: number, y: number) => { const percent = (x / (x + y)) * 100; return percent >= 0.5 ? Math.round(percent) : 1; }; @@ -89,7 +90,7 @@ const NonAlertProgressBarGroupTotal = ({ summary, }: NonAlertProgressBarGroupTotalProps) => { const nonAlertTotal = summary.ok + summary.info + summary.skip; - let textClassName; + let textClassName: string; if (nonAlertTotal === 0) { textClassName = "text-foreground-lightest"; } else if (summary.skip > summary.info && summary.skip > summary.ok) { @@ -115,29 +116,30 @@ export const ProgressBarGroup = ({ ); -export const ProgressBar = ({ className, percent }: ProgressBarProps) => { - if (!percent) { +export const ProgressBar = ({ className, width }: ProgressBarProps) => { + if (!width) { return null; } return (
); }; -export const getCheckSummaryChartPercent = (value, total) => { - if (!value) { +const getSegmentPixelWidth = ( + value: number, + divisor: number, + containerWidth: number, +) => { + if (!value || !divisor || !containerWidth) { return 0; } - const percentOfTotal = value / total; - const rounded = Math.floor(percentOfTotal * 100); - return Math.max(rounded, 3); + + const percent = value / divisor; + return Math.max(Math.round(percent * containerWidth), 1); }; const CheckSummaryChart = ({ @@ -145,6 +147,31 @@ const CheckSummaryChart = ({ summary, firstChildSummaries, }: CheckSummaryChartProps) => { + const [, setVersion] = useState(0); + const alertsContainerRef = useRef