From 1d7799f981bcd84916abe013f8ea25d5431d1688 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 19 Aug 2025 23:34:25 +0300 Subject: [PATCH] refactor(react/settings): add names to all form groups --- apps/client/src/widgets/dialogs/add_link.tsx | 2 +- .../src/widgets/dialogs/branch_prefix.tsx | 2 +- apps/client/src/widgets/dialogs/clone_to.tsx | 6 +-- apps/client/src/widgets/dialogs/import.tsx | 8 +-- .../src/widgets/dialogs/include_note.tsx | 7 +-- apps/client/src/widgets/dialogs/move_to.tsx | 2 +- .../src/widgets/dialogs/note_type_chooser.tsx | 4 +- apps/client/src/widgets/dialogs/prompt.tsx | 3 +- .../src/widgets/dialogs/sort_child_notes.tsx | 7 +-- .../widgets/dialogs/upload_attachments.tsx | 7 ++- .../client/src/widgets/react/FormCheckbox.tsx | 5 +- apps/client/src/widgets/react/FormGroup.tsx | 12 +++++ .../src/widgets/react/FormRadioGroup.tsx | 4 +- .../src/widgets/react/NoteAutocomplete.tsx | 4 +- apps/client/src/widgets/react/hooks.tsx | 4 +- .../type_widgets/options/ai_settings.tsx | 18 +++---- .../type_widgets/options/appearance.tsx | 19 ++++--- .../widgets/type_widgets/options/backup.tsx | 6 +-- .../type_widgets/options/code_notes.tsx | 5 +- .../options/components/AutoReadOnlySize.tsx | 5 +- .../src/widgets/type_widgets/options/i18n.tsx | 50 +++++++++---------- .../widgets/type_widgets/options/images.tsx | 13 ++--- .../options/multi_factor_authentication.tsx | 1 - .../widgets/type_widgets/options/other.tsx | 35 ++++++------- .../widgets/type_widgets/options/password.tsx | 21 ++++---- .../type_widgets/options/shortcuts.tsx | 5 +- .../type_widgets/options/spellcheck.tsx | 5 +- .../src/widgets/type_widgets/options/sync.tsx | 21 ++++---- .../type_widgets/options/text_notes.tsx | 17 +++---- 29 files changed, 144 insertions(+), 154 deletions(-) diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/add_link.tsx index 78867304c..e20e5a80e 100644 --- a/apps/client/src/widgets/dialogs/add_link.tsx +++ b/apps/client/src/widgets/dialogs/add_link.tsx @@ -107,7 +107,7 @@ function AddLinkDialogComponent() { }} show={shown} > - + } show={shown} > - +
setPrefix((e.target as HTMLInputElement).value)} /> diff --git a/apps/client/src/widgets/dialogs/clone_to.tsx b/apps/client/src/widgets/dialogs/clone_to.tsx index f8929f00d..173169858 100644 --- a/apps/client/src/widgets/dialogs/clone_to.tsx +++ b/apps/client/src/widgets/dialogs/clone_to.tsx @@ -69,15 +69,15 @@ function CloneToDialogComponent() { >
{t("clone_to.notes_to_clone")}
- + - - + + ) diff --git a/apps/client/src/widgets/dialogs/import.tsx b/apps/client/src/widgets/dialogs/import.tsx index 77b867219..df648b7fb 100644 --- a/apps/client/src/widgets/dialogs/import.tsx +++ b/apps/client/src/widgets/dialogs/import.tsx @@ -4,7 +4,7 @@ import tree from "../../services/tree"; import Button from "../react/Button"; import FormCheckbox from "../react/FormCheckbox"; import FormFileUpload from "../react/FormFileUpload"; -import FormGroup from "../react/FormGroup"; +import FormGroup, { FormMultiGroup } from "../react/FormGroup"; import Modal from "../react/Modal"; import RawHtml from "../react/RawHtml"; import ReactBasicWidget from "../react/ReactBasicWidget"; @@ -55,11 +55,11 @@ function ImportDialogComponent() { footer={
); +} + +/** + * Similar to {@link FormGroup} but allows more than one child. Due to this behaviour, there is no automatic ID assignment. + */ +export function FormMultiGroup({ label, children }: { label: string, children: ComponentChildren }) { + return ( +
+ {label && } + {children} +
+ ); } \ No newline at end of file diff --git a/apps/client/src/widgets/react/FormRadioGroup.tsx b/apps/client/src/widgets/react/FormRadioGroup.tsx index be05797a5..d71f53c42 100644 --- a/apps/client/src/widgets/react/FormRadioGroup.tsx +++ b/apps/client/src/widgets/react/FormRadioGroup.tsx @@ -31,9 +31,9 @@ export default function FormRadioGroup({ values, ...restProps }: FormRadioProps) export function FormInlineRadioGroup({ values, ...restProps }: FormRadioProps) { return ( - <> +
{values.map(({ value, label }) => ())} - +
) } diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsx index 3bec28a53..dd97f90d4 100644 --- a/apps/client/src/widgets/react/NoteAutocomplete.tsx +++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx @@ -6,6 +6,7 @@ import type { RefObject } from "preact"; import type { CSSProperties } from "preact/compat"; interface NoteAutocompleteProps { + id?: string; inputRef?: RefObject; text?: string; placeholder?: string; @@ -18,7 +19,7 @@ interface NoteAutocompleteProps { noteId?: string; } -export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, onChange, onTextChange, container, containerStyle, opts, noteId, noteIdChanged }: NoteAutocompleteProps) { +export default function NoteAutocomplete({ id, inputRef: _ref, text, placeholder, onChange, onTextChange, container, containerStyle, opts, noteId, noteIdChanged }: NoteAutocompleteProps) { const ref = _ref ?? useRef(null); useEffect(() => { @@ -74,6 +75,7 @@ export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, on return (
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 8575ccf37..dbc8866d8 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -190,6 +190,6 @@ export function useTriliumOptions(...names: T[]) { * @param prefix a prefix to add to the unique name. * @returns a name with the given prefix and a random alpanumeric string appended to it. */ -export function useUniqueName(prefix: string) { - return useMemo(() => prefix + "-" + utils.randomString(10), [ prefix]); +export function useUniqueName(prefix?: string) { + return useMemo(() => (prefix ? prefix + "-" : "") + utils.randomString(10), [ prefix ]); } \ No newline at end of file diff --git a/apps/client/src/widgets/type_widgets/options/ai_settings.tsx b/apps/client/src/widgets/type_widgets/options/ai_settings.tsx index 9cfefbd88..c60c85cac 100644 --- a/apps/client/src/widgets/type_widgets/options/ai_settings.tsx +++ b/apps/client/src/widgets/type_widgets/options/ai_settings.tsx @@ -28,9 +28,8 @@ function EnableAiSettings() { return ( <> - - + { if (isEnabled) { @@ -56,7 +55,7 @@ function ProviderSettings() { return ( - + } - + - + {validationErrorMessage} } {apiKeyOption && ( - + )} - + {isValid && - + } diff --git a/apps/client/src/widgets/type_widgets/options/appearance.tsx b/apps/client/src/widgets/type_widgets/options/appearance.tsx index bf6bf4854..2b43d9e82 100644 --- a/apps/client/src/widgets/type_widgets/options/appearance.tsx +++ b/apps/client/src/widgets/type_widgets/options/appearance.tsx @@ -189,7 +189,7 @@ function Font({ title, fontFamilyOption, fontSizeOption }: { title: string, font <>
{title}
- + - + - +
- + - + @@ -253,9 +253,8 @@ function MaxContentWidth() { {t("max_content_width.default_description")} - - + - + - + {t("backup.backup_recommendation")} diff --git a/apps/client/src/widgets/type_widgets/options/code_notes.tsx b/apps/client/src/widgets/type_widgets/options/code_notes.tsx index 1da25db8c..764b75732 100644 --- a/apps/client/src/widgets/type_widgets/options/code_notes.tsx +++ b/apps/client/src/widgets/type_widgets/options/code_notes.tsx @@ -32,9 +32,8 @@ function Editor() { return ( - + @@ -57,7 +56,7 @@ function Appearance() { return (
- + {t("text_auto_read_only_size.description")} - - + - + - {isElectron() && + {isElectron() && } @@ -65,34 +65,30 @@ function DateSettings() { return ( <> - -
- -
+ + - -
- -
+ + - {firstWeekOfYear === "2" && + {firstWeekOfYear === "2" && - +