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

switched to primer's toggle component on mapping UI

Jonas Jabari87c79792ba4e
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb
index 279fd228417..7e671f3d0ff 100644
--- a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb
+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb
@@ -3,14 +3,25 @@
flex_layout(align_items: :center, classes: 'op-project-custom-field', data: {
qa_selector: "project-custom-field-#{@project_custom_field.id}"
}) do |custom_field_container|
- custom_field_container.with_column(mr: 1) do
- toggle_button
- end
- custom_field_container.with_column(data: { qa_selector: "custom-field-type" } ) do
- render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) do
- @project_custom_field.field_format.capitalize
+ # prototypical implementation of the toggle button in order to review with the team
+ # TODO: once finally decided, it needs refactoring
+ custom_field_container.with_column(style: "width: 245px;", flex_layout: true) do |description_container|
+ description_container.with_column(mr: 2) do
+ render(Primer::Beta::Truncate.new) do |component|
+ component.with_item(max_width: 170) do
+ @project_custom_field.name
+ end
+ end
+ end
+ description_container.with_column(data: { qa_selector: "custom-field-type" } ) do
+ render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) do
+ @project_custom_field.field_format.capitalize
+ end
end
end
+ custom_field_container.with_column do
+ toggle_button
+ end
end
end
%>
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
index 4139e73509a..551cbec465e 100644
--- a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
@@ -55,21 +55,20 @@ module Projects
end
def toggle_button
- render(Primer::Beta::Button.new(
- tag: :a,
- href: toggle_project_settings_project_custom_fields_path(
+ render(Primer::Alpha::ToggleSwitch.new(
+ src: toggle_project_settings_project_custom_fields_path(
project_custom_field_project_mapping: {
project_id: @project.id,
custom_field_id: @project_custom_field.id
}
),
- scheme: :invisible,
+ csrf_token: form_authenticity_token,
data: { 'turbo-method': :put, 'turbo-stream': true,
- qa_selector: "toggle-project-custom-field-mapping-#{@project_custom_field.id}" }
- )) do |button|
- button.with_leading_visual_icon(icon: (active_in_project? ? 'check-circle' : 'circle'))
- @project_custom_field.name
- end
+ qa_selector: "toggle-project-custom-field-mapping-#{@project_custom_field.id}" },
+ checked: active_in_project?,
+ size: :small,
+ status_label_position: :end
+ ))
end
end
end
diff --git a/config/routes.rb b/config/routes.rb
index 60da8f8b193..a615d1313e5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -191,7 +191,7 @@ OpenProject::Application.routes.draw do
resource :types, only: %i[show update]
resource :project_custom_fields, only: %i[show] do
member do
- put :toggle
+ post :toggle
end
collection do
put :enable_all_of_section
diff --git a/spec/features/projects/project_custom_fields/settings/mapping_spec.rb b/spec/features/projects/project_custom_fields/settings/mapping_spec.rb
index f1bf221ad04..a3ef7368c56 100644
--- a/spec/features/projects/project_custom_fields/settings/mapping_spec.rb
+++ b/spec/features/projects/project_custom_fields/settings/mapping_spec.rb
@@ -106,7 +106,7 @@ RSpec.describe 'Projects custom fields mapping via project settings', :js, :with
visit project_settings_general_path(project)
within '#menu-sidebar' do
- expect(page).not_to have_css("li[data-name='settings_project_custom_fields']")
+ expect(page).to have_no_css("li[data-name='settings_project_custom_fields']")
end
end
@@ -128,7 +128,7 @@ RSpec.describe 'Projects custom fields mapping via project settings', :js, :with
visit project_settings_general_path(project)
within '#menu-sidebar' do
- expect(page).not_to have_css("li[data-name='settings_project_custom_fields']")
+ expect(page).to have_no_css("li[data-name='settings_project_custom_fields']")
end
end
end
@@ -182,7 +182,7 @@ RSpec.describe 'Projects custom fields mapping via project settings', :js, :with
within_custom_field_container(boolean_project_custom_field) do
expect_unchecked_state
- page.find("[data-qa-selector='toggle-project-custom-field-mapping-#{boolean_project_custom_field.id}']").click
+ page.find("[data-qa-selector='toggle-project-custom-field-mapping-#{boolean_project_custom_field.id}'] > button").click
expect_checked_state # without reloading the page
end
@@ -275,15 +275,15 @@ RSpec.describe 'Projects custom fields mapping via project settings', :js, :with
within_custom_field_section_container(section_for_input_fields) do
expect(page).to have_content('Boolean field')
- expect(page).not_to have_content('String field')
+ expect(page).to have_no_content('String field')
end
within_custom_field_section_container(section_for_select_fields) do
- expect(page).not_to have_content('List field')
+ expect(page).to have_no_content('List field')
end
within_custom_field_section_container(section_for_multi_select_fields) do
- expect(page).not_to have_content('Multi list field')
+ expect(page).to have_no_content('Multi list field')
end
end
@@ -346,11 +346,11 @@ RSpec.describe 'Projects custom fields mapping via project settings', :js, :with
end
def expect_checked_state
- expect(page).to have_css('.octicon-check-circle')
+ expect(page).to have_css('.ToggleSwitch-statusOn')
end
def expect_unchecked_state
- expect(page).to have_css('.octicon-circle')
+ expect(page).to have_css('.ToggleSwitch-statusOff')
end
def within_custom_field_section_container(section, &)