feat(Instructeurs::DossiersNavigationComponent): extract back button and next/prev within a component
This commit is contained in:
parent
b6e773f9fa
commit
f993393eb2
4 changed files with 62 additions and 0 deletions
43
app/components/instructeurs/dossiers_navigation_component.rb
Normal file
43
app/components/instructeurs/dossiers_navigation_component.rb
Normal 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
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
en:
|
||||||
|
next: Next file
|
||||||
|
previous: Previous file
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
fr:
|
||||||
|
next: Dossier suivant
|
||||||
|
previous: Dossier précédent
|
|
@ -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"
|
Loading…
Reference in a new issue