Skip to content

Build your personal knowledge base with Trilium Notes

fix(board): flag a card attribute that has more than one definition

Elian Doran7dda086c7e9b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 942fac232f..e65dd965d6 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1407,7 +1407,9 @@
"values_placeholder": "Type a value and press Enter",
"add_value": "Add this value",
"drawn_by_collection": "The collection is arranged by this, so its items do not repeat it",
- "display_on_items": "Display the attribute on the collection items"
+ "display_on_items": "Display the attribute on the collection items",
+ "conflicting": "Multiple definitions",
+ "conflicting_tooltip": "The items define this attribute in more than one way, so it is sorted as text and cannot be set from the item menu."
},
"script_executor": {
"query": "Query",
diff --git a/apps/client/src/widgets/collections/attribute_menu.spec.ts b/apps/client/src/widgets/collections/attribute_menu.spec.ts
index 6544951da8..9b92e49136 100644
--- a/apps/client/src/widgets/collections/attribute_menu.spec.ts
+++ b/apps/client/src/widgets/collections/attribute_menu.spec.ts
@@ -45,7 +45,13 @@ describe("buildAttributeMenuItems", () => {
expect(build({ title: "Card" }, [
attribute({ name: "notes", title: "Notes", labelType: "text" }),
// A select offering nothing would open on "Not set" alone.
- attribute({ name: "state", title: "State", labelType: "select" })
+ attribute({ name: "state", title: "State", labelType: "select" }),
+ // Items that define it in different ways would be offered one item's options.
+ attribute({
+ name: "priority", title: "Priority", labelType: "select",
+ selectOptions: [ "Low" ], isConflicting: true
+ }),
+ attribute({ name: "done", title: "Done", labelType: "boolean", isConflicting: true })
])).toEqual([]);
});
@@ -248,6 +254,7 @@ function attribute(fields: Partial<PromotedAttribute> & { name: string }): Promo
definitionValue: "",
isOwned: true,
isDefinedByItems: false,
+ isConflicting: false,
isInheritable: true,
...fields
};
diff --git a/apps/client/src/widgets/collections/attribute_menu.ts b/apps/client/src/widgets/collections/attribute_menu.ts
index 1159338757..63c79835af 100644
--- a/apps/client/src/widgets/collections/attribute_menu.ts
+++ b/apps/client/src/widgets/collections/attribute_menu.ts
@@ -32,7 +32,9 @@ export interface AttributeMenuOptions {
*
* Lists the attributes the items draw, in the order they are drawn, and only the two types a menu
* can hold: `boolean`, which the entry marks and toggles, and `select`, whose options open in a
- * submenu. The other types need a field to type into and stay in the attribute editor.
+ * submenu. The other types need a field to type into and stay in the attribute editor. An
+ * attribute the items define in different ways is left out, since one item's options might not
+ * apply to another.
*
* Returns an empty array when no attribute qualifies, so a caller can spread the result without
* checking for an empty section.
@@ -41,7 +43,7 @@ export function buildAttributeMenuItems<T>({
notes, attributes, title
}: AttributeMenuOptions): MenuItem<T>[] {
const items = attributes.flatMap<MenuItem<T>>((attribute) => {
- if (attribute.hidden || attribute.type !== "label") {
+ if (attribute.hidden || attribute.type !== "label" || attribute.isConflicting) {
return [];
}
diff --git a/apps/client/src/widgets/collections/board/data.spec.ts b/apps/client/src/widgets/collections/board/data.spec.ts
index d2d8610048..898d719622 100644
--- a/apps/client/src/widgets/collections/board/data.spec.ts
+++ b/apps/client/src/widgets/collections/board/data.spec.ts
@@ -660,6 +660,7 @@ function definitions(name: string, type: "label" | "relation") {
definitionValue: "",
isOwned: true,
isDefinedByItems: false,
+ isConflicting: false,
isInheritable: true
} ] ]);
}
diff --git a/apps/client/src/widgets/collections/promoted_attributes.spec.ts b/apps/client/src/widgets/collections/promoted_attributes.spec.ts
index fa996e4a58..a199a5d5d1 100644
--- a/apps/client/src/widgets/collections/promoted_attributes.spec.ts
+++ b/apps/client/src/widgets/collections/promoted_attributes.spec.ts
@@ -18,16 +18,17 @@ vi.mock("../../services/i18n", () => ({
/** A definition as the collection note carries it, `label:dueDate` naming `dueDate`. */
function definition(name: string, {
alias, noteId = "board1", value = "promoted,single,text", isPromoted = true,
- isInheritable = true
+ isInheritable = true, labelType, selectOptions
}: {
- alias?: string, noteId?: string, value?: string, isPromoted?: boolean, isInheritable?: boolean
+ alias?: string, noteId?: string, value?: string, isPromoted?: boolean, isInheritable?: boolean,
+ labelType?: string, selectOptions?: string[]
} = {}) {
return {
name,
value,
noteId,
isInheritable,
- getDefinition: () => ({ isPromoted, promotedAlias: alias })
+ getDefinition: () => ({ isPromoted, promotedAlias: alias, labelType, selectOptions })
};
}
@@ -61,6 +62,7 @@ describe("resolvePromotedAttributes", () => {
definitionValue: "promoted,single,text",
isOwned: true,
isDefinedByItems: false,
+ isConflicting: false,
isInheritable: true
},
// No alias, so the name is prefixed by the kind that defines it.
@@ -212,6 +214,42 @@ describe("resolvePromotedAttributes", () => {
expect(resolved[0].title).toBe("Due");
});
+ /**
+ * Items that define one name with a different type or different options are marked as
+ * conflicting, and so is an item that overrides the collection's definition with its own.
+ */
+ it("marks a name the items define in different ways", () => {
+ const item = (noteId: string, labelType?: string, selectOptions?: string[]) =>
+ collection([
+ definition("label:priority", { noteId: `tpl_${noteId}`, labelType, selectOptions })
+ ], noteId);
+
+ const conflicting = (items: FNote[]) => resolvePromotedAttributes(
+ collection([ definition("label:dueDate") ]), undefined, [], items)
+ .map((attribute) => [ attribute.name, attribute.isConflicting ]);
+
+ expect(conflicting([ item("a", "select", [ "Low" ]), item("b", "select", [ "Low" ]) ]))
+ .toEqual([ [ "dueDate", false ], [ "priority", false ] ]);
+ expect(conflicting([ item("a", "select", [ "Low" ]), item("b", "number") ]))
+ .toEqual([ [ "dueDate", false ], [ "priority", true ] ]);
+ expect(conflicting([ item("a", "select", [ "Low" ]), item("b", "select", [ "High" ]) ]))
+ .toEqual([ [ "dueDate", false ], [ "priority", true ] ]);
+ // A definition naming no type is a text field.
+ expect(conflicting([ item("a", "text"), item("b") ]))
+ .toEqual([ [ "dueDate", false ], [ "priority", false ] ]);
+
+ // An item inheriting the collection's `dueDate` reads the same definition back.
+ const board = collection([ definition("label:dueDate", { labelType: "date" }) ]);
+ const inheriting = collection([ definition("label:dueDate", { labelType: "date" }) ], "c");
+ const overriding = collection([
+ definition("label:dueDate", { noteId: "d", labelType: "text" })
+ ], "d");
+ const resolve = (items: FNote[]) =>
+ resolvePromotedAttributes(board, undefined, [], items)[0].isConflicting;
+ expect(resolve([ inheriting ])).toBe(false);
+ expect(resolve([ inheriting, overriding ])).toBe(true);
+ });
+
/** Two notes in the chain can define the same attribute; the nearer one is what applies. */
it("keeps the first of two definitions of one name", () => {
const resolved = resolvePromotedAttributes(collection([
diff --git a/apps/client/src/widgets/collections/promoted_attributes.ts b/apps/client/src/widgets/collections/promoted_attributes.ts
index 48db646750..5cd300384c 100644
--- a/apps/client/src/widgets/collections/promoted_attributes.ts
+++ b/apps/client/src/widgets/collections/promoted_attributes.ts
@@ -48,6 +48,12 @@ export interface PromotedAttribute {
* note does not. `PromotedAttributesCard` shows no edit or delete button for it.
*/
isDefinedByItems: boolean;
+ /**
+ * Whether an item defines it with another type or other select options than the listed
+ * definition. Sorting then compares its values as text, and `buildAttributeMenuItems()` leaves
+ * it out.
+ */
+ isConflicting: boolean;
/**
* Whether the definition passes to the notes below. Always true for a resolved attribute, and
* held so that the editor is handed the definition as it stands.
@@ -84,12 +90,25 @@ export function resolvePromotedAttributes(
const add = (definition: FAttribute, isDefinedByItems: boolean) => {
const [ type, name ] = definition.name.split(":", 2);
- if ((type !== "label" && type !== "relation") || !name || defined.has(name)
+ if ((type !== "label" && type !== "relation") || !name
|| (!isDefinedByItems && !definition.isInheritable)) {
return;
}
const parsed = definition.getDefinition();
+ const existing = defined.get(name);
+ if (existing) {
+ // An item inheriting the collection's definition reads the same one back; only an item
+ // that defines the name itself, or through a template, can differ.
+ if (isDefinedByItems
+ && (existing.type !== type
+ || (existing.labelType ?? "text") !== (parsed?.labelType ?? "text")
+ || !sameOptions(existing.selectOptions, parsed?.selectOptions))) {
+ existing.isConflicting = true;
+ }
+ return;
+ }
+
defined.set(name, {
name,
definitionName: definition.name,
@@ -103,6 +122,7 @@ export function resolvePromotedAttributes(
definitionValue: definition.value,
isOwned: definition.noteId === note?.noteId,
isDefinedByItems,
+ isConflicting: false,
isInheritable: definition.isInheritable
});
};
@@ -135,6 +155,13 @@ export function resolvePromotedAttributes(
return ordered;
}
+/** Returns whether two select definitions offer the same options in the same order. */
+function sameOptions(a: string[] | undefined, b: string[] | undefined) {
+ const left = a ?? [];
+ const right = b ?? [];
+ return left.length === right.length && left.every((option, index) => option === right[index]);
+}
+
/**
* What an attribute with no alias is listed as: the name behind the kind that defines it, so a bare
* `dueDate` reads as the field it is rather than as a name someone chose.
diff --git a/apps/client/src/widgets/collections/sort_menu.spec.ts b/apps/client/src/widgets/collections/sort_menu.spec.ts
index 2fecf365b7..853cb96c6a 100644
--- a/apps/client/src/widgets/collections/sort_menu.spec.ts
+++ b/apps/client/src/widgets/collections/sort_menu.spec.ts
@@ -233,6 +233,7 @@ function attribute(fields: Partial<PromotedAttribute> & { name: string }): Promo
definitionValue: "",
isOwned: true,
isDefinedByItems: false,
+ isConflicting: false,
isInheritable: true,
...fields
};
diff --git a/apps/client/src/widgets/collections/sorting.spec.ts b/apps/client/src/widgets/collections/sorting.spec.ts
index 37a47488a4..adbbbba60e 100644
--- a/apps/client/src/widgets/collections/sorting.spec.ts
+++ b/apps/client/src/widgets/collections/sorting.spec.ts
@@ -76,6 +76,18 @@ describe("sortItems", () => {
.toEqual([ "C", "B", "A", "D" ]);
});
+ /** Items defining the field in different ways hold values of different kinds. */
+ it("compares a conflicting field as text, whatever type it names", () => {
+ const items = build([
+ { title: "A", "#field": "Urgent" },
+ { title: "B", "#field": "10" },
+ { title: "C", "#field": "Low" }
+ ]);
+
+ expect(titles(sort(items, "attr:field", false, "select", [ "Low", "Urgent" ], true)))
+ .toEqual([ "B", "C", "A" ]);
+ });
+
it("sorts dates, date-times and times by the instant they name", () => {
const dates = build([
{ title: "A", "#field": "2026-02-01" },
@@ -259,7 +271,7 @@ function build(drafts: ItemDraft[]) {
function sort(
items: Item[], key: SortKey, isDescending = false, fieldType?: FieldType,
- selectOptions?: string[]
+ selectOptions?: string[], isConflicting = false
) {
const dates = new Map(items.map(({ note, createdAt }) => [ note.noteId, createdAt ]));
const definitions = new Map<string, PromotedAttribute>();
@@ -278,6 +290,7 @@ function sort(
selectOptions,
isOwned: true,
isDefinedByItems: false,
+ isConflicting,
isInheritable: true
});
}
diff --git a/apps/client/src/widgets/collections/sorting.ts b/apps/client/src/widgets/collections/sorting.ts
index 2314c2a136..28d5178540 100644
--- a/apps/client/src/widgets/collections/sorting.ts
+++ b/apps/client/src/widgets/collections/sorting.ts
@@ -163,6 +163,10 @@ function sortValueOf(note: FNote, key: SortKey, context: SortContext): SortValue
}
function labelValueOf(value: string, definition: PromotedAttribute | undefined): SortValue {
+ if (definition?.isConflicting) {
+ return value;
+ }
+
switch (definition?.labelType) {
case "number":
// `Number` rather than `parseFloat`, which would read "1-2" as 1 and sort it among
diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.css b/apps/client/src/widgets/react/PromotedAttributesCard.css
index 768e4842d7..31829fc137 100644
--- a/apps/client/src/widgets/react/PromotedAttributesCard.css
+++ b/apps/client/src/widgets/react/PromotedAttributesCard.css
@@ -14,6 +14,13 @@
font-size: 0.8em;
}
+ /* Shaped like `.shortcut-conflicts-badge`, in the warning color `MfaStatusBadge` uses. */
+ .promoted-attribute-conflict {
+ flex-shrink: 0;
+ --color: var(--admonition-warning-accent-color, #e0a800);
+ font-size: 0.8em;
+ }
+
.promoted-attribute-edit,
.promoted-attribute-delete {
flex-shrink: 0;
diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx
index 0b8655f613..38cdcd1909 100644
--- a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx
+++ b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx
@@ -201,6 +201,21 @@ describe("PromotedAttributesCard", () => {
expect(stored.at(-1)?.[2]).toMatchObject({ name: "project", hidden: true });
});
+ it("flags what the items define in different ways", () => {
+ const item = (noteId: string, labelType: string) => ({
+ noteId,
+ getAttributeDefinitions: () => [
+ { ...definition("label:priority", { labelType }), noteId: `tpl_${noteId}` }
+ ]
+ }) as unknown as FNote;
+ itemNotes = [ item("task1", "select"), item("task2", "number") ];
+ draw();
+
+ expect(segments().map((segment) =>
+ segment.querySelector(".promoted-attribute-conflict")?.textContent))
+ .toEqual([ undefined, undefined, "promoted_attributes.conflicting" ]);
+ });
+
/**
* A card that joins the board through a branch change, such as a sync, brings no attribute row,
* so the new `itemNotes` alone must add its definitions.
diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.tsx
index 5a8865fe73..2de53bf5d2 100644
--- a/apps/client/src/widgets/react/PromotedAttributesCard.tsx
+++ b/apps/client/src/widgets/react/PromotedAttributesCard.tsx
@@ -244,6 +244,16 @@ export default function PromotedAttributesCard({
outline
/>
+ {attribute.isConflicting && (
+ <Badge
+ className="promoted-attribute-conflict"
+ icon="bx bx-error-circle"
+ text={t("promoted_attributes.conflicting")}
+ tooltip={t("promoted_attributes.conflicting_tooltip")}
+ outline
+ />
+ )}
+
{!attribute.isDefinedByItems && <>
<ActionButton
className="promoted-attribute-edit"
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
index b7bf926fee..af22560043 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
@@ -557,6 +557,11 @@ class="admonition warning">
<p>Attributes that the cards get from a template or another parent note can
be reordered and hidden here, but not modified or deleted. Edit them on
the note that defines them.</p>
+<p>If cards define an attribute with the same name but a different type or
+ different select options, for example through two different templates,
+ or if a card overrides the board's definition with its own, the attribute
+ is marked <strong>Multiple definitions</strong>. Such an attribute is sorted
+ as text and does not appear in the card's context menu.</p>
<h3>Managing card templates</h3>
<p>When you create a new card, Trilium offers four templates by default: <strong>Text</strong>, <strong>Markdown</strong>, <strong>Canvas</strong>,
and <strong>Spreadsheet</strong>. You can customize this list to include
diff --git a/docs/User Guide/User Guide/Collections/Kanban Board.md b/docs/User Guide/User Guide/Collections/Kanban Board.md
index a4e816b60f..15dcd959a2 100644
--- a/docs/User Guide/User Guide/Collections/Kanban Board.md
+++ b/docs/User Guide/User Guide/Collections/Kanban Board.md
@@ -342,6 +342,8 @@ Go to **Note menu** → **Board properties**. Under the **Card attributes** sect
Attributes that the cards get from a template or another parent note can be reordered and hidden here, but not modified or deleted. Edit them on the note that defines them.
+If cards define an attribute with the same name but a different type or different select options, for example through two different templates, or if a card overrides the board's definition with its own, the attribute is marked **Multiple definitions**. Such an attribute is sorted as text and does not appear in the card's context menu.
+
### Managing card templates
When you create a new card, Trilium offers four templates by default: **Text**, **Markdown**, **Canvas**, and **Spreadsheet**. You can customize this list to include other note types or custom templates with predefined placeholder content and prefilled card attributes.