From 8125e8afcd38b14ec0a97772d183ef39c5cce441 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 27 Aug 2025 20:14:33 +0300 Subject: [PATCH] fix(react/options): plain text not disabled --- .../src/widgets/type_widgets/options/code_notes.tsx | 10 +++++++--- .../type_widgets/options/components/CheckboxList.tsx | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) 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 ded1e02d2..da33cfbce 100644 --- a/apps/client/src/widgets/type_widgets/options/code_notes.tsx +++ b/apps/client/src/widgets/type_widgets/options/code_notes.tsx @@ -131,18 +131,22 @@ function CodeMimeTypes() { ) } +type MimeTypeWithDisabled = MimeType & { disabled?: boolean }; + export function CodeMimeTypesList() { const [ codeNotesMimeTypes, setCodeNotesMimeTypes ] = useTriliumOptionJson("codeNotesMimeTypes"); const groupedMimeTypes: Record = useMemo(() => { mime_types.loadMimeTypes(); - const ungroupedMimeTypes = Array.from(mime_types.getMimeTypes()); + const ungroupedMimeTypes = Array.from(mime_types.getMimeTypes()) as MimeTypeWithDisabled[]; const plainTextMimeType = ungroupedMimeTypes.shift(); const result: Record = {}; ungroupedMimeTypes.sort((a, b) => a.title.localeCompare(b.title)); if (plainTextMimeType) { result[""] = [ plainTextMimeType ]; + plainTextMimeType.enabled = true; + plainTextMimeType.disabled = true; } for (const mimeType of ungroupedMimeTypes) { @@ -161,8 +165,8 @@ export function CodeMimeTypesList() {
{ initial &&
{initial}
} diff --git a/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx b/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx index 3e0b20814..a2f48a04f 100644 --- a/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx +++ b/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx @@ -2,12 +2,13 @@ interface CheckboxListProps { values: T[]; keyProperty: keyof T; titleProperty?: keyof T; + disabledProperty?: keyof T; currentValue: string[]; onChange: (newValues: string[]) => void; columnWidth?: string; } -export default function CheckboxList({ values, keyProperty, titleProperty, currentValue, onChange, columnWidth }: CheckboxListProps) { +export default function CheckboxList({ values, keyProperty, titleProperty, disabledProperty, currentValue, onChange, columnWidth }: CheckboxListProps) { function toggleValue(value: string) { if (currentValue.includes(value)) { // Already there, needs removing. @@ -28,6 +29,7 @@ export default function CheckboxList({ values, keyProperty, titleProperty, cu className="form-check-input" value={String(value[keyProperty])} checked={currentValue.includes(String(value[keyProperty]))} + disabled={!!(disabledProperty && value[disabledProperty])} onChange={e => toggleValue((e.target as HTMLInputElement).value)} /> {String(value[titleProperty ?? keyProperty] ?? value[keyProperty])}