Skip to content

Commit

Permalink
Align previews with recent changes in ui/table and ui/pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerdema committed Jul 26, 2023
1 parent 31c6029 commit 79ab261
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ def simple
model_class.new(id: n, name: "Product #{n}", price: n * 10.0, available_on: n.days.ago)
end

page = Struct.new(:records, :number, :next_param, :first?, :last?).new(rows, 1, '#', true, false)

page.records.define_singleton_method(:model) do
rows.define_singleton_method(:model) do
model_class
end

render component("ui/table").new(
page: page,
path: ->(_page_number) { "#" },
rows: rows,
search_key: :name_cont,
search_page_url: '',
turbo_frame_id: 'products',
previous_page_url: nil,
next_page_url: nil,
columns: [
{ header: :id, data: -> { _1.id.to_s } },
{ header: :name, data: :name },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,16 @@ class SolidusAdmin::UI::Table::Pagination::ComponentPreview < ViewComponent::Pre
include SolidusAdmin::Preview

def overview
render_with_template(
locals: {
page: page_proc,
path: path_proc
}
)
render_with_template
end

# @param left toggle
# @param right toggle
def playground(left: false, right: false)
render current_component.new(
page: page_proc.call(left, right),
path: path_proc
previous_page_url: left ? "#" : nil,
next_page_url: right ? "#" : nil,
turbo_frame_id: "pagination"
)
end

private

def page_proc
lambda { |left, right|
Struct.new(:number, :next_param, :first?, :last?).new(1, '#', !left, !right)
}
end

def path_proc
->(_page_number) { "#" }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<td class="font-bold px-3 py-1"><%= config[:title] %></td>
<td class="px-3 py-1 text-center">
<%= render current_component.new(
page: page.call(config[:left], config[:right]),
path: path
previous_page_url: config[:left] ? "#" : nil,
next_page_url: config[:right] ? "#" : nil,
turbo_frame_id: "pagination"
) %>
</td>
</tr>
Expand Down

0 comments on commit 79ab261

Please sign in to comment.