Merge pull request #10701 from tchak/refactor-virtual-displayable
refactor(columns): rename virtual to displayable
This commit is contained in:
commit
1d15689989
6 changed files with 49 additions and 48 deletions
|
@ -9,7 +9,7 @@ class Instructeurs::ColumnPickerComponent < ApplicationComponent
|
||||||
|
|
||||||
def displayable_columns_for_select
|
def displayable_columns_for_select
|
||||||
[
|
[
|
||||||
procedure.columns.reject(&:virtual).map { |column| [column.label, column.id] },
|
procedure.columns.filter(&:displayable).map { |column| [column.label, column.id] },
|
||||||
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys).id }
|
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys).id }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
class Column
|
class Column
|
||||||
attr_reader :table, :column, :label, :classname, :virtual, :type, :scope, :value_column, :filterable
|
attr_reader :table, :column, :label, :classname, :type, :scope, :value_column, :filterable, :displayable
|
||||||
|
|
||||||
def initialize(table:, column:, label: nil, virtual: false, type: :text, value_column: :value, filterable: true, classname: '', scope: '')
|
def initialize(table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, classname: '', scope: '', virtual: nil)
|
||||||
@table = table
|
@table = table
|
||||||
@column = column
|
@column = column
|
||||||
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
|
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
|
||||||
@classname = classname
|
@classname = classname
|
||||||
@virtual = virtual
|
|
||||||
@type = type
|
@type = type
|
||||||
@scope = scope
|
@scope = scope
|
||||||
@value_column = value_column
|
@value_column = value_column
|
||||||
@filterable = filterable
|
@filterable = filterable
|
||||||
|
# We need this for backward compatibility
|
||||||
|
@displayable = virtual ? false : displayable
|
||||||
end
|
end
|
||||||
|
|
||||||
def id
|
def id
|
||||||
|
@ -23,7 +24,7 @@ class Column
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
{
|
{
|
||||||
table:, column:, label:, classname:, virtual:, type:, scope:, value_column:, filterable:
|
table:, column:, label:, classname:, type:, scope:, value_column:, filterable:, displayable:
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,9 +21,9 @@ module ColumnsConcern
|
||||||
.map { |column| Column.new(table: 'self', column:, type: :date) }
|
.map { |column| Column.new(table: 'self', column:, type: :date) }
|
||||||
|
|
||||||
virtual_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
virtual_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
||||||
.map { |column| Column.new(table: 'self', column:, type: :date, virtual: true) }
|
.map { |column| Column.new(table: 'self', column:, type: :date, displayable: false) }
|
||||||
|
|
||||||
states = [Column.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)]
|
states = [Column.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', displayable: false)]
|
||||||
|
|
||||||
[common, dates, sva_svr_columns(for_filters: true), virtual_dates, states].flatten.compact
|
[common, dates, sva_svr_columns(for_filters: true), virtual_dates, states].flatten.compact
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ module ColumnsConcern
|
||||||
]
|
]
|
||||||
|
|
||||||
if for_filters
|
if for_filters
|
||||||
columns << Column.new(table: 'self', column: 'sva_svr_decision_before', type: :date, virtual: true,
|
columns << Column.new(table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false,
|
||||||
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe Instructeurs::ColumnFilterComponent, type: :component do
|
||||||
let(:included_displayable_field) do
|
let(:included_displayable_field) do
|
||||||
[
|
[
|
||||||
Column.new(label: 'email', table: 'user', column: 'email'),
|
Column.new(label: 'email', table: 'user', column: 'email'),
|
||||||
Column.new(label: "depose_since", table: "self", column: "depose_since", virtual: true)
|
Column.new(label: "depose_since", table: "self", column: "depose_since", displayable: false)
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe Instructeurs::ColumnPickerComponent, type: :component do
|
||||||
|
|
||||||
describe "#displayable_columns_for_select" do
|
describe "#displayable_columns_for_select" do
|
||||||
let(:default_user_email) { Column.new(label: 'email', table: 'user', column: 'email') }
|
let(:default_user_email) { Column.new(label: 'email', table: 'user', column: 'email') }
|
||||||
let(:excluded_displayable_field) { Column.new(label: "label1", table: "table1", column: "column1", virtual: true) }
|
let(:excluded_displayable_field) { Column.new(label: "label1", table: "table1", column: "column1", displayable: false) }
|
||||||
|
|
||||||
subject { component.displayable_columns_for_select }
|
subject { component.displayable_columns_for_select }
|
||||||
|
|
||||||
|
|
|
@ -14,37 +14,37 @@ describe ColumnsConcern do
|
||||||
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
|
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
|
||||||
let(:expected) {
|
let(:expected) {
|
||||||
[
|
[
|
||||||
{ label: 'Nº dossier', table: 'self', column: 'id', classname: 'number-col', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Nº dossier', table: 'self', column: 'id', classname: 'number-col', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'notifications', table: 'notifications', column: 'notifications', virtual: false, type: :text, scope: '', value_column: :value, filterable: false },
|
{ label: 'notifications', table: 'notifications', column: 'notifications', displayable: true, type: :text, scope: '', value_column: :value, filterable: false },
|
||||||
{ label: 'Créé le', table: 'self', column: 'created_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'Créé le', table: 'self', column: 'created_at', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Déposé le', table: 'self', column: 'depose_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'Déposé le', table: 'self', column: 'depose_at', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'En construction le', table: 'self', column: 'en_construction_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'En construction le', table: 'self', column: 'en_construction_at', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'En instruction le', table: 'self', column: 'en_instruction_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'En instruction le', table: 'self', column: 'en_instruction_at', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Terminé le', table: 'self', column: 'processed_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'Terminé le', table: 'self', column: 'processed_at', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: "Mis à jour depuis", table: "self", column: "updated_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: "Mis à jour depuis", table: "self", column: "updated_since", classname: "", displayable: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: "Déposé depuis", table: "self", column: "depose_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: "Déposé depuis", table: "self", column: "depose_since", classname: "", displayable: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: "En construction depuis", table: "self", column: "en_construction_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: "En construction depuis", table: "self", column: "en_construction_since", classname: "", displayable: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: "En instruction depuis", table: "self", column: "en_instruction_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: "En instruction depuis", table: "self", column: "en_instruction_since", classname: "", displayable: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: "Terminé depuis", table: "self", column: "processed_since", classname: "", virtual: true, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: "Terminé depuis", table: "self", column: "processed_since", classname: "", displayable: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: "Statut", table: "self", column: "state", classname: "", virtual: true, scope: 'instructeurs.dossiers.filterable_state', type: :enum, value_column: :value, filterable: true },
|
{ label: "Statut", table: "self", column: "state", classname: "", displayable: false, scope: 'instructeurs.dossiers.filterable_state', type: :enum, value_column: :value, filterable: true },
|
||||||
{ label: 'Demandeur', table: 'user', column: 'email', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Demandeur', table: 'user', column: 'email', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Email instructeur', table: 'followers_instructeurs', column: 'email', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Email instructeur', table: 'followers_instructeurs', column: 'email', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', classname: '', virtual: false, type: :enum, scope: '', value_column: :value, filterable: true },
|
{ label: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', classname: '', displayable: true, type: :enum, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: false },
|
{ label: 'Avis oui/non', table: 'avis', column: 'question_answer', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: false },
|
||||||
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'SIREN', table: 'etablissement', column: 'entreprise_siren', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Forme juridique', table: 'etablissement', column: 'entreprise_forme_juridique', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Raison sociale', table: 'etablissement', column: 'entreprise_raison_sociale', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Raison sociale', table: 'etablissement', column: 'entreprise_raison_sociale', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Date de création', table: 'etablissement', column: 'entreprise_date_creation', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
{ label: 'Date de création', table: 'etablissement', column: 'entreprise_date_creation', classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'SIRET', table: 'etablissement', column: 'siret', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'SIRET', table: 'etablissement', column: 'siret', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Libellé NAF', table: 'etablissement', column: 'libelle_naf', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Libellé NAF', table: 'etablissement', column: 'libelle_naf', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: 'Code postal', table: 'etablissement', column: 'code_postal', classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: 'Code postal', table: 'etablissement', column: 'code_postal', classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: tdc_1.libelle, table: 'type_de_champ', column: tdc_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: tdc_1.libelle, table: 'type_de_champ', column: tdc_1.stable_id.to_s, classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: tdc_2.libelle, table: 'type_de_champ', column: tdc_2.stable_id.to_s, classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: tdc_private_1.libelle, table: 'type_de_champ', column: tdc_private_1.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
{ label: tdc_private_1.libelle, table: 'type_de_champ', column: tdc_private_1.stable_id.to_s, classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true },
|
||||||
{ label: tdc_private_2.libelle, table: 'type_de_champ', column: tdc_private_2.stable_id.to_s, classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true }
|
{ label: tdc_private_2.libelle, table: 'type_de_champ', column: tdc_private_2.stable_id.to_s, classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true }
|
||||||
].map { Column.new(**_1) }
|
].map { Column.new(**_1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +69,9 @@ describe ColumnsConcern do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the procedure is for individuals' do
|
context 'when the procedure is for individuals' do
|
||||||
let(:name_field) { Column.new(label: "Prénom", table: "individual", column: "prenom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
let(:name_field) { Column.new(label: "Prénom", table: "individual", column: "prenom", classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||||
let(:surname_field) { Column.new(label: "Nom", table: "individual", column: "nom", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
let(:surname_field) { Column.new(label: "Nom", table: "individual", column: "nom", classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||||
let(:gender_field) { Column.new(label: "Civilité", table: "individual", column: "gender", classname: '', virtual: false, type: :text, scope: '', value_column: :value, filterable: true) }
|
let(:gender_field) { Column.new(label: "Civilité", table: "individual", column: "gender", classname: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true) }
|
||||||
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) }
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ describe ColumnsConcern do
|
||||||
let(:procedure) { create(:procedure, :for_individual, :sva) }
|
let(:procedure) { create(:procedure, :for_individual, :sva) }
|
||||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||||
|
|
||||||
let(:decision_on) { Column.new(label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
let(:decision_on) { Column.new(label: "Date décision SVA", table: "self", column: "sva_svr_decision_on", classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||||
let(:decision_before_field) { Column.new(label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
let(:decision_before_field) { Column.new(label: "Date décision SVA avant", table: "self", column: "sva_svr_decision_before", classname: '', displayable: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||||
|
|
||||||
it { is_expected.to include(decision_on, decision_before_field) }
|
it { is_expected.to include(decision_on, decision_before_field) }
|
||||||
end
|
end
|
||||||
|
@ -92,8 +92,8 @@ describe ColumnsConcern do
|
||||||
let(:procedure) { create(:procedure, :for_individual, :svr) }
|
let(:procedure) { create(:procedure, :for_individual, :svr) }
|
||||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||||
|
|
||||||
let(:decision_on) { Column.new(label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
let(:decision_on) { Column.new(label: "Date décision SVR", table: "self", column: "sva_svr_decision_on", classname: '', displayable: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||||
let(:decision_before_field) { Column.new(label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", classname: '', virtual: true, type: :date, scope: '', value_column: :value, filterable: true) }
|
let(:decision_before_field) { Column.new(label: "Date décision SVR avant", table: "self", column: "sva_svr_decision_before", classname: '', displayable: false, type: :date, scope: '', value_column: :value, filterable: true) }
|
||||||
|
|
||||||
it { is_expected.to include(decision_on, decision_before_field) }
|
it { is_expected.to include(decision_on, decision_before_field) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue