From 9af6c2dbb6f0949bb7a70dd4c7baf1776de68069 Mon Sep 17 00:00:00 2001 From: Augustinas Malinauskas Date: Thu, 11 Jul 2024 13:57:49 +0100 Subject: [PATCH] feat: table aggregates --- .../[id]/components/TasksTable/TasksTable.tsx | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app/runs/[id]/components/TasksTable/TasksTable.tsx b/src/app/runs/[id]/components/TasksTable/TasksTable.tsx index ffb0270..07cbb9c 100644 --- a/src/app/runs/[id]/components/TasksTable/TasksTable.tsx +++ b/src/app/runs/[id]/components/TasksTable/TasksTable.tsx @@ -11,7 +11,6 @@ import { Container, StatusTag, TaskStatusTag } from "@/app/components" import { formatDuration, fullDateTime } from "@/common" import { Task } from "@prisma/client" import bytes from "bytes" -import { FaCaretDown } from "react-icons/fa" type TasksTableProps = { tasks: Task[] @@ -35,11 +34,27 @@ const columns = [ id: "duration", header: "Duration", cell: (info) => formatDuration(info.getValue(), "ms"), + footer: ({ table }) => { + let rows = table.getFilteredRowModel().rows + let msSum = 0.0 + for (let i = 0; i < rows.length; i++) { + msSum += (rows[i].getValue("duration") as number) ?? 0 + } + return formatDuration(msSum, "ms") + }, }), columnHelper.accessor((row) => row.data.realtime, { id: "realtime", header: "Realtime", cell: (info) => formatDuration(info.getValue(), "ms"), + footer: ({ table }) => { + let rows = table.getFilteredRowModel().rows + let msSum = 0.0 + for (let i = 0; i < rows.length; i++) { + msSum += (rows[i].getValue("realtime") as number) ?? 0 + } + return formatDuration(msSum, "ms") + }, }), columnHelper.accessor((row) => row.data.pcpu, { id: "pcpu", @@ -194,6 +209,17 @@ export const TasksTable = ({ tasks, className, onTaskClick }: TasksTableProps) = ))} + + {table.getFooterGroups().map((footerEl) => ( + + {footerEl.headers.map((columnEl) => ( + + {flexRender(columnEl.column.columnDef.footer, columnEl.getContext())} + + ))} + + ))} +