Skip to content

Build your personal knowledge base with Trilium Notes

fix(react/options): plain text not disabled

Elian Doran8125e8afcd38
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 ded1e02d2a..da33cfbceb 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<string[]>("codeNotesMimeTypes");
const groupedMimeTypes: Record<string, MimeType[]> = 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<string, MimeType[]> = {};
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() {
<section>
{ initial && <h5>{initial}</h5> }
<CheckboxList
- values={mimeTypes}
- keyProperty="mime" titleProperty="title"
+ values={mimeTypes as MimeTypeWithDisabled[]}
+ keyProperty="mime" titleProperty="title" disabledProperty="disabled"
currentValue={codeNotesMimeTypes} onChange={setCodeNotesMimeTypes}
columnWidth="inherit"
/>
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 3e0b208143..a2f48a04fd 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<T> {
values: T[];
keyProperty: keyof T;
titleProperty?: keyof T;
+ disabledProperty?: keyof T;
currentValue: string[];
onChange: (newValues: string[]) => void;
columnWidth?: string;
}
-export default function CheckboxList<T>({ values, keyProperty, titleProperty, currentValue, onChange, columnWidth }: CheckboxListProps<T>) {
+export default function CheckboxList<T>({ values, keyProperty, titleProperty, disabledProperty, currentValue, onChange, columnWidth }: CheckboxListProps<T>) {
function toggleValue(value: string) {
if (currentValue.includes(value)) {
// Already there, needs removing.
@@ -28,6 +29,7 @@ export default function CheckboxList<T>({ 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])}