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

Sweep: Pagination Missing on "Shop Summary" Merchant Table (βœ“ Sandbox Passed) #99

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7b3d8c3
feat: Updated app/models/summary/shop.rb
sweep-ai[bot] Feb 3, 2024
29e1e9f
feat: Add pagination helper for generating navigat
sweep-ai[bot] Feb 3, 2024
7c7bb77
feat: Updated app/controllers/summarys/shop_contro
sweep-ai[bot] Feb 3, 2024
483ecf0
feat: Updated app/views/summarys/index.html.erb
sweep-ai[bot] Feb 3, 2024
aeab51f
feat: Updated app/controllers/summarys/shop_contro
sweep-ai[bot] Feb 3, 2024
5549357
feat: Updated app/views/summarys/index.html.erb
sweep-ai[bot] Feb 3, 2024
6da5ac6
feat: Updated app/controllers/summarys/shop_contro
sweep-ai[bot] Feb 3, 2024
4d8949d
feat: Updated app/helpers/pagination_helper.rb
sweep-ai[bot] Feb 3, 2024
383ba3d
feat: Updated app/controllers/summarys/shop_contro
sweep-ai[bot] Feb 3, 2024
51029a8
feat: Updated app/helpers/pagination_helper.rb
sweep-ai[bot] Feb 3, 2024
7d2f4fc
Delete app/helpers/pagination_helper.rb
sweep-ai[bot] Feb 3, 2024
ddc2f19
feat: Updated app/views/summarys/index.html.erb
sweep-ai[bot] Feb 3, 2024
30e8888
feat: Add controller test for shop summary paginat
sweep-ai[bot] Feb 4, 2024
171f49d
feat: Updated test/controllers/summarys/shop_contr
sweep-ai[bot] Feb 4, 2024
0168ab2
feat: Updated test/controllers/summarys/shop_contr
sweep-ai[bot] Feb 4, 2024
64d6c72
feat: Updated test/controllers/summarys/shop_contr
sweep-ai[bot] Feb 4, 2024
5b525cb
feat: Updated test/controllers/summarys/shop_contr
sweep-ai[bot] Feb 4, 2024
9f4eb5a
feat: Updated test/controllers/summarys/shop_contr
sweep-ai[bot] Feb 4, 2024
0e136f1
feat: Updated test/controllers/summarys/shop_contr
sweep-ai[bot] Feb 4, 2024
b92ac2f
Merge main into sweep/pagination_missing_on_shop_summary_merch
sweep-ai[bot] Feb 28, 2024
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
4 changes: 3 additions & 1 deletion app/controllers/summarys/shop_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Summarys::ShopController < SummarysController
def index
@selected_app = summary_params[:selected_app]
@summaries = Summary::Shop.new(user: current_user, selected_app: @selected_app).summarize
@page = params[:page] || 1
@per_page = Summary::Shop::TOP_SHOPS_LIMIT
@summaries = Summary::Shop.new(user: current_user, selected_app: @selected_app).summarize(page: @page.to_i, per_page: @per_page.to_i)

render "summarys/index"
end
Expand Down
17 changes: 17 additions & 0 deletions app/helpers/pagination_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module PaginationHelper
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
def paginate(total_items, items_per_page, current_page, base_url)
total_pages = (total_items.to_f / items_per_page).ceil
pagination_html = '<ul class="pagination">'

if current_page > 1
pagination_html += '<li>' + link_to('Previous', "#{base_url}?page=#{current_page - 1}") + '</li>'
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
end

if current_page < total_pages
pagination_html += '<li>' + link_to('Next', "#{base_url}?page=#{current_page + 1}") + '</li>'
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
end

pagination_html += "</ul>"
pagination_html.html_safe
end
end
forsbergplustwo marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions app/models/summary/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def summarize

private

def summarized_shop_data
def summarized_shop_data(page: 1, per_page: TOP_SHOPS_LIMIT)
offset = (page - 1) * per_page
result = payments
.select(SQL_QUERY)
.group(:shop)
.order("total_revenue DESC")
.limit(TOP_SHOPS_LIMIT)
.offset(offset)
.limit(per_page)

result.each_with_object({}) do |record, hash|
hash[record.shop] = record.attributes.except("shop")
Expand Down
1 change: 1 addition & 0 deletions app/views/summarys/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<%= polaris_card do %>
<%= render controller_name, rows: @summaries %>
<% end %>
<%= polaris_pagination(previous_url: summary_shop_path(page: @page.to_i - 1), next_url: summary_shop_path(page: @page.to_i + 1)) %>

<% end %>

Expand Down
Loading