fix: without machine will crash workflow page

This commit is contained in:
BennyKok 2024-01-13 00:36:47 +08:00
parent c4c64a5f04
commit f5991a1bf8
3 changed files with 17 additions and 14 deletions

View File

@ -209,7 +209,7 @@ export function APIKeyList({ data }: { data: APIKey[] }) {
<div className="w-full"> <div className="w-full">
<div className="flex items-center py-4"> <div className="flex items-center py-4">
<Input <Input
placeholder="Filter machines..." placeholder="Filter keys..."
value={(table.getColumn("name")?.getFilterValue() as string) ?? ""} value={(table.getColumn("name")?.getFilterValue() as string) ?? ""}
onChange={(event) => onChange={(event) =>
table.getColumn("name")?.setFilterValue(event.target.value) table.getColumn("name")?.setFilterValue(event.target.value)

View File

@ -87,9 +87,8 @@ export function MachineSelect({
}: { }: {
machines: Awaited<ReturnType<typeof getMachines>>; machines: Awaited<ReturnType<typeof getMachines>>;
}) { }) {
const [machine, setMachine] = useQueryState("machine", { const [machine, setMachine] = useSelectedMachine(machines);
defaultValue: machines?.[0].id ?? "",
});
return ( return (
<Select <Select
value={machine} value={machine}
@ -114,6 +113,14 @@ export function MachineSelect({
); );
} }
function useSelectedMachine(machines: Awaited<ReturnType<typeof getMachines>>) {
const a = useQueryState("machine", {
defaultValue: machines?.[0]?.id ?? "",
});
return a;
}
export function RunWorkflowButton({ export function RunWorkflowButton({
workflow, workflow,
machines, machines,
@ -125,9 +132,7 @@ export function RunWorkflowButton({
defaultValue: workflow?.versions[0].version ?? 1, defaultValue: workflow?.versions[0].version ?? 1,
...parseAsInteger, ...parseAsInteger,
}); });
const [machine] = useQueryState("machine", { const [machine] = useSelectedMachine(machines);
defaultValue: machines[0].id ?? "",
});
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [values, setValues] = useState<Record<string, string>>({}); const [values, setValues] = useState<Record<string, string>>({});
@ -241,9 +246,8 @@ export function CreateDeploymentButton({
defaultValue: workflow?.versions[0].version ?? 1, defaultValue: workflow?.versions[0].version ?? 1,
...parseAsInteger, ...parseAsInteger,
}); });
const [machine] = useQueryState("machine", { const [machine] = useSelectedMachine(machines);
defaultValue: machines[0].id ?? "",
});
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const workflow_version_id = workflow?.versions.find( const workflow_version_id = workflow?.versions.find(
(x) => x.version === version (x) => x.version === version

View File

@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox"; import { Checkbox } from "@/components/ui/checkbox";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuLabel, DropdownMenuLabel,
@ -36,7 +35,7 @@ import {
getSortedRowModel, getSortedRowModel,
useReactTable, useReactTable,
} from "@tanstack/react-table"; } from "@tanstack/react-table";
import { ArrowUpDown, ChevronDown, MoreHorizontal } from "lucide-react"; import { ArrowUpDown, MoreHorizontal } from "lucide-react";
import * as React from "react"; import * as React from "react";
export type Payment = { export type Payment = {
@ -203,7 +202,7 @@ export function WorkflowList({ data }: { data: Payment[] }) {
} }
className="max-w-sm" className="max-w-sm"
/> />
<DropdownMenu> {/* <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button variant="outline" className="ml-auto"> <Button variant="outline" className="ml-auto">
Columns <ChevronDown className="ml-2 h-4 w-4" /> Columns <ChevronDown className="ml-2 h-4 w-4" />
@ -228,7 +227,7 @@ export function WorkflowList({ data }: { data: Payment[] }) {
); );
})} })}
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu> */}
</div> </div>
<ScrollArea className="h-full w-full rounded-md border"> <ScrollArea className="h-full w-full rounded-md border">
<Table> <Table>