Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): give the definitions back a way in, and drop the empty state

Elian Doran0f0d20a53759
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 7b683ff65e..fda7bb58b3 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -802,7 +802,6 @@
"placeholder": "Type the labels and relations here"
},
"attribute_list_panel": {
- "no_attributes": "No attributes",
"section_owned": "Owned",
"section_inherited": "Inherited",
"section_definitions": "Definitions",
@@ -821,6 +820,7 @@
"type_relation_definition": "Relation definition",
"system_hint": "System: this name has a built-in meaning",
"add_attribute": "Add attribute",
+ "add_definition": "Add definition",
"creation_kind_label": "Label: press here, or type ~, to make it a relation",
"creation_kind_relation": "Relation: press here, or type #, to make it a label",
"copy_one": "Copy attribute",
diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
index 83e9217f5c..48ca1e1362 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
@@ -247,11 +247,17 @@ describe("AttributeList", () => {
expect(JSON.parse(options.get("rightPaneCollapsedItems") ?? "[]")).toContain("attributes-definitions");
});
- it("says so, rather than showing an empty list, for a note carrying no attributes at all", () => {
+ it("leaves a note carrying no attributes its heading and the way in, and says nothing besides", () => {
renderPanel(buildNote({ id: "empty", title: "Empty" }));
+ // The run stands, empty. Nothing stands in for its rows: the heading counts them — at zero —
+ // and the add row says what there is to do about it, so any "no attributes" beside those two
+ // would be a third telling of the one fact, and the loudest of the three at that.
expect(container.querySelectorAll(".attribute-row")).toHaveLength(0);
- expect(container.querySelector(".no-items")).not.toBeNull();
+ expect(container.querySelector(".no-items")).toBeNull();
+ expect(groupIds()).toEqual([ "attributes-owned" ]);
+ expect(group("attributes-owned").querySelector(".attribute-group-count")?.textContent).toBe("0");
+ expect(group("attributes-owned").querySelector(".attribute-add-row")).not.toBeNull();
});
it("leaves what Trilium wrote for itself out of a release build, and gives it its own run in a development one", () => {
@@ -342,7 +348,7 @@ describe("AttributeList", () => {
expect(namesIn(container)).not.toContain("author");
});
- it("adds a definition through the popup, saving it once the popup is closed", async () => {
+ it("adds a definition from the panel's menu or the run's own way in, saving it once the popup is closed", async () => {
renderPanel(noteWithAttributes());
// One list, so one button, and it offers every kind: the definitions had a button of their
@@ -369,6 +375,24 @@ describe("AttributeList", () => {
const [ , saved ] = put.mock.calls[0] as [ string, { name: string; value: string }[] ];
expect(saved.at(-1)).toEqual(
{ type: "label", name: "label:myLabel", value: "promoted,single,text", isInheritable: false });
+
+ // The run has a way in of its own too, as the note's own attributes do: the panel's button is
+ // a long way from the definitions once a template has filled the pane. It adds the one kind —
+ // the form's own list of field types is where a relation definition is reached — so it opens
+ // the same popup on the same thing the menu's third entry did, with no menu in between.
+ const definitionAddRow = group("attributes-definitions").querySelector<HTMLElement>(".attribute-add-row");
+ expect(definitionAddRow).not.toBeNull();
+ act(() => definitionAddRow?.click());
+ expect(document.querySelector(".attr-detail")).not.toBeNull();
+ expect(put).toHaveBeenCalledOnce();
+
+ await act(async () => {
+ document.body.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
+ });
+
+ const [ , savedAgain ] = put.mock.calls[1] as [ string, { name: string; value: string }[] ];
+ expect(savedAgain.at(-1)).toEqual(
+ { type: "label", name: "label:myLabel", value: "promoted,single,text", isInheritable: false });
});
it("creates a label straight in its row, and a draft left nameless not at all", async () => {
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index 440b323232..06a7a7ef00 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -26,7 +26,6 @@ import HelpButton from "../react/HelpButton";
import { useActiveNoteContext, useTriliumEvent, useTriliumOptionJson } from "../react/hooks";
import Icon from "../react/Icon";
import { DetailPane, MasterPane, useMasterDetail, useMasterDetailPage } from "../react/master_detail";
-import NoItems from "../react/NoItems";
import NoteLink from "../react/NoteLink";
import { ParentComponent } from "../react/react_utils";
import { ATTRIBUTE_HELP_PAGE } from "../ribbon/components/AttributeHelp";
@@ -707,16 +706,18 @@ export default function AttributeList() {
title={t("attribute_list_panel.section_owned")}
count={sections.owned.length}
>
- {sections.owned.length > 0 ? (
- <AttributeRowList rows={sections.owned} alignValuesEnd {...rowProps} />
- ) : (
- <NoItems icon="bx bx-hash" text={t("attribute_list_panel.no_attributes")} />
- )}
+ {/* Nothing stands in for a run holding nothing: the heading's count says it
+ is empty and the add row below says what there is to do about it, so a
+ "no attributes" of any size would be the third telling of one fact. */}
+ <AttributeRowList rows={sections.owned} alignValuesEnd {...rowProps} />
{/* Inside the run it adds to rather than at the foot of everything, and put
away with it. A phone adds from the header, page flow and all. */}
{!IS_MOBILE && note && (
- <AddAttributeRow onAdd={(e) => addAttribute("label", e)} />
+ <AddAttributeRow
+ text={t("attribute_list_panel.add_attribute")}
+ onAdd={(e) => addAttribute("label", e)}
+ />
)}
</AttributeGroup>
@@ -739,6 +740,13 @@ export default function AttributeList() {
count={sections.definitions.length}
>
<AttributeRowList rows={sections.definitions} {...rowProps} />
+
+ {!IS_MOBILE && note && (
+ <AddAttributeRow
+ text={t("attribute_list_panel.add_definition")}
+ onAdd={(e) => addAttribute("label-definition", e)}
+ />
+ )}
</AttributeGroup>
)}
@@ -1590,12 +1598,14 @@ function AttributeSelectionBar({ count, canDelete, canPaste, onCopy, onPaste, on
}
/**
- * The way in at the foot of the list: a ghost of a row that creates a label in place when pressed —
- * a label because that is nearly always the kind being added, and the creation editor it opens can
- * be switched to a relation from its own name box or kind icon (see AttributeCreationEditor). The
- * card header's menu stays the way to every kind, definitions included.
+ * The way in at the foot of a run: a ghost of a row that adds to the run it sits in, one kind and no
+ * menu — the kind that run is nearly always given, with the editor it opens being where the other is
+ * reached. A label for the note's own attributes, switched to a relation from the creation editor's
+ * own name box or kind icon (see AttributeCreationEditor); a label definition for the definitions,
+ * switched to a relation definition from the form's own list of field types, which offers "relation"
+ * among them. The panel header's menu stays the way to any kind from anywhere.
*/
-function AddAttributeRow({ onAdd }: { onAdd: (e: MouseEvent) => void }) {
+function AddAttributeRow({ text, onAdd }: { text: string; onAdd: (e: MouseEvent) => void }) {
return (
<div
class="attribute-add-row"
@@ -1606,7 +1616,7 @@ function AddAttributeRow({ onAdd }: { onAdd: (e: MouseEvent) => void }) {
}}
>
<Icon icon="bx bx-plus" />
- {t("attribute_list_panel.add_attribute")}
+ {text}
</div>
);
}