From 73293b0d0620c22acf4b2453bedaecffd4b6919e Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 19 Jul 2024 17:39:55 +0200 Subject: [PATCH] give facet object instead of field_id to instructeur_filter_component --- .../dossiers/instructeur_filter_component.rb | 13 +++++-------- .../instructeur_filter_component.html.haml | 4 ++-- .../instructeurs/procedures_controller.rb | 2 +- app/models/procedure_presentation.rb | 4 ---- .../procedures/_dossiers_filter_dropdown.html.haml | 2 +- .../procedures/update_filter.turbo_stream.haml | 2 +- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/components/dossiers/instructeur_filter_component.rb b/app/components/dossiers/instructeur_filter_component.rb index 7e841f5c4..eecef1897 100644 --- a/app/components/dossiers/instructeur_filter_component.rb +++ b/app/components/dossiers/instructeur_filter_component.rb @@ -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', diff --git a/app/components/dossiers/instructeur_filter_component/instructeur_filter_component.html.haml b/app/components/dossiers/instructeur_filter_component/instructeur_filter_component.html.haml index f98e93700..f347727f5 100644 --- a/app/components/dossiers/instructeur_filter_component/instructeur_filter_component.html.haml +++ b/app/components/dossiers/instructeur_filter_component/instructeur_filter_component.html.haml @@ -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' diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 6de8cfdee..8d0e66b7f 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -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 diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 64db2927f..d63f851c0 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -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? diff --git a/app/views/instructeurs/procedures/_dossiers_filter_dropdown.html.haml b/app/views/instructeurs/procedures/_dossiers_filter_dropdown.html.haml index 4bcafb3ed..3cd95da34 100644 --- a/app/views/instructeurs/procedures/_dossiers_filter_dropdown.html.haml +++ b/app/views/instructeurs/procedures/_dossiers_filter_dropdown.html.haml @@ -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:) diff --git a/app/views/instructeurs/procedures/update_filter.turbo_stream.haml b/app/views/instructeurs/procedures/update_filter.turbo_stream.haml index a5cd42c91..4d88e0852 100644 --- a/app/views/instructeurs/procedures/update_filter.turbo_stream.haml +++ b/app/views/instructeurs/procedures/update_filter.turbo_stream.haml @@ -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)