Skip to content

Build your personal knowledge base with Trilium Notes

fix(sidebar/attributes): keep the creation row at the foot of the list

Elian Dorancbfb5c9963c4
diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
index 5b256aa9c6..d1dd3055b6 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
@@ -233,6 +233,11 @@ describe("AttributeList", () => {
expect(container.querySelectorAll(".attribute-row")).toHaveLength(0);
expect(container.querySelector(".no-items")).not.toBeNull();
+
+ // Adding takes the placeholder's place: there is a row again, draft though it still is.
+ act(() => container.querySelector<HTMLElement>(".attribute-add-row")?.click());
+ expect(container.querySelectorAll(".attribute-row")).toHaveLength(1);
+ expect(container.querySelector(".no-items")).toBeNull();
});
it("leaves what Trilium wrote for itself out of a release build, and gives it its own card in a development one", () => {
@@ -411,6 +416,12 @@ describe("AttributeList", () => {
expect(editor?.querySelector(".attribute-creation-value input")).not.toBeNull();
expect(editor?.querySelector(".note-autocomplete-stub")).toBeNull();
+ // ...in a row at the foot of the list, where the press that opened it was — and not where
+ // the sort would file a name it does not have yet, above the ones Trilium reads for itself.
+ const ownedCard = container.querySelector("#attributes");
+ expect(namesIn(ownedCard ?? container)).toEqual([ "author", "cssClass", "template", "" ]);
+ expect([ ...(ownedCard?.querySelectorAll(".attribute-row") ?? []) ].at(-1)?.contains(editor ?? null)).toBe(true);
+
// ...until the `~` the attributes editor spells relations with is typed at the name's head:
// the prefix is spent on the switch, the name keeping only what follows it.
const nameInput = editor?.querySelector<HTMLInputElement>(".attribute-creation-name input");
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index 68976c3687..321aac5ebf 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -328,6 +328,12 @@ export default function AttributeList() {
/>
)
} : undefined;
+ // A draft still being created keeps the place it was added in — the foot of the list, next to the
+ // row that opened it — instead of the one its name will file it under: nameless, it is not a name
+ // Trilium reads for itself, so the sort has nothing to go on and would hoist the editor above the
+ // system rows, away from the press that opened it. It settles into place once the name is saved.
+ const creationRow = activeCreation && sections.owned.find((entry) => entry.attribute === activeCreation);
+ const ownedRows = creationRow ? sections.owned.filter((entry) => entry !== creationRow) : sections.owned;
const rowProps = {
note,
activeAttribute: detail?.attribute,
@@ -389,12 +395,16 @@ export default function AttributeList() {
the two lists of plain attributes reading as one ledger. The definitions keep
prose order: their "value" is a summary of settings, not a value. */}
<div class="attribute-list-panel align-values-end" ref={containerRef} onClick={commit}>
- {sections.owned.length > 0 ? (
- <AttributeRowList rows={sections.owned} {...rowProps} />
- ) : (
+ {ownedRows.length > 0 ? (
+ <AttributeRowList rows={ownedRows} {...rowProps} />
+ ) : !creationRow && (
<NoItems icon="bx bx-hash" text={t("attribute_list_panel.no_attributes")} />
)}
+ {/* The draft under creation, kept last (see above) and so out of the split the
+ list above draws between the note's own names and Trilium's. */}
+ {creationRow && <AttributeRowList rows={[ creationRow ]} {...rowProps} />}
+
{/* Only on a desktop: a phone adds from the header, page flow and all. */}
{!IS_MOBILE && note && (
<AddAttributeRow onAdd={(e) => addAttribute("label", e)} />