Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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_type].present?
left.with_column(ml: 2) do
render(Primer::Beta::Text.new(color: :muted, font_size: :small)) { @attribute[:field_type] }
Copy link
Copy Markdown
Contributor

@myabc myabc May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a Primer::Beta::Text, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already uses Primer::Beta::Text

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant Primer::Beta::Label

end
end
end

row.with_column(classes: "hide-when-print type-form-configuration-page--actions") do
Expand Down
17 changes: 16 additions & 1 deletion app/helpers/types_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,22 @@ 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_type: field_type_label(key, represented)
Comment thread
myabc marked this conversation as resolved.
}
end

# Resolves the format label directly via OpenProject::CustomFieldFormat rather than
# using CustomFieldsHelper#label_for_custom_field_format, because the helper is not
# available in the controller context during Turbo Stream re-renders.
def field_type_label(_key, represented)
if represented[:is_cf]
format = OpenProject::CustomFieldFormat.find_by(name: represented[:field_format])
return "" if format.nil?

format.label.is_a?(Proc) ? format.label.call : I18n.t(format.label)
else
I18n.t("types.edit.form_configuration.builtin_field")
end
end
end
3 changes: 2 additions & 1 deletion app/models/type/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions spec/features/types/form_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ def persisted_attribute_order(type, group_key)
loading_indicator_saveguard
end

it "shows field type 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)
Comment on lines +253 to +260

# 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

Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions spec/helpers/types_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,38 @@
expect(subject.first[:key]).to eq :details
end
end

describe ":field_type" 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_type]).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_type]).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_type]).to eq I18n.t(:label_string)
end
end
end
end
end
Loading