add feature flag
This commit is contained in:
parent
acd874ccdf
commit
ff2e9f0816
4 changed files with 45 additions and 16 deletions
|
@ -56,22 +56,32 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def types_of_type_de_champ
|
def types_of_type_de_champ
|
||||||
cat_scope = "activerecord.attributes.type_de_champ.categorie"
|
if Flipper.enabled?(:categories_type_de_champ, controller.current_user)
|
||||||
tdc_scope = "activerecord.attributes.type_de_champ.type_champs"
|
cat_scope = "activerecord.attributes.type_de_champ.categorie"
|
||||||
|
tdc_scope = "activerecord.attributes.type_de_champ.type_champs"
|
||||||
|
|
||||||
TypeDeChamp.type_champs
|
TypeDeChamp.type_champs
|
||||||
.keys
|
.keys
|
||||||
.filter(&method(:filter_type_champ))
|
.filter(&method(:filter_type_champ))
|
||||||
.filter(&method(:filter_featured_type_champ))
|
.filter(&method(:filter_featured_type_champ))
|
||||||
.filter(&method(:filter_block_type_champ))
|
.filter(&method(:filter_block_type_champ))
|
||||||
.group_by { TypeDeChamp::TYPE_DE_CHAMP_TO_CATEGORIE.fetch(_1.to_sym) }
|
.group_by { TypeDeChamp::TYPE_DE_CHAMP_TO_CATEGORIE.fetch(_1.to_sym) }
|
||||||
.sort_by { |k, _v| TypeDeChamp::CATEGORIES.find_index(k) }
|
.sort_by { |k, _v| TypeDeChamp::CATEGORIES.find_index(k) }
|
||||||
.to_h do |cat, tdc|
|
.to_h do |cat, tdc|
|
||||||
[
|
[
|
||||||
t(cat, scope: cat_scope),
|
t(cat, scope: cat_scope),
|
||||||
tdc.map { [t(_1, scope: tdc_scope), _1] }
|
tdc.map { [t(_1, scope: tdc_scope), _1] }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
TypeDeChamp.type_champs
|
||||||
|
.keys
|
||||||
|
.filter(&method(:filter_type_champ))
|
||||||
|
.filter(&method(:filter_featured_type_champ))
|
||||||
|
.filter(&method(:filter_block_type_champ))
|
||||||
|
.map { |type_champ| [t("activerecord.attributes.type_de_champ.type_champs.#{type_champ}"), type_champ] }
|
||||||
|
.sort_by(&:first)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def piece_justificative_options(form)
|
def piece_justificative_options(form)
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
%span.sr-only Déplacer le champ vers le bas
|
%span.sr-only Déplacer le champ vers le bas
|
||||||
.cell.flex.justify-start.column.flex-grow
|
.cell.flex.justify-start.column.flex-grow
|
||||||
= form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ)
|
= form.label :type_champ, "Type de champ", for: dom_id(type_de_champ, :type_champ)
|
||||||
= form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)
|
- if Flipper.enabled?(:categories_type_de_champ, controller.current_user)
|
||||||
|
= form.select :type_champ, grouped_options_for_select(types_of_type_de_champ, type_de_champ.type_champ), {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)
|
||||||
|
- else
|
||||||
|
= form.select :type_champ, types_of_type_de_champ, {}, class: 'small-margin small inline width-100', id: dom_id(type_de_champ, :type_champ)
|
||||||
.flex.column.justify-start.flex-grow
|
.flex.column.justify-start.flex-grow
|
||||||
.cell
|
.cell
|
||||||
.flex.align-center
|
.flex.align-center
|
||||||
|
|
|
@ -21,6 +21,7 @@ end
|
||||||
features = [
|
features = [
|
||||||
:administrateur_web_hook,
|
:administrateur_web_hook,
|
||||||
:api_particulier,
|
:api_particulier,
|
||||||
|
:categories_type_de_champ,
|
||||||
:dossier_pdf_vide,
|
:dossier_pdf_vide,
|
||||||
:expert_not_allowed_to_invite,
|
:expert_not_allowed_to_invite,
|
||||||
:hide_instructeur_email,
|
:hide_instructeur_email,
|
||||||
|
|
|
@ -69,4 +69,19 @@ describe 'Creating a new procedure', js: true do
|
||||||
expect(champs_card).to have_content('À modifier')
|
expect(champs_card).to have_content('À modifier')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with feature activated' do
|
||||||
|
let(:procedure) { create(:procedure, :with_service, administrateur: administrateur) }
|
||||||
|
before { Flipper.enable(:categories_type_de_champ, administrateur.user) }
|
||||||
|
after { Flipper.disable(:categories_type_de_champ, administrateur.user) }
|
||||||
|
|
||||||
|
it 'types de champ are grouped by categories ' do
|
||||||
|
visit champs_admin_procedure_path(procedure)
|
||||||
|
|
||||||
|
add_champ(remove_flash_message: true)
|
||||||
|
select('Bloc répétable', from: 'Type de champ')
|
||||||
|
|
||||||
|
expect(page).to have_selector('select > optgroup', count: 7)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue