Skip to content

Commit

Permalink
fix: actions select (#3636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Feb 4, 2025
1 parent 24649f4 commit aa56517
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/components/avo/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def action_data_attributes(action)
disabled: action.disabled?,
turbo_prefetch: false,
enabled_classes: "text-black",
disabled_classes: "text-gray-500"
disabled_classes: "text-gray-500",
resource_name: action.resource.model_key
}
end

Expand Down
3 changes: 2 additions & 1 deletion app/components/avo/resource_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def render_action(action)
turbo_prefetch: false,
# When action has record present behave as standalone and keep always active.
"actions-picker-target": (action.action.standalone || action.action.record.present?) ? "standaloneAction" : "resourceAction",
disabled: action.action.disabled?
disabled: action.action.disabled?,
resource_name: action.action.resource.model_key
} do
action.label
end
Expand Down
24 changes: 16 additions & 8 deletions app/javascript/js/controllers/item_selector_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,27 @@ export default class extends Controller {

enableResourceActions() {
this.actionLinks.forEach((link) => {
link.classList.add(link.dataset.enabledClasses)
link.classList.remove(link.dataset.disabledClasses)
link.setAttribute('data-href', link.getAttribute('href'))
link.dataset.disabled = false
// Enable only if is on the same resource context
// Avoiding to enable unrelated actions when selecting items on a has many table
if (link.dataset.resourceName === this.resourceName) {
link.classList.add(link.dataset.enabledClasses)
link.classList.remove(link.dataset.disabledClasses)
link.setAttribute('data-href', link.getAttribute('href'))
link.dataset.disabled = false
}
})
}

disableResourceActions() {
this.actionLinks.forEach((link) => {
link.classList.remove(link.dataset.enabledClasses)
link.classList.add(link.dataset.disabledClasses)
link.setAttribute('href', link.getAttribute('data-href'))
link.dataset.disabled = true
// Disable only if is on the same resource context
// Avoiding to disable unrelated actions when selecting items on a has many table
if (link.dataset.resourceName === this.resourceName) {
link.classList.remove(link.dataset.enabledClasses)
link.classList.add(link.dataset.disabledClasses)
link.setAttribute('href', link.getAttribute('data-href'))
link.dataset.disabled = true
}
})
}
}

0 comments on commit aa56517

Please sign in to comment.