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): leave the dates out of the event attributes card
Elian Doran3a29b3a906a0
diff --git a/apps/client/src/widgets/collections/calendar/CalendarProperties.spec.tsx b/apps/client/src/widgets/collections/calendar/CalendarProperties.spec.tsxindex a3589528d1..a466fcf3d5 100644--- a/apps/client/src/widgets/collections/calendar/CalendarProperties.spec.tsx+++ b/apps/client/src/widgets/collections/calendar/CalendarProperties.spec.tsx@@ -44,10 +44,12 @@ vi.mock("../../react/TemplateSelectionCard", () => ({// and where onChange writes.vi.mock("../../react/PromotedAttributesCard", () => ({default: ({- heading, instruction, settings, drawnByCollection, itemNotes, unarrangedHidden, onChange+ heading, instruction, settings, drawnByCollection, itemNotes, unarrangedHidden, omitDrawn,+ onChange}: {heading: string, instruction: string, settings?: { name: string }[],drawnByCollection?: string[], itemNotes?: FNote[], unarrangedHidden?: boolean,+ omitDrawn?: boolean,onChange: (attributes: { name: string, hidden: boolean }[]) => void}) => (<div@@ -58,6 +60,7 @@ vi.mock("../../react/PromotedAttributesCard", () => ({data-drawn={drawnByCollection?.join(",")}data-items={itemNotes?.map((item) => item.noteId).join(",")}data-unarranged-hidden={String(!!unarrangedHidden)}+ data-omit-drawn={String(!!omitDrawn)}onClick={() => onChange([{ name: "mood", hidden: false }, { name: "where", hidden: true }])}@@ -153,7 +156,8 @@ describe("CalendarProperties", () => {expect(card?.dataset.instruction).toBe("calendar_view.event_attributes_hint");expect(card?.dataset.settings).toBe("mood");expect(card?.dataset.unarrangedHidden).toBe("true");- // The date labels, custom names included, are drawn by the calendar itself.+ expect(card?.dataset.omitDrawn).toBe("true");+ // The calendar draws the date labels itself, custom names included, so the card omits them.expect(card?.dataset.drawn?.split(",")).toEqual(["startDate", "endDate", "startTime", "endTime", "recurrence", "myStart"]);diff --git a/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx b/apps/client/src/widgets/collections/calendar/CalendarProperties.tsxindex 96dbcc60c2..ce6074787f 100644--- a/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx+++ b/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx@@ -71,6 +71,7 @@ export default function CalendarProperties({drawnByCollection={drawnLabels}itemNotes={eventNotes}unarrangedHidden+ omitDrawnonChange={storeAttributes}/>diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsxindex 5525d16c03..904fea29c6 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx+++ b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx@@ -85,6 +85,7 @@ describe("PromotedAttributesCard", () => {let drawnByCollection: string[] | undefined;let itemNotes: FNote[] | undefined;let unarrangedHidden: boolean | undefined;+ let omitDrawn: boolean | undefined;beforeEach(() => {vi.clearAllMocks();@@ -93,6 +94,7 @@ describe("PromotedAttributesCard", () => {drawnByCollection = undefined;itemNotes = undefined;unarrangedHidden = undefined;+ omitDrawn = undefined;defined = [ definition("label:dueDate", { alias: "Due" }), definition("label:owner") ];mocks.detail.opts = null;mocks.confirm.mockResolvedValue(true);@@ -153,6 +155,17 @@ describe("PromotedAttributesCard", () => {expect(stored).toEqual([]);});+ /** A calendar always draws its dates itself, so a row for them could never be switched on. */+ it("leaves out what the collection draws itself, for a collection that asks", () => {+ settings = [ { name: "owner" }, { name: "dueDate" } ];+ drawnByCollection = [ "owner" ];+ omitDrawn = true;+ draw();++ expect(names()).toEqual([ "Due" ]);+ expect(shown()).toEqual([ true ]);+ });+/*** The collection can change what it draws itself while the card stands: a board is regrouped* from its header, and this card lives as long as the board does. The marks follow.@@ -532,6 +545,7 @@ describe("PromotedAttributesCard", () => {drawnByCollection={drawnByCollection}itemNotes={itemNotes}unarrangedHidden={unarrangedHidden}+ omitDrawn={omitDrawn}onChange={(attributes) => stored.push(attributes)}/></ParentComponent.Provider>,diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.tsxindex 68259894ef..77db39c267 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.tsx+++ b/apps/client/src/widgets/react/PromotedAttributesCard.tsx@@ -61,6 +61,11 @@ export interface PromotedAttributesCardProps {* little room. A definition created from this card is shown all the same.*/unarrangedHidden?: boolean;+ /**+ * Leaves out what `drawnByCollection` names, for a collection that always draws those itself,+ * such as a calendar's dates. Otherwise they are listed with their switch held off.+ */+ omitDrawn?: boolean;/** Called with the whole list after every change, for the caller to store. */onChange: (attributes: PromotedAttribute[]) => void;}@@ -73,10 +78,12 @@ export interface PromotedAttributesCardProps {* reports the order and what is hidden, which the caller stores.*/export default function PromotedAttributesCard({- heading, instruction, note, settings, drawnByCollection, itemNotes, unarrangedHidden, onChange+ heading, instruction, note, settings, drawnByCollection, itemNotes, unarrangedHidden, omitDrawn,+ onChange}: PromotedAttributesCardProps) {const resolve = (stored: PromotedAttributeSetting[] | undefined) => resolvePromotedAttributes(- note, stored, drawnByCollection, itemNotes, { unarrangedHidden });+ note, stored, drawnByCollection, itemNotes, { unarrangedHidden })+ .filter((attribute) => !omitDrawn || !attribute.drawnByCollection);const [ shown, setShown ] = useState(() => resolve(settings));const shownRef = useRef(shown);shownRef.current = shown;@@ -89,10 +96,12 @@ export default function PromotedAttributesCard({const [ lastDrawn, setLastDrawn ] = useState(drawn);if (lastDrawn !== drawn) {setLastDrawn(drawn);- setShown((was) => was.map((attribute) => ({- ...attribute,- drawnByCollection: drawnByCollection?.includes(attribute.name) ?? false- })));+ setShown((was) => omitDrawn+ ? resolve(storedPromotedAttributes(was))+ : was.map((attribute) => ({+ ...attribute,+ drawnByCollection: drawnByCollection?.includes(attribute.name) ?? false+ })));}// A card that joins through a branch change brings no attribute row for `entitiesReloaded`, so// the list is resolved again when the definition names of `itemNotes` change.diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.htmlindex 0c87613e13..0f8506871f 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Calendar.html@@ -199,8 +199,8 @@<li>Create a new attribute, which is shown on the events right away, or editor delete one the calendar defines.</li></ul>-<p>The dates, times and recurrence of the events are drawn by the calendar- itself, so they are listed but cannot be switched on.</p>+<p>The dates, times and recurrence of the events are not listed, as the calendar+ always shows them itself.</p><p>If an event has a <code>#calendar:displayedAttributes</code> label, includingone inherited from the calendar, the attributes listed in that label areshown instead.</p>diff --git a/docs/User Guide/User Guide/Collections/Calendar.md b/docs/User Guide/User Guide/Collections/Calendar.mdindex 0b65562a5e..32bd155f3b 100644--- a/docs/User Guide/User Guide/Collections/Calendar.md+++ b/docs/User Guide/User Guide/Collections/Calendar.md@@ -119,7 +119,7 @@ Events can show the values of their attributes below their title, in the month v* Drag an attribute by its handle to change the order in which the events show them.* Create a new attribute, which is shown on the events right away, or edit or delete one the calendar defines.-The dates, times and recurrence of the events are drawn by the calendar itself, so they are listed but cannot be switched on.+The dates, times and recurrence of the events are not listed, as the calendar always shows them itself.If an event has a `#calendar:displayedAttributes` label, including one inherited from the calendar, the attributes listed in that label are shown instead.