-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENHC0010020] Delete multiple samples from project samples table (#629)
* start delete multiple samples * Add tests * Fix validation and error handling for invalid sample ids * cleanup * Fix confirmation dialog * add fr translations * remove print statement * fix turbo_stream updates for destroy samples * remove unnecessary view * Add single remove functionality to remove selected samples * start implementing infinite scroll controller to delete multiple sample dialog * cleanup * change destructive button using tailwind.css file to actual tailwind classes * cleanup single delete controller * move single delete controller logic to use selection controller * Fix files deletion * Add infinite scroll description using singular/plural forms for selection count * Add and fix tests * refactor destroy_multiple to remove rubocop disables * revert to tailwind.css classes for action-link button * Improve sample query * update turbo stream replace in destroy.turbo_stream view * Add additional tests * add fr translations * Change testing logic to potentially prevent future flaky tests * further fix tests, add additional asserts * start changing over multi delete to different controller, add multi delete service * Continue refactoring multiple delete * test routes * test logic fix * Test different turbo streams for destroyu * Revert "Test different turbo streams for destroyu" This reverts commit b862f12. * Revert "test logic fix" This reverts commit 5b773b1. * Revert "test routes" This reverts commit 0df6153. * Revert "Continue refactoring multiple delete" This reverts commit cf31823. * Revert "start changing over multi delete to different controller, add multi delete service" This reverts commit 3eaf059. * Add multiple delete service for samples * fix test * Revert "fix test" This reverts commit e1b7068. * Revert "Add multiple delete service for samples" This reverts commit 51911c2. * Revert "Revert "start changing over multi delete to different controller, add multi delete service"" This reverts commit 9469e1b. * Revert "Revert "Continue refactoring multiple delete"" This reverts commit 8646591. * Revert "Revert "test routes"" This reverts commit 5fd6a2c. * Revert "Revert "test logic fix"" This reverts commit 37f026f. * Revert "Revert "Test different turbo streams for destroyu"" This reverts commit 9dfb191. * revert back to new controller, remove all old code from old controller/views * attempt to fix from show page * revert work prior to show page work * Further revert changes * Fix rubocop unhappiness * cleanup and add fr translations * fix up deletions controller test * Cleanup, add tests for multiple destroy service * Fix translations in samples testg * update multiple service test to use multiple samples for metadata summary test * move assert to prevent flaky testing * add before_action to get partial name for new action * change return if for def sample, fix def destroy block * fix test associated with previous commit * move multiple destroy service into original destroy service * cleanup, fix tests * Change destroy service to use params to specify between single sample and multiple sample ids * remove @ in destroy service * remove return from destroy_single * test removing unnecessary assertion to fix flaky test * test fixing flaky test * fix tests * fix test
- Loading branch information
1 parent
fdbb4d1
commit 8085ec6
Showing
27 changed files
with
958 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# frozen_string_literal: true | ||
|
||
module Projects | ||
module Samples | ||
# Controller actions for Project Samples Deletions | ||
class DeletionsController < Projects::ApplicationController | ||
before_action :sample, only: %i[new destroy] | ||
before_action :new_dialog_partial, only: :new | ||
|
||
def new | ||
authorize! @project, to: :destroy_sample? | ||
render turbo_stream: turbo_stream.update('samples_dialog', | ||
partial: @partial, | ||
locals: { | ||
open: true | ||
}), status: :ok | ||
end | ||
|
||
def destroy # rubocop:disable Metrics/AbcSize,Metrics/MethodLength | ||
::Samples::DestroyService.new(@project, current_user, { sample: @sample }).execute | ||
|
||
respond_to do |format| | ||
if @sample.deleted? | ||
format.html do | ||
flash[:success] = t('.success', sample_name: @sample.name, project_name: @project.namespace.human_name) | ||
redirect_to namespace_project_samples_path(format: :html) | ||
end | ||
format.turbo_stream do | ||
render status: :ok, locals: { type: 'success', | ||
message: t('.success', sample_name: @sample.name, | ||
project_name: @project.namespace.human_name) } | ||
end | ||
else | ||
format.turbo_stream do | ||
render status: :unprocessable_entity, | ||
locals: { type: 'alert', message: @sample.errors.full_messages.first } | ||
end | ||
end | ||
end | ||
end | ||
|
||
def destroy_multiple | ||
samples_to_delete_count = destroy_multiple_params['sample_ids'].count | ||
|
||
deleted_samples_count = ::Samples::DestroyService.new(@project, current_user, destroy_multiple_params).execute | ||
|
||
# No selected samples deleted | ||
if deleted_samples_count.zero? | ||
render status: :unprocessable_entity, locals: { type: :error, message: t('.no_deleted_samples') } | ||
# Partial sample deletion | ||
elsif deleted_samples_count.positive? && deleted_samples_count != samples_to_delete_count | ||
render status: :multi_status, | ||
locals: { messages: get_multi_status_destroy_multiple_message(deleted_samples_count, | ||
samples_to_delete_count) } | ||
# All samples deleted successfully | ||
else | ||
render status: :ok, locals: { type: :success, message: t('.success') } | ||
end | ||
end | ||
|
||
private | ||
|
||
def sample | ||
# Necessary return for new when deletion_type = 'multiple', as has no params[:sample_id] defined | ||
return if params[:deletion_type] == 'multiple' | ||
|
||
@sample = Sample.find_by(id: params[:id] || params[:sample_id], project_id: project.id) || not_found | ||
end | ||
|
||
def new_dialog_partial | ||
@partial = params['deletion_type'] == 'single' ? 'new_deletion_dialog' : 'new_multiple_deletions_dialog' | ||
end | ||
|
||
def destroy_multiple_params | ||
params.require(:multiple_deletion).permit(sample_ids: []) | ||
end | ||
|
||
def get_multi_status_destroy_multiple_message(deleted_samples_count, samples_to_delete_count) | ||
[ | ||
{ type: :success, | ||
message: t('.partial_success', | ||
deleted: "#{deleted_samples_count}/#{samples_to_delete_count}") }, | ||
{ type: :error, | ||
message: t('.partial_error', | ||
not_deleted: "#{samples_to_delete_count - deleted_samples_count}/#{samples_to_delete_count}") } | ||
] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/views/projects/samples/attachments/_delete_attachment_modal.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<%= viral_dialog(open: open, size: :large) do |dialog| %> | ||
<%= dialog.with_header(title: t(".title")) %> | ||
<%= dialog.with_section do %> | ||
|
||
<%= turbo_frame_tag("deletion-alert") %> | ||
|
||
<div | ||
data-controller="selection" | ||
data-selection-delete-id-param="<%= @attachment.id %>" | ||
data-selection-storage-key-value='<%="files-#{@sample.id}" %>' | ||
class="mb-4 font-normal text-slate-500 dark:text-slate-400 overflow-x-visible"> | ||
<p class="mb-4"> | ||
<%= t(".description") %> | ||
</p> | ||
<%= form_for(:deletion, url: namespace_project_sample_attachment_path(id: @attachment.id), method: :delete) do |form| %> | ||
<%= form.submit t(".submit_button"), | ||
class: " | ||
button | ||
text-sm | ||
px-5 | ||
py-2.5 | ||
text-white | ||
bg-red-700 | ||
border-red-800 | ||
focus:outline-none | ||
hover:bg-red-800 | ||
focus:ring-red-300 | ||
dark:focus:ring-red-700 | ||
dark:bg-red-600 | ||
dark:text-white | ||
dark:border-red-600 | ||
dark:hover:bg-red-700", | ||
data: { | ||
turbo_frame: "_top", | ||
action: "click->selection#remove", | ||
"selection-id-param": @attachment.id | ||
} %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% end %> |
Oops, something went wrong.