mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(react/options): plain text not disabled
This commit is contained in:
parent
e328f18558
commit
8125e8afcd
@ -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"
|
||||
/>
|
||||
|
@ -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])}
|
||||
|
Loading…
x
Reference in New Issue
Block a user