diff --git a/app/components/work_package_types/form_configuration/group_attribute_row_component.html.erb b/app/components/work_package_types/form_configuration/group_attribute_row_component.html.erb index 8ad7d6a2a65a..6e927ffa67d7 100644 --- a/app/components/work_package_types/form_configuration/group_attribute_row_component.html.erb +++ b/app/components/work_package_types/form_configuration/group_attribute_row_component.html.erb @@ -10,9 +10,14 @@ ) ) end - left.with_column(flex: 1) do + left.with_column do render(Primer::Beta::Text.new) { @attribute[:translation] } end + if @attribute[:field_format_label].present? + left.with_column(ml: 2) do + render(Primer::Beta::Text.new(color: :muted, font_size: :small)) { @attribute[:field_format_label] } + end + end end row.with_column(classes: "hide-when-print type-form-configuration-page--actions") do diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rb index 9ade93941933..1765140fb5d0 100644 --- a/app/helpers/types_helper.rb +++ b/app/helpers/types_helper.rb @@ -29,6 +29,8 @@ #++ module ::TypesHelper + include CustomFieldsHelper + # rubocop:disable Rails/HelperInstanceVariable def types_tabs [ @@ -150,7 +152,16 @@ def attr_form_map(key, represented) key:, is_cf: CustomField.custom_field_attribute?(key), is_required: represented[:required] && !represented[:has_default], - translation: Type.translated_attribute_name(key, represented) + translation: Type.translated_attribute_name(key, represented), + field_format_label: field_format_label(represented) } end + + def field_format_label(represented) + if represented[:is_cf] + label_for_custom_field_format(represented[:field_format]) + else + I18n.t("types.edit.form_configuration.builtin_field") + end + end end diff --git a/app/models/type/attributes.rb b/app/models/type/attributes.rb index bc4e787a1f5a..3b40e88db6a7 100644 --- a/app/models/type/attributes.rb +++ b/app/models/type/attributes.rb @@ -153,7 +153,8 @@ def add_custom_fields_to_form_attributes(attributes) required: field.is_required, has_default: field.default_value.present?, is_cf: true, - display_name: field.name + display_name: field.name, + field_format: field.field_format } end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 46c674d24539..37ce3b98946b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1435,6 +1435,7 @@ en: untitled_group: "Untitled group" reset_title: "Reset form configuration" confirm_reset: "Are you sure you want to reset the form configuration?" + builtin_field: "Built-in field" reset_description: > This will reset the attributes to their default group and disable ALL custom fields. projects: diff --git a/spec/features/types/form_configuration_spec.rb b/spec/features/types/form_configuration_spec.rb index 749fa00768f9..a82863788848 100644 --- a/spec/features/types/form_configuration_spec.rb +++ b/spec/features/types/form_configuration_spec.rb @@ -250,6 +250,24 @@ def persisted_attribute_order(type, group_key) loading_indicator_saveguard end + it "shows field format labels beside attributes" do + # Built-in attributes show "Builtin field" + builtin_label = I18n.t("types.edit.form_configuration.builtin_field") + assignee_row = page.find('li[data-attr-key="assignee"]') + expect(assignee_row).to have_text(builtin_label) + + date_row = page.find('li[data-attr-key="date"]') + expect(date_row).to have_text(builtin_label) + + # Custom fields show their format label + custom_field = create(:issue_custom_field, :integer, name: "MyNumber") + visit edit_type_form_configuration_path(type) + + form.move_to(custom_field.attribute_name, "Details") + cf_row = page.find("li[data-attr-key='#{custom_field.attribute_name}']") + expect(cf_row).to have_text(I18n.t(:label_integer)) + end + it "removes a newly added unsaved custom group when canceling edit" do initial_order = form.group_order @@ -259,6 +277,7 @@ def persisted_attribute_order(type, group_key) expect(page.find_test_selector("type-form-configuration-group-name-input", wait: 10).value).to eq("") page.find_test_selector("type-form-configuration-group-cancel", wait: 10).click + expect(page).to have_no_test_selector("type-form-configuration-group-name-input") expect(form.group_order).to eq(initial_order) end diff --git a/spec/helpers/types_helper_spec.rb b/spec/helpers/types_helper_spec.rb index 90515dc03c08..89f2839195eb 100644 --- a/spec/helpers/types_helper_spec.rb +++ b/spec/helpers/types_helper_spec.rb @@ -88,5 +88,38 @@ expect(subject.first[:key]).to eq :details end end + + describe ":field_format_label" do + before do + allow(type) + .to receive(:attribute_groups) + .and_return [Type::AttributeGroup.new(type, "group one", ["assignee"])] + end + + it "returns 'Builtin field' for built-in attributes" do + groups = helper.form_configuration_groups(type) + attribute = groups[:actives].first[:attributes].first + + expect(attribute[:field_format_label]).to eq I18n.t("types.edit.form_configuration.builtin_field") + end + + it "returns 'Builtin field' for inactive built-in attributes" do + groups = helper.form_configuration_groups(type) + inactive_builtin = groups[:inactives].find { |a| a[:key] == "date" } + + expect(inactive_builtin[:field_format_label]).to eq I18n.t("types.edit.form_configuration.builtin_field") + end + + context "with a custom field" do + let!(:custom_field) { create(:wp_custom_field, :string, name: "My CF") } + + it "returns the custom field format label" do + groups = helper.form_configuration_groups(type) + cf_attr = groups[:inactives].find { |a| a[:key] == custom_field.attribute_name } + + expect(cf_attr[:field_format_label]).to eq I18n.t(:label_string) + end + end + end end end