ProcedurePresentation.displayable_fields_for_select -> InstructeurFacetPickerComponent.displayable_fields_for_select

This commit is contained in:
mfo 2024-07-20 08:08:23 +02:00
parent 41ea39abb1
commit 60c6c86d70
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
11 changed files with 30 additions and 35 deletions

View file

@ -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

View file

@ -0,0 +1,3 @@
---
fr:
save: 'Enregistrer'

View file

@ -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'

View file

@ -72,7 +72,6 @@ module Instructeurs
@procedure_presentation = procedure_presentation @procedure_presentation = procedure_presentation
@current_filters = current_filters @current_filters = current_filters
@displayable_fields_for_select, @displayable_fields_selected = procedure_presentation.displayable_fields_for_select
@counts = current_instructeur @counts = current_instructeur
.dossiers_count_summary(groupe_instructeur_ids) .dossiers_count_summary(groupe_instructeur_ids)
.symbolize_keys .symbolize_keys

View file

@ -24,13 +24,6 @@ class ProcedurePresentation < ApplicationRecord
validate :check_allowed_filter_columns validate :check_allowed_filter_columns
validate :check_filters_max_length 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 def displayed_fields_for_headers
[ [
Facet.new(table: 'self', column: 'id', classname: 'number-col'), Facet.new(table: 'self', column: 'id', classname: 'number-col'),

View file

@ -109,12 +109,7 @@
- menu.with_button_inner_html do - menu.with_button_inner_html do
= t('views.instructeurs.dossiers.personalize') = t('views.instructeurs.dossiers.personalize')
- menu.with_form do - menu.with_form do
= form_tag update_displayed_fields_instructeur_procedure_path(@procedure), method: :patch, class: 'dropdown-form large columns-form' do = render Dossiers::InstructeurFacetPickerComponent.new(procedure: @procedure, procedure_presentation: @procedure_presentation)
%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'
%tbody %tbody
= render Dossiers::BatchSelectMoreComponent.new(dossiers_count: @dossiers_count, filtered_sorted_ids: @filtered_sorted_ids) = render Dossiers::BatchSelectMoreComponent.new(dossiers_count: @dossiers_count, filtered_sorted_ids: @filtered_sorted_ids)

View file

@ -414,7 +414,6 @@ en:
repasser_en_construction: Revert to submitted repasser_en_construction: Revert to submitted
show_deleted_dossiers: Show deleted files show_deleted_dossiers: Show deleted files
follow_file: Follow-up the file follow_file: Follow-up the file
save: Save
stop_follow: No longer follow stop_follow: No longer follow
no_file: No file no_file: No file
dossier_synthesis: Summary of files dossier_synthesis: Summary of files

View file

@ -419,7 +419,6 @@ fr:
repasser_en_construction: Repasser en construction repasser_en_construction: Repasser en construction
follow_file: Suivre le dossier follow_file: Suivre le dossier
stop_follow: Ne plus suivre stop_follow: Ne plus suivre
save: Enregistrer
no_file: Aucun dossier no_file: Aucun dossier
dossier_synthesis: Synthèse des dossiers dossier_synthesis: Synthèse des dossiers
passer_en_instruction_blocked_by_pending_correction: | passer_en_instruction_blocked_by_pending_correction: |

View file

@ -20,9 +20,8 @@ describe Dossiers::InstructeurFilterComponent, type: :component do
] ]
end end
before do before { allow(procedure).to receive(:facets).and_return(included_displayable_field) }
allow(Facet).to receive(:facets).and_return(included_displayable_field)
end
subject { component.filterable_fields_options } subject { component.filterable_fields_options }
it { is_expected.to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) } it { is_expected.to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) }

View file

@ -51,22 +51,6 @@ describe ProcedurePresentation do
end end
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 describe '#sorted_ids' do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) } let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }