make batch instruction button disable
This commit is contained in:
parent
220b71bbf7
commit
3577bcbffa
5 changed files with 16 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
- if opt.keys.include?(:instruction)
|
- if opt.keys.include?(:instruction)
|
||||||
= render Dropdown::MenuComponent.new(wrapper: :div, wrapper_options: { data: {controller: 'menu-button', popover: 'true', operation: opt[:operation]} }, menu_options: { id: "dropdown_batch" }, button_options: { class: "fr-btn fr-btn--sm fr-ml-1w"}, role: :region ) do |menu|
|
= render Dropdown::MenuComponent.new(wrapper: :div, wrapper_options: { data: {controller: 'menu-button', popover: 'true', operation: opt[:operation]} }, menu_options: { id: "dropdown_batch" }, button_options: { disabled: true, data: { batch_operation_target: "menu" }, class: "fr-btn fr-btn--sm fr-ml-1w"}, role: :region ) do |menu|
|
||||||
- menu.with_button_inner_html do
|
- menu.with_button_inner_html do
|
||||||
= t(".labels.instruction")
|
= t(".labels.instruction")
|
||||||
|
|
||||||
|
|
|
@ -51,4 +51,12 @@ class Dropdown::MenuComponent < ApplicationComponent
|
||||||
def button_class_names
|
def button_class_names
|
||||||
['fr-btn', 'dropdown-button'] + Array(@button_options[:class])
|
['fr-btn', 'dropdown-button'] + Array(@button_options[:class])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disabled?
|
||||||
|
@button_options[:disabled] == true
|
||||||
|
end
|
||||||
|
|
||||||
|
def data
|
||||||
|
{ menu_button_target: 'button' }.deep_merge(@button_options[:data].to_h)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
= content_tag(@wrapper, wrapper_options) do
|
= content_tag(@wrapper, wrapper_options) do
|
||||||
%button{ class: button_class_names, id: button_id, data: { menu_button_target: 'button' }, "aria-expanded": "false", 'aria-haspopup': 'true', 'aria-controls': menu_id }
|
%button{ class: button_class_names, id: button_id, disabled: disabled?, data: data, "aria-expanded": "false", 'aria-haspopup': 'true', 'aria-controls': menu_id }
|
||||||
= button_inner_html
|
= button_inner_html
|
||||||
|
|
||||||
%div{ data: { menu_button_target: 'menu' }, id: menu_id, 'aria-labelledby': button_id, role: menu_role, 'tab-index': -1, class: menu_class_names }
|
%div{ data: { menu_button_target: 'menu' }, id: menu_id, 'aria-labelledby': button_id, role: menu_role, 'tab-index': -1, class: menu_class_names }
|
||||||
|
|
|
@ -5,7 +5,7 @@ import invariant from 'tiny-invariant';
|
||||||
export class BatchOperationController extends ApplicationController {
|
export class BatchOperationController extends ApplicationController {
|
||||||
static targets = ['menu', 'input'];
|
static targets = ['menu', 'input'];
|
||||||
|
|
||||||
declare readonly menuTarget: HTMLButtonElement;
|
declare readonly menuTargets: HTMLButtonElement[];
|
||||||
declare readonly hasMenuTarget: boolean;
|
declare readonly hasMenuTarget: boolean;
|
||||||
declare readonly inputTargets: HTMLInputElement[];
|
declare readonly inputTargets: HTMLInputElement[];
|
||||||
|
|
||||||
|
@ -78,16 +78,17 @@ export class BatchOperationController extends ApplicationController {
|
||||||
switchButton(button, available);
|
switchButton(button, available);
|
||||||
return available;
|
return available;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.hasMenuTarget) {
|
if (this.hasMenuTarget) {
|
||||||
if (available.length) {
|
if (available.length) {
|
||||||
enable(this.menuTarget);
|
this.menuTargets.forEach((e) => enable(e));
|
||||||
} else {
|
} else {
|
||||||
disable(this.menuTarget);
|
this.menuTargets.forEach((e) => disable(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.hasMenuTarget) {
|
if (this.hasMenuTarget) {
|
||||||
disable(this.menuTarget);
|
this.menuTargets.forEach((e) => disable(e));
|
||||||
}
|
}
|
||||||
buttons.forEach((button) => switchButton(button, false));
|
buttons.forEach((button) => switchButton(button, false));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do
|
||||||
context 'statut suivis' do
|
context 'statut suivis' do
|
||||||
let(:statut) { 'suivis' }
|
let(:statut) { 'suivis' }
|
||||||
it { is_expected.to have_button('Passer les dossiers en instruction', disabled: true) }
|
it { is_expected.to have_button('Passer les dossiers en instruction', disabled: true) }
|
||||||
it { is_expected.to have_button('Accepter les dossiers', disabled: true) }
|
it { is_expected.to have_button('Instruire les dossiers', disabled: true) }
|
||||||
it { is_expected.to have_button('Autres actions multiples', disabled: true) }
|
it { is_expected.to have_button('Autres actions multiples', disabled: true) }
|
||||||
it { is_expected.to have_button('Repasser les dossiers en construction', disabled: true) }
|
it { is_expected.to have_button('Repasser les dossiers en construction', disabled: true) }
|
||||||
it { is_expected.to have_button('Ne plus suivre les dossiers', disabled: true) }
|
it { is_expected.to have_button('Ne plus suivre les dossiers', disabled: true) }
|
||||||
|
|
Loading…
Reference in a new issue