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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
preview long text values truncated and expand via dialog
Jonas Jabaric06fb416e33f
diff --git a/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.html.erbindex a7ae2774671..f60e84d7baa 100644--- a/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.html.erb@@ -9,13 +9,9 @@custom_field_value_container.with_row doif not_set?- # if @project_custom_field.default_value.present?- # render(Primer::Beta::Text.new()) { render_formatted_default_value }- # else- render(Primer::Beta::Text.new()) { t('label_not_set_yet') }- # end+ render(Primer::Beta::Text.new()) { t('label_not_set_yet') }else- render(Primer::Beta::Text.new()) { render_formatted_value }+ render_valueendendenddiff --git a/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.rb b/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.rbindex f3e4e0babfe..ac6ea253d1c 100644--- a/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.rb+++ b/modules/overviews/app/components/project_custom_fields/sections/project_custom_fields/show_component.rb@@ -43,19 +43,45 @@ module ProjectCustomFieldsprivate- def render_formatted_value- @project_custom_field_values&.map do |cf_value|- format_value(cf_value.value, @project_custom_field)- end&.join(", ")&.html_safe+ def render_value+ if @project_custom_field.field_format == "text"+ render_rich_text+ else+ render(Primer::Beta::Text.new) do+ @project_custom_field_values&.map do |cf_value|+ format_value(cf_value.value, @project_custom_field)+ end&.join(", ")&.html_safe+ end+ endend- def render_formatted_default_value- if @project_custom_field.default_value.is_a?(Array)- @project_custom_field.default_value.map do |default_value|- format_value(default_value, @project_custom_field)- end.join(", ").html_safe+ def render_rich_text+ truncation_length = 100++ if @project_custom_field_values.first&.value&.length.to_i > truncation_length+ render_truncated_preview_and_dialog_for_rich_text_value(truncation_length)else- format_value(@project_custom_field.default_value, @project_custom_field)+ render(Primer::Beta::Text.new) do+ format_value(@project_custom_field_values.first&.value, @project_custom_field)+ end+ end+ end++ def render_truncated_preview_and_dialog_for_rich_text_value(truncation_length)+ flex_layout do |rich_text_preview_container|+ rich_text_preview_container.with_row do+ render(Primer::Beta::Text.new) do+ format_value(@project_custom_field_values.first&.value&.truncate(truncation_length), @project_custom_field)+ end+ end+ rich_text_preview_container.with_row do+ render(Primer::Alpha::Dialog.new(size: :medium_portrait, title: @project_custom_field.name)) do |d|+ d.with_show_button(scheme: :link) { "Expand" }+ d.with_body(style: "max-height: 500px;") do+ format_value(@project_custom_field_values.first&.value, @project_custom_field)+ end+ end+ endendenddiff --git a/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb b/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rbindex 97aba36d81e..0682eb3412b 100644--- a/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb+++ b/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb@@ -501,13 +501,39 @@ RSpec.describe 'Show project custom fields on project overview page', :js, :withdescribe 'with text CF' dodescribe 'with value set by user' do- it 'shows the correct value for the project custom field if given' do- overview_page.visit_page+ context 'with a value that is shorter than 100 characters' do+ it 'shows the correct value for the project custom field if given without truncation and dialog button' do+ overview_page.visit_page- overview_page.within_async_loaded_sidebar do- overview_page.within_custom_field_container(text_project_custom_field) do- expect(page).to have_text 'Text field'- expect(page).to have_text "Lorem\nipsum"+ overview_page.within_async_loaded_sidebar do+ overview_page.within_custom_field_container(text_project_custom_field) do+ expect(page).to have_text 'Text field'+ expect(page).to have_text "Lorem\nipsum"+ end+ end+ end+ end++ context 'with a value that is longer than 100 characters' do+ before do+ text_project_custom_field.custom_values.where(customized: project).first.update!(value: 'a' * 101)+ end++ it 'shows the correct value for the project custom field if given with truncation and dialog button' do+ overview_page.visit_page++ overview_page.within_async_loaded_sidebar do+ overview_page.within_custom_field_container(text_project_custom_field) do+ expect(page).to have_text 'Text field'+ expect(page).to have_text ("#{'a' * 97}...")+ expect(page).to have_text 'Expand'++ click_on 'Expand'++ within 'modal-dialog' do+ expect(page).to have_text 'a' * 101+ end+ endendendend