feat(Instructeurs::DossiersNavigationComponent): extract back button and next/prev within a component

This commit is contained in:
mfo 2024-11-29 11:53:28 +01:00
parent b6e773f9fa
commit f993393eb2
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
4 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,43 @@
# frozen_string_literal: true
class Instructeurs::DossiersNavigationComponent < ApplicationComponent
attr_reader :dossier, :statut
def initialize(dossier:, procedure_presentation:, statut:)
@dossier = dossier
@cache = Cache::ProcedureDossierPagination.new(procedure_presentation: procedure_presentation, statut:)
@statut = statut
end
def back_url_options
options = { statut: }
options = options.merge(page: @cache.incoming_page) if @cache.incoming_page
options
end
def link_next
options = { class: "fr-link fr-icon-arrow-right-line fr-link--icon-right fr-ml-3w" }
if has_next?
tag.a(t('.next'), **options.merge(href: next_instructeur_dossier_path(dossier:, statut:)))
else
options[:class] = "#{options[:class]} fr-text-mention--grey"
tag.span(t('.next'), **options)
end
end
def link_previous
options = { class: "fr-link fr-icon-arrow-left-line fr-link--icon-left" }
if has_previous?
tag.a(t('.previous'), **options.merge(href: previous_instructeur_dossier_path(dossier:, statut:)))
else
options[:class] = "#{options[:class]} fr-text-mention--grey"
tag.span(t('.previous'), **options)
end
end
def has_next? = @has_next ||= @cache.next_dossier_id(from_id: dossier.id).present?
def has_previous? = @has_previous ||= @cache.previous_dossier_id(from_id: dossier.id).present?
end

View file

@ -0,0 +1,4 @@
---
en:
next: Next file
previous: Previous file

View file

@ -0,0 +1,4 @@
---
fr:
next: Dossier suivant
previous: Dossier précédent

View file

@ -0,0 +1,11 @@
.flex.fr-mb-1w.align-center
= render Instructeurs::BackButtonComponent.new(to: instructeur_procedure_path(dossier.procedure, **back_url_options))
%h1.fr-h3.fr-mb-0
= t('show_dossier', scope: [:layouts, :breadcrumb], dossier_id: dossier.id, owner_name: dossier.owner_name)
.fr.ml-auto.align-center.flex
= link_previous
= link_next
= link_to dossier.procedure.libelle.truncate_words(10), instructeur_procedure_path(dossier.procedure), title: dossier.procedure.libelle, class: "fr-link"