Skip to content

Commit

Permalink
Merge pull request #3805 from github/tausbn/compare-perf-add-sorting-…
Browse files Browse the repository at this point in the history
…options

compare-perf: Add support for sorting options
  • Loading branch information
tausbn authored Nov 14, 2024
2 parents f7caf01 + 2abe45b commit c08ef0e
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ChangeEvent } from "react";
import { useMemo, useState, Fragment } from "react";
import type {
SetPerformanceComparisonQueries,
Expand Down Expand Up @@ -178,6 +179,8 @@ const PipelineStepTR = styled.tr`
}
`;

const SortOrderDropdown = styled.select``;

interface PipelineStepProps {
before: number | undefined;
after: number | undefined;
Expand All @@ -204,6 +207,20 @@ function PipelineStep(props: PipelineStepProps) {
);
}

type TRow = {
name: string;
before: PredicateInfo;
after: PredicateInfo;
diff: number;
};

function getSortOrder(sortOrder: "delta" | "absDelta") {
if (sortOrder === "absDelta") {
return orderBy((row: TRow) => -Math.abs(row.diff));
}
return orderBy((row: TRow) => row.diff);
}

function Chevron({ expanded }: { expanded: boolean }) {
return <Codicon name={expanded ? "chevron-down" : "chevron-right"} />;
}
Expand Down Expand Up @@ -247,6 +264,8 @@ export function ComparePerformance(_: Record<string, never>) {

const [hideCacheHits, setHideCacheHits] = useState(false);

const [sortOrder, setSortOrder] = useState<"delta" | "absDelta">("delta");

if (!datasets) {
return <div>Loading performance comparison...</div>;
}
Expand Down Expand Up @@ -280,7 +299,7 @@ export function ComparePerformance(_: Record<string, never>) {
return { name, before, after, diff };
})
.filter((x) => !!x)
.sort(orderBy((row) => row.diff));
.sort(getSortOrder(sortOrder));

let totalBefore = 0;
let totalAfter = 0;
Expand Down Expand Up @@ -314,6 +333,15 @@ export function ComparePerformance(_: Record<string, never>) {
</label>
</WarningBox>
)}
<SortOrderDropdown
onChange={(e: ChangeEvent<HTMLSelectElement>) =>
setSortOrder(e.target.value as "delta" | "absDelta")
}
value={sortOrder}
>
<option value="delta">Delta</option>
<option value="absDelta">Absolute delta</option>
</SortOrderDropdown>
<Table>
<thead>
<tr>
Expand Down

0 comments on commit c08ef0e

Please sign in to comment.