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
Extract `WorkPackages::Share::ShareRowComponent`
Aaron Contreras2c1e9a3a990b
diff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erbindex cac0f6c2b03..43a4a1a951e 100644--- a/app/components/work_packages/share/modal_body_component.html.erb+++ b/app/components/work_packages/share/modal_body_component.html.erb@@ -9,16 +9,15 @@endend- if shared_users.none?- modal_content.with_row(mt: 3) do- render(Primer::Beta::Blankslate.new(border: true)) do |component|- component.with_visual_icon(icon: :people, size: :medium)- component.with_heading(tag: :h2).with_content(I18n.t('work_package.sharing.text_empty_state_header') )- component.with_description do- flex_layout do |flex|- flex.with_row(mb: 2) do- render(Primer::Beta::Text.new(color: :subtle)) { I18n.t('work_package.sharing.text_empty_state_description') }- end+ if shared_users.none?+ modal_content.with_row(mt: 3) do+ render(Primer::Beta::Blankslate.new(border: true)) do |component|+ component.with_visual_icon(icon: :people, size: :medium)+ component.with_heading(tag: :h2).with_content(I18n.t('work_package.sharing.text_empty_state_header') )+ component.with_description do+ flex_layout do |flex|+ flex.with_row(mb: 2) do+ render(Primer::Beta::Text.new(color: :subtle)) { I18n.t('work_package.sharing.text_empty_state_description') }endendend@@ -34,28 +33,10 @@shared_users.each do |user|share = user.work_package_shares.where(entity: @work_package).first- invited_user_list.with_row(data: { 'test-selector': "op-share-wp-active-user-#{user.id}" }) do- grid_layout('op-share-wp-modal-body--user-row', tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|- user_row_grid.with_area(:user, tag: :div, classes: 'ellipsis') do- render(Users::AvatarComponent.new(user: user, size: :medium))- end-- if share_editable?(share)- user_row_grid.with_area(:button, tag: :div, color: :subtle) do- render(WorkPackages::Share::PermissionButtonComponent.new(share:,- data: { 'test-selector': 'op-share-wp-update-role' }))- end- end-- if share_editable?(share)- user_row_grid.with_area(:remove, tag: :div) do- form_with url: work_packages_share_path(share), method: :delete do- render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') }- end- end- end- end- end+ render(WorkPackages::Share::ShareRowComponent.new(user:,+ share:,+ container: invited_user_list,+ render_controls: share_editable?(share)))endendenddiff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erbnew file mode 100644index 00000000000..e4f1e45c8b2--- /dev/null+++ b/app/components/work_packages/share/share_row_component.html.erb@@ -0,0 +1,24 @@+<%=+ component_wrapper do+ container.with_row(id: wrapper_key, data: { 'test-selector': "op-share-wp-active-user-#{user.id}" }) do+ grid_layout('op-share-wp-modal-body--user-row', tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|+ user_row_grid.with_area(:user, tag: :div, classes: 'ellipsis') do+ render(Users::AvatarComponent.new(user: user, size: :medium))+ end++ if render_controls?+ user_row_grid.with_area(:button, tag: :div, color: :subtle) do+ render(WorkPackages::Share::PermissionButtonComponent.new(share:,+ data: { 'test-selector': 'op-share-wp-update-role' }))+ end++ user_row_grid.with_area(:remove, tag: :div) do+ form_with url: work_packages_share_path(share), method: :delete do+ render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') }+ end+ end+ end+ end+ end+ end+%>diff --git a/app/components/work_packages/share/share_row_component.rb b/app/components/work_packages/share/share_row_component.rbnew file mode 100644index 00000000000..8b2ff3d4159--- /dev/null+++ b/app/components/work_packages/share/share_row_component.rb@@ -0,0 +1,63 @@+# frozen_string_literal: true++# -- 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.+# ++++module WorkPackages+ module Share+ class ShareRowComponent < ApplicationComponent+ include ApplicationHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ def initialize(share:,+ user: share.principal,+ render_controls: false,+ container: nil)+ super++ @share = share+ @user = user+ @render_controls = render_controls+ @container = container+ end++ def wrapper_uniq_by+ share.id+ end++ private++ attr_reader :user, :share, :container++ def render_controls?+ !!@render_controls+ end+ end+ end+end