From 3bddb26b48c038c09974813bcd21990626b3ecd5 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 12 May 2025 15:32:49 +0200 Subject: [PATCH] Fix: remove unused service endpoints from UI --- pkgs/webview-ui/app/src/api/inventory.ts | 94 +-------- .../app/src/routes/clans/details.tsx | 184 ------------------ 2 files changed, 1 insertion(+), 277 deletions(-) diff --git a/pkgs/webview-ui/app/src/api/inventory.ts b/pkgs/webview-ui/app/src/api/inventory.ts index 199a2f7ea..36d218490 100644 --- a/pkgs/webview-ui/app/src/api/inventory.ts +++ b/pkgs/webview-ui/app/src/api/inventory.ts @@ -1,11 +1,5 @@ import { QueryClient } from "@tanstack/solid-query"; -import { - ApiEnvelope, - callApi, - ClanServiceInstance, - ServiceNames, - Services, -} from "."; +import { ApiEnvelope, callApi } from "."; import { Schema as Inventory } from "@/api/Inventory"; export async function get_inventory(client: QueryClient, base_path: string) { @@ -23,89 +17,3 @@ export async function get_inventory(client: QueryClient, base_path: string) { return data; } - -export const generate_instance_name = ( - machine_name: string, - service_name: T, -) => [machine_name, service_name, 1].filter(Boolean).join("_"); - -export const get_first_instance_name = async ( - client: QueryClient, - base_path: string, - service_name: T, -): Promise => { - const r = await get_inventory(client, base_path); - if (r.status === "success") { - const service = r.data.services?.[service_name]; - if (!service) return null; - return Object.keys(service)[0] || null; - } - return null; -}; - -async function get_service( - client: QueryClient, - base_path: string, - service_name: T, -) { - const r = await get_inventory(client, base_path); - if (r.status === "success") { - const service = r.data.services?.[service_name]; - return service as Services[T]; - } - return null; -} - -export async function get_single_service( - client: QueryClient, - base_path: string, - service_name: T, -): Promise> { - const instance_key = await get_first_instance_name( - client, - base_path, - service_name, - ); - - if (!instance_key) { - throw new Error("No instance found"); - } - const service: Services[T] | null = await get_service( - client, - base_path, - service_name, - ); - if (service) { - const clanServiceInstance = service[instance_key] as ClanServiceInstance; - return clanServiceInstance; - } - throw new Error("No service found"); -} - -export async function set_single_service( - client: QueryClient, - base_path: string, - machine_name: string, - service_name: T, - service_config: ClanServiceInstance, -) { - const instance_key = - (await get_first_instance_name(client, base_path, service_name)) || - generate_instance_name(machine_name, service_name); - const r = await get_inventory(client, base_path); - if (r.status === "success") { - const inventory = r.data; - inventory.services = inventory.services || {}; - inventory.services[service_name] = inventory.services[service_name] || {}; - - inventory.services[service_name][instance_key] = service_config; - console.log("saving inventory", inventory); - return callApi("set_inventory", { - // @ts-expect-error: This doesn't check - inventory, - message: `update_single_service ${service_name}`, - flake_dir: base_path, - }); - } - return r; -} diff --git a/pkgs/webview-ui/app/src/routes/clans/details.tsx b/pkgs/webview-ui/app/src/routes/clans/details.tsx index 7ca49df5c..5f605270e 100644 --- a/pkgs/webview-ui/app/src/routes/clans/details.tsx +++ b/pkgs/webview-ui/app/src/routes/clans/details.tsx @@ -13,19 +13,10 @@ import { } from "@modular-forms/solid"; import { TextInput } from "@/src/Form/fields/TextInput"; import toast from "solid-toast"; -import { set_single_service } from "@/src/api/inventory"; import { Button } from "@/src/components/button"; import Icon from "@/src/components/icon"; import { Header } from "@/src/layout/header"; -interface AdminModuleFormProps { - admin: AdminData; - base_url: string; -} -interface AdminSettings extends FieldValues { - allowedKeys: { name: string; value: string }[]; -} - interface EditClanFormProps { initial: GeneralData; directory: string; @@ -145,182 +136,7 @@ const EditClanForm = (props: EditClanFormProps) => { ); }; -const AdminModuleForm = (props: AdminModuleFormProps) => { - const items = () => - Object.entries( - (props.admin?.config?.allowedKeys as Record) || {}, - ); - const [formStore, { Form, Field }] = createForm({ - initialValues: { - allowedKeys: items().map(([name, value]) => ({ name, value })), - }, - }); - const queryClient = useQueryClient(); - - const [keys, setKeys] = createSignal<1[]>( - new Array(items().length || 1).fill(1), - ); - - const handleSubmit = async (values: AdminSettings) => { - console.log("submitting", values, getValues(formStore)); - - const r = await set_single_service( - queryClient, - props.base_url, - "", - "admin", - { - meta: { - name: "admin", - }, - roles: { - default: { - tags: ["all"], - }, - }, - config: { - allowedKeys: values.allowedKeys.reduce( - (acc, curr) => ({ ...acc, [curr.name]: curr.value }), - {}, - ), - }, - }, - ); - if (r.status === "success") { - toast.success("Successfully updated admin settings"); - } - if (r.status === "error") { - toast.error(`Failed to update admin settings: ${r.errors[0].message}`); - } - queryClient.invalidateQueries({ - queryKey: [props.base_url, "get_admin_service"], - }); - }; - - return ( -
-
- Administration -
- - Each of the following keys can be used to authenticate on machines - - - {(name, idx) => ( - <> - - {(field, props) => ( - key - // ), - // }} - value={field.value ?? ""} - error={field.error} - class="col-span-4" - required - /> - )} - - - {(field, props) => ( - <> - - - - - - )} - - - - )} - -
- -
-
- { -
- -
- } -
-
- ); -}; - type GeneralData = SuccessQuery<"show_clan_meta">["data"]; -type AdminData = ClanServiceInstance<"admin">; export const ClanDetails = () => { const params = useParams();