remove make_id

This commit is contained in:
simon lehericey 2024-10-07 16:57:54 +02:00
parent 3740a79219
commit a8b41e90cc
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
8 changed files with 13 additions and 16 deletions

View file

@ -22,10 +22,6 @@ class Column
"#{table}/#{column}"
end
def self.make_id(table, column)
"#{table}/#{column}"
end
def ==(other)
other.to_json == to_json
end

View file

@ -201,7 +201,7 @@ class ProcedurePresentation < ApplicationRecord
.map do |(table, column), filters|
values = filters.pluck('value')
value_column = filters.pluck('value_column').compact.first || :value
dossier_column = procedure.find_column(id: Column.make_id(procedure.id, table, column)) # hack to find json path columns
dossier_column = procedure.find_column(h_id: { procedure_id: procedure.id, column_id: "#{table}/#{column}" }) # hack to find json path columns
if dossier_column.is_a?(Columns::JSONPathColumn)
dossier_column.filtered_ids(dossiers, values)
else

View file

@ -6,6 +6,6 @@
- filters.each_with_index do |filter, i|
- if i > 0
= " ou "
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: Column.make_id(procedure.id, filter['table'], filter['column']), value: filter['value'] }),
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: { procedure_id: procedure.id, column_id: filter['table'] + "/" + filter['column'] }.to_json, value: filter['value'] }),
class: "fr-tag fr-tag--dismiss fr-my-1w", aria: { label: "Retirer le filtre #{filter['column']}" } do
= "#{filter['label'].truncate(50)} : #{procedure_presentation.human_value_for_filter(filter)}"

View file

@ -27,7 +27,7 @@ describe Instructeurs::ColumnFilterComponent, type: :component do
subject { component.filterable_columns_options }
it { is_expected.to eq([["email", Column.make_id(procedure_id, "user", "email")], ["depose_since", Column.make_id(procedure_id, "self", "depose_since")]]) }
it { is_expected.to eq([["email", included_displayable_field.first.id], ["depose_since", included_displayable_field.second.id]]) }
end
end

View file

@ -12,7 +12,7 @@ describe Instructeurs::ColumnPickerComponent, type: :component do
describe "#displayable_columns_for_select" do
let(:default_user_email) { Column.new(procedure_id:, label: 'email', table: 'user', column: 'email') }
let(:excluded_displayable_field) { Column.new(procedure_id:, label: "label1", table: "table1", column: "column1", displayable: false) }
let(:email_column_id) { Column.make_id(procedure_id, 'user', 'email') }
let(:email_column_id) { default_user_email.id }
subject { component.displayable_columns_for_select }

View file

@ -886,7 +886,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end
it 'can change order' do
column_id = Column.make_id(procedure.id, "individual", "nom")
column_id = procedure.find_column(label: "Nom").id
expect { get :update_sort, params: { procedure_id: procedure.id, column_id:, order: 'asc' } }
.to change { procedure_presentation.sort }
.from({ "column" => "notifications", "order" => "desc", "table" => "notifications" })
@ -905,7 +905,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end
subject do
column = Column.make_id(procedure.id, "individual", "nom")
column = procedure.find_column(label: "Nom").id
post :add_filter, params: { procedure_id: procedure.id, column:, value: "n" * 110, statut: "a-suivre" }
end

View file

@ -94,7 +94,7 @@ RSpec.describe Export, type: :model do
let(:instructeur) { create(:instructeur) }
let!(:gi_1) { create(:groupe_instructeur, procedure: procedure, instructeurs: [instructeur]) }
let!(:pp) { gi_1.instructeurs.first.procedure_presentation_and_errors_for_procedure_id(procedure.id).first }
before { pp.add_filter('tous', Column.make_id(procedure.id, 'self', 'created_at'), '10/12/2021') }
before { pp.add_filter('tous', procedure.find_column(label: 'Créé le').id, '10/12/2021') }
context 'with procedure_presentation having different filters' do
it 'works once' do
@ -105,7 +105,7 @@ RSpec.describe Export, type: :model do
it 'works once, changes procedure_presentation, recreate a new' do
expect { Export.find_or_create_fresh_export(:zip, [gi_1], instructeur, time_span_type: Export.time_span_types.fetch(:everything), statut: Export.statuts.fetch(:tous), procedure_presentation: pp) }
.to change { Export.count }.by(1)
pp.add_filter('tous', Column.make_id(procedure.id, 'self', 'updated_at'), '10/12/2021')
pp.add_filter('tous', procedure.find_column(label: 'Mis à jour le').id, '10/12/2021')
expect { Export.find_or_create_fresh_export(:zip, [gi_1], instructeur, time_span_type: Export.time_span_types.fetch(:everything), statut: Export.statuts.fetch(:tous), procedure_presentation: pp) }
.to change { Export.count }.by(1)
end

View file

@ -850,10 +850,11 @@ describe ProcedurePresentation do
let(:filters) { { "suivis" => [] } }
context 'when type_de_champ yes_no' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }]) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no, libelle: 'oui ou non' }]) }
it 'should downcase and transform value' do
procedure_presentation.add_filter("suivis", "type_de_champ/#{first_type_de_champ_id}", +"Oui")
column_id = procedure.find_column(label: 'oui ou non').id
procedure_presentation.add_filter("suivis", column_id, "Oui")
expect(procedure_presentation.filters).to eq({
"suivis" =>
@ -866,7 +867,7 @@ describe ProcedurePresentation do
context 'when type_de_champ text' do
let(:filters) { { "suivis" => [] } }
let(:column_id) { Column.make_id(procedure.id, 'type_de_champ', first_type_de_champ_id) }
let(:column_id) { procedure.find_column(label: first_type_de_champ.libelle).id }
it 'should passthrough value' do
procedure_presentation.add_filter("suivis", column_id, "Oui")
@ -881,7 +882,7 @@ describe ProcedurePresentation do
context 'when type_de_champ departements' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :departements }]) }
let(:column_id) { Column.make_id(procedure.id, 'type_de_champ', first_type_de_champ_id) }
let(:column_id) { procedure.find_column(label: first_type_de_champ.libelle).id }
let(:filters) { { "suivis" => [] } }
it 'should set value_column' do