Skip to content

Commit

Permalink
feat(admin): Add pages index Stimulus controller
Browse files Browse the repository at this point in the history
This controller provides a openModal action that we can use to load
the modal remotely instead of returning the whole index page with
the table rendered below the modal.

Currently no page uses this, but it can be implemented page by page.
  • Loading branch information
tvdeyen committed Dec 19, 2024
1 parent 4f79ff7 commit b13d7cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion admin/app/components/solidus_admin/layout/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module SolidusAdmin::Layout::PageHelpers
def page(**attrs, &block)
tag.div(capture(&block), class: "px-4 relative", "data-controller": stimulus_id, **attrs) +
tag.div(capture(&block), class: "px-4 relative", "data-controller": attrs.fetch(:stimulus_id, stimulus_id), **attrs) +
tag.div(render(component("layout/feedback").new), class: "flex justify-center py-10")
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= page do %>
<%= page "data-controller": stimulus_id do %>
<% if @tabs %>
<%= page_header do %>
<%= render_title %>
Expand Down
10 changes: 10 additions & 0 deletions admin/app/components/solidus_admin/ui/pages/index/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
async openModal(event) {
event.preventDefault();
const url = event.target.href;
const response = await fetch(url);
document.body.insertAdjacentHTML("beforeend", await response.text());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def scopes; []; end
def filters; []; end
def columns; []; end

def self.stimulus_id
"ui--pages--index"
end

def initialize(page:)
@page = page
@tabs = tabs&.map { |tab| Tab.new(**tab) }
Expand Down

0 comments on commit b13d7cc

Please sign in to comment.