diff --git a/app/components/dossiers/instructeur_facet_picker_component.rb b/app/components/dossiers/instructeur_facet_picker_component.rb new file mode 100644 index 000000000..0b2b25a0f --- /dev/null +++ b/app/components/dossiers/instructeur_facet_picker_component.rb @@ -0,0 +1,16 @@ +class Dossiers::InstructeurFacetPickerComponent < ApplicationComponent + attr_reader :procedure, :procedure_presentation + + def initialize(procedure:, procedure_presentation:) + @procedure = procedure + @procedure_presentation = procedure_presentation + @displayable_fields_for_select, @displayable_fields_selected = displayable_fields_for_select + end + + def displayable_fields_for_select + [ + procedure.facets.reject(&:virtual).map { |facet| [facet.label, facet.id] }, + procedure_presentation.displayed_fields.map { Facet.new(**_1.deep_symbolize_keys).id } + ] + end +end diff --git a/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.en.yml b/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.en.yml new file mode 100644 index 000000000..4c5d618b4 --- /dev/null +++ b/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.en.yml @@ -0,0 +1,3 @@ +--- +en: + save: 'Save' diff --git a/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.fr.yml b/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.fr.yml new file mode 100644 index 000000000..8403f9691 --- /dev/null +++ b/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.fr.yml @@ -0,0 +1,3 @@ +--- +fr: + save: 'Enregistrer' diff --git a/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.html.haml b/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.html.haml new file mode 100644 index 000000000..e0a6cd958 --- /dev/null +++ b/app/components/dossiers/instructeur_facet_picker_component/instructeur_facet_picker_component.html.haml @@ -0,0 +1,5 @@ += form_tag update_displayed_fields_instructeur_procedure_path(@procedure), method: :patch, class: 'dropdown-form large columns-form' do + %react-fragment + = render ReactComponent.new "ComboBox/MultiComboBox", items: @displayable_fields_for_select, selected_keys: @displayable_fields_selected, name: 'values[]', 'aria-label': 'Colonne à afficher' + + = submit_tag t('.save'), class: 'fr-btn fr-btn--secondary' diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 96824488d..c7bd254b7 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -72,7 +72,6 @@ module Instructeurs @procedure_presentation = procedure_presentation @current_filters = current_filters - @displayable_fields_for_select, @displayable_fields_selected = procedure_presentation.displayable_fields_for_select @counts = current_instructeur .dossiers_count_summary(groupe_instructeur_ids) .symbolize_keys diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index cd6853a68..f3638529e 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -24,13 +24,6 @@ class ProcedurePresentation < ApplicationRecord validate :check_allowed_filter_columns validate :check_filters_max_length - def displayable_fields_for_select - [ - procedure.facets.reject(&:virtual).map { |facet| [facet.label, facet.id] }, - displayed_fields.map { Facet.new(**_1.deep_symbolize_keys).id } - ] - end - def displayed_fields_for_headers [ Facet.new(table: 'self', column: 'id', classname: 'number-col'), diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index a9fa7783f..e87989352 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -109,12 +109,7 @@ - menu.with_button_inner_html do = t('views.instructeurs.dossiers.personalize') - menu.with_form do - = form_tag update_displayed_fields_instructeur_procedure_path(@procedure), method: :patch, class: 'dropdown-form large columns-form' do - %react-fragment - = render ReactComponent.new "ComboBox/MultiComboBox", items: @displayable_fields_for_select, selected_keys: @displayable_fields_selected, name: 'values[]', 'aria-label': 'Colonne à afficher' - - = submit_tag t('views.instructeurs.dossiers.save'), class: 'fr-btn fr-btn--secondary' - + = render Dossiers::InstructeurFacetPickerComponent.new(procedure: @procedure, procedure_presentation: @procedure_presentation) %tbody = render Dossiers::BatchSelectMoreComponent.new(dossiers_count: @dossiers_count, filtered_sorted_ids: @filtered_sorted_ids) diff --git a/config/locales/en.yml b/config/locales/en.yml index e97328dee..50e1c8448 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -414,7 +414,6 @@ en: repasser_en_construction: Revert to submitted show_deleted_dossiers: Show deleted files follow_file: Follow-up the file - save: Save stop_follow: No longer follow no_file: No file dossier_synthesis: Summary of files diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 71dfd008a..7aba7889d 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -419,7 +419,6 @@ fr: repasser_en_construction: Repasser en construction follow_file: Suivre le dossier stop_follow: Ne plus suivre - save: Enregistrer no_file: Aucun dossier dossier_synthesis: Synthèse des dossiers passer_en_instruction_blocked_by_pending_correction: | diff --git a/spec/components/dossiers/instructeur_filter_component_spec.rb b/spec/components/dossiers/instructeur_filter_component_spec.rb index 801433961..f7e9aee3f 100644 --- a/spec/components/dossiers/instructeur_filter_component_spec.rb +++ b/spec/components/dossiers/instructeur_filter_component_spec.rb @@ -20,9 +20,8 @@ describe Dossiers::InstructeurFilterComponent, type: :component do ] end - before do - allow(Facet).to receive(:facets).and_return(included_displayable_field) - end + before { allow(procedure).to receive(:facets).and_return(included_displayable_field) } + subject { component.filterable_fields_options } it { is_expected.to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) } diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index a778655b6..f3367e91e 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -51,22 +51,6 @@ describe ProcedurePresentation do end end - describe "#displayable_fields_for_select" do - subject { create(:procedure_presentation, assign_to: assign_to) } - - let(:default_user_email) { Facet.new(label: 'email', table: 'user', column: 'email') } - let(:excluded_displayable_field) { Facet.new(label: "label1", table: "table1", column: "column1", virtual: true) } - - before do - allow(procedure).to receive(:facets).and_return([ - default_user_email, - excluded_displayable_field - ]) - end - - it { expect(subject.displayable_fields_for_select).to eq([[["email", "user/email"]], ["user/email"]]) } - end - describe '#sorted_ids' do let(:instructeur) { create(:instructeur) } let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }