Skip to content

Build your personal knowledge base with Trilium Notes

fix(attributes): keep a display name that is not promoted

Elian Doran645f0e6b85b3
diff --git a/packages/commons/src/lib/promoted_attribute_definition_parser.spec.ts b/packages/commons/src/lib/promoted_attribute_definition_parser.spec.ts
index 4b36bce1f0..60af67be35 100644
--- a/packages/commons/src/lib/promoted_attribute_definition_parser.spec.ts
+++ b/packages/commons/src/lib/promoted_attribute_definition_parser.spec.ts
@@ -103,12 +103,14 @@ describe("promoted_attribute_definition_parser.parse", () => {
});
describe("promoted_attribute_definition_parser.serialize", () => {
- it("writes the promoted flag and its alias, the alias only when promoted", () => {
+ it("writes the promoted flag and the alias independently of each other", () => {
expect(serialize({ isPromoted: true, promotedAlias: "Foo" }, "label"))
.toBe("promoted,alias=Foo,single,text");
- // An alias is meaningless without the flag, so it is left out.
- expect(serialize({ promotedAlias: "Foo" }, "label")).toBe("single,text");
+ // The alias is read by the table view and the attribute list as well, neither of which asks
+ // whether the attribute is promoted, so it is written whether or not the flag is set.
+ expect(serialize({ promotedAlias: "Foo" }, "label")).toBe("alias=Foo,single,text");
+ expect(serialize({ isPromoted: true }, "label")).toBe("promoted,single,text");
});
it("falls back to the multiplicity and label type the consumers assume", () => {
diff --git a/packages/commons/src/lib/promoted_attribute_definition_parser.ts b/packages/commons/src/lib/promoted_attribute_definition_parser.ts
index 37c814bb96..a581abc6ca 100644
--- a/packages/commons/src/lib/promoted_attribute_definition_parser.ts
+++ b/packages/commons/src/lib/promoted_attribute_definition_parser.ts
@@ -80,10 +80,12 @@ function serialize(definition: DefinitionObject, valueType: "label" | "relation"
if (definition.isPromoted) {
props.push("promoted");
+ }
- if (definition.promotedAlias) {
- props.push(`alias=${definition.promotedAlias}`);
- }
+ // Not only the promoted field's label: the table view titles its columns with it and the attribute
+ // list names its values by it, neither of which asks whether the attribute is promoted.
+ if (definition.promotedAlias) {
+ props.push(`alias=${definition.promotedAlias}`);
}
props.push(definition.multiplicity ?? "single");