UI: add vars step to installation
This commit is contained in:
@@ -311,9 +311,9 @@ def test_generated_shared_secret_sops(
|
|||||||
shared_generator["script"] = "echo hello > $out/my_shared_secret"
|
shared_generator["script"] = "echo hello > $out/my_shared_secret"
|
||||||
m2_config = flake.machines["machine2"]
|
m2_config = flake.machines["machine2"]
|
||||||
m2_config["nixpkgs"]["hostPlatform"] = "x86_64-linux"
|
m2_config["nixpkgs"]["hostPlatform"] = "x86_64-linux"
|
||||||
m2_config["clan"]["core"]["vars"]["generators"][
|
m2_config["clan"]["core"]["vars"]["generators"]["my_shared_generator"] = (
|
||||||
"my_shared_generator"
|
shared_generator.copy()
|
||||||
] = shared_generator.copy()
|
)
|
||||||
flake.refresh()
|
flake.refresh()
|
||||||
monkeypatch.chdir(flake.path)
|
monkeypatch.chdir(flake.path)
|
||||||
sops_setup.init()
|
sops_setup.init()
|
||||||
@@ -732,9 +732,9 @@ def test_migration(
|
|||||||
my_service = config["clan"]["core"]["facts"]["services"]["my_service"]
|
my_service = config["clan"]["core"]["facts"]["services"]["my_service"]
|
||||||
my_service["public"]["my_value"] = {}
|
my_service["public"]["my_value"] = {}
|
||||||
my_service["secret"]["my_secret"] = {}
|
my_service["secret"]["my_secret"] = {}
|
||||||
my_service["generator"][
|
my_service["generator"]["script"] = (
|
||||||
"script"
|
"echo -n hello > $facts/my_value && echo -n hello > $secrets/my_secret"
|
||||||
] = "echo -n hello > $facts/my_value && echo -n hello > $secrets/my_secret"
|
)
|
||||||
my_generator = config["clan"]["core"]["vars"]["generators"]["my_generator"]
|
my_generator = config["clan"]["core"]["vars"]["generators"]["my_generator"]
|
||||||
my_generator["files"]["my_value"]["secret"] = False
|
my_generator["files"]["my_value"]["secret"] = False
|
||||||
my_generator["files"]["my_secret"]["secret"] = True
|
my_generator["files"]["my_secret"]["secret"] = True
|
||||||
|
|||||||
@@ -28,11 +28,20 @@ export const Modal = (props: ModalProps) => {
|
|||||||
|
|
||||||
const handleMouseMove = (e: MouseEvent) => {
|
const handleMouseMove = (e: MouseEvent) => {
|
||||||
if (dragging()) {
|
if (dragging()) {
|
||||||
const newTop = e.clientY - startOffset().y;
|
let newTop = e.clientY - startOffset().y;
|
||||||
const newLeft = e.clientX - startOffset().x;
|
let newLeft = e.clientX - startOffset().x;
|
||||||
|
|
||||||
|
if (newTop < 0) {
|
||||||
|
newTop = 0;
|
||||||
|
}
|
||||||
|
if (newLeft < 0) {
|
||||||
|
newLeft = 0;
|
||||||
|
}
|
||||||
dialogRef.style.top = `${newTop}px`;
|
dialogRef.style.top = `${newTop}px`;
|
||||||
dialogRef.style.left = `${newLeft}px`;
|
dialogRef.style.left = `${newLeft}px`;
|
||||||
|
|
||||||
|
// dialogRef.style.maxHeight = `calc(100vh - ${newTop}px - 2rem)`;
|
||||||
|
// dialogRef.style.maxHeight = `calc(100vh - ${newTop}px - 2rem)`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +62,7 @@ export const Modal = (props: ModalProps) => {
|
|||||||
)}
|
)}
|
||||||
classList={{
|
classList={{
|
||||||
"!cursor-grabbing": dragging(),
|
"!cursor-grabbing": dragging(),
|
||||||
[cx("scale-105 transition-transform")]: dragging(),
|
[cx("scale-[101%] transition-transform")]: dragging(),
|
||||||
}}
|
}}
|
||||||
ref={(el) => {
|
ref={(el) => {
|
||||||
dialogRef = el;
|
dialogRef = el;
|
||||||
@@ -112,7 +121,10 @@ export const Modal = (props: ModalProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Dialog.Label>
|
</Dialog.Label>
|
||||||
<Dialog.Description class="flex flex-col bg-def-1" as="div">
|
<Dialog.Description
|
||||||
|
class="flex max-h-[90vh] flex-col overflow-y-hidden bg-def-1"
|
||||||
|
as="div"
|
||||||
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</Dialog.Description>
|
</Dialog.Description>
|
||||||
</Dialog.Content>
|
</Dialog.Content>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { HardwareValues, HWStep } from "./install/hardware-step";
|
|||||||
import { DiskStep, DiskValues } from "./install/disk-step";
|
import { DiskStep, DiskValues } from "./install/disk-step";
|
||||||
import { SummaryStep } from "./install/summary-step";
|
import { SummaryStep } from "./install/summary-step";
|
||||||
import cx from "classnames";
|
import cx from "classnames";
|
||||||
import { SectionHeader } from "@/src/components/group";
|
import { VarsStep, VarsValues } from "./install/vars-step";
|
||||||
|
|
||||||
type MachineFormInterface = MachineData & {
|
type MachineFormInterface = MachineData & {
|
||||||
sshKey?: File;
|
sshKey?: File;
|
||||||
@@ -37,7 +37,8 @@ type MachineData = SuccessData<"get_inventory_machine_details">;
|
|||||||
const steps: Record<StepIdx, string> = {
|
const steps: Record<StepIdx, string> = {
|
||||||
"1": "Hardware detection",
|
"1": "Hardware detection",
|
||||||
"2": "Disk schema",
|
"2": "Disk schema",
|
||||||
"3": "Installation",
|
"3": "Credentials & Data",
|
||||||
|
"4": "Installation",
|
||||||
};
|
};
|
||||||
|
|
||||||
type StepIdx = keyof AllStepsValues;
|
type StepIdx = keyof AllStepsValues;
|
||||||
@@ -45,7 +46,8 @@ type StepIdx = keyof AllStepsValues;
|
|||||||
export interface AllStepsValues extends FieldValues {
|
export interface AllStepsValues extends FieldValues {
|
||||||
"1": HardwareValues;
|
"1": HardwareValues;
|
||||||
"2": DiskValues;
|
"2": DiskValues;
|
||||||
"3": NonNullable<unknown>;
|
"3": VarsValues;
|
||||||
|
"4": NonNullable<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LoadingBar = () => (
|
const LoadingBar = () => (
|
||||||
@@ -190,7 +192,7 @@ const InstallMachine = (props: InstallMachineProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Footer = () => (
|
const Footer = () => (
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between p-4">
|
||||||
<Button
|
<Button
|
||||||
startIcon={<Icon icon="ArrowLeft" />}
|
startIcon={<Icon icon="ArrowLeft" />}
|
||||||
variant="light"
|
variant="light"
|
||||||
@@ -214,7 +216,10 @@ const InstallMachine = (props: InstallMachineProps) => {
|
|||||||
return (
|
return (
|
||||||
<Switch
|
<Switch
|
||||||
fallback={
|
fallback={
|
||||||
<Form onSubmit={handleInstall}>
|
<Form
|
||||||
|
onSubmit={handleInstall}
|
||||||
|
class="relative top-0 flex h-full flex-col gap-0"
|
||||||
|
>
|
||||||
{/* Register each step as form field */}
|
{/* Register each step as form field */}
|
||||||
{/* @ts-expect-error: object type is not statically supported */}
|
{/* @ts-expect-error: object type is not statically supported */}
|
||||||
<Field name="1">{(field, fieldProps) => <></>}</Field>
|
<Field name="1">{(field, fieldProps) => <></>}</Field>
|
||||||
@@ -269,11 +274,7 @@ const InstallMachine = (props: InstallMachineProps) => {
|
|||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
</div>
|
</div>
|
||||||
|
<Switch fallback={"Undefined content. This Step seems to not exist."}>
|
||||||
<div class="flex flex-col gap-6 p-6">
|
|
||||||
<Switch
|
|
||||||
fallback={"Undefined content. This Step seems to not exist."}
|
|
||||||
>
|
|
||||||
<Match when={step() === "1"}>
|
<Match when={step() === "1"}>
|
||||||
<HWStep
|
<HWStep
|
||||||
// @ts-expect-error: This cannot be undefined in this context.
|
// @ts-expect-error: This cannot be undefined in this context.
|
||||||
@@ -315,6 +316,23 @@ const InstallMachine = (props: InstallMachineProps) => {
|
|||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={step() === "3"}>
|
<Match when={step() === "3"}>
|
||||||
|
<VarsStep
|
||||||
|
// @ts-expect-error: This cannot be undefined in this context.
|
||||||
|
machine_id={props.name}
|
||||||
|
// @ts-expect-error: This cannot be undefined in this context.
|
||||||
|
dir={activeURI()}
|
||||||
|
footer={<Footer />}
|
||||||
|
handleNext={(data) => {
|
||||||
|
// const prev = getValue(formStore, "2");
|
||||||
|
// setValue(formStore, "2", { ...prev, ...data });
|
||||||
|
handleNext();
|
||||||
|
}}
|
||||||
|
initial={{
|
||||||
|
...getValue(formStore, "3"),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Match>
|
||||||
|
<Match when={step() === "4"}>
|
||||||
<SummaryStep
|
<SummaryStep
|
||||||
// @ts-expect-error: This cannot be undefined in this context.
|
// @ts-expect-error: This cannot be undefined in this context.
|
||||||
machine_id={props.name}
|
machine_id={props.name}
|
||||||
@@ -324,7 +342,7 @@ const InstallMachine = (props: InstallMachineProps) => {
|
|||||||
// @ts-expect-error: This cannot be known.
|
// @ts-expect-error: This cannot be known.
|
||||||
initial={getValues(formStore)}
|
initial={getValues(formStore)}
|
||||||
footer={
|
footer={
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between p-4">
|
||||||
<Button
|
<Button
|
||||||
startIcon={<Icon icon="ArrowLeft" />}
|
startIcon={<Icon icon="ArrowLeft" />}
|
||||||
variant="light"
|
variant="light"
|
||||||
@@ -340,7 +358,6 @@ const InstallMachine = (props: InstallMachineProps) => {
|
|||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
|
||||||
</Form>
|
</Form>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ export const HWStep = (props: StepProps<HardwareValues>) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} class="flex flex-col gap-6">
|
<Form onSubmit={handleSubmit} class="flex flex-col gap-6">
|
||||||
|
<div class="max-h-[calc(100vh-20rem)] overflow-y-scroll">
|
||||||
|
<div class="flex h-full flex-col gap-6 p-4">
|
||||||
<Group>
|
<Group>
|
||||||
<Field name="target" validate={required("Target must be provided")}>
|
<Field name="target" validate={required("Target must be provided")}>
|
||||||
{(field, fieldProps) => (
|
{(field, fieldProps) => (
|
||||||
@@ -200,6 +202,8 @@ export const HWStep = (props: StepProps<HardwareValues>) => {
|
|||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
</Group>
|
</Group>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{props.footer}
|
{props.footer}
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export const SummaryStep = (props: StepProps<AllStepsValues>) => {
|
|||||||
const diskValues = () => props.initial?.["2"];
|
const diskValues = () => props.initial?.["2"];
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<div class="max-h-[calc(100vh-20rem)] overflow-y-scroll">
|
||||||
|
<div class="flex h-full flex-col gap-6 p-4">
|
||||||
<Section>
|
<Section>
|
||||||
<Typography
|
<Typography
|
||||||
hierarchy="label"
|
hierarchy="label"
|
||||||
@@ -79,7 +81,12 @@ export const SummaryStep = (props: StepProps<AllStepsValues>) => {
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
headline={
|
headline={
|
||||||
<span>
|
<span>
|
||||||
<Typography hierarchy="body" size="s" weight="bold" color="inherit">
|
<Typography
|
||||||
|
hierarchy="body"
|
||||||
|
size="s"
|
||||||
|
weight="bold"
|
||||||
|
color="inherit"
|
||||||
|
>
|
||||||
Setup your device.
|
Setup your device.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
@@ -93,6 +100,8 @@ export const SummaryStep = (props: StepProps<AllStepsValues>) => {
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{props.footer}
|
{props.footer}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import { callApi } from "@/src/api";
|
||||||
|
import {
|
||||||
|
createForm,
|
||||||
|
SubmitHandler,
|
||||||
|
validate,
|
||||||
|
FieldValues,
|
||||||
|
} from "@modular-forms/solid";
|
||||||
|
import { createQuery } from "@tanstack/solid-query";
|
||||||
|
import { StepProps } from "./hardware-step";
|
||||||
|
import { Typography } from "@/src/components/Typography";
|
||||||
|
import { Group } from "@/src/components/group";
|
||||||
|
import { For, Match, Show, Switch } from "solid-js";
|
||||||
|
|
||||||
|
export type VarsValues = FieldValues & Record<string, string>;
|
||||||
|
|
||||||
|
export const VarsStep = (props: StepProps<VarsValues>) => {
|
||||||
|
const [formStore, { Form, Field }] = createForm<VarsValues>({
|
||||||
|
initialValues: { ...props.initial, schema: "single-disk" },
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit: SubmitHandler<VarsValues> = async (values, event) => {
|
||||||
|
console.log("Submit Disk", { values });
|
||||||
|
const valid = await validate(formStore);
|
||||||
|
console.log("Valid", valid);
|
||||||
|
if (!valid) return;
|
||||||
|
props.handleNext(values);
|
||||||
|
};
|
||||||
|
|
||||||
|
const generatorsQuery = createQuery(() => ({
|
||||||
|
queryKey: [props.dir, props.machine_id, "generators"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const result = await callApi("get_generators", {
|
||||||
|
base_dir: props.dir,
|
||||||
|
machine_name: props.machine_id,
|
||||||
|
});
|
||||||
|
if (result.status === "error") throw new Error("Failed to fetch data");
|
||||||
|
return result.data;
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
class="flex h-full flex-col gap-6"
|
||||||
|
noValidate={false}
|
||||||
|
>
|
||||||
|
<div class="max-h-[calc(100vh-20rem)] overflow-y-scroll">
|
||||||
|
<div class="flex h-full flex-col gap-6 p-4">
|
||||||
|
<Switch>
|
||||||
|
<Match when={generatorsQuery.isLoading}>Loading ...</Match>
|
||||||
|
<Match when={generatorsQuery.data}>
|
||||||
|
{(generators) => (
|
||||||
|
<For each={generators()}>
|
||||||
|
{(generator) => (
|
||||||
|
<Group>
|
||||||
|
<Typography hierarchy="label" size="default">
|
||||||
|
{generator.name}
|
||||||
|
</Typography>
|
||||||
|
<div>
|
||||||
|
Bound to module (shared):{" "}
|
||||||
|
{generator.share ? "True" : "False"}
|
||||||
|
</div>
|
||||||
|
<For each={generator.prompts}>
|
||||||
|
{(f) => (
|
||||||
|
<Group>
|
||||||
|
<Typography hierarchy="label" size="s">
|
||||||
|
{!f.previous_value ? "Required" : "Optional"}
|
||||||
|
</Typography>
|
||||||
|
<Typography hierarchy="label" size="s">
|
||||||
|
{f.name}
|
||||||
|
</Typography>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
)}
|
||||||
|
</Match>
|
||||||
|
</Switch>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Show when={generatorsQuery.isFetched}>{props.footer}</Show>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user