Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(columns): rename virtual to displayable #10701

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/instructeurs/column_picker_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(procedure:, procedure_presentation:)

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 }
]
end
Expand Down
9 changes: 5 additions & 4 deletions app/models/column.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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
@column = column
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
@classname = classname
@virtual = virtual
@type = type
@scope = scope
@value_column = value_column
@filterable = filterable
# We need this for backward compatibility
@displayable = virtual ? false : displayable
end

def id
Expand All @@ -23,7 +24,7 @@ def ==(other)

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
6 changes: 3 additions & 3 deletions app/models/concerns/columns_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def dossier_columns
.map { |column| Column.new(table: 'self', column:, type: :date) }

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
end
Expand All @@ -39,7 +39,7 @@ def sva_svr_columns(for_filters: false)
]

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:))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let(:included_displayable_field) do
[
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

describe "#displayable_columns_for_select" do
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 }

Expand Down
76 changes: 38 additions & 38 deletions spec/models/concerns/columns_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
let(:expected) {
[
{ label: 'Nº dossier', table: 'self', column: 'id', classname: 'number-col', virtual: false, 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: 'Créé le', table: 'self', column: 'created_at', classname: '', virtual: false, 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: 'Déposé le', table: 'self', column: 'depose_at', classname: '', virtual: false, 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 instruction le', table: 'self', column: 'en_instruction_at', classname: '', virtual: false, 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: "Mis à jour depuis", table: "self", column: "updated_since", classname: "", virtual: true, 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: "En construction depuis", table: "self", column: "en_construction_since", classname: "", virtual: true, 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: "Terminé depuis", table: "self", column: "processed_since", classname: "", virtual: true, 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: 'Demandeur', table: 'user', column: 'email', classname: '', virtual: false, 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: 'Groupe instructeur', table: 'groupe_instructeur', column: 'id', classname: '', virtual: false, 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: 'SIREN', table: 'etablissement', column: 'entreprise_siren', classname: '', virtual: false, 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: 'Nom commercial', table: 'etablissement', column: 'entreprise_nom_commercial', classname: '', virtual: false, 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: 'SIRET siège social', table: 'etablissement', column: 'entreprise_siret_siege_social', classname: '', virtual: false, 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: 'SIRET', table: 'etablissement', column: 'siret', classname: '', virtual: false, 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: 'Code postal', table: 'etablissement', column: 'code_postal', 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: '', 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: '', 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: '', 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: '', 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', displayable: true, type: :text, scope: '', value_column: :value, filterable: false },
{ 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: '', displayable: true, 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: '', displayable: true, 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: '', displayable: 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: "", displayable: false, 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: "", displayable: false, 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: "", displayable: false, scope: 'instructeurs.dossiers.filterable_state', type: :enum, 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: '', displayable: true, type: :text, 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: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: false },
{ 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: '', displayable: true, 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: '', displayable: true, 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: '', displayable: true, type: :date, 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: '', displayable: true, 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: '', 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: '', 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: '', 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: '', displayable: true, type: :text, scope: '', value_column: :value, filterable: true }
].map { Column.new(**_1) }
}

Expand All @@ -69,9 +69,9 @@
end

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(:surname_field) { Column.new(label: "Nom", table: "individual", column: "nom", classname: '', virtual: false, 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(: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: '', displayable: true, 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_presentation) { create(:procedure_presentation, assign_to: assign_to) }

Expand All @@ -82,8 +82,8 @@
let(:procedure) { create(:procedure, :for_individual, :sva) }
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_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_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: '', displayable: false, type: :date, scope: '', value_column: :value, filterable: true) }

it { is_expected.to include(decision_on, decision_before_field) }
end
Expand All @@ -92,8 +92,8 @@
let(:procedure) { create(:procedure, :for_individual, :svr) }
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_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_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: '', displayable: false, type: :date, scope: '', value_column: :value, filterable: true) }

it { is_expected.to include(decision_on, decision_before_field) }
end
Expand Down
Loading