diff --git a/web/src/api/storage.ts b/web/src/api/storage.ts index 2f3608427d..875255fadb 100644 --- a/web/src/api/storage.ts +++ b/web/src/api/storage.ts @@ -23,7 +23,7 @@ import { get, post, put } from "~/api/http"; import { Job } from "~/types/job"; import { calculate, fetchSettings } from "~/api/storage/proposal"; -import { config } from "~/api/storage/types"; +import { config, configModel } from "~/api/storage/types"; /** * Starts the storage probing process. @@ -38,6 +38,9 @@ const fetchConfig = (): Promise => const fetchSolvedConfig = (): Promise => get("/api/storage/solved_config").then((config) => config.storage); +const fetchConfigModel = (): Promise => + get("/api/storage/config_model"); + const setConfig = (config: config.Config) => put("/api/storage/config", config); /** @@ -68,6 +71,7 @@ export { probe, fetchConfig, fetchSolvedConfig, + fetchConfigModel, setConfig, fetchStorageJobs, findStorageJob, diff --git a/web/src/api/storage/types.ts b/web/src/api/storage/types.ts index d295e566ae..216d0eda10 100644 --- a/web/src/api/storage/types.ts +++ b/web/src/api/storage/types.ts @@ -21,6 +21,7 @@ */ import * as config from "./types/config"; +import * as configModel from "./types/config-model"; export * from "./types/openapi"; -export { config }; +export { config, configModel }; diff --git a/web/src/api/storage/types/config-model.ts b/web/src/api/storage/types/config-model.ts new file mode 100644 index 0000000000..4d09b437b4 --- /dev/null +++ b/web/src/api/storage/types/config-model.ts @@ -0,0 +1,65 @@ +/* eslint-disable */ +/** + * This file was automatically generated by json-schema-to-typescript. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run json-schema-to-typescript to regenerate this file. + */ + +export type FilesystemType = + | "bcachefs" + | "btrfs" + | "exfat" + | "ext2" + | "ext3" + | "ext4" + | "f2fs" + | "jfs" + | "nfs" + | "nilfs2" + | "ntfs" + | "reiserfs" + | "swap" + | "tmpfs" + | "vfat" + | "xfs"; +export type SpacePolicy = "delete" | "resize" | "keep" | "custom"; +export type PtableType = "gpt" | "msdos" | "dasd"; +export type PartitionId = "linux" | "swap" | "lvm" | "raid" | "esp" | "prep" | "bios_boot"; + +/** + * Config model + */ +export interface Config { + drives?: Drive[]; +} +export interface Drive { + name: string; + alias?: string; + mountPath?: string; + filesystem?: Filesystem; + spacePolicy?: SpacePolicy; + ptableType?: PtableType; + partitions?: Partition[]; +} +export interface Filesystem { + default: boolean; + type?: FilesystemType; + snapshots?: boolean; +} +export interface Partition { + name?: string; + alias?: string; + id?: PartitionId; + mountPath?: string; + filesystem?: Filesystem; + size?: Size; + delete?: boolean; + deleteIfNeeded?: boolean; + resize?: boolean; + resizeIfNeeded?: boolean; +} +export interface Size { + default: boolean; + min: number; + max?: number; +} diff --git a/web/src/queries/storage.ts b/web/src/queries/storage.ts index a6a53b7a48..c1e57520dd 100644 --- a/web/src/queries/storage.ts +++ b/web/src/queries/storage.ts @@ -28,7 +28,7 @@ import { useSuspenseQuery, } from "@tanstack/react-query"; import React from "react"; -import { fetchConfig, fetchSolvedConfig, setConfig } from "~/api/storage"; +import { fetchConfig, fetchSolvedConfig, fetchConfigModel, setConfig } from "~/api/storage"; import { fetchDevices, fetchDevicesDirty } from "~/api/storage/devices"; import { calculate, @@ -40,6 +40,7 @@ import { import { useInstallerClient } from "~/context/installer"; import { config, + configModel, ProductParams, Volume as APIVolume, ProposalSettingsPatch, @@ -67,6 +68,12 @@ const solvedConfigQuery = { staleTime: Infinity, }; +const configModelQuery = { + queryKey: ["storage", "configModel"], + queryFn: fetchConfigModel, + staleTime: Infinity, +}; + const devicesQuery = (scope: "result" | "system") => ({ queryKey: ["storage", "devices", scope], queryFn: () => fetchDevices(scope), @@ -137,6 +144,16 @@ const useSolvedConfig = (options?: QueryHookOptions): config.Config => { return data; }; +/** + * Hook that returns the config model. + */ +const useConfigModel = (options?: QueryHookOptions): configModel.Config => { + const query = configModelQuery; + const func = options?.suspense ? useSuspenseQuery : useQuery; + const { data } = func(query); + return data; +}; + /** * Hook for setting a new config. */ @@ -347,6 +364,7 @@ export { useConfig, useSolvedConfig, useConfigMutation, + useConfigModel, useConfigDevices, useDevices, useAvailableDevices,