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

[52127] project list truncate long text fields and disable expand action (#14838)

Behrokh Satarnejada5ee5ca606f7
diff --git a/app/components/_index.sass b/app/components/_index.sass
index ec865cc19ae..1c262068b87 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -1,3 +1,4 @@
@import "work_packages/share/modal_body_component"
@import "work_packages/share/invite_user_form_component"
+@import "open_project/common/attribute_component"
@import "filters_component"
diff --git a/app/components/open_project/common/attribute_component.html.erb b/app/components/open_project/common/attribute_component.html.erb
new file mode 100644
index 00000000000..2d62ab96b2c
--- /dev/null
+++ b/app/components/open_project/common/attribute_component.html.erb
@@ -0,0 +1,17 @@
+<div
+ data-controller="attribute"
+ data-application-target="dynamic"
+ class="op-long-text-attribute">
+ <p
+ data-attribute-target="descriptionText"
+ class="op-long-text-attribute--text">
+ <%= @attr_value %>
+ </p>
+
+ <%= render(Primer::Alpha::Dialog.new(id: @id, title: @name, size: :large)) do |component|
+ component.with_show_button(scheme: :link, display: (is_multi_type(@description) ? :block : :none), data: { 'attribute-target': 'expandButton' }) { I18n.t('js.label_expand') }
+ component.with_body(mt: 2) { helpers.format_text(@description) }
+ component.with_header
+ end
+ %>
+</div>
\ No newline at end of file
diff --git a/app/components/open_project/common/attribute_component.rb b/app/components/open_project/common/attribute_component.rb
new file mode 100644
index 00000000000..e675f3b1c66
--- /dev/null
+++ b/app/components/open_project/common/attribute_component.rb
@@ -0,0 +1,50 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+require 'nokogiri'
+
+module OpenProject
+ module Common
+ class AttributeComponent < Primer::Component
+
+ def initialize(id, name, description, **args)
+ super
+ @id = id
+ @name = name
+ @description = description
+ @attr_value = is_multi_type(description) ? I18n.t('js.label_preview_not_available') : Nokogiri::HTML(description).text
+ @system_arguments = args
+ end
+
+ private
+
+ def is_multi_type(text)
+ text.to_s.include?('figure') || text.to_s.include?('macro')
+ end
+ end
+ end
+end
diff --git a/app/components/open_project/common/attribute_component.sass b/app/components/open_project/common/attribute_component.sass
new file mode 100644
index 00000000000..34d65c088e8
--- /dev/null
+++ b/app/components/open_project/common/attribute_component.sass
@@ -0,0 +1,6 @@
+.op-long-text-attribute
+ display: flex
+ align-items: center
+ &--text
+ @include text-shortener
+ margin: 0
diff --git a/app/components/projects/row_component.html.erb b/app/components/projects/row_component.html.erb
index c87c63e5c71..6d76a31066d 100644
--- a/app/components/projects/row_component.html.erb
+++ b/app/components/projects/row_component.html.erb
@@ -30,8 +30,6 @@ See COPYRIGHT and LICENSE files for more details.
<tr
<%= "id=\"#{row_css_id}\"".html_safe if row_css_id %>
<%= "class=\"#{row_css_class}\"".html_safe if row_css_class %>
- data-project-target="projectRow"
- data-project-id="<%= project.id %>"
>
<% columns.each do |column| %>
<td class="<%= column_css_class(column) %>">
@@ -54,31 +52,5 @@ See COPYRIGHT and LICENSE files for more details.
</li>
</ul>
<% end %>
- <% unless project.description.blank? %>
- <a class="icon collapse icon-arrow-up1 projects-table--description-toggle"
- href
- title="<%= t('label_project_hide_details') %>"
- data-project-target="descriptionToggle"
- data-action="click->project#toggleDescription"
- data-project-project-id-param="<%= project.id %>"></a>
- <a class="icon expand icon-arrow-down1 projects-table--description-toggle"
- href
- title="<%= t('label_project_show_details') %>"
- data-project-target="descriptionToggle"
- data-action="click->project#toggleDescription"
- data-project-project-id-param="<%= project.id %>"></a>
- <% end %>
</td>
-</tr>
-<% if User.current.allowed_in_project?(:view_project, project) && project.description.present? %>
- <tr class="project-description <%= project_css_classes %> <%= row_css_level_classes %> <%= params[:expand] == 'all' ? '-expanded' : '' %>"
- data-project-target="descriptionRow"
- data-project-id="<%= project.id %>">
- <td></td>
- <td colspan="<%= columns.length%>" class="project--hierarchy">
- <div class="description-container wiki">
- <%= helpers.format_text(helpers.short_project_description(project), project: project) %>
- </div>
- </td>
- </tr>
-<% end %>
+</tr>
\ No newline at end of file
diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb
index 487c1a8c9ac..5219058453a 100644
--- a/app/components/projects/row_component.rb
+++ b/app/components/projects/row_component.rb
@@ -27,7 +27,6 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
-
module Projects
class RowComponent < ::RowComponent
def project
@@ -57,8 +56,8 @@ module Projects
cf = custom_field(column)
custom_value = project.formatted_custom_value_for(cf)
- if cf.field_format == 'text'
- custom_value.html_safe # rubocop:disable Rails/OutputSafety
+ if cf.field_format == 'text' && custom_value.present?
+ render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-cf-#{cf.id}", cf.name, custom_value.html_safe) # rubocop:disable Rails/OutputSafety
elsif custom_value.is_a?(Array)
safe_join(Array(custom_value).compact_blank, ', ')
else
@@ -112,8 +111,15 @@ module Projects
def status_explanation
return nil unless user_can_view_project?
- if project.status_explanation
- content_tag :div, helpers.format_text(project.status_explanation), class: 'wiki'
+ if project.status_explanation.present? && project.status_explanation
+ render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-status-explanation", I18n.t('activerecord.attributes.project.status_explanation'), project.status_explanation)
+ end
+ end
+
+ def description
+ return nil unless user_can_view_project?
+ if project.description.present?
+ render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-description", I18n.t('activerecord.attributes.project.description'), project.description)
end
end
@@ -126,10 +132,6 @@ module Projects
classes << project_css_classes
classes << row_css_level_classes
- if params[:expand] == 'all' && project.description.present?
- classes << ' -no-highlighting -expanded'
- end
-
classes.join(" ")
end
@@ -163,11 +165,11 @@ module Projects
case column
when :name
"project--hierarchy #{project.archived? ? 'archived' : ''}"
- when :status_explanation
- "-no-ellipsis"
+ when :status_explanation, :description
+ "project-long-text-container"
when /\Acf_/
cf = custom_field(column)
- formattable = cf.field_format == 'text' ? ' -no-ellipsis' : ''
+ formattable = cf.field_format == 'text' ? ' project-long-text-container' : ''
"format-#{cf.field_format}#{formattable}"
end
end
diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erb
index 75faa0f8ef8..5c9f81d7037 100644
--- a/app/components/projects/table_component.html.erb
+++ b/app/components/projects/table_component.html.erb
@@ -76,17 +76,6 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<th class="-right">
<div class="generic-table--header-outer">
- <div class="generic-table--header"
- data-controller="params-from-query"
- data-application-target="dynamic"
- data-params-from-query-all-anchors-value="true"
- data-params-from-query-allowed-value='["query_id", "per_page", "page", "sortBy", "filters"]'>
- <% if params[:expand] == 'all' %>
- <%= link_to t(:button_collapse_all) %>
- <% else %>
- <%= link_to t(:button_expand_all), { params: { expand: 'all' } } %>
- <% end %>
- </div>
</div>
</th>
</tr>
diff --git a/app/components/projects/table_component.rb b/app/components/projects/table_component.rb
index 9ee2bba361b..643d0712c94 100644
--- a/app/components/projects/table_component.rb
+++ b/app/components/projects/table_component.rb
@@ -97,6 +97,7 @@ module Projects
[:project_status, { caption: Project.human_attribute_name(:status) }],
[:status_explanation, { caption: Project.human_attribute_name(:status_explanation) }],
[:public, { caption: Project.human_attribute_name(:public) }],
+ [:description, { caption: Project.human_attribute_name(:description) }],
*custom_field_columns,
*admin_columns
]
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index c1b2804e8a4..543a1abae3a 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -54,13 +54,10 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<div data-controller="project"
- data-application-target="dynamic">
- <%= render Projects::TableComponent.new(
- query:,
- current_user: current_user,
- params:) %>
-</div>
+<%= render Projects::TableComponent.new(
+ query:,
+ current_user: current_user,
+ params:) %>
<%= render Projects::StorageInformationComponent.new(
current_user: current_user) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 6ab48a4a4eb..e9818481f81 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -637,6 +637,7 @@ en:
false: "private"
queries: "Queries"
status_code: "Project status"
+ description: "Description"
status_explanation: "Project status description"
status_codes:
not_started: "Not started"
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 29db9812c92..adb84b415af 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -460,6 +460,7 @@ en:
label_email: "Email"
label_equals: "is"
label_expand: "Expand"
+ label_preview_not_available: "Preview not available"
label_expanded: "expanded"
label_expand_all: "Expand all"
label_expand_project_menu: "Expand project menu"
diff --git a/frontend/src/global_styles/content/_projects_list.sass b/frontend/src/global_styles/content/_projects_list.sass
index 064e67d29aa..9475a583a06 100644
--- a/frontend/src/global_styles/content/_projects_list.sass
+++ b/frontend/src/global_styles/content/_projects_list.sass
@@ -79,21 +79,7 @@ $project-table--description-indention: 9px
span.archived-label
text-transform: uppercase
- .project-description
- display: none
- td
- padding-top: 0
- padding-bottom: 1rem
- p
- font-size: inherit
- padding-left: 0
- max-width: 800px // improve readability
- // Hide everything else than text for now to avoid a too large table
- pre
- display: none !important
-
- .project-description.-expanded
- display: table-row
+
td.name
@include text-shortener
diff --git a/frontend/src/stimulus/controllers/dynamic/attribute.controller.ts b/frontend/src/stimulus/controllers/dynamic/attribute.controller.ts
new file mode 100644
index 00000000000..15e533434af
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/attribute.controller.ts
@@ -0,0 +1,52 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) 2023 the OpenProject GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+ * Copyright (C) 2006-2013 Jean-Philippe Lang
+ * Copyright (C) 2010-2013 the ChiliProject Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * See COPYRIGHT and LICENSE files for more details.
+ * ++
+ *
+ */
+
+import { Controller } from '@hotwired/stimulus';
+
+export default class AttributeController extends Controller {
+ static targets = [
+ 'descriptionText',
+ 'expandButton',
+ ];
+
+ declare readonly descriptionTextTarget:HTMLParagraphElement;
+ declare readonly expandButtonTarget:HTMLButtonElement;
+
+ descriptionTextTargetConnected(element:HTMLParagraphElement) {
+ if (this.isEllipssed(element)) {
+ this.expandButtonTarget.classList.remove('d-none');
+ }
+ }
+
+ isEllipssed(e:HTMLElement) {
+ return (e.offsetWidth < e.scrollWidth);
+ }
+}
diff --git a/frontend/src/stimulus/controllers/dynamic/project.controller.ts b/frontend/src/stimulus/controllers/dynamic/project.controller.ts
deleted file mode 100644
index 1686861f978..00000000000
--- a/frontend/src/stimulus/controllers/dynamic/project.controller.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * -- copyright
- * OpenProject is an open source project management software.
- * Copyright (C) 2023 the OpenProject GmbH
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 3.
- *
- * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
- * Copyright (C) 2006-2013 Jean-Philippe Lang
- * Copyright (C) 2010-2013 the ChiliProject Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * See COPYRIGHT and LICENSE files for more details.
- * ++
- *
- */
-
-import { Controller } from '@hotwired/stimulus';
-
-export default class ProjectController extends Controller {
- static targets = [
- 'descriptionToggle',
- 'projectRow',
- 'descriptionRow',
- ];
-
- declare readonly descriptionToggleTargets:HTMLAnchorElement[];
- declare readonly projectRowTargets:HTMLTableRowElement[];
- declare readonly descriptionRowTargets:HTMLTableRowElement[];
-
- toggleDescription({ target, params: { projectId } }:{ target:HTMLAnchorElement, params:{ projectId:number } }) {
- const toggledTrigger = target;
- const otherTrigger = this.descriptionToggleTargets.find((trigger) => trigger !== toggledTrigger);
- // The projectId action parameter is automatically typecast to Number
- // and to compare it with a data attribute it needs to be converted to
- // a string.
- const clickedProjectRow = this.projectRowTargets.find((projectRow) => projectRow.getAttribute('data-project-id') === projectId.toString());
- const projectDescriptionRow = this.descriptionRowTargets.find((descriptionRow) => descriptionRow.getAttribute('data-project-id') === projectId.toString());
-
- if (clickedProjectRow && projectDescriptionRow) {
- clickedProjectRow.classList.toggle('-no-highlighting');
- clickedProjectRow.classList.toggle('-expanded');
- projectDescriptionRow.classList.toggle('-expanded');
-
- this.setAriaLive(projectDescriptionRow);
- }
-
- if (otherTrigger) {
- otherTrigger.focus();
- }
- }
-
- private setAriaLive(descriptionRow:HTMLElement) {
- if (descriptionRow.classList.contains('-expanded')) {
- descriptionRow.setAttribute('aria-live', 'polite');
- } else {
- descriptionRow.removeAttribute('aria-live');
- }
- }
-}
diff --git a/lookbook/previews/open_project/common/attribute_component_preview.rb b/lookbook/previews/open_project/common/attribute_component_preview.rb
new file mode 100644
index 00000000000..06819bac156
--- /dev/null
+++ b/lookbook/previews/open_project/common/attribute_component_preview.rb
@@ -0,0 +1,13 @@
+module OpenProject
+ module Common
+ # @logical_path OpenProject/Common
+ class AttributeComponentPreview < Lookbook::Preview
+ # @param id
+ # @param name
+ # @param description
+ def default(id: 'attribute_modal', name: 'Description', description: '<figure>This button is only visible when the description is truncated or it includes a figure or macro</figure>')
+ render OpenProject::Common::AttributeComponent.new(id, name, description)
+ end
+ end
+ end
+end
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index b2f27c2cccb..0785f25889e 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -228,6 +228,7 @@ RSpec.describe 'Projects index page',
end
context 'with valid Enterprise token', with_ee: %i[custom_fields_in_projects_list] do
+ shared_let(:long_text_custom_field) { create(:text_project_custom_field) }
specify 'CF columns and filters are not visible by default' do
load_and_open_filters admin
@@ -248,6 +249,40 @@ RSpec.describe 'Projects index page',
expect(page).to have_text(invisible_custom_field.name.upcase)
expect(page).to have_select('add_filter_select', with_options: [invisible_custom_field.name])
end
+
+ specify 'long-text fields are truncated' do
+ development_project.update(
+ description: 'I am a nice project with a very long long long long long long long long long description',
+ status_explanation: '<figure>I am a nice project status description with a figure</figure>',
+ custom_field_values: { custom_field.id => 'This is a short value', long_text_custom_field.id => 'This is a very long long long long long long long value' }
+ )
+
+ development_project.save!
+ login_as(admin)
+ Setting.enabled_projects_columns += [custom_field.column_name, long_text_custom_field.column_name, 'description', 'status_explanation']
+ projects_page.visit!
+
+ tr_project_development = page.first('tr', text: 'Development project')
+
+ # Check if the description is truncated and shows the Expand button correctly
+ td_project_development_description = tr_project_development.first('td.description')
+ expect(td_project_development_description).to have_css('button', text: 'Expand')
+ td_project_development_description.find('button', text: 'Expand').click
+ expect(page).to have_css('.Overlay-body', text: development_project.description)
+
+ # Check if the status explanation with an html tag is truncated and shows the cell text and Expand button correctly
+ td_project_development_status_description = tr_project_development.first('td.status_explanation')
+ expect(td_project_development_status_description).to have_css('button', text: 'Expand')
+ expect(td_project_development_status_description).to have_text('Preview not available')
+
+ # Check if a long-text costum field which has a short text as value is not truncated and there is no Expand button there
+ td_project_development_short_cf = tr_project_development.first('td', text: 'This is a short value')
+ expect(td_project_development_short_cf).to have_no_css('button', text: 'Expand')
+
+ # Check if a long-text costum field which has a long text as value is truncated and there is an Expand button there
+ td_project_development_long_cf = tr_project_development.first('td', text: 'This is a very long long long long long long long value')
+ expect(td_project_development_long_cf).to have_css('button', text: 'Expand')
+ end
end
context 'with a filter set' do