UI/queries: add machine hw query
This commit is contained in:
@@ -182,3 +182,43 @@ export const useSystemStorageOptions = (): SystemStorageOptionsQuery => {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type MachineHardwareSummary =
|
||||||
|
SuccessData<"get_machine_hardware_summary">;
|
||||||
|
export type MachineHardwareSummaryQuery =
|
||||||
|
UseQueryResult<MachineHardwareSummary>;
|
||||||
|
|
||||||
|
export const useMachineHardwareSummary = (
|
||||||
|
clanUri: string,
|
||||||
|
machineName: string,
|
||||||
|
): MachineHardwareSummaryQuery => {
|
||||||
|
const client = useApiClient();
|
||||||
|
return useQuery<MachineHardwareSummary>(() => ({
|
||||||
|
queryKey: [
|
||||||
|
"clans",
|
||||||
|
encodeBase64(clanUri),
|
||||||
|
"machines",
|
||||||
|
machineName,
|
||||||
|
"hardware_summary",
|
||||||
|
],
|
||||||
|
queryFn: async () => {
|
||||||
|
const call = client.fetch("get_machine_hardware_summary", {
|
||||||
|
machine: {
|
||||||
|
flake: {
|
||||||
|
identifier: clanUri,
|
||||||
|
},
|
||||||
|
name: machineName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const result = await call.result;
|
||||||
|
|
||||||
|
if (result.status === "error") {
|
||||||
|
// todo should we create some specific error types?
|
||||||
|
console.error("Error fetching clan details:", result.errors);
|
||||||
|
throw new Error(result.errors[0].message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.data;
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user