Refactor(api/list_machines): rename from list_inv_machines

This commit is contained in:
Johannes Kirschbauer
2025-06-09 13:32:08 +02:00
parent 155f3721eb
commit 0b6bc81efe
5 changed files with 18 additions and 18 deletions

View File

@@ -9,7 +9,7 @@ import { Typography } from "../Typography";
import "./css/index.css"; import "./css/index.css";
import { useClanContext } from "@/src/contexts/clan"; import { useClanContext } from "@/src/contexts/clan";
type MachineDetails = SuccessQuery<"list_inv_machines">["data"][string]; type MachineDetails = SuccessQuery<"list_machines">["data"][string];
interface MachineListItemProps { interface MachineListItemProps {
name: string; name: string;

View File

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

View File

@@ -10,7 +10,7 @@ import { makePersisted } from "@solid-primitives/storage";
import { useClanContext } from "@/src/contexts/clan"; import { useClanContext } from "@/src/contexts/clan";
type MachinesModel = Extract< type MachinesModel = Extract<
OperationResponse<"list_inv_machines">, OperationResponse<"list_machines">,
{ status: "success" } { status: "success" }
>["data"]; >["data"];
@@ -25,14 +25,14 @@ export const MachineListView: Component = () => {
const { activeClanURI } = useClanContext(); const { activeClanURI } = useClanContext();
const inventoryQuery = useQuery<MachinesModel>(() => ({ const inventoryQuery = useQuery<MachinesModel>(() => ({
queryKey: [activeClanURI(), "list_inv_machines"], queryKey: [activeClanURI(), "list_machines"],
placeholderData: {}, placeholderData: {},
enabled: !!activeClanURI(), enabled: !!activeClanURI(),
queryFn: async () => { queryFn: async () => {
console.log("fetching inventory", activeClanURI()); console.log("fetching inventory", activeClanURI());
const uri = activeClanURI(); const uri = activeClanURI();
if (uri) { if (uri) {
const response = await callApi("list_inv_machines", { const response = await callApi("list_machines", {
flake: { flake: {
identifier: uri, identifier: uri,
}, },
@@ -60,7 +60,7 @@ export const MachineListView: Component = () => {
await queryClient.invalidateQueries({ await queryClient.invalidateQueries({
// Invalidates the cache for of all types of machine list at once // Invalidates the cache for of all types of machine list at once
queryKey: [clanURI, "list_inv_machines"], queryKey: [clanURI, "list_machines"],
}); });
}; };

View File

@@ -20,18 +20,6 @@ from clan_cli.machines.hardware import HardwareConfig
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@API.register
def list_inv_machines(flake: Flake) -> dict[str, InventoryMachine]:
"""
List machines in the inventory for the UI.
"""
inventory_store = InventoryStore(flake=flake)
inventory = inventory_store.read()
res = inventory.get("machines", {})
return res
def list_machines( def list_machines(
flake: Flake, nix_options: list[str] | None = None flake: Flake, nix_options: list[str] | None = None
) -> dict[str, Machine]: ) -> dict[str, Machine]:

View File

@@ -10,6 +10,18 @@ from clan_lib.persist.inventory_store import InventoryStore
from clan_lib.persist.util import set_value_by_path from clan_lib.persist.util import set_value_by_path
@API.register
def list_machines(flake: Flake) -> dict[str, InventoryMachine]:
"""
List machines in the inventory for the UI.
"""
inventory_store = InventoryStore(flake=flake)
inventory = inventory_store.read()
machine = inventory.get("machines", {})
return machine
@API.register @API.register
def get_machine(flake: Flake, name: str) -> InventoryMachine: def get_machine(flake: Flake, name: str) -> InventoryMachine:
inventory_store = InventoryStore(flake=flake) inventory_store = InventoryStore(flake=flake)