From e0d7a423b440e75292330e408fff20e900ee1e3f Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 3 Aug 2024 13:12:33 +0200 Subject: [PATCH] Clan-app: show nixos machines and inventory machines --- .../app/src/components/MachineListItem.tsx | 60 +------------------ .../app/src/routes/machines/view.tsx | 56 ++++++++++++----- 2 files changed, 44 insertions(+), 72 deletions(-) diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx index 26079d7e4..749291f32 100644 --- a/pkgs/webview-ui/app/src/components/MachineListItem.tsx +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -5,7 +5,7 @@ type MachineDetails = SuccessData<"list_inventory_machines">["data"][string]; interface MachineListItemProps { name: string; - info: MachineDetails; + info?: MachineDetails; } type HWInfo = Record["data"]>; @@ -53,21 +53,6 @@ const [errors, setErrors] = createSignal({}); export const MachineListItem = (props: MachineListItemProps) => { const { name, info } = props; - // const clan_dir = currClanURI(); - // if (clan_dir) { - // pyApi.show_machine_hardware_info.dispatch({ - // op_key: name, - // clan_dir, - // machine_name: name, - // }); - - // pyApi.show_machine_deployment_target.dispatch({ - // op_key: name, - // clan_dir, - // machine_name: name, - // }); - // } - return (
  • @@ -80,48 +65,9 @@ export const MachineListItem = (props: MachineListItemProps) => {

    {name}

    -
    }> - No description - - } - > - {(d) => d()?.description} - -
    -
    -
    - System: - {hwInfo()[name]?.system ? ( - {hwInfo()[name]?.system} - ) : ( - Not set - )} -
    - -
    - Target Host: - {deploymentInfo()[name] ? ( - {deploymentInfo()[name]} - ) : ( - Not set - )} - {/*
    }> - - No deployment target detected - - - } - > - {(i) => + i()} - */} -
    + {(d) => d()?.description}
    +
    {/* Show only the first error at the bottom */} {(error) => ( diff --git a/pkgs/webview-ui/app/src/routes/machines/view.tsx b/pkgs/webview-ui/app/src/routes/machines/view.tsx index c30ea1f86..34b368cb1 100644 --- a/pkgs/webview-ui/app/src/routes/machines/view.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/view.tsx @@ -11,6 +11,7 @@ import { activeURI, route, setActiveURI, setRoute } from "@/src/App"; import { callApi, OperationResponse, pyApi } from "@/src/api"; import toast from "solid-toast"; import { MachineListItem } from "@/src/components/MachineListItem"; +import { createQuery } from "@tanstack/solid-query"; // type FilesModel = Extract< // OperationResponse<"get_directory">, @@ -39,20 +40,28 @@ type MachinesModel = Extract< // }); export const MachineListView: Component = () => { - // const [files, setFiles] = createSignal([]); - - // pyApi.get_directory.receive((r) => { - // const { status } = r; - // if (status === "error") return console.error(r.errors); - // setFiles(r.data.files); - // }); - - // const [services, setServices] = createSignal(); - // pyApi.show_mdns.receive((r) => { - // const { status } = r; - // if (status === "error") return console.error(r.errors); - // setServices(r.data.services); - // }); + const { + data: nixosMachines, + isFetching, + isLoading, + } = createQuery(() => ({ + queryKey: [activeURI(), "list_nixos_machines"], + queryFn: async () => { + const uri = activeURI(); + if (uri) { + const response = await callApi("list_nixos_machines", { + flake_url: uri, + }); + if (response.status === "error") { + toast.error("Failed to fetch data"); + } else { + return response.data; + } + } + return []; + }, + staleTime: 1000 * 60 * 5, + })); const [machines, setMachines] = createSignal({}); const [loading, setLoading] = createSignal(false); @@ -77,6 +86,14 @@ export const MachineListView: Component = () => { }); const unpackedMachines = () => Object.entries(machines()); + const nixOnlyMachines = () => + nixosMachines?.filter( + (name) => !unpackedMachines().some(([key, machine]) => key === name), + ); + + createEffect(() => { + console.log(nixOnlyMachines(), unpackedMachines()); + }); return (
    @@ -155,7 +172,13 @@ export const MachineListView: Component = () => {
    - + No machines found @@ -163,6 +186,9 @@ export const MachineListView: Component = () => { {([name, info]) => } + + {(name) => } +