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
fix(calendar): put a month chip's promoted attributes back beneath it
Elian Doran76b9672ca2b5
diff --git a/apps/client/src/widgets/collections/calendar/index.css b/apps/client/src/widgets/collections/calendar/index.cssindex 2229c5a1b2..a0c39433d0 100644--- a/apps/client/src/widgets/collections/calendar/index.css+++ b/apps/client/src/widgets/collections/calendar/index.css@@ -31,12 +31,24 @@height: 100%;}-/* Stacked beneath the title, the chip's own container being a column wherever these are shown at- all (see hasRoomForAttributes). Kept narrow so the overflow below has something to bite on. */+/* Stacked beneath the title. Kept narrow so the overflow below has something to bite on. */.calendar-view .calendar-event-attributes {min-width: 0;}+/* A month cell's chip is a row, so the title is fallen beneath rather than followed down: the+ chip's own container is asked to wrap (see eventInnerClass) and the attributes claim a whole+ line of it. The inline padding is the one the row's title wears — Forma states it on the title+ rather than on the container — so that the two read as one column of text. */+.calendar-view .calendar-event-inner-wrapped {+ flex-wrap: wrap;++ > .calendar-event-attributes {+ flex-basis: 100%;+ padding-inline: 4px;+ }+}+.calendar-container .promoted-attribute {font-size: 0.85em;opacity: 0.85;diff --git a/apps/client/src/widgets/collections/calendar/index.spec.ts b/apps/client/src/widgets/collections/calendar/index.spec.tsnew file mode 100644index 0000000000..c43683166b--- /dev/null+++ b/apps/client/src/widgets/collections/calendar/index.spec.ts@@ -0,0 +1,33 @@+import { EventDisplayInfo } from "fullcalendar";+import { describe, expect, it } from "vitest";++import { roomForAttributes } from "./index.js";++/** As much of a chip as the question is asked of: which view it is drawn in, and how it sits there. */+function chip({ view, allDay = false, isShort = false, isNarrow = false }: {+ view: string, allDay?: boolean, isShort?: boolean, isNarrow?: boolean+}) {+ return { view: { type: view }, event: { allDay }, isShort, isNarrow } as EventDisplayInfo;+}++describe("roomForAttributes", () => {+ it("wraps a month cell's chip, which is a row wide enough to be worth wrapping", () => {+ expect(roomForAttributes(chip({ view: "dayGridMonth" }))).toBe("wrapped");+ expect(roomForAttributes(chip({ view: "dayGridMonth", allDay: true }))).toBe("wrapped");+ // A cell too narrow to hold much of a title is left as the one line it is.+ expect(roomForAttributes(chip({ view: "dayGridMonth", isNarrow: true }))).toBe(null);+ });++ it("lets a timed event on a time grid stack them, its content being a column already", () => {+ expect(roomForAttributes(chip({ view: "timeGridWeek" }))).toBe("stacked");+ expect(roomForAttributes(chip({ view: "timeGridDay" }))).toBe("stacked");+ // Too short to say anything beneath its title, and the all-day band is a row.+ expect(roomForAttributes(chip({ view: "timeGridWeek", isShort: true }))).toBe(null);+ expect(roomForAttributes(chip({ view: "timeGridWeek", allDay: true }))).toBe(null);+ });++ it("has nowhere to put them on a year's chips or in a list", () => {+ expect(roomForAttributes(chip({ view: "multiMonthYear" }))).toBe(null);+ expect(roomForAttributes(chip({ view: "listMonth" }))).toBe(null);+ });+});diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsxindex f5abdac265..66edc1db8e 100644--- a/apps/client/src/widgets/collections/calendar/index.tsx+++ b/apps/client/src/widgets/collections/calendar/index.tsx@@ -169,7 +169,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVireturn true;}, []);- const { eventContent, eventDidMount } = useEventDisplayCustomization(note, parentComponent?.componentId, dismissSurface);+ const { eventContent, eventDidMount, eventInnerClass } = useEventDisplayCustomization(note, parentComponent?.componentId, dismissSurface);const editingProps = useEditing(note, isEditable, isCalendarRoot, parentComponent?.componentId,(draft, anchor) => setSelection({ draft, anchor }), effectiveSlotDuration);@@ -368,6 +368,7 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi&& "calendar-event-selected no-tooltip-preview")}eventContent={eventContent}+ eventInnerClass={eventInnerClass}eventDidMount={eventDidMount}viewDidMount={({ view }) => {if (initialView.current !== view.type) {@@ -654,7 +655,7 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u{iconClass && <span className={`calendar-event-icon ${iconClass}`} />}{e.event.title}</div>- {!!promotedAttributes?.length && hasRoomForAttributes(e) && (+ {!!promotedAttributes?.length && roomForAttributes(e) && (<div className="calendar-event-attributes">{(promotedAttributes as Array<[string, string]>).map(([name, value], i) => (<div className="promoted-attribute" key={`${name}-${i}`}>@@ -704,18 +705,43 @@ function useEventDisplayCustomization(parentNote: FNote, componentId: string | u// belongs to the event sheet, which offers what the menu offers and more (see onEventClick).e.el.addEventListener("contextmenu", onContextMenu);}, [ dismissSurface ]);- return { eventContent, eventDidMount };+ return { eventContent, eventDidMount, eventInnerClass };}/**- * Whether a chip has the room to say anything beyond its title.+ * Whether a chip has the room to say anything beyond its title, and how that room is come by.*- * Only a timed event on a time grid stacks its content, and only where it is tall enough to. A row- * event — a month cell's chip, an all-day band — is one centred line however wide it gets, so- * attributes put there crowd the title along it rather than fall beneath it.+ * A timed event on a time grid stacks its content of its own accord, wherever it is tall enough to:+ * the attributes follow the title down the column with nothing further asked of the chip.+ *+ * Every other chip is a row — a month cell's, an all-day band's, a list item's — one centred line+ * however wide it gets, so attributes put there would crowd the title along it. A month cell is+ * wide enough for the row to be worth wrapping instead, which is what puts them beneath the title+ * there, where they stood before v7 (see eventInnerClass). A cell too narrow to hold much of a+ * title, the all-day bands and the lists are left as one line.+ */+export function roomForAttributes(e: EventDisplayInfo): "stacked" | "wrapped" | null {+ if (e.view.type === "dayGridMonth") {+ return !e.isNarrow ? "wrapped" : null;+ }++ if (e.view.type.startsWith("timeGrid")) {+ return (!e.event.allDay && !e.isShort) ? "stacked" : null;+ }++ return null;+}++/**+ * Turns the chip's inner — Forma's, and a row wherever this says anything at all — into something+ * the attributes can fall beneath: a row that wraps, of which they claim a whole line (see+ * index.css). Said as a class on the inner rather than drawn in eventContent because wrapping is+ * the container's to declare and the container is the theme's, not ours.*/-function hasRoomForAttributes(e: EventDisplayInfo) {- return e.view.type.startsWith("timeGrid") && !e.event.allDay && !e.isShort;+function eventInnerClass(e: EventDisplayInfo) {+ const { promotedAttributes } = e.event.extendedProps;+ return clsx(!!promotedAttributes?.length && roomForAttributes(e) === "wrapped"+ && "calendar-event-inner-wrapped");}function useOnDatesSet(calendarRef: RefObject<FullCalendar>) {