From 5f3d95c63f1b024c3970cd62671c9c47d970c769 Mon Sep 17 00:00:00 2001 From: Kevin Ness Date: Wed, 1 May 2024 20:14:25 -0400 Subject: [PATCH] Patch % sort options --- .../conformance/ResultsDisplay/nav.tsx | 4 +- src/components/conformance/utils.ts | 41 +++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/components/conformance/ResultsDisplay/nav.tsx b/src/components/conformance/ResultsDisplay/nav.tsx index 79d0923e..ec230085 100644 --- a/src/components/conformance/ResultsDisplay/nav.tsx +++ b/src/components/conformance/ResultsDisplay/nav.tsx @@ -132,7 +132,9 @@ type SortProps = { }; function SortingDropdown(props: SortProps): JSX.Element { - const [sortValue, setSortValue] = React.useState(props.sortValue ? props.sortValue : "alpha"); + const [sortValue, setSortValue] = React.useState( + props.sortValue ? props.sortValue : "alpha", + ); React.useEffect(() => { setSortValue(props.sortValue); diff --git a/src/components/conformance/utils.ts b/src/components/conformance/utils.ts index 0b5e23c2..6bf96461 100644 --- a/src/components/conformance/utils.ts +++ b/src/components/conformance/utils.ts @@ -54,20 +54,20 @@ export const availableSortingOptions: SortOption[] = [ { id: "most-pass-percentage", name: "Most Passed (%)", - callback: (a, b) => - b.stats.total - - a.stats.total + - b.stats.passed / b.stats.total - - a.stats.passed / a.stats.total, + callback: (a, b) => { + const p1 = a.stats.passed / a.stats.total; + const p2 = b.stats.passed / b.stats.total; + return p1 === p2 ? b.stats.total - a.stats.total : p2 - p1; + }, }, { id: "least-pass-percentage", name: "Least Passed (%)", - callback: (a, b) => - b.stats.total - - a.stats.total + - a.stats.passed / a.stats.total - - b.stats.passed / b.stats.total, + callback: (a, b) => { + const p1 = a.stats.passed / a.stats.total; + const p2 = b.stats.passed / b.stats.total; + return p1 === p2 ? b.stats.total - a.stats.total : p1 - p2; + }, }, { id: "most-ignored", @@ -98,21 +98,20 @@ export const availableSortingOptions: SortOption[] = [ { id: "most-fail-percentage", name: "Most Failed (%)", - callback: (a, b) => - b.stats.total - - a.stats.total + - (b.stats.total - (b.stats.passed + b.stats.ignored)) - - (a.stats.total - (a.stats.passed + a.stats.ignored)), + callback: (a, b) => { + const p1 = (b.stats.passed + b.stats.ignored) / b.stats.total; + const p2 = (a.stats.passed + a.stats.ignored) / a.stats.total; + return p2 === p1 ? b.stats.total - a.stats.total : p2 - p1; + }, }, { id: "least-fail-percentage", name: "Least Failed (%)", - callback: (a, b) => - b.stats.total - - a.stats.total + - (a.stats.total - b.stats.total) + - a.stats.passed / a.stats.total - - b.stats.passed / b.stats.total, + callback: (a, b) => { + const p1 = (b.stats.passed + b.stats.ignored) / b.stats.total; + const p2 = (a.stats.passed + a.stats.ignored) / a.stats.total; + return p2 === p1 ? b.stats.total - a.stats.total : p1 - p2; + }, }, ];