Skip to content

Commit

Permalink
fix(admin/table): Only add rowClicked action if rowUrl is present
Browse files Browse the repository at this point in the history
If a table has no rowUrl defined we currently redirect to
root path. Which is not preferable. We should do nothing instead.
  • Loading branch information
tvdeyen committed Dec 20, 2024
1 parent 323dafe commit 8dca849
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@
<%= "data-sortable-animation-value=#{@sortable.animation}" if @sortable&.animation %>
>
<% @data.rows.each do |row| %>
<% rowUrl = @data.url&.call(row) %>
<tr
class="border-b border-gray-100 last:border-0 hover:bg-gray-50 cursor-pointer <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>"
<% if @data.url %>
class="border-b border-gray-100 last:border-0 <%= 'hover:bg-gray-50 cursor-pointer' if rowUrl %> <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>"
<% if rowUrl %>
data-action="click-><%= stimulus_id %>#rowClicked"
data-<%= stimulus_id %>-url-param="<%= @data.url.call(row) %>"
data-<%= stimulus_id %>-url-param="<%= rowUrl %>"
<%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %>
<% end %>
>
Expand Down
2 changes: 1 addition & 1 deletion admin/app/components/solidus_admin/ui/table/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class extends Controller {

if (this.modeValue === "batch") {
this.toggleCheckbox(event.currentTarget)
} else {
} else if (event.params.url) {
const url = new URL(event.params.url, "http://dummy.com")
const params = new URLSearchParams(url.search)
const frameId = params.get('_turbo_frame')
Expand Down

0 comments on commit 8dca849

Please sign in to comment.