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

Table, fixes #38

Merged
merged 4 commits into from
Jul 11, 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"@mui/material": "^5.14.5",
"@prisma/client": "^5.1.1",
"@tailwindcss/forms": "^0.5.4",
"@tanstack/match-sorter-utils": "^8.15.1",
"@tanstack/react-table": "^8.19.2",
"@textea/json-viewer": "^3.1.1",
"@types/bytes": "^3.1.1",
"@types/moment": "^2.13.0",
Expand Down
6 changes: 4 additions & 2 deletions src/app/components/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { clsx } from "clsx"

type ContainerProps = {
children: React.ReactNode
headerChildren?: React.ReactNode
sectionName: string
className?: string
}

export const Container = ({ children, className, sectionName }: ContainerProps) => {
export const Container = ({ children, className, sectionName, headerChildren }: ContainerProps) => {
return (
<div className={clsx(className, "bg-white shadow-sm rounded-s mx-4 md:mx-0")}>
<header className="px-5 py-4 border-b border-gray-100">
<header className="flex items-center gap-x-4 px-5 py-4 border-b border-gray-100">
<h2 className="font-semibold text-gray-800">{sectionName}</h2>
{headerChildren}
</header>
<div className="px-6 py-6">{children}</div>
</div>
Expand Down
14 changes: 6 additions & 8 deletions src/app/runs/[id]/components/AggregateStats/AggregateStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,36 @@ export const AggregateStats: React.FC<AggregateStatsProps> = ({
<dl className={clsx(className, "grid grid-cols-3 gap-5 px-4 md:px-0 mt-8 md:mt-0")}>
<div className="overflow-hidden rounded-md bg-white px-4 py-5 shadow h-24">
<dt className="truncate text-sm font-medium text-gray-500">Wall Time</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight text-gray-900">
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">
{completedAt && <div>{formatDifference(startedAt, completedAt)}</div>}
{!completedAt && <TimerDisplayDynamic startedAt={startedAt} />}
</dd>
</div>
<div className="overflow-hidden rounded-md bg-white px-4 py-5 shadow h-24">
<dt className="truncate text-sm font-medium text-gray-500">CPU time</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight text-gray-900">
{aggregates.cpuTime.toFixed(2)} h
</dd>
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">{aggregates.cpuTime.toFixed(2)} h</dd>
</div>
<div className="overflow-hidden rounded-md bg-white px-4 py-5 shadow h-24">
<dt className="truncate text-sm font-medium text-gray-500">Total Memory</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight text-gray-900">
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">
{bytes(aggregates.totalMemory, { unitSeparator: " " })}
</dd>
</div>
<div className="overflow-hidden rounded-md bg-white px-4 py-5 shadow h-24">
<dt className="truncate text-sm font-medium text-gray-500">Storage Read</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight text-gray-900">
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">
{bytes(aggregates.storageRead, { unitSeparator: " " })}
</dd>
</div>
<div className="overflow-hidden rounded-md bg-white px-4 py-5 shadow h-24">
<dt className="truncate text-sm font-medium text-gray-500">Storage Write</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight text-gray-900">
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">
{bytes(aggregates.storageWrite, { unitSeparator: " " })}
</dd>
</div>
<div className="overflow-hidden rounded-md bg-white px-4 py-5 shadow h-24">
<dt className="truncate text-sm font-medium text-gray-500">Estimated Cost</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight text-gray-900">$ {costEstimate.toFixed(3)}</dd>
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">$ {costEstimate.toFixed(3)}</dd>
</div>
</dl>
</div>
Expand Down
297 changes: 175 additions & 122 deletions src/app/runs/[id]/components/TasksTable/TasksTable.tsx
Original file line number Diff line number Diff line change
@@ -1,143 +1,196 @@
import React, { useMemo, useState } from "react"
import {
createColumnHelper,
flexRender,
getCoreRowModel,
getFilteredRowModel,
getSortedRowModel,
useReactTable,
} from "@tanstack/react-table"
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[]
className?: string
onTaskClick: (task: Task) => void
}

const columnHelper = createColumnHelper<Task>()

const columns = [
columnHelper.accessor((row) => row.data.status, {
id: "status",
header: "Status",
cell: (info) => <TaskStatusTag status={info.getValue().toLowerCase()} />,
}),
columnHelper.accessor((row) => row.data.process, {
id: "process",
header: "Process",
}),
columnHelper.accessor((row) => row.data.duration, {
id: "duration",
header: "Duration",
cell: (info) => formatDuration(info.getValue(), "ms"),
}),
columnHelper.accessor((row) => row.data.realtime, {
id: "realtime",
header: "Realtime",
cell: (info) => formatDuration(info.getValue(), "ms"),
}),
columnHelper.accessor((row) => row.data.pcpu, {
id: "pcpu",
header: "% CPU",
}),
columnHelper.accessor((row) => row.data.pmem, {
id: "pmem",
header: "% Memory",
}),
columnHelper.accessor((row) => row.data.tag, {
id: "tag",
header: "Tag",
}),
columnHelper.accessor("id", {
header: "Task Id",
}),
columnHelper.accessor((row) => row.data.hash, {
id: "hash",
header: "Hash",
}),
columnHelper.accessor((row) => row.data.exit, {
id: "exit",
header: "Exit",
}),
columnHelper.accessor((row) => row.data.container, {
id: "container",
header: "Container",
}),
columnHelper.accessor((row) => row.data.nativeId, {
id: "nativeId",
header: "Native Id",
}),
columnHelper.accessor((row) => row.data.submit, {
id: "submit",
header: "Submitted",
cell: (info) => fullDateTime(info.getValue()),
}),
columnHelper.accessor((row) => row.data.peakRss, {
id: "peakRss",
header: "Peak RSS",
cell: (info) => bytes(info.getValue() ?? 0),
}),
columnHelper.accessor((row) => row.data.peakVmem, {
id: "peakVmem",
header: "Peak VMEM",
cell: (info) => bytes(info.getValue() ?? 0),
}),
columnHelper.accessor((row) => row.data.rchar, {
id: "rchar",
header: "rchar",
cell: (info) => bytes(info.getValue()),
}),
columnHelper.accessor((row) => row.data.wchar, {
id: "wchar",
header: "wchar",
cell: (info) => bytes(info.getValue()),
}),
columnHelper.accessor((row) => row.data.volCtxt, {
id: "volCtxt",
header: "vol_ctxt",
}),
columnHelper.accessor((row) => row.data.invCtxt, {
id: "invCtxt",
header: "inv_ctxt",
}),
]

export const TasksTable = ({ tasks, className, onTaskClick }: TasksTableProps) => {
const data = useMemo(() => tasks, [tasks])
const [globalFilter, setGlobalFilter] = useState("")

const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
globalFilterFn: "includesString",
state: {
globalFilter,
},
onGlobalFilterChange: setGlobalFilter,
})

return (
<Container sectionName="Tasks" className={className}>
<Container
sectionName="Tasks"
className={className}
headerChildren={
<div>
<div className="relative">
<input
id="search"
name="search"
type="text"
value={globalFilter}
onChange={(e) => setGlobalFilter(e.target.value)}
placeholder="Search status, process, tag"
className="peer block w-64 border-0 bg-gray-50 py-1.5 text-gray-900 focus:ring-0 sm:text-sm sm:leading-6"
/>
<div
aria-hidden="true"
className="absolute inset-x-0 bottom-0 border-t border-gray-300 peer-focus:border-t-2 peer-focus:border-indigo-600"
/>
</div>
</div>
}
>
<div className="overflow-x-auto">
<table className="table-auto w-full text-black">
<thead className="text-xs font-semibold uppercase text-gray-400 bg-gray-50">
<tr>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Status</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-left">Process</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Duration</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Realtime</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">% CPU</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">% Memory</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-left">Tag</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-left">Task Id</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Hash</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Exit</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Container</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Native Id</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Submitted</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Peak RSS</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">Peak VMEM</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">rchar</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">wchar</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">vol_ctxt</div>
</th>
<th className="p-2 whitespace-nowrap">
<div className="font-semibold text-center">inv_ctxt</div>
</th>
</tr>
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id} className="p-2 whitespace-nowrap">
{header.isPlaceholder ? null : (
<div
className={header.column.getCanSort() ? "cursor-pointer select-none" : ""}
onClick={header.column.getToggleSortingHandler()}
title={
header.column.getCanSort()
? header.column.getNextSortingOrder() === "asc"
? "Sort ascending"
: header.column.getNextSortingOrder() === "desc"
? "Sort descending"
: "Clear sort"
: undefined
}
>
{flexRender(header.column.columnDef.header, header.getContext())}
{{
asc: " ▲",
desc: " ▼",
}[header.column.getIsSorted() as string] ?? null}
</div>
)}
</th>
))}
</tr>
))}
</thead>
<tbody className="text-sm divide-y divide-gray-100">
{tasks.map((task) => (
<tr key={task.id} className="hover:bg-gray-50 cursor-pointer" onClick={() => onTaskClick(task)}>
<td className="p-2 whitespace-nowrap">
<div className="text-left">
<TaskStatusTag status={task.data.status.toLowerCase()} />
</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.process}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{formatDuration(task.data.duration, "ms")}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{formatDuration(task.data.realtime, "ms")}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.pcpu}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{task.data.pmem}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.tag}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.id}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.hash}</div>
</td>

<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.exit}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.container}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{task.data.nativeId}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-left">{fullDateTime(task.data.submit)}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{bytes(task.data.peakRss ?? 0)}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{bytes(task.data.peakVmem ?? 0)}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{bytes(task.data.rchar)}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{bytes(task.data.wchar)}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{task.data.volCtxt}</div>
</td>
<td className="p-2 whitespace-nowrap">
<div className="text-center">{task.data.invCtxt}</div>
</td>
{table.getRowModel().rows.map((row) => (
<tr key={row.id} className="hover:bg-gray-50 cursor-pointer" onClick={() => onTaskClick(row.original)}>
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="p-2 whitespace-nowrap">
<div className={cell.column.id === "process" ? "text-left" : "text-center"}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</div>
</td>
))}
</tr>
))}
</tbody>
Expand Down
Loading
Loading