ProcedurePresentation.filterable_fields_options -> InstructeurFilterComponent.filterable_fields_options
This commit is contained in:
parent
379c9fb812
commit
41ea39abb1
4 changed files with 28 additions and 33 deletions
|
@ -27,7 +27,7 @@ class Dossiers::InstructeurFilterComponent < ApplicationComponent
|
|||
def filter_react_props
|
||||
{
|
||||
selected_key: facet.present? ? facet.id : '',
|
||||
items: procedure_presentation.filterable_fields_options,
|
||||
items: filterable_fields_options,
|
||||
name: :field,
|
||||
id: 'search-filter',
|
||||
'aria-describedby': 'instructeur-filter-combo-label',
|
||||
|
@ -36,6 +36,14 @@ class Dossiers::InstructeurFilterComponent < ApplicationComponent
|
|||
}
|
||||
end
|
||||
|
||||
def filterable_fields_options
|
||||
procedure.facets.filter_map do |facet|
|
||||
next if facet.filterable == false
|
||||
|
||||
[facet.label, facet.id]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_type_de_champ(column)
|
||||
|
|
|
@ -31,14 +31,6 @@ class ProcedurePresentation < ApplicationRecord
|
|||
]
|
||||
end
|
||||
|
||||
def filterable_fields_options
|
||||
procedure.facets.filter_map do |facet|
|
||||
next if facet.filterable == false
|
||||
|
||||
[facet.label, facet.id]
|
||||
end
|
||||
end
|
||||
|
||||
def displayed_fields_for_headers
|
||||
[
|
||||
Facet.new(table: 'self', column: 'id', classname: 'number-col'),
|
||||
|
|
|
@ -10,6 +10,25 @@ describe Dossiers::InstructeurFilterComponent, type: :component do
|
|||
allow(component).to receive(:current_instructeur).and_return(instructeur)
|
||||
end
|
||||
|
||||
describe ".filterable_fields_options" do
|
||||
context 'filders' do
|
||||
let(:facet) { nil }
|
||||
let(:included_displayable_field) do
|
||||
[
|
||||
Facet.new(label: 'email', table: 'user', column: 'email'),
|
||||
Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true)
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
allow(Facet).to receive(:facets).and_return(included_displayable_field)
|
||||
end
|
||||
subject { component.filterable_fields_options }
|
||||
|
||||
it { is_expected.to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.options_for_select_of_field' do
|
||||
subject { component.options_for_select_of_field }
|
||||
|
||||
|
|
|
@ -66,30 +66,6 @@ describe ProcedurePresentation do
|
|||
|
||||
it { expect(subject.displayable_fields_for_select).to eq([[["email", "user/email"]], ["user/email"]]) }
|
||||
end
|
||||
describe "#filterable_fields_options" do
|
||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
context 'filders' do
|
||||
let(:included_displayable_field) do
|
||||
[
|
||||
Facet.new(label: 'email', table: 'user', column: 'email'),
|
||||
Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true)
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
allow(procedure).to receive(:facets).and_return(included_displayable_field)
|
||||
end
|
||||
|
||||
it { expect(subject.filterable_fields_options).to eq([["label1", "table1/column1"], ["depose_since", "self/depose_since"]]) }
|
||||
end
|
||||
context 'with rna' do
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :rna, libelle: 'rna', stable_id: 1 }]) }
|
||||
it { expect(subject.filterable_fields_options.map { _1[0] }).to include('rna – commune') }
|
||||
it { expect(subject.filterable_fields_options.map { _1[1] }).to include('type_de_champ/1->data.commune') }
|
||||
it { expect(subject.filterable_fields_options).to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sorted_ids' do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
|
Loading…
Reference in a new issue