Skip to content

Build your personal knowledge base with Trilium Notes

feat(table): add a properties dialog for the included notes

Elian Doranfad39b4a13ff
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 85a61f79fd..f32a0824f9 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3525,7 +3525,9 @@
"delete_column_confirmation": "Are you sure you want to delete this column? The corresponding attribute will be removed from all notes.",
"delete-column": "Delete column...",
"new-column-label": "Label...",
- "new-column-relation": "Relation..."
+ "new-column-relation": "Relation...",
+ "properties": "Table properties...",
+ "properties-title": "Table properties"
},
"book_properties_config": {
"board-inbox-column": "Show inbox column",
diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx
index 4ff156598c..472b352e64 100644
--- a/apps/client/src/widgets/collections/table/index.tsx
+++ b/apps/client/src/widgets/collections/table/index.tsx
@@ -7,9 +7,12 @@ import { DataTreeModule, EditModule, FormatModule, FrozenColumnsModule, Interact
import { t } from "../../../services/i18n";
import SpacedUpdate from "../../../services/spaced_update";
-import CollectionProperties from "../../note_bars/CollectionProperties";
+import CollectionProperties, {
+ CollectionPropertiesDialog, IncludedNotesCard
+} from "../../note_bars/CollectionProperties";
import Button, { ButtonOrActionButton } from "../../react/Button";
-import { useEffectiveReadOnly, useNoteContext } from "../../react/hooks";
+import { FormListItem } from "../../react/FormList";
+import { useEffectiveReadOnly, useNoteContext, useTriliumEvent } from "../../react/hooks";
import { ParentComponent } from "../../react/react_utils";
import { ViewModeProps } from "../interface";
import { useContextMenu } from "./context_menu";
@@ -39,6 +42,14 @@ export default function TableView({ note, noteIds, viewConfig, saveConfig }: Vie
const { noteContext } = useNoteContext();
const isReadOnly = useEffectiveReadOnly(note, noteContext);
const canAddRows = !isReadOnly && note.type !== "search";
+ const [ isEditingProperties, setIsEditingProperties ] = useState(false);
+
+ // The note actions menu offers the properties dialog, which lives here rather than in the menu.
+ useTriliumEvent("showCollectionProperties", ({ ntxId }) => {
+ if (ntxId === noteContext?.ntxId && !isReadOnly) {
+ setIsEditingProperties(true);
+ }
+ });
const contextMenuEvents = useContextMenu(note, parentComponent, tabulatorRef, isReadOnly);
const persistenceProps = usePersistence(viewConfig, saveConfig);
const [ editingEvents, setEditingEvents ] = useState<TableEditingEvents>();
@@ -73,6 +84,11 @@ export default function TableView({ note, noteIds, viewConfig, saveConfig }: Vie
<div className="table-view">
<CollectionProperties
note={note}
+ optionsChildren={!isReadOnly && (
+ <FormListItem icon="bx bx-cog" onClick={() => setIsEditingProperties(true)}>
+ {t("table_view.properties")}
+ </FormListItem>
+ )}
rightChildren={canAddRows &&
<>
<ButtonOrActionButton triggerCommand="addNewRow" icon="bx bx-plus" text={t("table_view.new-row")} />
@@ -134,6 +150,17 @@ export default function TableView({ note, noteIds, viewConfig, saveConfig }: Vie
/>
</Suspense>
)}
+ {isEditingProperties && createPortal(
+ <CollectionPropertiesDialog
+ className="table-properties-dialog"
+ title={t("table_view.properties-title")}
+ show
+ onHidden={() => setIsEditingProperties(false)}
+ >
+ <IncludedNotesCard note={note} />
+ </CollectionPropertiesDialog>,
+ document.body
+ )}
</div>
);
}
diff --git a/apps/client/src/widgets/layout/NoteActions.spec.tsx b/apps/client/src/widgets/layout/NoteActions.spec.tsx
index 3af99b3c68..664484a77d 100644
--- a/apps/client/src/widgets/layout/NoteActions.spec.tsx
+++ b/apps/client/src/widgets/layout/NoteActions.spec.tsx
@@ -120,6 +120,31 @@ describe("NoteContextMenu", () => {
}
});
+ it("offers the properties dialog of the collections that have one", async () => {
+ const hasPropertiesItem = async (viewType: string) => {
+ const note = buildNote({ title: viewType, type: "book", "#viewType": viewType });
+ const noteContext = new NoteContext("ntx-collection");
+ noteContext.noteId = note.noteId;
+ noteContext.viewScope = { viewMode: "default" };
+ render((
+ <ParentComponent.Provider value={new Component()}>
+ <NoteContextContext.Provider value={noteContext}>
+ <NoteContextMenu note={note} noteContext={noteContext} />
+ </NoteContextContext.Provider>
+ </ParentComponent.Provider>
+ ), host);
+ host.querySelector<HTMLButtonElement>("button")?.click();
+ await vi.waitFor(() => expect(document.querySelector(".tn-popup li.dropdown-item")).toBeTruthy());
+ const item = document.querySelector(".tn-popup li.dropdown-item:has(.bx-cog)");
+ render(null, host);
+ return !!item;
+ };
+
+ expect(await hasPropertiesItem("table")).toBe(true);
+ expect(await hasPropertiesItem("geoMap")).toBe(true);
+ expect(await hasPropertiesItem("list")).toBe(false);
+ });
+
it("offers to print a render note only while it has a render target", async () => {
const isPrintEnabled = async (note: FNote) => {
const noteContext = new NoteContext("ntx-render");
diff --git a/apps/client/src/widgets/layout/NoteActions.tsx b/apps/client/src/widgets/layout/NoteActions.tsx
index b3f7fffca6..722349f22c 100644
--- a/apps/client/src/widgets/layout/NoteActions.tsx
+++ b/apps/client/src/widgets/layout/NoteActions.tsx
@@ -85,6 +85,7 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
const isSearchOrBook = ["search", "book"].includes(noteType);
const isBoard = noteType === "book" && viewType === "board";
const isGeoMap = noteType === "book" && viewType === "geoMap";
+ const isTable = noteType === "book" && viewType === "table";
// A calendar root makes day notes rather than events, so it has no templates to configure.
const isEventCalendar = noteType === "book" && viewType === "calendar"
&& !note.hasLabel("calendarRoot") && !note.hasLabel("workspaceCalendarRoot");
@@ -178,9 +179,10 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
{note.type === "render" && <CommandItem command="renderActiveNote" icon="bx bx-extension" text={t("note_actions.re_render_note")}
/>}
- {(isBoard || isEventCalendar || isGeoMap) && <CommandItem icon="bx bx-cog"
+ {(isBoard || isEventCalendar || isGeoMap || isTable) && <CommandItem icon="bx bx-cog"
text={isBoard ? t("board_view.properties")
- : isGeoMap ? t("geo-map.properties") : t("calendar_view.properties")}
+ : isGeoMap ? t("geo-map.properties")
+ : isTable ? t("table_view.properties") : t("calendar_view.properties")}
command={() => parentComponent?.triggerEvent("showCollectionProperties", { ntxId: noteContext?.ntxId })} />}
<FormDropdownSubmenu icon="bx bx-wrench" title={t("note_actions.advanced")}>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.html
index b0d41edf4f..12ce8c6389 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.html
@@ -159,6 +159,9 @@
<li><span class="tn-icon bx bx-cog"></span><em>Geo map properties</em> appears
on a&nbsp;<a class="reference-link" href="#root/_help_81SGnPGMk7Xc">Geo Map</a>,
and configures its map settings and the image of an <a href="#root/_help_ZRDXGc0nAIh4">image map</a>.</li>
+ <li><span class="tn-icon bx bx-cog"></span><em>Table properties</em> appears
+ on a <a class="reference-link" href="#root/_help_2FvYrpmOXm29">Table</a>,
+ and configures which notes it shows.</li>
</ul>
<h2>Advanced</h2>
<p>The <span class="tn-icon bx bx-wrench"></span><em>Advanced</em> submenu
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Table.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Table.html
index fddc55ffac..d7b12d02b3 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Table.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Table.html
@@ -157,8 +157,10 @@
<p>Next to the title of each element there will be a button to expand or
collapse. By default, all items are expanded.</p>
<p>Since nesting is not always desirable, it is possible to limit the nesting
- to a certain number of levels or even disable it completely, by setting
- the <code>#maxNestingDepth</code> <a href="#root/_help_HI6GBBIduIgv">label</a> of
+ to a certain number of levels or even disable it completely. To do so,
+ go to <a class="reference-link" href="#root/_help_8YBEPzcpUgxw">Note menu</a> → <em>Table properties</em> and
+ set <em>Maximum nesting depth</em> (under the <em>Included notes</em> section),
+ or set the <code>#maxNestingDepth</code> <a href="#root/_help_HI6GBBIduIgv">label</a> of
the collection:</p>
<ul>
<li><code>0</code> disables nesting, showing only the children of the collection.</li>
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.md b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.md
index 42ad1ef9bd..718a0ec726 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note menu.md
@@ -65,6 +65,7 @@ The following entries only appear on some notes:
* <span class="tn-icon bx bx-cog"></span>_Board properties_ appears on a <a class="reference-link" href="../../Collections/Kanban%20Board.md">Kanban Board</a>, and configures its columns, card attributes and card templates.
* <span class="tn-icon bx bx-cog"></span>_Calendar properties_ appears on a <a class="reference-link" href="../../Collections/Calendar.md">Calendar</a> that creates events, and configures its event templates.
* <span class="tn-icon bx bx-cog"></span>_Geo map properties_ appears on a <a class="reference-link" href="../../Collections/Geo%20Map.md">Geo Map</a>, and configures its map settings and the image of an [image map](../../Collections/Geo%20Map/Image%20maps.md).
+* <span class="tn-icon bx bx-cog"></span>_Table properties_ appears on a <a class="reference-link" href="../../Collections/Table.md">Table</a>, and configures which notes it shows.
## Advanced
diff --git a/docs/User Guide/User Guide/Collections/Table.md b/docs/User Guide/User Guide/Collections/Table.md
index c485f9a73d..467ea4a2d8 100644
--- a/docs/User Guide/User Guide/Collections/Table.md
+++ b/docs/User Guide/User Guide/Collections/Table.md
@@ -123,7 +123,7 @@ If the child notes of the collection also have their own child notes, then they
Next to the title of each element there will be a button to expand or collapse. By default, all items are expanded.
-Since nesting is not always desirable, it is possible to limit the nesting to a certain number of levels or even disable it completely, by setting the `#maxNestingDepth` [label](../Advanced%20Usage/Attributes/Labels.md) of the collection:
+Since nesting is not always desirable, it is possible to limit the nesting to a certain number of levels or even disable it completely. To do so, go to <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a> → _Table properties_ and set _Maximum nesting depth_ (under the _Included notes_ section), or set the `#maxNestingDepth` [label](../Advanced%20Usage/Attributes/Labels.md) of the collection:
* `0` disables nesting, showing only the children of the collection.
* `1` also shows their children, `2` the level below that, and so on.