Merge pull request #7465 from betagouv/sentry/3338723979
fix(procedure_presentation): split displayable_fields_for_select and filterable_fields_options to exclude depose_since to avoid projection on this virtual column
This commit is contained in:
commit
4d42ae705e
6 changed files with 94 additions and 49 deletions
|
@ -55,8 +55,8 @@ module Instructeurs
|
||||||
@procedure_presentation = procedure_presentation
|
@procedure_presentation = procedure_presentation
|
||||||
|
|
||||||
@current_filters = current_filters
|
@current_filters = current_filters
|
||||||
@displayed_fields_options, @displayed_fields_selected = procedure_presentation.displayed_fields_for_select
|
@displayable_fields_for_select, @displayable_fields_selected = procedure_presentation.displayable_fields_for_select
|
||||||
|
@filterable_fields_for_select = procedure_presentation.filterable_fields_options
|
||||||
@counts = current_instructeur
|
@counts = current_instructeur
|
||||||
.dossiers_count_summary(groupe_instructeur_ids)
|
.dossiers_count_summary(groupe_instructeur_ids)
|
||||||
.symbolize_keys
|
.symbolize_keys
|
||||||
|
|
|
@ -41,8 +41,8 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
field_hash('self', 'en_construction_at'),
|
field_hash('self', 'en_construction_at'),
|
||||||
field_hash('self', 'depose_at'),
|
field_hash('self', 'depose_at'),
|
||||||
field_hash('self', 'updated_at'),
|
field_hash('self', 'updated_at'),
|
||||||
field_hash('self', 'depose_since'),
|
field_hash('self', 'depose_since', virtual: true),
|
||||||
field_hash('self', 'updated_since'),
|
field_hash('self', 'updated_since', virtual: true),
|
||||||
field_hash('user', 'email'),
|
field_hash('user', 'email'),
|
||||||
field_hash('followers_instructeurs', 'email'),
|
field_hash('followers_instructeurs', 'email'),
|
||||||
field_hash('groupe_instructeur', 'label')
|
field_hash('groupe_instructeur', 'label')
|
||||||
|
@ -80,13 +80,18 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
fields
|
fields
|
||||||
end
|
end
|
||||||
|
|
||||||
def displayed_fields_for_select
|
def displayable_fields_for_select
|
||||||
[
|
[
|
||||||
fields.map { |field| [field['label'], field_id(field)] },
|
fields.reject { |field| field['virtual'] }
|
||||||
|
.map { |field| [field['label'], field_id(field)] },
|
||||||
displayed_fields.map { |field| field_id(field) }
|
displayed_fields.map { |field| field_id(field) }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filterable_fields_options
|
||||||
|
fields.map { |field| [field['label'], field_id(field)] }
|
||||||
|
end
|
||||||
|
|
||||||
def displayed_fields_for_headers
|
def displayed_fields_for_headers
|
||||||
[
|
[
|
||||||
field_hash('self', 'id', classname: 'number-col'),
|
field_hash('self', 'id', classname: 'number-col'),
|
||||||
|
@ -333,12 +338,13 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def field_hash(table, column, label: nil, classname: '')
|
def field_hash(table, column, label: nil, classname: '', virtual: false)
|
||||||
{
|
{
|
||||||
'label' => label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table]),
|
'label' => label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table]),
|
||||||
TABLE => table,
|
TABLE => table,
|
||||||
COLUMN => column,
|
COLUMN => column,
|
||||||
'classname' => classname
|
'classname' => classname,
|
||||||
|
'virtual' => virtual
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#filter-menu.dropdown-content.left-aligned.fade-in-down{ data: { menu_button_target: 'menu' } }
|
#filter-menu.dropdown-content.left-aligned.fade-in-down{ data: { menu_button_target: 'menu' } }
|
||||||
= form_tag add_filter_instructeur_procedure_path(procedure), method: :post, class: 'dropdown-form large' do
|
= form_tag add_filter_instructeur_procedure_path(procedure), method: :post, class: 'dropdown-form large' do
|
||||||
= label_tag :field, t('views.instructeurs.dossiers.filters.column')
|
= label_tag :field, t('views.instructeurs.dossiers.filters.column')
|
||||||
= select_tag :field, options_for_select(displayed_fields_options)
|
= select_tag :field, options_for_select(filterable_fields_for_select)
|
||||||
%br
|
%br
|
||||||
= label_tag :value, t('views.instructeurs.dossiers.filters.value')
|
= label_tag :value, t('views.instructeurs.dossiers.filters.value')
|
||||||
= text_field_tag :value, nil, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH
|
= text_field_tag :value, nil, maxlength: ProcedurePresentation::FILTERS_VALUE_MAX_LENGTH
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
= pagination
|
= pagination
|
||||||
.flex
|
.flex
|
||||||
.flex-grow
|
.flex-grow
|
||||||
= render partial: "dossiers_filter", locals: { procedure: @procedure, procedure_presentation: @procedure_presentation, current_filters: @current_filters, statut: @statut, displayed_fields_options: @displayed_fields_options }
|
= render partial: "dossiers_filter", locals: { procedure: @procedure, procedure_presentation: @procedure_presentation, current_filters: @current_filters, statut: @statut, filterable_fields_for_select: @filterable_fields_for_select }
|
||||||
- if @dossiers_count > 0
|
- if @dossiers_count > 0
|
||||||
.dossiers-export
|
.dossiers-export
|
||||||
= render Dossiers::ExportComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count)
|
= render Dossiers::ExportComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count)
|
||||||
|
@ -86,8 +86,8 @@
|
||||||
= form_tag update_displayed_fields_instructeur_procedure_path(@procedure), method: :patch, class: 'dropdown-form large columns-form' do
|
= form_tag update_displayed_fields_instructeur_procedure_path(@procedure), method: :patch, class: 'dropdown-form large columns-form' do
|
||||||
= hidden_field_tag :values, nil
|
= hidden_field_tag :values, nil
|
||||||
= react_component("ComboMultiple",
|
= react_component("ComboMultiple",
|
||||||
options: @displayed_fields_options,
|
options: @displayable_fields_for_select,
|
||||||
selected: @displayed_fields_selected,
|
selected: @displayable_fields_selected,
|
||||||
disabled: [],
|
disabled: [],
|
||||||
label: 'Colonne à afficher',
|
label: 'Colonne à afficher',
|
||||||
group: '.columns-form',
|
group: '.columns-form',
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: fix_procedure_presentation_with_depose_since'
|
||||||
|
task fix_procedure_presentation_with_depose_since: :environment do
|
||||||
|
puts "Running deploy task 'fix_procedure_presentation_with_depose_since'"
|
||||||
|
|
||||||
|
# Put your task implementation HERE.
|
||||||
|
errored_presentation = {
|
||||||
|
'label' => "Déposé depuis",
|
||||||
|
'table' => "self",
|
||||||
|
'column' => "depose_since",
|
||||||
|
'classname' => ""
|
||||||
|
}
|
||||||
|
procedures_presentations = ProcedurePresentation.where("displayed_fields @> ?", [errored_presentation].to_json)
|
||||||
|
progress = ProgressReport.new(procedures_presentations.size)
|
||||||
|
|
||||||
|
procedures_presentations.find_each do |procedure_presentation|
|
||||||
|
procedure_presentation.displayed_fields.delete_if do |field|
|
||||||
|
['updated_since', 'depose_since'].include?(field['column'])
|
||||||
|
end
|
||||||
|
procedure_presentation.save
|
||||||
|
progress.inc
|
||||||
|
end
|
||||||
|
|
||||||
|
progress.finish
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -58,28 +58,28 @@ describe ProcedurePresentation do
|
||||||
let(:tdc_private_2) { procedure.types_de_champ_private[1] }
|
let(:tdc_private_2) { procedure.types_de_champ_private[1] }
|
||||||
let(:expected) {
|
let(:expected) {
|
||||||
[
|
[
|
||||||
{ "label" => 'Créé le', "table" => 'self', "column" => 'created_at', 'classname' => '' },
|
{ "label" => 'Créé le', "table" => 'self', "column" => 'created_at', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at', 'classname' => '' },
|
{ "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at', 'classname' => '' },
|
{ "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at', 'classname' => '' },
|
{ "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => "Déposé depuis", "table" => "self", "column" => "depose_since", "classname" => "" },
|
{ "label" => "Déposé depuis", "table" => "self", "column" => "depose_since", "classname" => "", 'virtual' => true },
|
||||||
{ "label" => "Mis à jour depuis", "table" => "self", "column" => "updated_since", "classname" => "" },
|
{ "label" => "Mis à jour depuis", "table" => "self", "column" => "updated_since", "classname" => "", 'virtual' => true },
|
||||||
{ "label" => 'Demandeur', "table" => 'user', "column" => 'email', 'classname' => '' },
|
{ "label" => 'Demandeur', "table" => 'user', "column" => 'email', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email', 'classname' => '' },
|
{ "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Groupe instructeur', "table" => 'groupe_instructeur', "column" => 'label', 'classname' => '' },
|
{ "label" => 'Groupe instructeur', "table" => 'groupe_instructeur', "column" => 'label', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'SIREN', "table" => 'etablissement', "column" => 'entreprise_siren', 'classname' => '' },
|
{ "label" => 'SIREN', "table" => 'etablissement', "column" => 'entreprise_siren', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Forme juridique', "table" => 'etablissement', "column" => 'entreprise_forme_juridique', 'classname' => '' },
|
{ "label" => 'Forme juridique', "table" => 'etablissement', "column" => 'entreprise_forme_juridique', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Nom commercial', "table" => 'etablissement', "column" => 'entreprise_nom_commercial', 'classname' => '' },
|
{ "label" => 'Nom commercial', "table" => 'etablissement', "column" => 'entreprise_nom_commercial', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Raison sociale', "table" => 'etablissement', "column" => 'entreprise_raison_sociale', 'classname' => '' },
|
{ "label" => 'Raison sociale', "table" => 'etablissement', "column" => 'entreprise_raison_sociale', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'SIRET siège social', "table" => 'etablissement', "column" => 'entreprise_siret_siege_social', 'classname' => '' },
|
{ "label" => 'SIRET siège social', "table" => 'etablissement', "column" => 'entreprise_siret_siege_social', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Date de création', "table" => 'etablissement', "column" => 'entreprise_date_creation', 'classname' => '' },
|
{ "label" => 'Date de création', "table" => 'etablissement', "column" => 'entreprise_date_creation', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'SIRET', "table" => 'etablissement', "column" => 'siret', 'classname' => '' },
|
{ "label" => 'SIRET', "table" => 'etablissement', "column" => 'siret', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Libellé NAF', "table" => 'etablissement', "column" => 'libelle_naf', 'classname' => '' },
|
{ "label" => 'Libellé NAF', "table" => 'etablissement', "column" => 'libelle_naf', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => 'Code postal', "table" => 'etablissement', "column" => 'code_postal', 'classname' => '' },
|
{ "label" => 'Code postal', "table" => 'etablissement', "column" => 'code_postal', 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => tdc_1.libelle, "table" => 'type_de_champ', "column" => tdc_1.stable_id.to_s, 'classname' => '' },
|
{ "label" => tdc_1.libelle, "table" => 'type_de_champ', "column" => tdc_1.stable_id.to_s, 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => tdc_2.libelle, "table" => 'type_de_champ', "column" => tdc_2.stable_id.to_s, 'classname' => '' },
|
{ "label" => tdc_2.libelle, "table" => 'type_de_champ', "column" => tdc_2.stable_id.to_s, 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => tdc_private_1.libelle, "table" => 'type_de_champ_private', "column" => tdc_private_1.stable_id.to_s, 'classname' => '' },
|
{ "label" => tdc_private_1.libelle, "table" => 'type_de_champ_private', "column" => tdc_private_1.stable_id.to_s, 'classname' => '', 'virtual' => false },
|
||||||
{ "label" => tdc_private_2.libelle, "table" => 'type_de_champ_private', "column" => tdc_private_2.stable_id.to_s, 'classname' => '' }
|
{ "label" => tdc_private_2.libelle, "table" => 'type_de_champ_private', "column" => tdc_private_2.stable_id.to_s, 'classname' => '', 'virtual' => false }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,9 +96,9 @@ describe ProcedurePresentation do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the procedure is for individuals' do
|
context 'when the procedure is for individuals' do
|
||||||
let(:name_field) { { "label" => "Prénom", "table" => "individual", "column" => "prenom", 'classname' => '' } }
|
let(:name_field) { { "label" => "Prénom", "table" => "individual", "column" => "prenom", 'classname' => '', 'virtual' => false } }
|
||||||
let(:surname_field) { { "label" => "Nom", "table" => "individual", "column" => "nom", 'classname' => '' } }
|
let(:surname_field) { { "label" => "Nom", "table" => "individual", "column" => "nom", 'classname' => '', 'virtual' => false } }
|
||||||
let(:gender_field) { { "label" => "Civilité", "table" => "individual", "column" => "gender", 'classname' => '' } }
|
let(:gender_field) { { "label" => "Civilité", "table" => "individual", "column" => "gender", 'classname' => '', 'virtual' => false } }
|
||||||
let(:procedure) { create(:procedure, :for_individual) }
|
let(:procedure) { create(:procedure, :for_individual) }
|
||||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||||
|
|
||||||
|
@ -108,25 +108,34 @@ describe ProcedurePresentation do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#displayed_fields_for_select" do
|
describe "#displayable_fields_for_select" do
|
||||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||||
|
let(:excluded_displayable_field) { { "label" => "depose_since", "table" => "self", "column" => "depose_since", 'virtual' => true } }
|
||||||
|
let(:included_displayable_field) { { "label" => "label1", "table" => "table1", "column" => "column1", 'virtual' => false } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(subject).to receive(:fields).and_return([
|
allow(subject).to receive(:fields).and_return([
|
||||||
{
|
excluded_displayable_field,
|
||||||
"label" => "label1",
|
included_displayable_field
|
||||||
"table" => "table1",
|
|
||||||
"column" => "column1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label" => "label2",
|
|
||||||
"table" => "table2",
|
|
||||||
"column" => "column2"
|
|
||||||
}
|
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(subject.displayed_fields_for_select).to eq([[["label1", "table1/column1"], ["label2", "table2/column2"]], ["user/email"]]) }
|
it { expect(subject.displayable_fields_for_select).to eq([[["label1", "table1/column1"]], ["user/email"]]) }
|
||||||
|
end
|
||||||
|
describe "#filterable_fields_options" do
|
||||||
|
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||||
|
let(:included_displayable_field) do
|
||||||
|
[
|
||||||
|
{ "label" => "label1", "table" => "table1", "column" => "column1", 'virtual' => false },
|
||||||
|
{ "label" => "depose_since", "table" => "self", "column" => "depose_since", 'virtual' => true }
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(subject).to receive(:fields).and_return(included_displayable_field)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject.filterable_fields_options).to eq([["label1", "table1/column1"], ["depose_since", "self/depose_since"]]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#sorted_ids' do
|
describe '#sorted_ids' do
|
||||||
|
|
Loading…
Reference in a new issue