Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#62257] display parent and project prefix in attribute tokens

Eric Schubertb270a71f8403
diff --git a/app/components/work_packages/types/pattern_input.html.erb b/app/components/work_packages/types/pattern_input.html.erb
index eda2e088844..58ce8d6fef0 100644
--- a/app/components/work_packages/types/pattern_input.html.erb
+++ b/app/components/work_packages/types/pattern_input.html.erb
@@ -34,6 +34,7 @@ See COPYRIGHT and LICENSE files for more details.
classes: "pattern-input",
"data-controller": "pattern-input",
"data-pattern-input-pattern-initial-value": @value,
+ "data-pattern-input-heading-locales-value": heading_locales,
"data-pattern-input-insert-as-text-template-value": I18n.t("types.edit.subject_configuration.pattern.insert_as_text"),
"data-pattern-input-suggestions-initial-value": suggestions_for_stimulus
)
diff --git a/app/components/work_packages/types/pattern_input.rb b/app/components/work_packages/types/pattern_input.rb
index c3ecf19d0cc..1b84803b51b 100644
--- a/app/components/work_packages/types/pattern_input.rb
+++ b/app/components/work_packages/types/pattern_input.rb
@@ -43,9 +43,14 @@ module WorkPackages
end
def suggestions_for_stimulus
- @suggestions_for_stimulus ||= @suggestions
- .transform_keys { |key| key.to_s.humanize }
- .to_json
+ @suggestions_for_stimulus ||= @suggestions.to_json
+ end
+
+ def heading_locales
+ @suggestions.keys.reduce({}) do |key, acc|
+ acc[key] = I18n.t("types.edit.subject_configuration.pattern.headings.#{key}")
+ acc
+ end.to_json
end
def suggestions_list_component
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a7105f45a3e..ffa453101c6 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -677,6 +677,10 @@ en:
pattern:
label: "Subject pattern"
caption: "Add text or type / to search for an attribute. You can add spaces to separate them."
+ headings:
+ work_package: "Work package"
+ parent: "Parent"
+ project: "Project"
insert_as_text: "No attributes found. Add as text: \"%{word}\""
export_configuration:
tab: "Generate PDF"
diff --git a/frontend/src/stimulus/controllers/pattern-input.controller.ts b/frontend/src/stimulus/controllers/pattern-input.controller.ts
index 614fa63e4e3..94a4910a717 100644
--- a/frontend/src/stimulus/controllers/pattern-input.controller.ts
+++ b/frontend/src/stimulus/controllers/pattern-input.controller.ts
@@ -68,21 +68,21 @@ export default class PatternInputController extends Controller {
static values = {
patternInitial: String,
+ headingLocales: Object,
suggestionsInitial: Object,
insertAsTextTemplate: String,
};
declare readonly patternInitialValue:string;
declare readonly suggestionsInitialValue:Record<string, Record<string, string>>;
+ declare readonly headingLocalesValue:Record<string, string>;
declare readonly insertAsTextTemplateValue:string;
validTokenMap:Record<string, string> = {};
currentRange:Range|undefined = undefined;
connect() {
- this.validTokenMap = Object.values(this.suggestionsInitialValue)
- .reduce((acc, val) => ({ ...acc, ...val }), {});
-
+ this.validTokenMap = this.flatLocalizedTokenMap();
this.contentTarget.innerHTML = this.toHtml(this.patternInitialValue) || ' ';
this.tagInvalidTokens();
this.clearSuggestionsFilter();
@@ -204,6 +204,19 @@ export default class PatternInputController extends Controller {
this.clearSuggestionsFilter();
}
+ private flatLocalizedTokenMap():Record<string, string> {
+ return Object.entries(this.suggestionsInitialValue)
+ .reduce((acc, [groupKey, attributes]) => {
+ if (groupKey !== 'work_package') {
+ Object.entries(attributes).forEach(([key, value]) => {
+ attributes[key] = `${this.headingLocalesValue[groupKey]}: ${value}`;
+ });
+ }
+
+ return { ...acc, ...attributes };
+ }, {});
+ }
+
private updateFormInputValue():void {
this.formInputTarget.value = this.toBlueprint();
}
@@ -358,7 +371,7 @@ export default class PatternInputController extends Controller {
if (groupHeader) {
const headerElement = groupHeader.querySelector('h2');
if (headerElement) {
- headerElement.innerText = group.key;
+ headerElement.innerText = this.headingLocalesValue[group.key];
}
this.suggestionsTarget.appendChild(groupHeader);