diff --git a/pkgs/webview-ui/app/src/components/MachineListItem.tsx b/pkgs/webview-ui/app/src/components/MachineListItem.tsx index 0b60f7cfc..b2831ebb6 100644 --- a/pkgs/webview-ui/app/src/components/MachineListItem.tsx +++ b/pkgs/webview-ui/app/src/components/MachineListItem.tsx @@ -1,4 +1,4 @@ -import { createSignal, Show } from "solid-js"; +import { createSignal, For, Setter, Show } from "solid-js"; import { callApi, SuccessQuery } from "../api"; import { Menu } from "./Menu"; import { activeURI } from "../App"; @@ -6,6 +6,7 @@ import toast from "solid-toast"; import { A, useNavigate } from "@solidjs/router"; import { RndThumbnail } from "./noiseThumbnail"; import Icon from "./icon"; +import { Filter } from "../routes/machines"; type MachineDetails = SuccessQuery<"list_inventory_machines">["data"][string]; @@ -13,6 +14,7 @@ interface MachineListItemProps { name: string; info?: MachineDetails; nixOnly?: boolean; + setFilter: Setter; } export const MachineListItem = (props: MachineListItemProps) => { @@ -128,7 +130,34 @@ export const MachineListItem = (props: MachineListItemProps) => { {(d) => ( <> - cast_connected + + {(tags) => ( + + + {(tag) => ( + + )} + + + )} + {d()?.deploy.targetHost} )} diff --git a/pkgs/webview-ui/app/src/routes/machines/list.tsx b/pkgs/webview-ui/app/src/routes/machines/list.tsx index d4a5f706a..d09201493 100644 --- a/pkgs/webview-ui/app/src/routes/machines/list.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/list.tsx @@ -1,13 +1,9 @@ -import { type Component, For, Match, Switch } from "solid-js"; +import { type Component, createSignal, For, Match, Switch } from "solid-js"; import { activeURI } from "@/src/App"; import { callApi, OperationResponse } from "@/src/api"; import toast from "solid-toast"; import { MachineListItem } from "@/src/components/MachineListItem"; -import { - createQueries, - createQuery, - useQueryClient, -} from "@tanstack/solid-query"; +import { createQuery, useQueryClient } from "@tanstack/solid-query"; import { useNavigate } from "@solidjs/router"; import { Button } from "@/src/components/button"; import Icon from "@/src/components/icon"; @@ -17,13 +13,15 @@ type MachinesModel = Extract< { status: "success" } >["data"]; -type ExtendedMachine = MachinesModel & { - nixOnly: boolean; -}; +export interface Filter { + tags: string[]; +} export const MachineListView: Component = () => { const queryClient = useQueryClient(); + const [filter, setFilter] = createSignal({ tags: [] }); + const inventoryQuery = createQuery(() => ({ queryKey: [activeURI(), "list_machines", "inventory"], placeholderData: {}, @@ -44,26 +42,6 @@ export const MachineListView: Component = () => { }, })); - const nixosQuery = createQuery(() => ({ - queryKey: [activeURI(), "list_machines", "nixos"], - enabled: !!activeURI(), - placeholderData: [], - 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 []; - }, - })); - const refresh = async () => { queryClient.invalidateQueries({ // Invalidates the cache for of all types of machine list at once @@ -71,11 +49,12 @@ export const MachineListView: Component = () => { }); }; - const inventoryMachines = () => Object.entries(inventoryQuery.data || {}); - const nixOnlyMachines = () => - nixosQuery.data?.filter( - (name) => !inventoryMachines().some(([key, machine]) => key === name), - ); + const inventoryMachines = () => + Object.entries(inventoryQuery.data || {}).filter((e) => { + const hasAllTags = filter().tags.every((tag) => e[1].tags?.includes(tag)); + + return hasAllTags; + }); const navigate = useNavigate(); return ( @@ -88,6 +67,7 @@ export const MachineListView: Component = () => { startIcon={} > +
+
+
+ +
+ + {(tag) => ( + + )} + +
{/* Loading skeleton */} @@ -113,11 +117,7 @@ export const MachineListView: Component = () => {
@@ -135,10 +135,13 @@ export const MachineListView: Component = () => {
    - {([name, info]) => } - - - {(name) => } + {([name, info]) => ( + + )}