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(right pane): keep the outline tab through notes that have none
Elian Dorand65b37504fb7
diff --git a/apps/client/src/widgets/sidebar/RightPaneTabs.tsx b/apps/client/src/widgets/sidebar/RightPaneTabs.tsxindex c7cd1bf12e..eb06aec9f6 100644--- a/apps/client/src/widgets/sidebar/RightPaneTabs.tsx+++ b/apps/client/src/widgets/sidebar/RightPaneTabs.tsx@@ -12,14 +12,24 @@ export interface RightPaneTabDefinition {id: RightPaneTabId;title: string;icon: string;+ /**+ * Keep the tab in the strip for a note it has nothing to show, saying so in its body instead of+ * going away. For a tab whose widgets come and go with the type of the note being read: leaving+ * would take the strip's shape — and, where it is the tab on show, the pane's contents — with it,+ * so that merely moving between notes moves the tabs about under the pointer.+ */+ alwaysShown?: boolean;}/*** The groups the right pane's widgets are divided into, in the order they are offered. A tab with- * nothing to show for the current note is left out entirely, so most notes see fewer than all four.+ * nothing to show for the current note is left out entirely unless it asks to stay, so most notes see+ * fewer than all four.*/export const RIGHT_PANE_TABS: RightPaneTabDefinition[] = [- { id: "outline", title: t("right_pane.tab_outline"), icon: "bx bx-list-ul" },+ // The outline is what a note's type decides the most: a text note has headings, a PDF has pages,+ // an image has neither. It stays put through all of them.+ { id: "outline", title: t("right_pane.tab_outline"), icon: "bx bx-list-ul", alwaysShown: true },{ id: "attributes", title: t("right_pane.tab_attributes"), icon: "bx bx-hash" },{ id: "chat", title: t("right_pane.tab_chat"), icon: "bx bx-bot" },// Widgets contributed by the user's own scripts, which belong to none of the groups above.diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsxindex d4953bccee..fc9f6a61eb 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx@@ -28,6 +28,16 @@ describe("groupIntoTabs", () => {it("has nothing to show when no widget is enabled", () => {expect(groupIntoTabs([ widget("outline", { enabled: false }) ])).toEqual([]);});++ it("keeps a tab that asks to stay, empty, so that reading another note does not move the strip", () => {+ const attributes = widget("attributes");+ const tabs = groupIntoTabs([ attributes, widget("outline", { enabled: false }) ], true);++ // The outline is the tab that asks; the chat and the widgets go as they did.+ expect(tabs.map((tab) => tab.id)).toEqual([ "outline", "attributes" ]);+ expect(tabs[0].items).toEqual([]);+ expect(tabs[1].items).toEqual([ attributes.el ]);+ });});function widget(tab: RightPanelWidgetDefinition["tab"], overrides: Partial<RightPanelWidgetDefinition> = {}) {diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsxindex 674ce5fd9f..4298c6c356 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx@@ -43,7 +43,7 @@ export interface RightPanelWidgetDefinition {}export interface RightPaneTabContents extends RightPaneTabDefinition {- /** The enabled widgets of this tab, in the order they are shown. Never empty. */+ /** The enabled widgets of this tab, in the order they are shown. Empty only for an always-shown tab. */items: VNode[];}@@ -135,7 +135,11 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare{/* Collapsing the only widget of a tab would leave the tab empty,so a tab of one offers no collapsing at all. */}<CollapsibleWidgets.Provider value={tab.items.length > 1}>- {tab.items}+ {tab.items.length > 0 ? tab.items : (+ // A tab that stays for a note it has nothing to show+ // (see RightPaneTabDefinition.alwaysShown) says so.+ <NoItems icon={tab.icon} text={t("right_pane.empty_message")} />+ )}</CollapsibleWidgets.Provider></div>))}@@ -240,15 +244,20 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent):})];- return groupIntoTabs(definitions);+ // A note-less pane (an empty tab) keeps its own empty state rather than an outline with nothing in+ // it: there is no navigating between notes to keep the strip still for.+ return groupIntoTabs(definitions, !!note);}/**- * Splits the enabled widgets into the pane's tabs, each in position order. A tab with no enabled- * widget is dropped rather than shown empty, which is what makes the strip follow the note: a plain- * image note offers attributes alone, a PDF the whole outline.+ * Splits the enabled widgets into the pane's tabs, each in position order. A tab with no enabled widget+ * is dropped rather than shown empty, which is what makes the strip follow the note: a plain image note+ * offers attributes alone, a PDF the whole outline.+ *+ * @param keepAlwaysShown keeps the tabs that ask to stay (see {@link RightPaneTabDefinition.alwaysShown})+ * even with nothing to show, for the caller to fill with a word to that effect.*/-export function groupIntoTabs(definitions: RightPanelWidgetDefinition[]): RightPaneTabContents[] {+export function groupIntoTabs(definitions: RightPanelWidgetDefinition[], keepAlwaysShown = false): RightPaneTabContents[] {// Assign a position to items that don't have one yet.let pos = 10;for (const definition of definitions) {@@ -264,7 +273,7 @@ export function groupIntoTabs(definitions: RightPanelWidgetDefinition[]): RightPreturn RIGHT_PANE_TABS.map((tab) => ({ ...tab, items: enabled.filter((e) => e.tab === tab.id).map((e) => e.el) }))- .filter((tab) => tab.items.length > 0);+ .filter((tab) => tab.items.length > 0 || (keepAlwaysShown && tab.alwaysShown));}function useSplit(mode: PaneMode) {