This commit is contained in:
Dan Ditomaso
2025-04-02 17:59:59 -04:00
parent 1a6e99971a
commit 8fffde0165
7 changed files with 421 additions and 528 deletions
+7 -2
View File
@@ -10,13 +10,14 @@ import {
SelectValue,
} from "@components/UI/Select.tsx";
import { useController, type FieldValues } from "react-hook-form";
import { computeHeadingLevel } from "@core/utils/test.tsx";
export interface SelectFieldProps<T> extends BaseFormBuilderProps<T> {
type: "select";
selectChange?: (e: string, name: string) => void;
validate?: (newValue: string) => Promise<boolean>;
defaultValue?: string;
properties: BaseFormBuilderProps<T>["properties"] & {
defaultValue?: T;
enumValue: {
[s: string]: string | number;
};
@@ -38,11 +39,15 @@ export function SelectInput<T extends FieldValues>({
disabled,
field,
}: GenericFormElementProps<T, SelectFieldProps<T>>) {
// Get default value and set it
const defaultValue = field.properties.defaultValue ?? field.defaultValue;
const {
field: { value, onChange, ...rest },
} = useController({
name: field.name,
control,
defaultValue: defaultValue ? defaultValue.toString() : undefined,
});
const { enumValue, formatEnumName, ...remainingProperties } = field.properties;
@@ -70,12 +75,12 @@ export function SelectInput<T extends FieldValues>({
onChange(Number.parseInt(newValue));
};
return (
<Select
onValueChange={handleValueChange}
disabled={disabled}
value={value?.toString()}
defaultValue={defaultValue?.toString()}
{...remainingProperties}
{...rest}
>
@@ -1,4 +1,4 @@
import type { NetworkValidation } from "@app/validation/config/network.tsx";
import type { NetworkValidation } from "@app/validation/config/network.ts";
import { create } from "@bufbuild/protobuf";
import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.ts";
@@ -12,6 +12,9 @@ export const Network = () => {
const { config, setWorkingConfig } = useDevice();
const onSubmit = (data: NetworkValidation) => {
console.log("Network data", data);
setWorkingConfig(
create(Protobuf.Config.ConfigSchema, {
payloadVariant: {
@@ -21,7 +24,7 @@ export const Network = () => {
ipv4Config: create(
Protobuf.Config.Config_NetworkConfig_IpV4ConfigSchema,
{
ip: convertIpAddressToInt(data.ipv4Config.ip) ?? 0,
ip: convertIpAddressToInt(data?.ipv4Config?.ip) ?? 0,
gateway: convertIpAddressToInt(data.ipv4Config.gateway) ?? 0,
subnet: convertIpAddressToInt(data.ipv4Config.subnet) ?? 0,
dns: convertIpAddressToInt(data.ipv4Config.dns) ?? 0,
@@ -165,6 +168,22 @@ export const Network = () => {
},
],
},
{
label: "UDP Config",
description: "UDP over Mesh configuration",
fields: [
{
type: "select",
name: "enabledProtocols",
label: "Mesh via UDP enabled",
properties: {
enumValue:
Protobuf.Config.Config_NetworkConfig_ProtocolFlags,
formatEnumName: true,
}
},
],
},
{
label: "NTP Config",
description: "NTP configuration",