Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(calendar): show time-slot settings only on Day/Week views
Elian Doranc4c7f2bc9c7d
diff --git a/apps/client/src/widgets/react/NotePropertyMenu.tsx b/apps/client/src/widgets/react/NotePropertyMenu.tsxindex 0264d0d098..65dd5bdcce 100644--- a/apps/client/src/widgets/react/NotePropertyMenu.tsx+++ b/apps/client/src/widgets/react/NotePropertyMenu.tsx@@ -81,6 +81,8 @@ export interface SubmenuProperty {type: "submenu";label: string;icon?: string;+ /** When provided, the submenu is only rendered if this returns true for the current note. */+ isVisible?: (note: FNote) => boolean;children: BookProperty[];}@@ -95,7 +97,16 @@ export interface OptionGroupProperty {export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty | SplitButtonProperty | SubmenuProperty | OptionGroupProperty | Separator;+/** Whether a property should render for the given note, honouring an optional `isVisible` predicate. */+export function isPropertyVisible(property: BookProperty, note: FNote): boolean {+ return !("isVisible" in property) || (property.isVisible?.(note) ?? true);+}+export function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) {+ if (!isPropertyVisible(property, note)) {+ return null;+ }+switch (property.type) {case "button":return <ButtonPropertyView note={note} property={property} />;diff --git a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsxindex 3055388e5d..b4ba72fd1b 100644--- a/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx+++ b/apps/client/src/widgets/ribbon/CollectionPropertiesTab.tsx@@ -1,6 +1,6 @@import "./CollectionPropertiesTab.css";-import { ComponentChildren } from "preact";+import { ComponentChildren, Fragment } from "preact";import { useContext, useMemo } from "preact/hooks";import FNote from "../../entities/fnote";@@ -13,7 +13,7 @@ import FormCheckbox from "../react/FormCheckbox";import FormSelect, { FormSelectWithGroups } from "../react/FormSelect";import FormTextBox from "../react/FormTextBox";import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks";-import { BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxGroup, ComboBoxItem, ComboBoxProperty, NumberProperty, SplitButtonProperty } from "../react/NotePropertyMenu";+import { BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxGroup, ComboBoxItem, ComboBoxProperty, isPropertyVisible, NumberProperty, OptionGroupProperty, SplitButtonProperty } from "../react/NotePropertyMenu";import { ParentComponent } from "../react/react_utils";import { bookPropertiesConfig } from "./collection-properties-config";import { TabContext } from "./ribbon-interface";@@ -72,7 +72,7 @@ function CollectionTypeSwitcher({ viewType, setViewType }: { viewType: string, sfunction BookProperties({ note, properties }: { viewType: ViewTypeOptions, note: FNote, properties: BookProperty[] }) {return (<>- {properties.map((property, index) => (+ {properties.filter((property) => isPropertyVisible(property, note)).map((property, index) => (<div key={index} className={`type-${property}`}>{mapPropertyView({ note, property })}</div>@@ -101,6 +101,17 @@ function mapPropertyView({ note, property }: { note: FNote, property: BookProperreturn <NumberPropertyView note={note} property={property} />;case "combobox":return <ComboBoxPropertyView note={note} property={property} />;+ case "option-group":+ return <OptionGroupPropertyView note={note} property={property} />;+ case "submenu":+ // The ribbon is a flat strip, so a submenu is flattened to its (visible) children inline.+ return (+ <>+ {property.children.filter((child) => isPropertyVisible(child, note)).map((child, index) => (+ <Fragment key={index}>{mapPropertyView({ note, property: child })}</Fragment>+ ))}+ </>+ );}}@@ -182,6 +193,20 @@ function ComboBoxPropertyView({ note, property }: { note: FNote, property: Combo);}+function OptionGroupPropertyView({ note, property }: { note: FNote, property: OptionGroupProperty }) {+ const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);++ return (+ <LabelledEntry label={property.label}>+ <FormSelectWithGroups+ values={property.options}+ keyProperty="value" titleProperty="label"+ currentValue={value ?? property.defaultValue} onChange={setValue}+ />+ </LabelledEntry>+ );+}+function LabelledEntry({ label, children }: { label: string, children: ComponentChildren }) {return (<>diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsxindex 25889ab5f4..f1cdfae2f3 100644--- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx@@ -64,6 +64,8 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {label: t("calendar_view.time_slots"),icon: "bx bx-time",type: "submenu",+ // Time slots only apply to the time-grid views (Day / Week).+ isVisible: isTimeGridCalendarView,children: [{label: t("calendar_view.slot_duration"),@@ -183,6 +185,12 @@ function pad(n: number) {return String(n).padStart(2, "0");}+/** The calendar's slot settings only apply to the time-grid views (Day / Week). */+function isTimeGridCalendarView(note: FNote) {+ const view = note.getLabelValue("calendar:view");+ return view === "timeGridDay" || view === "timeGridWeek";+}+function ListExpandDepth(context: { note: FNote, parentComponent: Component }) {const [ currentDepth ] = useNoteLabel(context.note, "expanded");