Merge pull request #6489 from betagouv/sort_tdc_alphabetically

Dans l'éditeur de champ, affiche les types de champ dans l'ordre alphabétique
This commit is contained in:
LeSim 2021-09-27 15:55:15 +02:00 committed by GitHub
commit daf0f412c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -291,16 +291,19 @@ class TypeDeChamp < ApplicationRecord
def self.type_de_champ_types_for(procedure, user)
has_legacy_number = (procedure.types_de_champ + procedure.types_de_champ_private).any?(&:legacy_number?)
type_champs.map do |type_champ|
[I18n.t("activerecord.attributes.type_de_champ.type_champs.#{type_champ.last}"), type_champ.first]
end.filter do |tdc|
if tdc.last == TypeDeChamp.type_champs.fetch(:number)
has_legacy_number
else
feature_name = FEATURE_FLAGS[tdc.last]
feature_name.blank? || Flipper.enabled?(feature_name, user)
end
show_number = -> (tdc) { tdc != TypeDeChamp.type_champs.fetch(:number) || has_legacy_number }
enabled_featured_champ = -> (tdc) do
feature_name = FEATURE_FLAGS[tdc]
feature_name.blank? || Flipper.enabled?(feature_name, user)
end
type_champs
.keys
.filter(&show_number)
.filter(&enabled_featured_champ)
.map { |tdc| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{tdc}"), tdc] }
.sort_by(&:first)
end
TYPES_DE_CHAMP_BASE = {