Skip to content

Commit

Permalink
feat: table aggregates
Browse files Browse the repository at this point in the history
  • Loading branch information
gluonfield committed Jul 11, 2024
1 parent 7faadc3 commit 9af6c2d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/app/runs/[id]/components/TasksTable/TasksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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",
Expand Down Expand Up @@ -194,6 +209,17 @@ export const TasksTable = ({ tasks, className, onTaskClick }: TasksTableProps) =
</tr>
))}
</tbody>
<tfoot className="border-solid border-t-[1px] border-gray-100">
{table.getFooterGroups().map((footerEl) => (
<tr key={footerEl.id}>
{footerEl.headers.map((columnEl) => (
<th className="text-sm" key={columnEl.id} colSpan={columnEl.colSpan}>
{flexRender(columnEl.column.columnDef.footer, columnEl.getContext())}
</th>
))}
</tr>
))}
</tfoot>
</table>
</div>
</Container>
Expand Down

0 comments on commit 9af6c2d

Please sign in to comment.