From d855c94fbfb82b4f0abcbb7ff8c7a3ba6f48ae4e Mon Sep 17 00:00:00 2001
From: Colin Darie <colin@darie.eu>
Date: Tue, 12 Mar 2024 17:18:18 +0100
Subject: [PATCH] feat(faq): breadcrumb

---
 app/views/faq/_breadcrumb.html.haml             | 13 +++++++++++++
 app/views/faq/index.html.haml                   |  1 +
 app/views/faq/show.html.haml                    |  5 ++++-
 config/locales/faqs.fr.yml                      |  3 +++
 config/locales/views/layouts/_breadcrumb.en.yml |  1 +
 config/locales/views/layouts/_breadcrumb.fr.yml |  1 +
 6 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 app/views/faq/_breadcrumb.html.haml

diff --git a/app/views/faq/_breadcrumb.html.haml b/app/views/faq/_breadcrumb.html.haml
new file mode 100644
index 000000000..205b5effb
--- /dev/null
+++ b/app/views/faq/_breadcrumb.html.haml
@@ -0,0 +1,13 @@
+%nav.fr-breadcrumb{ role: "navigation", 'aria-label': t('you_are_here', scope: [:layouts, :breadcrumb]) }
+  %button.fr-breadcrumb__button{ 'aria-expanded' => "false", 'aria-controls' => "breadcrumb-1" }
+    = t('show', scope: [:layouts, :breadcrumb])
+  .fr-collapse#breadcrumb-1
+    %ol.fr-breadcrumb__list
+      %li= link_to t('root', scope: [:layouts, :breadcrumb]), root_path, class: 'fr-breadcrumb__link'
+
+      %li
+        %a.fr-breadcrumb__link{ **(defined?(faq_title) ? { href: faq_index_path } : { "aria-current": "page" }) }= t('faq', scope: [:layouts, :breadcrumb])
+
+      - if defined?(faq_title)
+        %li
+          %a.fr-breadcrumb__link{ 'aria-current' => "page" }= faq_title
diff --git a/app/views/faq/index.html.haml b/app/views/faq/index.html.haml
index e0c311e18..a2026b203 100644
--- a/app/views/faq/index.html.haml
+++ b/app/views/faq/index.html.haml
@@ -1,6 +1,7 @@
 - content_for(:title, t('.meta_title'))
 
 .fr-container.fr-my-4w
+  = render partial: "breadcrumb"
   .fr-grid-row
     .fr-col-12.fr-col-md-10
       %h1= t('.title', app_name: Current.application_name)
diff --git a/app/views/faq/show.html.haml b/app/views/faq/show.html.haml
index cca79a4f0..b2ff97df6 100644
--- a/app/views/faq/show.html.haml
+++ b/app/views/faq/show.html.haml
@@ -1,9 +1,12 @@
 - content_for(:title, @metadata[:title])
 
 .fr-container.fr-my-4w
+
   .fr-grid-row
     .fr-col-12.fr-col-md-4
       = render partial: "sidebar", locals: { faqs: @siblings, current: @metadata }
-    .fr-col-12.fr-col-md-8.fr-py-12v
+    .fr-col-12.fr-col-md-8
+      = render partial: "breadcrumb", locals: { faq_title: "#{t(:short_name, scope: [:faq, :categories, @metadata[:category]])} : #{@metadata[:title]}" }
+
       .markdown-content
         = @renderer.render(@content).html_safe
diff --git a/config/locales/faqs.fr.yml b/config/locales/faqs.fr.yml
index bf647efa8..b7bf89765 100644
--- a/config/locales/faqs.fr.yml
+++ b/config/locales/faqs.fr.yml
@@ -6,12 +6,15 @@ fr:
     sidebar_button: Dans cette Foire Aux Questions
     categories:
       usager:
+        short_name: Usager
         name: Usager (dépôt d’un dossier)
         description: Aide pour les usagers sur la soumission et le suivi des dossiers, incluant la résolution des problèmes courants.
       instructeur:
+        short_name: Instructeur
         name: Instructeur (traitement des dossiers)
         description: À destination des instructeurs sur l’accès et la gestion des dossiers.
       administrateur:
+        short_name: Administrateur
         name: Administrateur (création d’un formulaire)
         description: Informations pour les administrateurs sur la configuration de la plateforme ou la création de démarches.
     subcategories:
diff --git a/config/locales/views/layouts/_breadcrumb.en.yml b/config/locales/views/layouts/_breadcrumb.en.yml
index 167f44f30..03328421e 100644
--- a/config/locales/views/layouts/_breadcrumb.en.yml
+++ b/config/locales/views/layouts/_breadcrumb.en.yml
@@ -16,3 +16,4 @@ en:
       more_info_on_test: "For more information on test stage"
       go_to_FAQ: "read FAQ"
       url_FAQ: "https://faq.demarches-simplifiees.fr/category/49-comment-tester-ma-demarche"
+      faq: Frequently Asked Questions
diff --git a/config/locales/views/layouts/_breadcrumb.fr.yml b/config/locales/views/layouts/_breadcrumb.fr.yml
index 27086e424..f67542e4e 100644
--- a/config/locales/views/layouts/_breadcrumb.fr.yml
+++ b/config/locales/views/layouts/_breadcrumb.fr.yml
@@ -16,3 +16,4 @@ fr:
       more_info_on_test: "Pour plus d’information sur la phase de test"
       go_to_FAQ: "consulter la FAQ"
       url_FAQ: "https://faq.demarches-simplifiees.fr/category/49-comment-tester-ma-demarche"
+      faq: Foire aux Questions