From 0dcc2b19750a88115e92bf2920179199590599e0 Mon Sep 17 00:00:00 2001 From: Hunter Thornsberry Date: Wed, 4 Sep 2024 21:50:23 -0400 Subject: [PATCH 1/2] rewrite disabled dynamicforms stuff and fix factory reset in command palette --- src/components/CommandPalette.tsx | 11 +++++++++-- src/components/Form/DynamicForm.tsx | 12 ++++++++---- src/components/PageComponents/Config/Security.tsx | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/CommandPalette.tsx b/src/components/CommandPalette.tsx index 07f456e1..c101e6b0 100644 --- a/src/components/CommandPalette.tsx +++ b/src/components/CommandPalette.tsx @@ -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(); }, }, ], diff --git a/src/components/Form/DynamicForm.tsx b/src/components/Form/DynamicForm.tsx index 58bf241e..63d2dbf5 100644 --- a/src/components/Form/DynamicForm.tsx +++ b/src/components/Form/DynamicForm.tsx @@ -16,13 +16,14 @@ import { } from "react-hook-form"; interface DisabledBy { - fieldName: Path | "always"; + fieldName: Path; selector?: number; invert?: boolean; } export interface BaseFormBuilderProps { name: Path; + disabled?: boolean; disabledBy?: DisabledBy[]; label: string; description?: string; @@ -62,11 +63,14 @@ export function DynamicForm({ defaultValues: defaultValues, }); - const isDisabled = (disabledBy?: DisabledBy[]): boolean => { + const isDisabled = ( + disabledBy?: DisabledBy[], + 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({ ))} diff --git a/src/components/PageComponents/Config/Security.tsx b/src/components/PageComponents/Config/Security.tsx index c9e1175c..ba4d3d8b 100644 --- a/src/components/PageComponents/Config/Security.tsx +++ b/src/components/PageComponents/Config/Security.tsx @@ -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" }], }, ], }, From 300fb5c3e507da0c9cc80b844e4a9258e53d6a7f Mon Sep 17 00:00:00 2001 From: Hunter Thornsberry Date: Wed, 4 Sep 2024 21:54:48 -0400 Subject: [PATCH 2/2] fix disabled check location --- src/components/Form/DynamicForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Form/DynamicForm.tsx b/src/components/Form/DynamicForm.tsx index 63d2dbf5..f957e7f0 100644 --- a/src/components/Form/DynamicForm.tsx +++ b/src/components/Form/DynamicForm.tsx @@ -67,10 +67,10 @@ export function DynamicForm({ disabledBy?: DisabledBy[], disabled?: boolean, ): boolean => { + if (disabled) return true; if (!disabledBy) return false; return disabledBy.some((field) => { - if (disabled) return true; const value = getValues(field.fieldName); if (value === "always") return true; if (typeof value === "boolean") return field.invert ? value : !value;