Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): group time-slot settings under one menu entry

Elian Doran94bab98ce3f3
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index c299cf5c85..8cc33a42b2 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2577,8 +2577,9 @@
},
"calendar_view": {
"delete_note": "Delete note...",
- "set_slot_duration": "Time slot duration",
- "set_slot_label_interval": "Time slot label interval",
+ "time_slots": "Time slots",
+ "slot_duration": "Duration",
+ "slot_label_interval": "Label interval",
"minutes_one": "{{count}} minute",
"minutes_other": "{{count}} minutes",
"hours_one": "{{count}} hour",
diff --git a/apps/client/src/widgets/react/NotePropertyMenu.tsx b/apps/client/src/widgets/react/NotePropertyMenu.tsx
index 72c7a12d86..0264d0d098 100644
--- a/apps/client/src/widgets/react/NotePropertyMenu.tsx
+++ b/apps/client/src/widgets/react/NotePropertyMenu.tsx
@@ -77,7 +77,23 @@ export interface ComboBoxProperty {
dropStart?: boolean;
}
-export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty | SplitButtonProperty | Separator;
+export interface SubmenuProperty {
+ type: "submenu";
+ label: string;
+ icon?: string;
+ children: BookProperty[];
+}
+
+/** A labelled group of radio-style options rendered inline (e.g. inside a {@link SubmenuProperty}), bound to its own label. */
+export interface OptionGroupProperty {
+ type: "option-group";
+ label: string;
+ bindToLabel: FilterLabelsByType<string>;
+ defaultValue?: string;
+ options: ComboBoxItem[];
+}
+
+export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty | SplitButtonProperty | SubmenuProperty | OptionGroupProperty | Separator;
export function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) {
switch (property.type) {
@@ -91,11 +107,48 @@ export function ViewProperty({ note, property }: { note: FNote, property: BookPr
return <NumberPropertyView note={note} property={property} />;
case "combobox":
return <ComboBoxPropertyView note={note} property={property} />;
+ case "submenu":
+ return <SubmenuPropertyView note={note} property={property} />;
+ case "option-group":
+ return <OptionGroupPropertyView note={note} property={property} />;
case "separator":
return <FormDropdownDivider />;
}
}
+function SubmenuPropertyView({ note, property }: { note: FNote, property: SubmenuProperty }) {
+ return (
+ <FormDropdownSubmenu
+ title={property.label}
+ icon={property.icon ?? "bx bx-empty"}
+ >
+ {property.children.map((child, index) => (
+ <ViewProperty key={index} note={note} property={child} />
+ ))}
+ </FormDropdownSubmenu>
+ );
+}
+
+function OptionGroupPropertyView({ note, property }: { note: FNote, property: OptionGroupProperty }) {
+ const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
+ const valueWithDefault = value ?? property.defaultValue ?? null;
+
+ return (
+ <Fragment>
+ <FormListItem disabled>{property.label}</FormListItem>
+ {property.options.map((option) => (
+ <FormListItem
+ key={option.value}
+ checked={valueWithDefault === option.value}
+ onClick={() => setValue(option.value)}
+ >
+ {option.label}
+ </FormListItem>
+ ))}
+ </Fragment>
+ );
+}
+
function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) {
const parentComponent = useContext(ParentComponent);
diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsx
index 7e686c919a..25889ab5f4 100644
--- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx
+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx
@@ -61,19 +61,25 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {
bindToLabel: "calendar:weekNumbers"
},
{
- label: t("calendar_view.set_slot_duration"),
+ label: t("calendar_view.time_slots"),
icon: "bx bx-time",
- type: "combobox",
- bindToLabel: "calendar:slotDuration",
- options: slotDurationOptions([5, 10, 15, 20, 30, 60])
- },
- {
- label: t("calendar_view.set_slot_label_interval"),
- icon: "bx bx-time",
- type: "combobox",
- bindToLabel: "calendar:slotLabelInterval",
- // Labels want to be coarser than the slots themselves.
- options: slotDurationOptions([15, 30, 60])
+ type: "submenu",
+ children: [
+ {
+ label: t("calendar_view.slot_duration"),
+ type: "option-group",
+ bindToLabel: "calendar:slotDuration",
+ options: slotDurationOptions([5, 10, 15, 20, 30, 60])
+ },
+ { type: "separator" },
+ {
+ label: t("calendar_view.slot_label_interval"),
+ type: "option-group",
+ bindToLabel: "calendar:slotLabelInterval",
+ // Labels want to be coarser than the slots themselves.
+ options: slotDurationOptions([15, 30, 60])
+ }
+ ]
}
]
},