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

Update `ShareRowComponent` to include checkboxes for selection

Aaron Contreras167d0656329c
diff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erb
index bdd24d120d7..01e95097557 100644
--- a/app/components/work_packages/share/modal_body_component.html.erb
+++ b/app/components/work_packages/share/modal_body_component.html.erb
@@ -20,10 +20,24 @@
end
end
else
- modal_content.with_row(mt: 3, data: { 'test-selector': 'op-share-wp-active-list'}) do
+ modal_content.with_row(mt: 3,
+ data: { 'test-selector': 'op-share-wp-active-list',
+ controller: 'work-packages--share--bulk-selection',
+ application_target: 'dynamic' }) do
invited_user_list do |border_box|
- border_box.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-active-count' }) do
- render(WorkPackages::Share::ShareCounterComponent.new(count: shared_principals.count))
+ border_box.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-header' }) do
+ grid_layout('op-share-wp-modal-body--header', tag: :div, align_items: :center) do |header_grid|
+ header_grid.with_area(:counter, tag: :div) do
+ render(WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: shared_principals.size))
+ end
+
+ header_grid.with_area(:remove, tag: :div) do
+ form_with url: work_package_shares_bulk_path, method: :delete do
+ concat(content_tag(:div, {}, data: { 'work-packages--share--bulk-selection-target': 'hiddenShareIdsContainer' }))
+ concat(render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') })
+ end
+ end
+ end
end
shared_principals.each do |principal|
@@ -31,8 +45,7 @@
.where(entity: @work_package)
.first
- render(WorkPackages::Share::ShareRowComponent.new(share:,
- container: border_box))
+ render(WorkPackages::Share::ShareRowComponent.new(share:, container: border_box))
end
end
end
diff --git a/app/components/work_packages/share/modal_body_component.rb b/app/components/work_packages/share/modal_body_component.rb
index 7adedf78ad0..12d4fd911bb 100644
--- a/app/components/work_packages/share/modal_body_component.rb
+++ b/app/components/work_packages/share/modal_body_component.rb
@@ -32,6 +32,7 @@ module WorkPackages
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
+ include WorkPackages::Share::Concerns::Authorization
def initialize(work_package:)
super
diff --git a/app/components/work_packages/share/modal_body_component.sass b/app/components/work_packages/share/modal_body_component.sass
index dea5e674881..3b0049d8431 100644
--- a/app/components/work_packages/share/modal_body_component.sass
+++ b/app/components/work_packages/share/modal_body_component.sass
@@ -1,6 +1,13 @@
.op-share-wp-modal-body
&--user-row
display: grid
- grid-template-columns: 1fr auto auto
- grid-template-areas: "user button remove"
+ grid-template-columns: 20px 1fr auto auto
+ grid-template-areas: "selection user button remove"
grid-gap: 10px
+ &--header
+ display: grid
+ grid-template-columns: 1fr auto
+ grid-template-areas: "counter remove"
+ &--counter
+ &--container
+ display: flex // Vertically align checkbox and counter
diff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erb
index e4f961d7fb9..97ac8ea9d03 100644
--- a/app/components/work_packages/share/share_row_component.html.erb
+++ b/app/components/work_packages/share/share_row_component.html.erb
@@ -1,10 +1,20 @@
<%=
component_wrapper(:border_box_row, data: { 'test-selector': "op-share-wp-active-user-#{principal.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: principal, size: :medium))
+ user_row_grid.with_area(:selection, tag: :div) do
+ if share_editable?
+ render(Primer::Alpha::CheckBox.new(name: "share_ids", value: share.id, label: "#{principal.name}",
+ visually_hide_label: true, scheme: :array,
+ data: {
+ 'work-packages--share--bulk-selection-target': 'shareCheckbox',
+ action: 'work-packages--share--bulk-selection#refresh'
+ }))
+ end
end
+ user_row_grid.with_area(:user, tag: :div, classes: 'ellipsis') do
+ render(Users::AvatarComponent.new(user: principal, size: :medium))
+ end
if share_editable?
user_row_grid.with_area(:button, tag: :div, color: :subtle) do
diff --git a/app/components/work_packages/share/share_row_component.rb b/app/components/work_packages/share/share_row_component.rb
index f0d399b1f1c..3ef9de12159 100644
--- a/app/components/work_packages/share/share_row_component.rb
+++ b/app/components/work_packages/share/share_row_component.rb
@@ -69,6 +69,16 @@ module WorkPackages
def share_editable?
@share_editable ||= User.current != share.principal && sharing_manageable?
end
+
+ def select_share_checkbox_options
+ {
+ name: "share_ids",
+ value: share.id,
+ scheme: :array,
+ label: principal.name,
+ visually_hide_label: true
+ }
+ end
end
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3813e0620dd..b16e3682615 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3201,6 +3201,7 @@ en:
invite: "Invite"
label_search: "Search for users to invite"
label_search_placeholder: "Search by user or email address"
+ label_toggle_all: "Toggle all shares"
permissions:
comment: "Comment"
comment_description: "Can view and comment this work package."