Skip to content

Commit

Permalink
Patch % sort options (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss authored May 3, 2024
1 parent a4d2683 commit adbd8a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/components/conformance/ResultsDisplay/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ type SortProps = {
};

function SortingDropdown(props: SortProps): JSX.Element {
const [sortValue, setSortValue] = React.useState<string>(props.sortValue ? props.sortValue : "alpha");
const [sortValue, setSortValue] = React.useState<string>(
props.sortValue ? props.sortValue : "alpha",
);

React.useEffect(() => {
setSortValue(props.sortValue);
Expand Down
41 changes: 20 additions & 21 deletions src/components/conformance/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
},
},
];

Expand Down

0 comments on commit adbd8a6

Please sign in to comment.