From d0fecbe11a304efef396ce35b1517c381f4489f8 Mon Sep 17 00:00:00 2001 From: John Brunton <1276413+jbrunton@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:28:52 +0000 Subject: [PATCH] refactor: issues table (#375) --- .vscode/settings.json | 4 +++ .../reports/scatterplot/scatterplot-page.tsx | 4 +-- packages/components/src/issues-table.tsx | 33 ++++++++++++------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5fffaeb3..db91c59c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,9 @@ "**/.turbo": true, "**/dist": true, "**/node_modules": true + }, + "sonarlint.connectedMode.project": { + "connectionId": "agileplanning-io", + "projectKey": "agileplanning-io_jira-flow-metrics" } } \ No newline at end of file diff --git a/apps/client/src/app/projects/reports/scatterplot/scatterplot-page.tsx b/apps/client/src/app/projects/reports/scatterplot/scatterplot-page.tsx index ecdcd7bb..f300cf0b 100644 --- a/apps/client/src/app/projects/reports/scatterplot/scatterplot-page.tsx +++ b/apps/client/src/app/projects/reports/scatterplot/scatterplot-page.tsx @@ -28,7 +28,7 @@ import { ChartParamsForm } from "./components/chart-params-form"; import { useFilterParams } from "@app/filter/use-filter-params"; import { Project } from "@data/projects"; import { Button } from "antd"; -import { sortBy } from "remeda"; +import { reverse, sortBy } from "remeda"; import { downloadCsv } from "@data/csv"; export const ScatterplotPage = () => { @@ -61,7 +61,7 @@ export const ScatterplotPage = () => { .map((issue) => issue.metrics.cycleTime), ); setFilteredIssues(filteredIssues); - setPercentiles(percentiles); + setPercentiles(reverse(percentiles)); } }, [issues, filter, setFilteredIssues, setPercentiles, excludedIssues]); diff --git a/packages/components/src/issues-table.tsx b/packages/components/src/issues-table.tsx index 62e05124..b0593e14 100644 --- a/packages/components/src/issues-table.tsx +++ b/packages/components/src/issues-table.tsx @@ -16,7 +16,7 @@ import { import { compareAsc, differenceInMinutes } from "date-fns"; import { ColumnType, ColumnsType, SortOrder } from "antd/es/table/interface"; import { FC, useEffect, useState } from "react"; -import { isNil } from "remeda"; +import { isNullish } from "remeda"; import { QuestionCircleOutlined, ZoomInOutlined } from "@ant-design/icons"; import { CheckboxChangeEvent } from "antd/es/checkbox"; @@ -202,19 +202,10 @@ export const IssuesTable: React.FC = ({ if (!percentiles) { return formatNumber(cycleTime); } - const percentile = isNil(cycleTime) + const percentile = isNullish(cycleTime) ? undefined : percentiles.find((p) => cycleTime >= p.value)?.percentile; - const color = - percentile === undefined - ? "blue" - : percentile >= 95 - ? "rgb(244, 67, 54)" - : percentile >= 85 - ? "red" - : percentile >= 70 - ? "orange" - : "blue"; + const color = getPercentileColor(percentile); return ( {formatNumber(cycleTime)} @@ -456,3 +447,21 @@ const compareNumbers = ( return 0; }; + +const percentileThresholds = [ + { threshold: 95, color: "rgb(244, 67, 54)" }, + { threshold: 85, color: "red" }, + { threshold: 70, color: "orange" }, +]; + +const getPercentileColor = (percentile: number | undefined) => { + if (percentile === undefined) { + return "blue"; + } + + const threshold = percentileThresholds.find( + ({ threshold }) => percentile >= threshold, + ); + + return threshold?.color ?? "blue"; +};