diff --git a/pkgs/webview-ui/app/src/api.ts b/pkgs/webview-ui/app/src/api.ts index 6fcb9ee4b..d3ae83c27 100644 --- a/pkgs/webview-ui/app/src/api.ts +++ b/pkgs/webview-ui/app/src/api.ts @@ -6,14 +6,17 @@ export type OperationNames = keyof API; export type OperationArgs = API[T]["arguments"]; export type OperationResponse = API[T]["return"]; -export type SuccessData = Extract< +export type SuccessQuery = Extract< OperationResponse, { status: "success" } >; -export type ErrorData = Extract< +export type SuccessData = SuccessQuery["data"]; + +export type ErrorQuery = Extract< OperationResponse, { status: "error" } >; +export type ErrorData = ErrorQuery["errors"]; export type ClanOperations = { [K in OperationNames]: (str: string) => void; diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx index 17a833b25..22494e4db 100644 --- a/pkgs/webview-ui/app/src/components/MachineListItem.tsx +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -1,11 +1,11 @@ import { createSignal, Show } from "solid-js"; -import { callApi, SuccessData } from "../api"; +import { callApi, SuccessQuery } from "../api"; import { Menu } from "./Menu"; import { activeURI } from "../App"; import toast from "solid-toast"; import { A, useNavigate } from "@solidjs/router"; -type MachineDetails = SuccessData<"list_inventory_machines">["data"][string]; +type MachineDetails = SuccessQuery<"list_inventory_machines">["data"][string]; interface MachineListItemProps { name: string; diff --git a/pkgs/webview-ui/app/src/routes/clan/details.tsx b/pkgs/webview-ui/app/src/routes/clan/details.tsx index 21048d329..f1ff3d81a 100644 --- a/pkgs/webview-ui/app/src/routes/clan/details.tsx +++ b/pkgs/webview-ui/app/src/routes/clan/details.tsx @@ -1,4 +1,4 @@ -import { callApi, SuccessData } from "@/src/api"; +import { callApi, SuccessQuery } from "@/src/api"; import { BackButton } from "@/src/components/BackButton"; import { useParams } from "@solidjs/router"; import { createQuery } from "@tanstack/solid-query"; @@ -17,7 +17,7 @@ import { } from "@modular-forms/solid"; import { TextInput } from "@/src/components/TextInput"; -type AdminData = SuccessData<"get_admin_service">["data"]; +type AdminData = SuccessQuery<"get_admin_service">["data"]; interface ClanDetailsProps { admin: AdminData; diff --git a/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx b/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx index 4acfcc694..c83a21b41 100644 --- a/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/[name]/view.tsx @@ -1,4 +1,4 @@ -import { callApi, SuccessData } from "@/src/api"; +import { callApi, SuccessData, SuccessQuery } from "@/src/api"; import { activeURI } from "@/src/App"; import { BackButton } from "@/src/components/BackButton"; import { FileInput } from "@/src/components/FileInput"; @@ -11,15 +11,14 @@ import { createSignal, For, Show, Switch, Match } from "solid-js"; import toast from "solid-toast"; // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -type MachineFormInterface = { - name: string; - description: string; - targetHost?: string; +type MachineFormInterface = MachineType & { sshKey?: File; disk?: string; }; -type Disks = SuccessData<"show_block_devices">["data"]["blockdevices"]; +type MachineType = SuccessData<"get_inventory_machine_details">; + +type Disks = SuccessQuery<"show_block_devices">["data"]["blockdevices"]; /** * Opens the custom file dialog @@ -50,7 +49,7 @@ type InstallForm = { disk?: string }; interface InstallMachineProps { name?: string; - targetHost?: string; + targetHost?: string | null; sshKey?: File; disks: Disks; } @@ -296,17 +295,19 @@ const InstallMachine = (props: InstallMachineProps) => { }; interface MachineDetailsProps { - initialData: MachineFormInterface; + initialData: MachineType; } const MachineForm = (props: MachineDetailsProps) => { - const [formStore, { Form, Field }] = createForm({ - initialValues: props.initialData, - }); + const [formStore, { Form, Field }] = + // TODO: retrieve the correct initial values from API + createForm({ + initialValues: props.initialData, + }); const sshKey = () => getValue(formStore, "sshKey"); - const targetHost = () => getValue(formStore, "targetHost"); + const targetHost = () => getValue(formStore, "machine.deploy.targetHost"); const machineName = () => - getValue(formStore, "name") || props.initialData.name; + getValue(formStore, "machine.name") || props.initialData.machine.name; const onlineStatusQuery = createQuery(() => ({ queryKey: [activeURI(), "machine", targetHost(), "check_machine_online"], @@ -361,14 +362,8 @@ const MachineForm = (props: MachineDetailsProps) => { const machine_response = await callApi("set_machine", { flake_url: curr_uri, - machine_name: props.initialData.name, - machine: { - name: values.name, - description: values.description, - deploy: { - targetHost: values.targetHost, - }, - }, + machine_name: props.initialData.machine.name, + machine: values.machine, }); if (machine_response.status === "error") { toast.error( @@ -445,7 +440,7 @@ const MachineForm = (props: MachineDetailsProps) => {
Details
- + {(field, props) => ( { /> )} - + {(field, props) => ( { Connection Settings
- + {(field, props) => ( {
@@ -613,13 +608,7 @@ export const MachineDetails = () => { when={query.data} fallback={} > - + {(data) => } );