From 307ba68970059fb436af7af23d13a65fdf86762e Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 20 Sep 2023 14:00:18 +0200 Subject: [PATCH] feat(exports): humanize status name --- .../dossiers/export_link_component.rb | 11 ++++++++-- app/helpers/tabs_helper.rb | 21 +++++++++++++++++++ .../instructeurs/procedures/_tabs.html.haml | 15 +++++++------ .../instructeurs/procedures/exports/en.yml | 2 +- .../instructeurs/procedures/exports/fr.yml | 2 +- spec/system/instructeurs/instruction_spec.rb | 6 +++--- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/components/dossiers/export_link_component.rb b/app/components/dossiers/export_link_component.rb index 7edc3782a..e79214ae5 100644 --- a/app/components/dossiers/export_link_component.rb +++ b/app/components/dossiers/export_link_component.rb @@ -1,5 +1,6 @@ class Dossiers::ExportLinkComponent < ApplicationComponent include ApplicationHelper + include TabsHelper def initialize(procedure:, exports:, statut: nil, count: nil, class_btn: nil, export_url: nil) @procedure = procedure @@ -35,12 +36,18 @@ class Dossiers::ExportLinkComponent < ApplicationComponent case count when nil - t(".export_title", export_tabs: export.statut.to_s, export_format: export.format) + t(".export_title", export_tabs: human_export_status(export), export_format: export.format) else - t(".export_title_counted", export_tabs: export.statut.to_s, export_format: export.format, count: count) + t(".export_title_counted", export_tabs: human_export_status(export), export_format: export.format, count: count) end end + def human_export_status(export) + key = tab_i18n_key_from_status(export.statut) + + t(key, count: export.count) || export.statut + end + def badge(export) if export.available? content_tag(:span, t(".success_label"), { class: "fr-badge fr-badge--success fr-text-right" }) diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index 6080aa2ad..a40dbbb81 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -1,4 +1,25 @@ module TabsHelper + def tab_i18n_key_from_status(status) + case status + when 'a-suivre' + 'views.instructeurs.dossiers.tab_steps.to_follow' # i18n-tasks-use t('views.instructeurs.dossiers.tab_steps.to_follow') + when 'suivis' + 'pluralize.followed' + when 'traites' + 'pluralize.processed' + when 'tous' + 'views.instructeurs.dossiers.tab_steps.total' # i18n-tasks-use t('views.instructeurs.dossiers.tab_steps.total') + when 'supprimes_recemment' + 'pluralize.dossiers_supprimes_recemment' + when 'expirant' + 'pluralize.dossiers_close_to_expiration' + when 'archives' + 'pluralize.archived' + else + fail ArgumentError, "Unknown tab status: #{status}" + end + end + def tab_item(label, url, active: false, badge: nil, notification: false) render partial: 'shared/tab_item', locals: { label: label, diff --git a/app/views/instructeurs/procedures/_tabs.html.haml b/app/views/instructeurs/procedures/_tabs.html.haml index e250f4840..b3dc9f2ff 100644 --- a/app/views/instructeurs/procedures/_tabs.html.haml +++ b/app/views/instructeurs/procedures/_tabs.html.haml @@ -1,40 +1,39 @@ %nav.tabs.mt-3 %ul - = tab_item(t('views.instructeurs.dossiers.tab_steps.to_follow'), + = tab_item(t(tab_i18n_key_from_status('a-suivre')), instructeur_procedure_path(procedure, statut: 'a-suivre'), active: statut == 'a-suivre', badge: number_with_html_delimiter(a_suivre_count)) - = tab_item(t('pluralize.followed', count: suivis_count), + = tab_item(t(tab_i18n_key_from_status('suivis'), count: suivis_count), instructeur_procedure_path(procedure, statut: 'suivis'), active: statut == 'suivis', badge: number_with_html_delimiter(suivis_count), notification: has_en_cours_notifications) - = tab_item(t('pluralize.processed', count: traites_count), + = tab_item(t(tab_i18n_key_from_status('traites'), count: traites_count), instructeur_procedure_path(procedure, statut: 'traites'), active: statut == 'traites', badge: number_with_html_delimiter(traites_count), notification: has_termine_notifications) - = tab_item(t('views.instructeurs.dossiers.tab_steps.total'), + = tab_item(t(tab_i18n_key_from_status('tous')), instructeur_procedure_path(procedure, statut: 'tous'), active: statut == 'tous', badge: number_with_html_delimiter(tous_count)) - = tab_item(t('pluralize.dossiers_supprimes_recemment', count: supprimes_recemment_count), + = tab_item(t(tab_i18n_key_from_status('supprimes_recemment'), count: supprimes_recemment_count), instructeur_procedure_path(procedure, statut: 'supprimes_recemment'), active: statut == 'supprimes_recemment', badge: number_with_html_delimiter(supprimes_recemment_count)) - if procedure.procedure_expires_when_termine_enabled - = tab_item(t('pluralize.dossiers_close_to_expiration', count: expirant_count), + = tab_item(t(tab_i18n_key_from_status('expirant'), count: expirant_count), instructeur_procedure_path(procedure, statut: 'expirant'), active: statut == 'expirant', badge: number_with_html_delimiter(expirant_count)) - = tab_item(t('pluralize.archived', count: archives_count), + = tab_item(t(tab_i18n_key_from_status('archives'), count: archives_count), instructeur_procedure_path(procedure, statut: 'archives'), active: statut == 'archives', badge: number_with_html_delimiter(archives_count)) - diff --git a/config/locales/views/instructeurs/procedures/exports/en.yml b/config/locales/views/instructeurs/procedures/exports/en.yml index 9c0f3302d..5307ee6a3 100644 --- a/config/locales/views/instructeurs/procedures/exports/en.yml +++ b/config/locales/views/instructeurs/procedures/exports/en.yml @@ -5,5 +5,5 @@ en: export_pending_html: We generate this export. You will be able to download it in a few minutes from the exports list. exports: title: Exports list - export_description: This list of exports contains the exports you requested as well as those requested by instructors belonging to the same group. + export_description: This list of exports contains the last exports you requested as well as those requested by instructors belonging to the same group. no_export_html: You have no export at the moment.
Can't find an export? It may have expired, exports are deleted after %{expiration_time} hours. diff --git a/config/locales/views/instructeurs/procedures/exports/fr.yml b/config/locales/views/instructeurs/procedures/exports/fr.yml index 6f8c49091..fc0b8f1f8 100644 --- a/config/locales/views/instructeurs/procedures/exports/fr.yml +++ b/config/locales/views/instructeurs/procedures/exports/fr.yml @@ -5,5 +5,5 @@ fr: export_pending_html: Nous générons cet export. Vous pourrez le télécharger dans quelques minutes depuis la liste des exports. exports: title: Liste des exports - export_description: Cette liste d'exports contient les exports que vous avez demandé ainsi que ceux demandés par les instructeurs appartenant au même groupe. + export_description: Cette liste d'exports contient les derniers exports que vous avez demandés ainsi que ceux demandés par les instructeurs appartenant au même groupe. no_export_html: Vous n'avez pas d'export pour le moment.
Vous ne trouvez pas un export ? Il a peut-être expiré, les exports sont supprimés au bout de %{expiration_time} heures. diff --git a/spec/system/instructeurs/instruction_spec.rb b/spec/system/instructeurs/instruction_spec.rb index f8c45f36c..97999e069 100644 --- a/spec/system/instructeurs/instruction_spec.rb +++ b/spec/system/instructeurs/instruction_spec.rb @@ -122,15 +122,15 @@ describe 'Instructing a dossier:', js: true, retry: 3 do expect(page).to have_text('Nous générons cet export.') click_on "voir les exports" - expect(page).to have_text("Export .csv pour les dossiers « a-suivre » - demandé il y a moins d'une minute") - expect(page).to have_text("En cours") + expect(page).to have_text("Export .csv d’un dossier « à suivre » demandé il y a moins d'une minute") + expect(page).to have_text("En préparation") assert_performed_jobs 2 do perform_enqueued_jobs(only: ExportJob) end page.driver.browser.navigate.refresh - expect(page).to have_text('Télécharger l’export au format .csv') + expect(page).to have_text('Télécharger l’export .csv') end scenario 'A instructeur can see the personnes impliquées' do