From b29781b614aedcbc9786723e9dad85f8766195d1 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 26 Jul 2025 09:29:27 +0300 Subject: [PATCH] feat(promoted_attributes): add color type --- .../src/services/promoted_attribute_definition_parser.ts | 4 ++-- apps/client/src/translations/en/translation.json | 3 ++- .../src/widgets/attribute_widgets/attribute_detail.ts | 1 + .../src/widgets/ribbon_widgets/promoted_attributes.ts | 8 ++++++++ .../src/widgets/view_widgets/table_view/columns.ts | 9 +++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/client/src/services/promoted_attribute_definition_parser.ts b/apps/client/src/services/promoted_attribute_definition_parser.ts index 6cdb8edc6..fe3a9cf2e 100644 --- a/apps/client/src/services/promoted_attribute_definition_parser.ts +++ b/apps/client/src/services/promoted_attribute_definition_parser.ts @@ -1,4 +1,4 @@ -export type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url"; +export type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url" | "color"; type Multiplicity = "single" | "multi"; export interface DefinitionObject { @@ -17,7 +17,7 @@ function parse(value: string) { for (const token of tokens) { if (token === "promoted") { defObj.isPromoted = true; - } else if (["text", "number", "boolean", "date", "datetime", "time", "url"].includes(token)) { + } else if (["text", "number", "boolean", "date", "datetime", "time", "url", "color"].includes(token)) { defObj.labelType = token as LabelType; } else if (["single", "multi"].includes(token)) { defObj.multiplicity = token as Multiplicity; diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index a61220ddc..13f9258e0 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -443,7 +443,8 @@ "other_notes_with_name": "Other notes with {{attributeType}} name \"{{attributeName}}\"", "and_more": "... and {{count}} more.", "print_landscape": "When exporting to PDF, changes the orientation of the page to landscape instead of portrait.", - "print_page_size": "When exporting to PDF, changes the size of the page. Supported values: A0, A1, A2, A3, A4, A5, A6, Legal, Letter, Tabloid, Ledger." + "print_page_size": "When exporting to PDF, changes the size of the page. Supported values: A0, A1, A2, A3, A4, A5, A6, Legal, Letter, Tabloid, Ledger.", + "color_type": "Color" }, "attribute_editor": { "help_text_body1": "To add label, just type e.g. #rock or if you want to add also value then e.g. #year = 2020", diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.ts b/apps/client/src/widgets/attribute_widgets/attribute_detail.ts index f4134745d..cdb7c7b43 100644 --- a/apps/client/src/widgets/attribute_widgets/attribute_detail.ts +++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.ts @@ -142,6 +142,7 @@ const TPL = /*html*/` + diff --git a/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts b/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts index 8895d5e42..5f21cb6e5 100644 --- a/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts +++ b/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts @@ -66,6 +66,12 @@ const TPL = /*html*/` appearance: auto; } + .promoted-attribute-cell input[type="color"] { + width: 50px; + padding: 0; + border: 0; + } + @@ -265,6 +271,8 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget { .on("click", () => window.open($input.val() as string, "_blank")); $input.after($openButton); + } else if (definition.labelType === "color") { + $input.prop("type", "color"); } else { ws.logError(t("promoted_attributes.unknown_label_type", { type: definition.labelType })); } diff --git a/apps/client/src/widgets/view_widgets/table_view/columns.ts b/apps/client/src/widgets/view_widgets/table_view/columns.ts index 65991fb5f..39047fa70 100644 --- a/apps/client/src/widgets/view_widgets/table_view/columns.ts +++ b/apps/client/src/widgets/view_widgets/table_view/columns.ts @@ -35,6 +35,15 @@ const labelTypeMappings: Record> = { formatter: "link", editor: "input" }, + color: { + editor: "input", + formatter: "color", + editorParams: { + elementAttributes: { + type: "color" + } + } + }, relation: { editor: RelationEditor, formatter: NoteFormatter