clan-cli: Unify list_machines and use flake caching

This commit is contained in:
Qubasa
2025-05-16 10:47:49 +02:00
parent 37180ff2af
commit d765f1078b
21 changed files with 198 additions and 247 deletions

View File

@@ -23,6 +23,9 @@
},
{
"path": "../clan-cli/clan_lib"
},
{
"path": "../webview-ui"
}
],
"settings": {

View File

@@ -0,0 +1,10 @@
export interface Machine {
machine: {
name: string;
flake: {
identifier: string;
};
override_target_host: string | null;
private_key: string | null;
};
}

View File

@@ -10,7 +10,7 @@ import { Filter } from "../../routes/machines";
import { Typography } from "../Typography";
import "./css/index.css";
type MachineDetails = SuccessQuery<"list_machines">["data"][string];
type MachineDetails = SuccessQuery<"list_inv_machines">["data"][string];
interface MachineListItemProps {
name: string;

View File

@@ -61,7 +61,7 @@ export function CreateMachine() {
reset(formStore);
queryClient.invalidateQueries({
queryKey: [activeURI(), "list_machines"],
queryKey: [activeURI(), "list_inv_machines"],
});
navigate("/machines");
} else {

View File

@@ -391,12 +391,14 @@ const MachineForm = (props: MachineDetailsProps) => {
return;
}
const machine_response = await callApi("set_machine", {
flake: {
identifier: curr_uri,
},
machine_name: props.initialData.machine.name || "My machine",
const machine_response = await callApi("set_inv_machine", {
machine: {
name: props.initialData.machine.name || "My machine",
flake: {
identifier: curr_uri,
},
},
inventory_machine: {
...values.machine,
// TODO: Remove this workaround
tags: Array.from(

View File

@@ -18,7 +18,7 @@ import { Header } from "@/src/layout/header";
import { makePersisted } from "@solid-primitives/storage";
type MachinesModel = Extract<
OperationResponse<"list_machines">,
OperationResponse<"list_inv_machines">,
{ status: "success" }
>["data"];
@@ -32,13 +32,13 @@ export const MachineListView: Component = () => {
const [filter, setFilter] = createSignal<Filter>({ tags: [] });
const inventoryQuery = createQuery<MachinesModel>(() => ({
queryKey: [activeURI(), "list_machines"],
queryKey: [activeURI(), "list_inv_machines"],
placeholderData: {},
enabled: !!activeURI(),
queryFn: async () => {
const uri = activeURI();
if (uri) {
const response = await callApi("list_machines", {
const response = await callApi("list_inv_machines", {
flake: {
identifier: uri,
},
@@ -56,7 +56,7 @@ export const MachineListView: Component = () => {
const refresh = async () => {
queryClient.invalidateQueries({
// Invalidates the cache for of all types of machine list at once
queryKey: [activeURI(), "list_machines"],
queryKey: [activeURI(), "list_inv_machines"],
});
};