From f541503f34641607bc1e59f3d067bb46a0a7c00c Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 27 Jan 2025 12:45:37 +0200 Subject: [PATCH 1/2] fix: grid view item selector --- .../js/controllers/item_selector_controller.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/javascript/js/controllers/item_selector_controller.js b/app/javascript/js/controllers/item_selector_controller.js index 2c241edf59..ac60eb61c5 100644 --- a/app/javascript/js/controllers/item_selector_controller.js +++ b/app/javascript/js/controllers/item_selector_controller.js @@ -44,15 +44,19 @@ export default class extends Controller { ids.push(this.resourceId) - // Mark the row as selected - this.element.closest('tr').classList.add('selected-row') + // Mark the row as selected if on table view + if (this.element.closest('tr')) { + this.element.closest('tr').classList.add('selected-row') + } this.currentIds = ids } removeFromSelected() { - // Un-mark the row as selected - this.element.closest('tr').classList.remove('selected-row') + // Un-mark the row as selected if on table view + if (this.element.closest('tr')) { + this.element.closest('tr').classList.remove('selected-row') + } this.currentIds = this.currentIds.filter( (item) => item.toString() !== this.resourceId, From 7111af72b2274e057570f8dfc03e7a616bfe4cae Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 27 Jan 2025 13:11:30 +0200 Subject: [PATCH 2/2] test --- spec/system/avo/actions_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/system/avo/actions_spec.rb b/spec/system/avo/actions_spec.rb index 549c1cbaf6..a095136a58 100644 --- a/spec/system/avo/actions_spec.rb +++ b/spec/system/avo/actions_spec.rb @@ -408,6 +408,30 @@ end end + describe "select items on grid view" do + let!(:post) { create :post } + + it "enables and disables the actions" do + visit avo.resources_posts_path + + # Find disabled action + click_on "Actions" + expect(page.find("a", text: "Toggle post published")["data-disabled"]).to eq "true" + + # Hover grid element, select post, and verify that action is not disabled anymore + find("[data-component-name=\"avo/index/grid_item_component\"][data-resource-name=\"posts\"][data-record-id=\"#{post.id}\"]").hover + find('input[type="checkbox"][data-action="input->item-selector#toggle input->item-select-all#selectRow"]', visible: false).click + click_on "Actions" + expect(page.find("a", text: "Toggle post published")["data-disabled"]).to eq "false" + + # Hover grid element, "unselect" post, and verify that action is disabled again + find("[data-component-name=\"avo/index/grid_item_component\"][data-resource-name=\"posts\"][data-record-id=\"#{post.id}\"]").hover + find('input[type="checkbox"][data-action="input->item-selector#toggle input->item-select-all#selectRow"]', visible: false).click + click_on "Actions" + expect(page.find("a", text: "Toggle post published")["data-disabled"]).to eq "true" + end + end + # let!(:roles) { { admin: false, manager: false, writer: false } } # let!(:user) { create :user, active: true, roles: roles }