Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: grid view item selector #3613

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/javascript/js/controllers/item_selector_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions spec/system/avo/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
Loading