File tree Expand file tree Collapse file tree
components/avo/view_types
javascript/js/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 tabindex : ( @reflection . present? ? nil : "-1" ) ,
77 data : {
88 component_name : self . class . to_s . underscore ,
9+ controller : "item-select-all" ,
10+ resource_name : @resource . model_key ,
911 selected_resources_name : @resource . model_key ,
1012 selected_resources : [ ] ,
1113 **( @reflection . present? ? { } : { "content-focus" : "" } ) ,
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ export default class extends Controller {
2222 }
2323
2424 elementAttributeValueChanged ( element ) {
25+ if ( ! this . hasCheckboxTarget ) return
26+
2527 // Check if anything is selected.
2628 const selectedResources = JSON . parse ( element . dataset . selectedResources )
2729 // If all are selected, mark the checkbox as checked.
@@ -47,7 +49,10 @@ export default class extends Controller {
4749
4850 deselectAll ( ) {
4951 this . itemCheckboxTargets . forEach ( ( checkbox ) => checkbox . checked && checkbox . click ( ) )
50- this . checkboxTarget . checked = false
52+
53+ if ( this . hasCheckboxTarget ) {
54+ this . checkboxTarget . checked = false
55+ }
5156
5257 if ( this . selectAllEnabled ( ) ) {
5358 this . selectAllOverlay ( false )
@@ -73,7 +78,10 @@ export default class extends Controller {
7378 let allSelected = true
7479 // eslint-disable-next-line no-return-assign
7580 this . itemCheckboxTargets . forEach ( ( checkbox ) => allSelected = allSelected && checkbox . checked )
76- this . checkboxTarget . checked = allSelected
81+
82+ if ( this . hasCheckboxTarget ) {
83+ this . checkboxTarget . checked = allSelected
84+ }
7785
7886 if ( this . selectAllEnabled ( ) ) {
7987 this . selectAllOverlay ( allSelected )
Original file line number Diff line number Diff line change 484484 click_on "Actions"
485485 expect ( page . find ( "a" , text : "Toggle post published" ) [ "data-disabled" ] ) . to eq "true"
486486 end
487+
488+ # Regression for https://github.com/avo-hq/avo/pull/4595 — selected grid
489+ # records must reach the action (confirmation message + handle query).
490+ it "runs an action with the selected records on the products grid" do
491+ product = create :product , title : "Grid Product One"
492+
493+ visit avo . resources_products_path
494+
495+ grid_component = find (
496+ "[data-component-name=\" avo/index/grid_item_component\" ]" \
497+ "[data-resource-name=\" products\" ]" \
498+ "[data-record-id=\" #{ product . to_param } \" ]"
499+ )
500+
501+ within grid_component do
502+ grid_component . hover
503+ find ( "input[type=checkbox]" ) . click
504+ end
505+
506+ open_panel_action ( action_name : "Show products" )
507+
508+ expect ( page ) . to have_text "Selected products: Grid Product One"
509+
510+ run_action
511+
512+ expect ( page ) . to have_text "Selected products: Grid Product One"
513+ end
487514 end
488515
489516 describe "record assignment" do
You can’t perform that action at this time.
0 commit comments