improve color selection for Admin and improve generic label lists

This commit is contained in:
Lisa Durand 2024-10-28 14:33:57 +01:00
parent 725a97da7e
commit 507ea70398
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
8 changed files with 51 additions and 43 deletions

View file

@ -5,18 +5,11 @@ $colors: "green-tilleul-verveine",
"green-bourgeon", "green-bourgeon",
"green-emeraude", "green-emeraude",
"green-menthe", "green-menthe",
"green-archipel",
"blue-ecume", "blue-ecume",
"blue-cumulus",
"purple-glycine", "purple-glycine",
"pink-macaron", "pink-macaron",
"pink-tuile",
"yellow-tournesol", "yellow-tournesol",
"yellow-moutarde",
"orange-terre-battue",
"brown-cafe-creme", "brown-cafe-creme",
"brown-caramel",
"brown-opera",
"beige-gris-galet"; "beige-gris-galet";
@ -35,3 +28,15 @@ $colors: "green-tilleul-verveine",
color: var(--text-action-high-#{$color}); color: var(--text-action-high-#{$color});
} }
} }
.grid-tags {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 62em) {
.grid-tags {
display: grid;
grid-template-columns: repeat(5, 1fr);
}
}

View file

@ -6,9 +6,11 @@ class Label < ApplicationRecord
NAME_MAX_LENGTH = 30 NAME_MAX_LENGTH = 30
GENERIC_LABELS = [ GENERIC_LABELS = [
{ name: 'à relancer', color: 'brown_caramel' }, { name: 'À examiner', color: 'purple_glycine' },
{ name: 'complet', color: 'green_bourgeon' }, { name: 'À relancer', color: 'green_tilleul_verveine' },
{ name: 'prêt pour validation', color: 'green_archipel' } { name: 'Complet', color: 'green_emeraude' },
{ name: 'À signer', color: 'blue_ecume' },
{ name: 'Urgent', color: 'pink_macaron' }
] ]
enum color: { enum color: {
@ -16,18 +18,11 @@ class Label < ApplicationRecord
green_bourgeon: "green-bourgeon", green_bourgeon: "green-bourgeon",
green_emeraude: "green-emeraude", green_emeraude: "green-emeraude",
green_menthe: "green-menthe", green_menthe: "green-menthe",
green_archipel: "green-archipel",
blue_ecume: "blue-ecume", blue_ecume: "blue-ecume",
blue_cumulus: "blue-cumulus",
purple_glycine: "purple-glycine", purple_glycine: "purple-glycine",
pink_macaron: "pink-macaron", pink_macaron: "pink-macaron",
pink_tuile: "pink-tuile",
yellow_tournesol: "yellow-tournesol", yellow_tournesol: "yellow-tournesol",
yellow_moutarde: "yellow-moutarde",
orange_terre_battue: "orange-terre-battue",
brown_cafe_creme: "brown-cafe-creme", brown_cafe_creme: "brown-cafe-creme",
brown_caramel: "brown-caramel",
brown_opera: "brown-opera",
beige_gris_galet: "beige-gris-galet" beige_gris_galet: "beige-gris-galet"
} }

View file

@ -1,8 +1,16 @@
= form_with model: label, url: admin_procedure_procedure_labels_path(@procedure, id: @label.id), local: true do |f| = form_with model: label, url: admin_procedure_procedure_labels_path(@procedure, id: @label.id), local: true do |f|
= render Dsfr::InputComponent.new(form: f, attribute: :name, input_type: :text_field, opts: { maxlength: ProcedureLabel::NAME_MAX_LENGTH}) = render Dsfr::InputComponent.new(form: f, attribute: :name, input_type: :text_field, opts: { maxlength: ProcedureLabel::NAME_MAX_LENGTH})
= f.label :color, class: 'fr-label' do
%fieldset.fr-fieldset
%legend.fr-fieldset__legend.fr-fieldset__legend--regular
= t('activerecord.attributes.procedure_label.color') = t('activerecord.attributes.procedure_label.color')
= render EditableChamp::AsteriskMandatoryComponent.new = render EditableChamp::AsteriskMandatoryComponent.new
= f.select :color, options_for_select(@colors_collection, selected: @label.color), {prompt: 'Choisir une couleur'}, {class: 'fr-select'}
.grid-tags
- @colors_collection.each do |color|
.fr-fieldset__element
.fr-radio-group
= f.radio_button :color, color, checked: (label.color == color.underscore)
= f.label :color, value: color, class: "fr-label fr-tag fr-tag--sm fr-tag--#{color}"
= render Procedure::FixedFooterComponent.new(procedure: @procedure, form: f) = render Procedure::FixedFooterComponent.new(procedure: @procedure, form: f)

View file

@ -515,8 +515,8 @@ describe Administrateurs::ProceduresController, type: :controller do
end end
it "create generic labels" do it "create generic labels" do
expect(subject.labels.size).to eq(3) expect(subject.labels.size).to eq(5)
expect(subject.labels.first.name).to eq('à relancer') expect(subject.labels.first.name).to eq('À examiner')
end end
end end

View file

@ -1529,7 +1529,7 @@ describe Instructeurs::DossiersController, type: :controller do
dossier.reload dossier.reload
expect(dossier.dossier_labels.count).to eq(1) expect(dossier.dossier_labels.count).to eq(1)
expect(subject.body).to include('fr-tag--brown-caramel') expect(subject.body).to include('fr-tag--purple-glycine')
expect(subject.body).not_to include('Ajouter un label') expect(subject.body).not_to include('Ajouter un label')
end end
end end

View file

@ -663,10 +663,10 @@ describe Instructeurs::ProceduresController, type: :controller do
it 'displays correctly labels in instructeur table' do it 'displays correctly labels in instructeur table' do
expect(response.body).to include("Labels") expect(response.body).to include("Labels")
expect(response.body).to have_selector('ul.fr-tags-group li span.fr-tag', text: 'à relancer') expect(response.body).to have_selector('ul.fr-tags-group li span.fr-tag', text: 'À examiner')
expect(response.body).to have_selector('ul.fr-tags-group li span.fr-tag', text: 'complet') expect(response.body).to have_selector('ul.fr-tags-group li span.fr-tag', text: 'À relancer')
expect(response.body).not_to have_selector('ul li span.fr-tag', text: 'prêt pour validation') expect(response.body).not_to have_selector('ul li span.fr-tag', text: 'Urgent')
expect(response.body).to have_selector('span.fr-tag', text: 'prêt pour validation') expect(response.body).to have_selector('span.fr-tag', text: 'Urgent')
end end
end end
end end

View file

@ -281,26 +281,26 @@ describe 'Instructing a dossier:', js: true do
visit instructeur_dossier_path(procedure, dossier) visit instructeur_dossier_path(procedure, dossier)
click_on 'Ajouter un label' click_on 'Ajouter un label'
check 'à relancer', allow_label_click: true check 'À relancer', allow_label_click: true
expect(page).to have_css('.fr-tag', text: "à relancer", count: 2) expect(page).to have_css('.fr-tag', text: "À relancer", count: 2)
expect(dossier.dossier_labels.count).to eq(1) expect(dossier.dossier_labels.count).to eq(1)
expect(page).not_to have_text('Ajouter un label') expect(page).not_to have_text('Ajouter un label')
find('span.dropdown button.dropdown-button').click find('span.dropdown button.dropdown-button').click
expect(page).to have_checked_field('à relancer') expect(page).to have_checked_field('À relancer')
check 'complet', allow_label_click: true check 'Complet', allow_label_click: true
expect(page).to have_css('.fr-tag', text: "complet", count: 2) expect(page).to have_css('.fr-tag', text: "Complet", count: 2)
expect(dossier.dossier_labels.count).to eq(2) expect(dossier.dossier_labels.count).to eq(2)
find('span.dropdown button.dropdown-button').click find('span.dropdown button.dropdown-button').click
uncheck 'à relancer', allow_label_click: true uncheck 'À relancer', allow_label_click: true
expect(page).to have_unchecked_field('à relancer') expect(page).to have_unchecked_field('À relancer')
expect(page).to have_checked_field('complet') expect(page).to have_checked_field('Complet')
expect(page).to have_css('.fr-tag', text: "à relancer", count: 1) expect(page).to have_css('.fr-tag', text: "À relancer", count: 1)
expect(page).to have_css('.fr-tag', text: "complet", count: 2) expect(page).to have_css('.fr-tag', text: "Complet", count: 2)
expect(dossier.dossier_labels.count).to eq(1) expect(dossier.dossier_labels.count).to eq(1)
end end
end end

View file

@ -227,7 +227,7 @@ describe 'instructeurs/dossiers/show', type: :view do
let(:dossier) { create(:dossier, :en_construction, procedure: procedure_without_labels) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure_without_labels) }
it 'does not display button to add label or dropdown' do it 'does not display button to add label or dropdown' do
expect(subject).not_to have_text("Ajouter un label") expect(subject).not_to have_text("Ajouter un label")
expect(subject).not_to have_text("à relancer") expect(subject).not_to have_text("À examiner")
end end
end end
@ -235,9 +235,9 @@ describe 'instructeurs/dossiers/show', type: :view do
it 'displays button with text to add label' do it 'displays button with text to add label' do
expect(subject).to have_text("Ajouter un label") expect(subject).to have_text("Ajouter un label")
expect(subject).to have_selector("button.dropdown-button") expect(subject).to have_selector("button.dropdown-button")
expect(subject).to have_text("à relancer", count: 1) expect(subject).to have_text("À examiner", count: 1)
within('.dropdown') do within('.dropdown') do
expect(subject).to have_text("à relancer", count: 1) expect(subject).to have_text("À examiner", count: 1)
end end
end end
end end
@ -250,9 +250,9 @@ describe 'instructeurs/dossiers/show', type: :view do
it 'displays labels and button without text to add label' do it 'displays labels and button without text to add label' do
expect(subject).not_to have_text("Ajouter un label") expect(subject).not_to have_text("Ajouter un label")
expect(subject).to have_selector("button.dropdown-button") expect(subject).to have_selector("button.dropdown-button")
expect(subject).to have_text("à relancer", count: 2) expect(subject).to have_text("À examiner", count: 2)
within('.dropdown') do within('.dropdown') do
expect(subject).to have_text("à relancer", count: 1) expect(subject).to have_text("À examiner", count: 1)
end end
end end
end end