Skip to content

Commit 026da08

Browse files
authored
fix: grid view item selector (#3613)
* fix: grid view item selector * test
1 parent b12b3f9 commit 026da08

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

app/javascript/js/controllers/item_selector_controller.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@ export default class extends Controller {
4444

4545
ids.push(this.resourceId)
4646

47-
// Mark the row as selected
48-
this.element.closest('tr').classList.add('selected-row')
47+
// Mark the row as selected if on table view
48+
if (this.element.closest('tr')) {
49+
this.element.closest('tr').classList.add('selected-row')
50+
}
4951

5052
this.currentIds = ids
5153
}
5254

5355
removeFromSelected() {
54-
// Un-mark the row as selected
55-
this.element.closest('tr').classList.remove('selected-row')
56+
// Un-mark the row as selected if on table view
57+
if (this.element.closest('tr')) {
58+
this.element.closest('tr').classList.remove('selected-row')
59+
}
5660

5761
this.currentIds = this.currentIds.filter(
5862
(item) => item.toString() !== this.resourceId,

spec/system/avo/actions_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,30 @@
408408
end
409409
end
410410

411+
describe "select items on grid view" do
412+
let!(:post) { create :post }
413+
414+
it "enables and disables the actions" do
415+
visit avo.resources_posts_path
416+
417+
# Find disabled action
418+
click_on "Actions"
419+
expect(page.find("a", text: "Toggle post published")["data-disabled"]).to eq "true"
420+
421+
# Hover grid element, select post, and verify that action is not disabled anymore
422+
find("[data-component-name=\"avo/index/grid_item_component\"][data-resource-name=\"posts\"][data-record-id=\"#{post.id}\"]").hover
423+
find('input[type="checkbox"][data-action="input->item-selector#toggle input->item-select-all#selectRow"]', visible: false).click
424+
click_on "Actions"
425+
expect(page.find("a", text: "Toggle post published")["data-disabled"]).to eq "false"
426+
427+
# Hover grid element, "unselect" post, and verify that action is disabled again
428+
find("[data-component-name=\"avo/index/grid_item_component\"][data-resource-name=\"posts\"][data-record-id=\"#{post.id}\"]").hover
429+
find('input[type="checkbox"][data-action="input->item-selector#toggle input->item-select-all#selectRow"]', visible: false).click
430+
click_on "Actions"
431+
expect(page.find("a", text: "Toggle post published")["data-disabled"]).to eq "true"
432+
end
433+
end
434+
411435
# let!(:roles) { { admin: false, manager: false, writer: false } }
412436
# let!(:user) { create :user, active: true, roles: roles }
413437

0 commit comments

Comments
 (0)