poc(batch_operation_alert): simplier wording

This commit is contained in:
Martin 2022-12-05 17:07:59 +01:00 committed by mfo
parent 3d2f0ebb88
commit 7c65af3be0
8 changed files with 28 additions and 68 deletions

View file

@ -4,6 +4,7 @@ class Dossiers::BatchAlertComponent < ApplicationComponent
def initialize(batch:, procedure:)
@batch = batch
@procedure = procedure
set_seen_at! if batch.finished_at.present?
end
def set_seen_at!

View file

@ -1,17 +1,13 @@
en:
finish:
title: The bulk action is finished
text_success:
one: 1 file has been archived
other: "%{count} files have been archived"
text_fail:
one: 1 file has not been archived
other: "%{count} have not been archived"
text:
one: 1/1 file has been archived
other: "%{success_count}/%{count} files have been archived"
in_progress:
title: A bulk action is processing
text_beginning: "0/ %{count} file archived"
text_success:
one: 1 file has been archived
other: "%{count} files have been archived"
one: 1/1 is being archived
other: "%{progress_count}/%{count} files have been archived"
link_text: Refresh this webpage
after_link_text: to check if the process is over.

View file

@ -3,15 +3,11 @@ fr:
title: L'action de masse est terminée
text_success:
one: 1 dossier a été archivé
other: "%{count} dossiers ont été archivés"
text_fail:
one: 1 dossier n'a pas été archivé
other: "%{count} dossiers n'ont pas été archivés"
other: "%{success_count}/%{count} dossiers ont été archivés"
in_progress:
title: Une action de masse est en cours
text_beginning: "0/ %{count} dossier archivé"
text_success:
one: 1 dossier a été archivé
other: "%{count} dossiers ont été archivés"
one: 1 dossier sera archivé
other: "%{progress_count}/%{count} dossiers ont été archivés"
link_text: Recharger la page
after_link_text: pour voir si l'opération est finie.

View file

@ -1,34 +1,15 @@
.fr-mb-5v
- if @batch.finished_and_success? && @batch.seen_at.nil?
= render Dsfr::AlertComponent.new(title: t('.finish.title'), state: :success, heading_level: 'h2') do |c|
- if @batch.finished_at.present?
= render Dsfr::AlertComponent.new(title: t('.finish.title'), state: (@batch.failed_dossier_ids.size.positive? ? :warning : :success), heading_level: 'h2') do |c|
- c.body do
%p
= t('.finish.text_success', count: @batch.success_dossier_ids.count)
- set_seen_at!
= t('.finish.text_success', count: @batch.total_count, success_count: @batch.success_dossier_ids.size)
- if @batch.finished_and_fails? && @batch.seen_at.nil?
= render Dsfr::AlertComponent.new(title: t('.finish.title'), state: :warning, heading_level: 'h2') do |c|
- c.body do
%p
= t('.finish.text_fail', count: @batch.failed_dossier_ids.count)
- set_seen_at!
- if @batch.beginning?
- else
= render Dsfr::AlertComponent.new(title: t('.in_progress.title'), state: :info, heading_level: 'h2') do |c|
- c.body do
%p
= t('.in_progress.text_beginning', count: @batch.dossiers.count)
%p
= link_to t('.link_text'), instructeur_procedure_path(@procedure, statut: params["statut"]), data: { action: 'turbo-poll#refresh' }
= t('.after_link_text')
- if @batch.in_progress?
= render Dsfr::AlertComponent.new(title: t('.in_progress.title'), state: :info, heading_level: 'h2') do |c|
- c.body do
- if @batch.success_dossier_ids.present?
%p
= t('.in_progress.text_success', count: @batch.success_dossier_ids.count)
%p= t('.in_progress.text_success', count: @batch.total_count, progress_count: @batch.progress_count)
%p
= link_to t('.link_text'), instructeur_procedure_path(@procedure, statut: params["statut"]), data: { action: 'turbo-poll#refresh' }

View file

@ -93,6 +93,7 @@ module Instructeurs
@batch_operations = BatchOperation.joins(:groupe_instructeurs)
.where(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id))
.where(seen_at: nil)
.distinct
end

View file

@ -108,20 +108,17 @@ class BatchOperation < ApplicationRecord
dossiers.count.zero?
end
def finished_and_success?
called_for_last_time? && failed_dossier_ids.empty?
def total_count
total = failed_dossier_ids.size + success_dossier_ids.size
if finished_at.blank?
total += dossiers.count
end
total
end
def finished_and_fails?
called_for_last_time? && failed_dossier_ids.present?
end
def in_progress?
!called_for_last_time? && (failed_dossier_ids + success_dossier_ids).present?
end
def beginning?
!called_for_last_time? && (failed_dossier_ids + success_dossier_ids).empty?
def progress_count
failed_dossier_ids.size + success_dossier_ids.size
end
private

View file

@ -13,12 +13,6 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
subject { render_inline(component).to_html }
context 'beginning' do
it { is_expected.to have_selector('.fr-alert--info') }
it { is_expected.to have_text("Une action de masse est en cours") }
it { is_expected.to have_text("0/ 2 dossier archivé") }
end
context 'in_progress' do
before {
batch_operation.track_processed_dossier(true, dossier)
@ -27,7 +21,7 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
it { is_expected.to have_selector('.fr-alert--info') }
it { is_expected.to have_text("Une action de masse est en cours") }
it { is_expected.to have_text("1 dossier a été archivé") }
it { is_expected.to have_text("1/2 dossiers ont été archivés") }
end
context 'finished and success' do
@ -41,12 +35,6 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
it { is_expected.to have_text("L'action de masse est terminée") }
it { is_expected.to have_text("2 dossiers ont été archivés") }
it { expect(batch_operation.seen_at).to eq(nil) }
it 'does not display alert on the next render' do
render_inline(component).to_html
expect(batch_operation.seen_at).not_to eq(nil)
expect(subject).not_to have_text("2 dossiers ont été archivés")
end
end
context 'finished and fail' do
@ -58,7 +46,7 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
it { is_expected.to have_selector('.fr-alert--warning') }
it { is_expected.to have_text("L'action de masse est terminée") }
it { is_expected.to have_text("1 dossier n'a pas été archivé") }
it { is_expected.to have_text("1/2 dossiers ont été archivés") }
it { expect(batch_operation.seen_at).to eq(nil) }
it 'does not display alert on the next render' do

View file

@ -36,7 +36,7 @@ describe 'BatchOperation a dossier:', js: true do
# ensure alert is present
expect(page).to have_content("Information : Une action de masse est en cours")
expect(page).to have_content("0/ 1 dossier archivé")
expect(page).to have_content("1 dossier sera archivé")
# ensure jobs are queued
perform_enqueued_jobs(only: [BatchOperationEnqueueAllJob])