-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] feat: Adds data and UX for task run concurrency limit (#16287)
- Loading branch information
1 parent
6aaf035
commit 404090b
Showing
22 changed files
with
1,070 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ui-v2/src/components/concurrency/task-run-concurrenct-view/data-table/actions-cell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { Icon } from "@/components/ui/icons"; | ||
import { type TaskRunConcurrencyLimit } from "@/hooks/task-run-concurrency-limits"; | ||
import { useToast } from "@/hooks/use-toast"; | ||
import { CellContext } from "@tanstack/react-table"; | ||
|
||
type Props = CellContext<TaskRunConcurrencyLimit, unknown> & { | ||
onDeleteRow: (row: TaskRunConcurrencyLimit) => void; | ||
onResetRow: (row: TaskRunConcurrencyLimit) => void; | ||
}; | ||
|
||
export const ActionsCell = ({ onDeleteRow, onResetRow, ...props }: Props) => { | ||
const { toast } = useToast(); | ||
|
||
const handleCopyId = (id: string | undefined) => { | ||
if (!id) { | ||
throw new Error("'id' field expected in GlobalConcurrencyLimit"); | ||
} | ||
void navigator.clipboard.writeText(id); | ||
toast({ title: "Name copied" }); | ||
}; | ||
|
||
const row = props.row.original; | ||
|
||
return ( | ||
<div className="flex flex-row justify-end"> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline" className="h-8 w-8 p-0"> | ||
<span className="sr-only">Open menu</span> | ||
<Icon id="MoreVertical" className="h-4 w-4" /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end"> | ||
<DropdownMenuLabel>Actions</DropdownMenuLabel> | ||
<DropdownMenuItem onClick={() => handleCopyId(row.id)}> | ||
Copy ID | ||
</DropdownMenuItem> | ||
<DropdownMenuItem onClick={() => onDeleteRow(row)}> | ||
Delete | ||
</DropdownMenuItem> | ||
<DropdownMenuItem onClick={() => onResetRow(row)}> | ||
Reset | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</div> | ||
); | ||
}; |
90 changes: 90 additions & 0 deletions
90
ui-v2/src/components/concurrency/task-run-concurrenct-view/data-table/data-table.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { DataTable } from "@/components/ui/data-table"; | ||
import { type TaskRunConcurrencyLimit } from "@/hooks/task-run-concurrency-limits"; | ||
import { getRouteApi } from "@tanstack/react-router"; | ||
import { | ||
createColumnHelper, | ||
getCoreRowModel, | ||
getPaginationRowModel, | ||
useReactTable, | ||
} from "@tanstack/react-table"; | ||
|
||
import { SearchInput } from "@/components/ui/input"; | ||
import { useDeferredValue, useMemo } from "react"; | ||
import { ActionsCell } from "./actions-cell"; | ||
|
||
const routeApi = getRouteApi("/concurrency-limits"); | ||
|
||
const columnHelper = createColumnHelper<TaskRunConcurrencyLimit>(); | ||
|
||
const createColumns = ({ | ||
onDeleteRow, | ||
onResetRow, | ||
}: { | ||
onDeleteRow: (row: TaskRunConcurrencyLimit) => void; | ||
onResetRow: (row: TaskRunConcurrencyLimit) => void; | ||
}) => [ | ||
columnHelper.accessor("tag", { | ||
header: "Tag", // TODO: Make this a link when starting the tak run concurrency page | ||
}), | ||
columnHelper.accessor("concurrency_limit", { | ||
header: "Slots", | ||
}), | ||
columnHelper.accessor("active_slots", { | ||
header: "Active Task Runs", // TODO: Give this styling once knowing what it looks like | ||
}), | ||
columnHelper.display({ | ||
id: "actions", | ||
cell: (props) => ( | ||
<ActionsCell | ||
{...props} | ||
onDeleteRow={onDeleteRow} | ||
onResetRow={onResetRow} | ||
/> | ||
), | ||
}), | ||
]; | ||
|
||
type Props = { | ||
data: Array<TaskRunConcurrencyLimit>; | ||
onDeleteRow: (row: TaskRunConcurrencyLimit) => void; | ||
onResetRow: (row: TaskRunConcurrencyLimit) => void; | ||
}; | ||
|
||
export const TaskRunConcurrencyDataTable = ({ | ||
data, | ||
onDeleteRow, | ||
onResetRow, | ||
}: Props) => { | ||
const navigate = routeApi.useNavigate(); | ||
const { search } = routeApi.useSearch(); | ||
const deferredSearch = useDeferredValue(search ?? ""); | ||
|
||
const filteredData = useMemo(() => { | ||
return data.filter((row) => | ||
row.tag.toLowerCase().includes(deferredSearch.toLowerCase()), | ||
); | ||
}, [data, deferredSearch]); | ||
|
||
const table = useReactTable({ | ||
data: filteredData, | ||
columns: createColumns({ onDeleteRow, onResetRow }), | ||
getCoreRowModel: getCoreRowModel(), | ||
getPaginationRowModel: getPaginationRowModel(), //load client-side pagination code | ||
}); | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<SearchInput | ||
placeholder="Search active task limit" | ||
value={search} | ||
onChange={(e) => | ||
void navigate({ | ||
to: ".", | ||
search: (prev) => ({ ...prev, search: e.target.value }), | ||
}) | ||
} | ||
/> | ||
<DataTable table={table} /> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
ui-v2/src/components/concurrency/task-run-concurrenct-view/data-table/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { TaskRunConcurrencyDataTable } from "./data-table"; |
Oops, something went wrong.