rewrite disabled dynamicforms stuff and fix factory reset in command palette
This commit is contained in:
@@ -200,10 +200,17 @@ export const CommandPalette = (): JSX.Element => {
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Factory Reset",
|
||||
label: "Soft Factory Reset",
|
||||
icon: FactoryIcon,
|
||||
action() {
|
||||
connection?.factoryReset();
|
||||
connection?.factoryResetConfig();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Hard Factory Reset",
|
||||
icon: FactoryIcon,
|
||||
action() {
|
||||
connection?.factoryResetDevice();
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -16,13 +16,14 @@ import {
|
||||
} from "react-hook-form";
|
||||
|
||||
interface DisabledBy<T> {
|
||||
fieldName: Path<T> | "always";
|
||||
fieldName: Path<T>;
|
||||
selector?: number;
|
||||
invert?: boolean;
|
||||
}
|
||||
|
||||
export interface BaseFormBuilderProps<T> {
|
||||
name: Path<T>;
|
||||
disabled?: boolean;
|
||||
disabledBy?: DisabledBy<T>[];
|
||||
label: string;
|
||||
description?: string;
|
||||
@@ -62,11 +63,14 @@ export function DynamicForm<T extends FieldValues>({
|
||||
defaultValues: defaultValues,
|
||||
});
|
||||
|
||||
const isDisabled = (disabledBy?: DisabledBy<T>[]): boolean => {
|
||||
const isDisabled = (
|
||||
disabledBy?: DisabledBy<T>[],
|
||||
disabled?: boolean,
|
||||
): boolean => {
|
||||
if (!disabledBy) return false;
|
||||
|
||||
return disabledBy.some((field) => {
|
||||
if (field.fieldName === "always") return true;
|
||||
if (disabled) return true;
|
||||
const value = getValues(field.fieldName);
|
||||
if (value === "always") return true;
|
||||
if (typeof value === "boolean") return field.invert ? value : !value;
|
||||
@@ -111,7 +115,7 @@ export function DynamicForm<T extends FieldValues>({
|
||||
<DynamicFormField
|
||||
field={field}
|
||||
control={control}
|
||||
disabled={isDisabled(field.disabledBy)}
|
||||
disabled={isDisabled(field.disabledBy, field.disabled)}
|
||||
/>
|
||||
</FieldWrapper>
|
||||
))}
|
||||
|
||||
@@ -72,9 +72,9 @@ export const Security = (): JSX.Element => {
|
||||
type: "text",
|
||||
name: "publicKey",
|
||||
label: "Public Key",
|
||||
disabled: true,
|
||||
description:
|
||||
"Sent out to other nodes on the mesh to allow them to compute a shared secret key",
|
||||
disabledBy: [{ fieldName: "always" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user