From e6198809baf7253195adc93b00bf93f52d745fff Mon Sep 17 00:00:00 2001 From: navaneeth Date: Wed, 19 May 2021 14:46:42 +0530 Subject: [PATCH] Fix for incorrect total number of apps --- app/controllers/apps_controller.rb | 8 ++--- frontend/src/_components/Pagination.jsx | 45 ++++++++++++------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index e8be990a3d..cad014243f 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -7,20 +7,20 @@ class AppsController < ApplicationController folder_id = params[:folder] if folder_id.blank? - @apps = App.where(organization: @current_user.organization) + @scope = App.where(organization: @current_user.organization) else @folder = Folder.find folder_id - @apps = @folder.apps + @scope = @folder.apps end - @apps = @apps.order('created_at desc') + @apps = @scope.order('created_at desc') .page(params[:page]) .per(10) .includes(:user) @meta = { total_pages: @apps.total_pages, - count: App.count, + count: @scope.count, current_page: @apps.current_page } end diff --git a/frontend/src/_components/Pagination.jsx b/frontend/src/_components/Pagination.jsx index 4fa0a841fc..b5e3239e0a 100644 --- a/frontend/src/_components/Pagination.jsx +++ b/frontend/src/_components/Pagination.jsx @@ -3,37 +3,36 @@ import React from 'react'; export const Pagination = function Pagination({ currentPage, count, totalPages, pageChanged }) { + function renderPageItem(i) { + return
  • gotoPage(i + 1)} className={`page-item ${currentPage === i + 1 ? 'active' : ''}`}>{i + 1}
  • ; + } - function renderPageItem(i) { - return
  • gotoPage(i + 1)} className={`page-item ${currentPage === i + 1 ? 'active' : ''}`}>{i + 1}
  • - } + function gotoPage(page) { + pageChanged(page); + } - function gotoPage(page) { - pageChanged(page) - } + function gotoNextPage() { + gotoPage(currentPage + 1); + } - function gotoNextPage() { - gotoPage(currentPage + 1); - } + function gotoPreviousPage() { + gotoPage(currentPage - 1); + } - function gotoPreviousPage() { - gotoPage(currentPage - 1); - } - - return (
    -

    Showing { (currentPage - 1) * 10 + 1} to {currentPage * 10} of {count} entries

    + return (
    +

    Showing { (currentPage - 1) * 10 + 1} to {currentPage * 10} of {count}

      -
    • - - +
    • + +
    • - {Array.from(Array(totalPages).keys()).map((i) => ( renderPageItem(i) ) )} + {Array.from(Array(totalPages).keys()).map((i) => (renderPageItem(i)))}
    • - - + +
    -
    ) -} +
    ); +};