Skip to content

Build your personal knowledge base with Trilium Notes

feat(calendar): pick a new event's template in a field of its own

Elian Doran53cb4d8a45ca
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0029ec2fd6..8bce40bbe9 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3693,7 +3693,8 @@
"event_templates_hint": "Choose what note types and note templates you would like to use when creating new calendar events.",
"new_template_name": "New event template",
"event_template": "Select an event template",
- "more_templates": "More templates…"
+ "more_templates": "More templates…",
+ "template": "Template"
},
"ocr": {
"extracted_text": "Extracted Text (OCR)",
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index e297ae49d4..7803a65390 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -16,7 +16,7 @@ import {
import server from "../../../services/server";
import ws from "../../../services/ws";
import toast from "../../../services/toast";
-import { offeredTemplateIds } from "../../react/TemplatePill";
+import { offeredTemplateIds } from "../../react/TemplateDropdown";
import {
type PromotedAttribute, resolvePromotedAttributes, storedPromotedAttributes,
visiblePromotedAttributeNames
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index a7d564621a..9dea3aca49 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -40,7 +40,7 @@ const MIN_CARD_HEIGHT = 32;
/** How long an open takes. Matches `--board-expand-duration` in the board's own rules. */
export const EXPAND_MS = 200;
import NoteLink from "../../react/NoteLink";
-import TemplatePill, { type TemplateChoice } from "../../react/TemplatePill";
+import TemplateDropdown, { type TemplateChoice } from "../../react/TemplateDropdown";
import {
BoardActionsContext, BoardDragStateContext, BoardEditingContext, BoardOverlayHostContext,
BoardSelectionModeContext
@@ -1148,9 +1148,10 @@ function AddNewItem({
// the card itself.
openPlacements={!insert && !isSorted ? openCreateCardMenu : undefined}
footer={(hold) => (
- <TemplatePill
+ <TemplateDropdown
{...cardTemplates}
{...hold}
+ pill
title={t("board_view.card-template")}
moreText={t("board_view.more-templates")}
/>
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index fcf49151de..f4743008a9 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -2523,7 +2523,7 @@ describe("Board column rename", () => {
"Text", "Markdown", "Canvas", "Spreadsheet", "board_view.more-templates"
]);
// The one a card would be made from is ticked, rather than standing out by its background.
- expect(items.map(item => !!item.querySelector(".template-pill-current")))
+ expect(items.map(item => !!item.querySelector(".template-dropdown-current")))
.toEqual([ true, false, false, false, false ]);
expect(items.some(item => item.classList.contains("active"))).toBe(false);
@@ -2543,7 +2543,7 @@ describe("Board column rename", () => {
});
const reopened = [ ...document.querySelectorAll<HTMLElement>(".template-pill") ].at(-1);
expect([ ...(reopened?.querySelectorAll(".dropdown-item") ?? []) ]
- .map(item => !!item.querySelector(".template-pill-current")))
+ .map(item => !!item.querySelector(".template-dropdown-current")))
.toEqual([ false, false, true, false, false ]);
await type(editor, "Drawn");
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 68f0637eab..22d2673da0 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -38,7 +38,7 @@ import {
useTrackedElement, useTriliumEvent
} from "../../react/hooks";
import OverlayControlGroup, { OverlayControlButton } from "../../react/OverlayControlGroup";
-import { type TemplateChoiceConfig, useTemplateChoice } from "../../react/TemplatePill";
+import { type TemplateChoiceConfig, useTemplateChoice } from "../../react/TemplateDropdown";
import { ShortcutHintOverlayButton } from "../../shortcut_hints/shortcut_hint_button";
import { onWheelHorizontalScroll } from "../../widget_utils";
import { useDragPan } from "../../react/drag_pan";
diff --git a/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx b/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx
index 2758b15182..fea961a46f 100644
--- a/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx
+++ b/apps/client/src/widgets/collections/calendar/CalendarProperties.tsx
@@ -6,7 +6,7 @@ import type FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import Modal from "../../react/Modal";
import TemplateSelectionCard from "../../react/TemplateSelectionCard";
-import { offeredTemplateIds } from "../../react/TemplatePill";
+import { offeredTemplateIds } from "../../react/TemplateDropdown";
import { type CalendarViewData, DEFAULT_EVENT_TEMPLATES } from "./api";
/** The calendar's settings that the collection properties bar does not hold. */
diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.css b/apps/client/src/widgets/collections/calendar/GhostPopover.css
index 9d288ec698..dedf1b9c0e 100644
--- a/apps/client/src/widgets/collections/calendar/GhostPopover.css
+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.css
@@ -18,15 +18,14 @@
gap: 10px;
}
- .calendar-ghost-actions {
- display: flex;
- justify-content: space-between;
- align-items: center;
- gap: 8px;
+ .calendar-ghost-when .template-dropdown {
+ flex: 0 1 auto;
+ min-width: 0;
}
- .calendar-ghost-actions .template-pill {
- min-width: 0;
+ .calendar-ghost-actions {
+ display: flex;
+ justify-content: flex-end;
}
}
diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx b/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx
index 30d6fd9572..b0c2a53a1a 100644
--- a/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx
+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.spec.tsx
@@ -3,7 +3,7 @@ import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { type NoteTypeOption } from "../../../services/note_types";
-import { type TemplateChoice } from "../../react/TemplatePill";
+import { type TemplateChoice } from "../../react/TemplateDropdown";
import GhostPopover from "./GhostPopover";
import { EventDraft } from "./selection";
@@ -50,7 +50,7 @@ describe("GhostPopover", () => {
container));
}
- /** The button that asks for the note, beside the template pill. */
+ /** The button that asks for the note. */
const createButton = () => document.querySelector<HTMLButtonElement>(".calendar-ghost-actions .btn-primary");
const titleInput = () => document.querySelector<HTMLInputElement>(".calendar-ghost-body input");
const timeInputs = () => [ ...document.querySelectorAll<HTMLInputElement>(".calendar-ghost-body input[type=time]") ];
@@ -133,14 +133,20 @@ describe("GhostPopover", () => {
};
const onCommit = vi.fn().mockResolvedValue(undefined);
const choice = { offered: [ TEXT, canvas ], onSelect() {}, onMore() {} };
- const pillName = () => document.querySelector(".calendar-ghost-actions .template-pill-name");
+ const field = () => document.querySelector(".calendar-ghost-when .template-dropdown");
+ const fieldName = () => field()?.querySelector(".template-dropdown-name")?.textContent;
mount(onCommit, { ...choice, current: TEXT });
- expect(pillName()?.textContent).toBe("Text");
+ // A row of the form like the dates, led by its own icon and showing the template's.
+ const row = field()?.closest(".calendar-event-row");
+ expect(row?.querySelector(".calendar-event-row-icon.bx-copy")).not.toBeNull();
+ expect(field()?.querySelector(".select-button .bx-note")).not.toBeNull();
+ expect(field()?.classList.contains("template-pill")).toBe(false);
+ expect(fieldName()).toBe("Text");
// A pick is stored by the calendar, which hands the ghost the new choice.
mount(onCommit, { ...choice, current: canvas });
- expect(pillName()?.textContent).toBe("Canvas");
+ expect(fieldName()).toBe("Canvas");
await act(async () => { createButton()?.click(); });
expect(onCommit).toHaveBeenCalledWith("", draft, canvas);
diff --git a/apps/client/src/widgets/collections/calendar/GhostPopover.tsx b/apps/client/src/widgets/collections/calendar/GhostPopover.tsx
index 0faa7d53c6..13b2e8afe6 100644
--- a/apps/client/src/widgets/collections/calendar/GhostPopover.tsx
+++ b/apps/client/src/widgets/collections/calendar/GhostPopover.tsx
@@ -10,8 +10,9 @@ import Button from "../../react/Button";
import FormTextBox from "../../react/FormTextBox";
import Modal from "../../react/Modal";
import Popover from "../../react/Popover";
-import TemplatePill, { type TemplateChoice } from "../../react/TemplatePill";
+import TemplateDropdown, { type TemplateChoice } from "../../react/TemplateDropdown";
import { EventDatesFields } from "./EventDatesEditor";
+import { EventRow } from "./EventField";
import { AnchorPoint, EventDraft, narrowAnchorRect, normalizeEventDates } from "./selection";
/**
@@ -37,7 +38,7 @@ export default function GhostPopover({
anchor: AnchorPoint | null;
/** The calendar the range's shading is read out of (see {@link ghostAnchorRect}). */
container: HTMLElement | null;
- /** What the event is made from, picked with the pill beside the create button. */
+ /** What the event is made from, picked in the row below the dates. */
templates: TemplateChoice;
/** Answers when the note has been made, or rejects having failed to make one — the ghost stays
* up for a second try either way it is told (see {@link commit}). */
@@ -114,14 +115,16 @@ export default function GhostPopover({
<div className="calendar-ghost-when">
<EventDatesFields value={draft} onChange={setDraft} />
+ <EventRow icon="bx-copy" title={t("calendar_view.template")}>
+ <TemplateDropdown
+ {...templates}
+ title={t("calendar_view.event_template")}
+ moreText={t("calendar_view.more_templates")}
+ />
+ </EventRow>
</div>
<div className="calendar-ghost-actions">
- <TemplatePill
- {...templates}
- title={t("calendar_view.event_template")}
- moreText={t("calendar_view.more_templates")}
- />
<Button
kind="primary"
text={t("calendar_view.create_event")}
diff --git a/apps/client/src/widgets/collections/calendar/api.ts b/apps/client/src/widgets/collections/calendar/api.ts
index 58ef58d149..95a960e259 100644
--- a/apps/client/src/widgets/collections/calendar/api.ts
+++ b/apps/client/src/widgets/collections/calendar/api.ts
@@ -7,7 +7,7 @@ import { t } from "../../../services/i18n";
import note_create from "../../../services/note_create";
import { deleteNoteOrBranch } from "../../../services/note_deletion";
import { type NoteTypeOption } from "../../../services/note_types";
-import { type TemplateChoiceConfig } from "../../react/TemplatePill";
+import { type TemplateChoiceConfig } from "../../react/TemplateDropdown";
import { EventLabelName } from "./utils";
/** What the calendar stores in its view config. */
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 4f087b5439..8269b89d7e 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -31,7 +31,7 @@ import Dropdown from "../../react/Dropdown";
import { FormListItem } from "../../react/FormList";
import { useEffectiveReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteTypeOptions, useSpacedUpdate, useTriliumEvent, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";
import { ParentComponent } from "../../react/react_utils";
-import { offeredTemplateIds, useTemplateChoice } from "../../react/TemplatePill";
+import { offeredTemplateIds, useTemplateChoice } from "../../react/TemplateDropdown";
import { ViewModeProps } from "../interface";
import { type CalendarViewData, changeEvent, DEFAULT_EVENT_TEMPLATES, newEvent } from "./api";
import Calendar from "./calendar";
diff --git a/apps/client/src/widgets/react/TemplatePill.css b/apps/client/src/widgets/react/TemplateDropdown.css
similarity index 67%
rename from apps/client/src/widgets/react/TemplatePill.css
rename to apps/client/src/widgets/react/TemplateDropdown.css
index 66f2a6c469..2f80cf82f0 100644
--- a/apps/client/src/widgets/react/TemplatePill.css
+++ b/apps/client/src/widgets/react/TemplateDropdown.css
@@ -1,3 +1,17 @@
+.template-dropdown .template-dropdown-name {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.template-dropdown .template-dropdown-button {
+ display: flex;
+ align-items: center;
+ gap: 0.4em;
+ max-width: 100%;
+ text-align: start;
+}
+
.template-pill .template-pill-button {
display: flex;
align-items: center;
@@ -18,18 +32,12 @@
color: var(--main-text-color);
}
-.template-pill .template-pill-name {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.tn-dropdown-portal.template-pill .dropdown-item {
+.tn-dropdown-portal.template-dropdown .dropdown-item {
display: flex;
align-items: center;
}
-.tn-dropdown-portal.template-pill .template-pill-current {
+.tn-dropdown-portal.template-dropdown .template-dropdown-current {
margin-inline-start: auto;
padding-inline-start: 1.5em;
}
diff --git a/apps/client/src/widgets/react/TemplatePill.spec.tsx b/apps/client/src/widgets/react/TemplateDropdown.spec.tsx
similarity index 97%
rename from apps/client/src/widgets/react/TemplatePill.spec.tsx
rename to apps/client/src/widgets/react/TemplateDropdown.spec.tsx
index 451b88d76e..efe1f1ba64 100644
--- a/apps/client/src/widgets/react/TemplatePill.spec.tsx
+++ b/apps/client/src/widgets/react/TemplateDropdown.spec.tsx
@@ -4,13 +4,13 @@ import { describe, expect, it, vi } from "vitest";
import { type NoteTypeOption } from "../../services/note_types";
import { renderInto } from "../../test/render";
-import { offeredTemplateIds, type TemplateChoice, useTemplateChoice } from "./TemplatePill";
+import { offeredTemplateIds, type TemplateChoice, useTemplateChoice } from "./TemplateDropdown";
function option(id: string, title: string): NoteTypeOption {
return { id, title, icon: "bx bx-note", group: "type", options: { type: "text" } };
}
-describe("TemplatePill", () => {
+describe("TemplateDropdown", () => {
it("offers the stored templates, or the defaults while none are stored", () => {
const defaults = [ "type:text:text/html" ];
diff --git a/apps/client/src/widgets/react/TemplatePill.tsx b/apps/client/src/widgets/react/TemplateDropdown.tsx
similarity index 79%
rename from apps/client/src/widgets/react/TemplatePill.tsx
rename to apps/client/src/widgets/react/TemplateDropdown.tsx
index bd20208e81..41d22a2586 100644
--- a/apps/client/src/widgets/react/TemplatePill.tsx
+++ b/apps/client/src/widgets/react/TemplateDropdown.tsx
@@ -1,6 +1,7 @@
-import "./TemplatePill.css";
+import "./TemplateDropdown.css";
import { type NoteTypeId } from "@triliumnext/commons";
+import clsx from "clsx";
import { useMemo, useState } from "preact/hooks";
import {
@@ -23,7 +24,7 @@ export interface TemplateChoice {
/**
* What a collection stores about its templates in its view config. Extended by the view config of
- * every collection that offers a {@link TemplatePill}.
+ * every collection that offers a {@link TemplateDropdown}.
*/
export interface TemplateChoiceConfig {
/**
@@ -39,16 +40,19 @@ export interface TemplateChoiceConfig {
* A dropdown naming what a new note will be made from, listing what the collection offers and a
* way to the dialog that decides what that is.
*
- * The pill reports a pick rather than storing one, so the collection decides where the last used
- * template is kept.
+ * Drawn as a select button showing the template's icon and name, or with `pill` as a small chip
+ * showing the name alone. The dropdown reports a pick rather than storing one, so the collection
+ * decides where the last used template is kept.
*/
-export default function TemplatePill({
- offered, current, onSelect, onMore, title, moreText, onOpened, onClosed
+export default function TemplateDropdown({
+ offered, current, onSelect, onMore, title, moreText, pill, onOpened, onClosed
}: TemplateChoice & {
/** The tooltip of the button, naming what is created. */
title: string;
/** The label of the entry that calls `onMore`. */
moreText: string;
+ /** Draws the button as a chip naming the template, for a field that has no room for more. */
+ pill?: boolean;
/**
* Called as the dropdown opens and closes, for a host that closes on losing focus: the menu
* takes the focus while it is open.
@@ -68,18 +72,21 @@ export default function TemplatePill({
{template.title}
{/* A check mark rather than a highlight, which reads as the row under the pointer. */}
{template.id === current?.id && (
- <Icon className="template-pill-current" icon="bx bx-check" />
+ <Icon className="template-dropdown-current" icon="bx bx-check" />
)}
</FormListItem>
)), [ offered, current, onSelect ]);
return (
<Dropdown
- className="template-pill"
- buttonClassName="template-pill-button"
- text={<span className="template-pill-name">{current?.title ?? ""}</span>}
+ className={clsx("template-dropdown", pill && "template-pill")}
+ buttonClassName={pill ? "template-pill-button" : "template-dropdown-button"}
+ text={<>
+ {!pill && current && <Icon icon={current.icon} />}
+ <span className="template-dropdown-name">{current?.title ?? ""}</span>
+ </>}
title={title}
- noSelectButtonStyle
+ noSelectButtonStyle={pill}
onShown={() => {
setIsShown(true);
onOpened?.();
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.html
index dcc69f8986..02ae50f6a6 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
@@ -38,10 +38,10 @@
clicks. Add a title optionally and press the <em>Create</em> button. If no
title is provided, the event will follow the&nbsp;<a class="reference-link"
href="#root/_help_47ZrP6FNuoG8">Default Note Title</a>&nbsp;rules.</p>
-<p>The template the event's note is made from is shown at the bottom of the
- popup, next to the <em>Create</em> button. To make the event from another
- note type or template, press it and select one from the list; the calendar
- remembers the choice for the next event. Select <em>More templates…</em> to
+<p>The <span class="tn-icon bx bx-copy"></span> template field below the date
+ and time shows the note type or template the event's note is made from.
+ To make the event from another one, press the field and select it from
+ the list; the calendar remembers the choice for the next event. Select <em>More templates…</em> to
change which templates are listed (see <a href="#event-templates">Event templates</a>).</p>
<p>To give the event a time before creating it (for example, after clicking
a day in the month view), press <em>Add time</em> and set the start and end
diff --git a/docs/User Guide/User Guide/Collections/Calendar.md b/docs/User Guide/User Guide/Collections/Calendar.md
index 4edffb6fa7..b1cf269a54 100644
--- a/docs/User Guide/User Guide/Collections/Calendar.md
+++ b/docs/User Guide/User Guide/Collections/Calendar.md
@@ -28,7 +28,7 @@ In either cases, a small popup will show with a prompt for a title and the date
At this point, the event hasn't been created yet to protect against accidental clicks. Add a title optionally and press the _Create_ button. If no title is provided, the event will follow the <a class="reference-link" href="../Advanced%20Usage/Default%20Note%20Title.md">Default Note Title</a> rules.
-The template the event's note is made from is shown at the bottom of the popup, next to the _Create_ button. To make the event from another note type or template, press it and select one from the list; the calendar remembers the choice for the next event. Select _More templates…_ to change which templates are listed (see [Event templates](#event-templates)).
+The <span class="tn-icon bx bx-copy"></span> template field below the date and time shows the note type or template the event's note is made from. To make the event from another one, press the field and select it from the list; the calendar remembers the choice for the next event. Select _More templates…_ to change which templates are listed (see [Event templates](#event-templates)).
To give the event a time before creating it (for example, after clicking a day in the month view), press _Add time_ and set the start and end time; the duration is shown to the right of them. To make the event all-day again, press the <span class="tn-icon bx bx-x"></span> button at the end of the row. Adding or removing a time keeps the dates, so an event can start at a time on one day and end at a time on another (for example, a night shift). Changing the start date or time moves the end by the same amount, keeping the duration. An empty end date means the event ends on the day it starts; setting the end time before the start time moves the end date to the next day.