Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunList: Show job totals in footer #85

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/components/RunList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from 'react';
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import type {
DecodedValueMap,
Expand All @@ -20,8 +21,15 @@ import { parse } from "date-fns";
import { useRuns } from "../../lib/paddles";
import { formatDate, formatDay, formatDuration } from "../../lib/utils";
import IconLink from "../../components/IconLink";
import type { Run } from "../../lib/paddles.d";
import { RunStatuses } from "../../lib/paddles.d";
import type {
Run,
RunResult,
RunResults,
} from "../../lib/paddles.d";
import {
RunResultKeys,
RunStatuses,
} from "../../lib/paddles.d";
import useDefaultTableOptions from "../../lib/table";


Expand All @@ -31,7 +39,7 @@ const NON_FILTER_PARAMS = [
"pageSize",
];

const columns: MRT_ColumnDef<Run>[] = [
const _columns: MRT_ColumnDef<Run>[] = [
{
accessorKey: "name",
header: "link",
Expand Down Expand Up @@ -164,6 +172,11 @@ const columns: MRT_ColumnDef<Run>[] = [
size: 30,
enableColumnFilter: false,
},
{
accessorKey: "results.total",
header: "total",
size: 30,
},
];

function runStatusToThemeCategory(status: string): keyof Theme["palette"] {
Expand Down Expand Up @@ -198,9 +211,9 @@ export default function RunList(props: RunListProps) {
columnFilters.push({
id: "scheduled",
value: parse(value, "yyyy-MM-dd", new Date())
})
})
} else {
columnFilters.push({id, value})
columnFilters.push({id, value})
}
});
let pagination = {
Expand Down Expand Up @@ -233,6 +246,21 @@ export default function RunList(props: RunListProps) {
};
const query = useRuns(debouncedParams);
let data = query.data || [];
const jobTotals = useMemo(() => {
const result: Partial<RunResults> = {};
RunResultKeys.forEach(
status => {
let sub = result[status] || 0;
data.forEach(run => {
sub += run.results[status]
});
result[status] = sub;
});
return result;
}, [data])
const columns = useMemo(() => _columns.map(col =>
col.header in jobTotals? {...col, Footer: jobTotals[col.header as RunResult]} : col
), [data]);
const table = useMaterialReactTable({
...options,
columns,
Expand All @@ -250,6 +278,7 @@ export default function RunList(props: RunListProps) {
columnVisibility: {
started: false,
posted: false,
'results.total': false,
},
sorting: [
{
Expand Down
10 changes: 3 additions & 7 deletions src/lib/paddles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ export type Job = {

export type NodeRoles = string[];

export type RunResults = {
queued: number;
pass: number;
fail: number;
dead: number;
running: number;
}
export const RunResultKeys = JobStatuses.concat(["total"]);
export type RunResult = (typeof RunResultKeys)[number];
export type RunResults = Record<RunResult, number>;

export const RunStatuses = [
"queued", "waiting", "running", "finished dead", "finished fail", "finished pass"
Expand Down
Loading