"use client"; import { LoadingIcon } from "@/components/LoadingIcon"; import { callServerPromise } from "@/components/MachineList"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { createRun } from "@/server/createRun"; import { createDeployments } from "@/server/curdDeploments"; import type { getMachines } from "@/server/curdMachine"; import type { findFirstTableWithVersion } from "@/server/findFirstTableWithVersion"; import { MoreVertical, Play } from "lucide-react"; import { parseAsInteger, useQueryState } from "next-usequerystate"; import { useState } from "react"; export function VersionSelect({ workflow, }: { workflow: Awaited>; }) { const [version, setVersion] = useQueryState("version", { defaultValue: workflow?.versions[0].version?.toString() ?? "", }); return ( ); } export function MachineSelect({ machines, }: { machines: Awaited>; }) { const [machine, setMachine] = useQueryState("machine", { defaultValue: machines?.[0].id ?? "", }); return ( ); } export function RunWorkflowButton({ workflow, machines, }: { workflow: Awaited>; machines: Awaited>; }) { const [version] = useQueryState("version", { defaultValue: workflow?.versions[0].version ?? 1, ...parseAsInteger, }); const [machine] = useQueryState("machine", { defaultValue: machines[0].id ?? "", }); const [isLoading, setIsLoading] = useState(false); return ( ); } export function CreateDeploymentButton({ workflow, machines, }: { workflow: Awaited>; machines: Awaited>; }) { const [version] = useQueryState("version", { defaultValue: workflow?.versions[0].version ?? 1, ...parseAsInteger, }); const [machine] = useQueryState("machine", { defaultValue: machines[0].id ?? "", }); const [isLoading, setIsLoading] = useState(false); const workflow_version_id = workflow?.versions.find( (x) => x.version === version )?.id; return ( { if (!workflow_version_id) return; setIsLoading(true); await callServerPromise( createDeployments( workflow.id, workflow_version_id, machine, "production" ) ); setIsLoading(false); }} > Production { if (!workflow_version_id) return; setIsLoading(true); await callServerPromise( createDeployments( workflow.id, workflow_version_id, machine, "staging" ) ); setIsLoading(false); }} > Staging ); }