Skip to content

Build your personal knowledge base with Trilium Notes

client/ui/popup editor: add a flag to show the note type switcher

Adorian Doran0b718d245f84
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 7dc33f55e4..1d3e2833ad 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -162,7 +162,12 @@ export type CommandMappings = {
openNewNoteSplit: NoteCommandData;
openInWindow: NoteCommandData;
/** Opens a note in the quick-edit popup. A `viewScope` carrying an `attachmentId` opens that attachment instead of the note itself. */
- openInPopup: CommandData & { noteIdOrPath: string; viewScope?: ViewScope; };
+ openInPopup: CommandData & {
+ noteIdOrPath: string;
+ viewScope?: ViewScope;
+ /** Offers the note type switcher while the note is still blank, as the tab layout does. */
+ showNoteTypeSwitcher?: boolean;
+ };
/** Dismisses the quick-edit popup, for something within it that has sent the reader elsewhere. Does nothing if it isn't open. */
closePopupEditor: CommandData;
openInTreePopup: CommandData & { noteIdOrPath: string; hoistedNoteId: string; };
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.css b/apps/client/src/widgets/dialogs/PopupEditor.css
index 0819b0adc2..00fe43d33b 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.css
+++ b/apps/client/src/widgets/dialogs/PopupEditor.css
@@ -37,6 +37,14 @@ body.mobile .modal.popup-editor-dialog .modal-dialog {
font-size: 1.1em;
}
+/* Pinned to the foot of the dialog rather than following the content, which has no room set
+ aside for it. Anchored to `.modal-content`, which Bootstrap positions. */
+.modal.popup-editor-dialog .note-type-switcher {
+ position: absolute;
+ inset-block: auto 12px;
+ inset-inline: 12px;
+}
+
/* The note-title header (icon + editable title) is shared with the tree popup, the calendar's event
sheet and the geo map's marker sheet, which reuse the same TitleRow; keep the selectors together
so the dialogs stay pixel-identical. This file is loaded wherever the app is: the quick editor
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx
index 244656dce7..009108cdf9 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx
@@ -108,6 +108,9 @@ vi.mock("../FloatingButtonsDefinitions", () => ({
vi.mock("../PromotedAttributes", () => ({ default: () => null }));
vi.mock("../ReadOnlyNoteInfoBar", () => ({ default: () => null }));
vi.mock("../layout/NoteBadges", () => ({ default: () => null }));
+vi.mock("../layout/NoteTypeSwitcher", () => ({
+ default: () => <div className="note-type-switcher-stub" />
+}));
vi.mock("../ribbon/components/StandaloneRibbonAdapter", () => ({ default: () => null }));
vi.mock("../ribbon/FormattingToolbar", () => ({ default: () => null, showFormattingToolbar: () => false }));
vi.mock("../type_widgets/text/mobile_editor_toolbar", () => ({ default: () => <div className="mobile-toolbar-stub" /> }));
@@ -133,7 +136,9 @@ function fakeNote(labels: string[] = [], isOptions = false) {
let container: HTMLDivElement;
let parent: Component;
-async function openPopup(data: { noteIdOrPath: string, viewScope?: ViewScope }) {
+async function openPopup(
+ data: { noteIdOrPath: string, viewScope?: ViewScope, showNoteTypeSwitcher?: boolean }
+) {
await act(async () => {
await parent.handleEvent("openInPopup", data as never);
});
@@ -417,6 +422,22 @@ describe("PopupEditor", () => {
underlying.remove();
});
+ /**
+ * The switcher offers the note types a note can still become, which only the caller knows is
+ * wanted: a template opened to be written is, an attachment or a note map is not.
+ */
+ it("offers the note type switcher only where the caller asked for it", async () => {
+ await openPopup({ noteIdOrPath: "n1" });
+ expect(container.querySelector(".note-type-switcher-stub")).toBeNull();
+
+ await openPopup({ noteIdOrPath: "n1", showNoteTypeSwitcher: true });
+ expect(container.querySelector(".note-type-switcher-stub")).not.toBeNull();
+
+ // And gone again for the next note opened without it.
+ await openPopup({ noteIdOrPath: "n1" });
+ expect(container.querySelector(".note-type-switcher-stub")).toBeNull();
+ });
+
it("gives mobile its own toolbar and hides the buttons that make no sense in a popup", async () => {
expect(container.querySelector(".mobile-toolbar-stub")).toBeNull();
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsx
index 5a8c9943a1..62ea947ef6 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx
@@ -13,6 +13,7 @@ import utils from "../../services/utils";
import NoteList from "../collections/NoteList";
import FloatingButtons from "../FloatingButtons";
import { DESKTOP_FLOATING_BUTTONS, POPUP_HIDDEN_FLOATING_BUTTONS } from "../FloatingButtonsDefinitions";
+import NoteTypeSwitcher from "../layout/NoteTypeSwitcher";
import TitleRow from "../layout/TitleRow";
import NoteDetail from "../NoteDetail";
import PromotedAttributes from "../PromotedAttributes";
@@ -35,6 +36,7 @@ const COVERED_LAYER = 1090;
export default function PopupEditor() {
const [ shown, setShown ] = useState(false);
const [ stacked, setStacked ] = useState(false);
+ const [ switchable, setSwitchable ] = useState(false);
const parentComponent = useContext(ParentComponent);
const [ noteContext, setNoteContext ] = useState(() => new NoteContext("_popup-editor"));
const modalRef = useRef<HTMLDivElement>(null);
@@ -44,7 +46,7 @@ export default function PopupEditor() {
return baseItems.filter(item => !POPUP_HIDDEN_FLOATING_BUTTONS.includes(item));
}, [ isMobile ]);
- useTriliumEvent("openInPopup", async ({ noteIdOrPath, viewScope }) => {
+ useTriliumEvent("openInPopup", async ({ noteIdOrPath, viewScope, showNoteTypeSwitcher }) => {
const noteId = tree.getNoteIdAndParentIdFromUrl(noteIdOrPath);
if (!noteId.noteId) return;
const note = await froca.getNote(noteId.noteId);
@@ -58,6 +60,7 @@ export default function PopupEditor() {
const noteContext = new NoteContext("_popup-editor");
setStacked(!!document.querySelector(".modal.show"));
+ setSwitchable(!!showNoteTypeSwitcher);
const hasUserSetNoteReadOnly = note.hasLabel("readOnly");
await noteContext.setNote(noteIdOrPath, {
@@ -191,6 +194,7 @@ export default function PopupEditor() {
<FloatingButtons items={items} />
<NoteDetail />
<NoteList media="screen" displayOnlyCollections />
+ {switchable && <NoteTypeSwitcher note={noteContext.note} />}
</Modal>
</DialogWrapper>
</NoteContextContext.Provider>