From d7fb65dbca1a9982bd0c6cc07ce9e91dd31580cd Mon Sep 17 00:00:00 2001 From: opoliarush Date: Thu, 19 Sep 2024 19:23:17 +0300 Subject: [PATCH] fix sorting --- .../NewReport/MetricsTable/index.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/Dashboard/NewReport/MetricsTable/index.tsx b/src/components/Dashboard/NewReport/MetricsTable/index.tsx index 73a515a6b..b3a2ff745 100644 --- a/src/components/Dashboard/NewReport/MetricsTable/index.tsx +++ b/src/components/Dashboard/NewReport/MetricsTable/index.tsx @@ -3,6 +3,7 @@ import { flexRender, getCoreRowModel, getSortedRowModel, + SortingFn, sortingFns, useReactTable } from "@tanstack/react-table"; @@ -18,6 +19,20 @@ import { getSeverity } from "../utils"; import * as s from "./styles"; import { ColumnMeta, MetricsTableProps, Severity } from "./types"; +const sortImpactFn: SortingFn = (rowA, rowB) => { + const impactA = rowA.original.impact; + const impactB = rowB.original.impact; + + return impactA - impactB; +}; + +const sortIssuesFn: SortingFn = (rowA, rowB) => { + const issuesA = rowA.original.issues; + const issuesB = rowB.original.issues; + + return issuesA - issuesB; +}; + const IssuesLink = ({ children, onClick @@ -87,7 +102,7 @@ export const MetricsTable = ({ ); }, - sortingFn: sortingFns.alphanumeric, + sortingFn: sortIssuesFn, meta: { contentAlign: "center" }, @@ -105,7 +120,7 @@ export const MetricsTable = ({ {Math.round(info.getValue().impact * 100)} ), - sortingFn: sortingFns.alphanumeric, + sortingFn: sortImpactFn, enableSorting: true, meta: { contentAlign: "center"