give facet object instead of field_id to instructeur_filter_component

This commit is contained in:
simon lehericey 2024-07-19 17:39:55 +02:00 committed by mfo
parent 437e632f6a
commit 73293b0d06
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
6 changed files with 10 additions and 17 deletions

View file

@ -1,17 +1,14 @@
class Dossiers::InstructeurFilterComponent < ApplicationComponent
def initialize(procedure:, procedure_presentation:, statut:, field_id: nil)
def initialize(procedure:, procedure_presentation:, statut:, facet: nil)
@procedure = procedure
@procedure_presentation = procedure_presentation
@statut = statut
@field_id = field_id
@facet = facet
end
attr_reader :procedure, :procedure_presentation, :statut, :field_id
attr_reader :procedure, :procedure_presentation, :statut, :facet
def field_type
return :text if field_id.nil?
procedure_presentation.field_type(field_id)
end
def facet_type = facet.present? ? facet.type : :text
def options_for_select_of_field
procedure_presentation.field_enum(field_id)
@ -19,7 +16,7 @@ class Dossiers::InstructeurFilterComponent < ApplicationComponent
def filter_react_props
{
selected_key: @field_id || '',
selected_key: facet.present? ? facet.id : '',
items: procedure_presentation.filterable_fields_options,
name: :field,
id: 'search-filter',

View file

@ -7,10 +7,10 @@
%input.hidden{ type: 'submit', formaction: update_filter_instructeur_procedure_path(procedure), data: { autosubmit_target: 'submitter' } }
= label_tag :value, t('.value'), for: 'value', class: 'fr-label'
- if field_type == :enum
- if facet_type == :enum
= select_tag :value, options_for_select(options_for_select_of_field), id: 'value', name: 'value', class: 'fr-select', data: { no_autosubmit: true }
- else
%input#value.fr-input{ type: field_type, name: :value, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH, disabled: field_id.nil? ? true : false, data: { no_autosubmit: true } }
%input#value.fr-input{ type: facet_type, name: :value, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH, disabled: facet.nil? ? true : false, data: { no_autosubmit: true } }
= hidden_field_tag :statut, statut
= submit_tag t('.add_filter'), class: 'fr-btn fr-btn--secondary fr-mt-2w'

View file

@ -159,7 +159,7 @@ module Instructeurs
@statut = statut
@procedure = procedure
@procedure_presentation = procedure_presentation
@field = params[:field]
@facet = Facet.find(procedure: , id: params[:field])
end
def remove_filter

View file

@ -271,10 +271,6 @@ class ProcedurePresentation < ApplicationRecord
slice(:filters, :sort, :displayed_fields)
end
def field_type(facet_id)
Facet.find(procedure:, id: facet_id).type
end
def field_enum(facet_id)
facet = Facet.find(procedure:, id: facet_id)
if facet.scope.present?

View file

@ -3,4 +3,4 @@
= t('views.instructeurs.dossiers.filters.title')
- menu.with_form do
= render Dossiers::InstructeurFilterComponent.new(procedure: procedure, procedure_presentation: @procedure_presentation, statut: statut)
= render Dossiers::InstructeurFilterComponent.new(procedure:, procedure_presentation: @procedure_presentation, statut:)

View file

@ -1,2 +1,2 @@
= turbo_stream.replace 'filter-component' do
= render Dossiers::InstructeurFilterComponent.new(procedure: @procedure, procedure_presentation: @procedure_presentation, statut: @statut, field_id: @field)
= render Dossiers::InstructeurFilterComponent.new(procedure: @procedure, procedure_presentation: @procedure_presentation, statut: @statut, facet: @facet)