From 42fc086f50589fc259eb066e35d10e2f903a506c Mon Sep 17 00:00:00 2001 From: Mat Busby <83598933+matbusby-fw@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:42:25 -0600 Subject: [PATCH] [MDS-6095] Minespace Report Pagination (#3240) * added BE pagination to minespace reports table view * update Reports.spec.tsx * fix sorting of mine reports --- .../components/common/ResponsivePagination.js | 0 .../app/api/mines/reports/report_helpers.py | 11 +- .../mines/reports/resources/mine_reports.py | 2 +- .../contactsHomePage/ContactHomePage.js | 2 +- .../dashboard/customHomePage/VarianceTable.js | 2 +- .../MajorProjectHomePage.js | 2 +- .../dashboard/minesHomePage/Dashboard.js | 2 +- .../NoticeOfWorkHomePage.tsx | 2 +- .../reportsHomePage/ReportsTable.tsx | 2 +- .../mine/Reports/MineReportInfo.tsx | 2 +- .../mine/Tailings/MineTailingsInfoTabs.tsx | 2 +- .../common/ResponsivePagination.spec.js | 2 +- .../dashboard/mine/reports/Reports.tsx | 22 ++- .../dashboard/mine/reports/ReportsTable.tsx | 7 +- .../dashboard/mine/reports/Reports.spec.tsx | 4 +- .../__snapshots__/Reports.spec.tsx.snap | 125 ++---------------- 16 files changed, 53 insertions(+), 136 deletions(-) rename services/{core-web => common}/src/components/common/ResponsivePagination.js (100%) diff --git a/services/core-web/src/components/common/ResponsivePagination.js b/services/common/src/components/common/ResponsivePagination.js similarity index 100% rename from services/core-web/src/components/common/ResponsivePagination.js rename to services/common/src/components/common/ResponsivePagination.js diff --git a/services/core-api/app/api/mines/reports/report_helpers.py b/services/core-api/app/api/mines/reports/report_helpers.py index 6a586ee0a9..a844597f33 100644 --- a/services/core-api/app/api/mines/reports/report_helpers.py +++ b/services/core-api/app/api/mines/reports/report_helpers.py @@ -15,7 +15,7 @@ def build_filter(cls, model, field, op, argfield): return {'model': model, 'field': field, 'op': op, 'value': argfield} @staticmethod - def apply_filters_and_pagination(query, args): + def apply_filters_and_pagination(query, args, mine_guid=None): sort_models = { "mine_report_id": 'MineReport', "mine_report_category": 'MineReportCategoryXref', @@ -24,6 +24,7 @@ def apply_filters_and_pagination(query, args): "received_date": 'MineReport', "submission_year": 'MineReport', "mine_report_status_code": 'MineReportSubmissionStatusCode', + "mine_report_status": 'MineReportSubmissionStatusCode', "created_by_idir": 'MineReport', "mine_name": 'Mine', } @@ -36,6 +37,7 @@ def apply_filters_and_pagination(query, args): "received_date": 'received_date', "submission_year": 'submission_year', "mine_report_status_code": 'mine_report_status_description', + "mine_report_status": 'mine_report_status_description', "created_by_idir": 'created_by_idir', "mine_name": 'mine_name', } @@ -47,7 +49,7 @@ def apply_filters_and_pagination(query, args): query = query.join(Mine) if args["report_type"] or args["report_name"] or (args['sort_field'] and sort_models[ - args['sort_field']] in ['MineReportCategoryXref', 'MineReportDefinition']): + args['sort_field']] in ['MineReportCategoryXref', 'MineReportDefinition'] and not mine_guid): query = query.join( MineReportDefinition, MineReport.mine_report_definition_id == MineReportDefinition.mine_report_definition_id) @@ -115,9 +117,12 @@ def apply_filters_and_pagination(query, args): ] conditions.append({'or': search_conditions}) + if mine_guid: + query = query.filter(MineReport.mine_guid == mine_guid) + filtered_query = apply_filters(query, conditions) - if args['sort_field'] == 'mine_report_status_code': + if args['sort_field'] == 'mine_report_status_code' or args['sort_field'] == 'mine_report_status': if args['sort_dir'] == 'asc': filtered_query = filtered_query.order_by( asc(MineReport.mine_report_status_description)) diff --git a/services/core-api/app/api/mines/reports/resources/mine_reports.py b/services/core-api/app/api/mines/reports/resources/mine_reports.py index 41da0cadc5..ac07a02544 100644 --- a/services/core-api/app/api/mines/reports/resources/mine_reports.py +++ b/services/core-api/app/api/mines/reports/resources/mine_reports.py @@ -114,7 +114,7 @@ def get(self, mine_guid): MineReportCategory.mine_report_category == 'TSF' ) - records, pagination_details = ReportFilterHelper.apply_filters_and_pagination(query, args) + records, pagination_details = ReportFilterHelper.apply_filters_and_pagination(query, args, mine_guid) if not records: raise BadRequest('Unable to fetch reports') diff --git a/services/core-web/src/components/dashboard/contactsHomePage/ContactHomePage.js b/services/core-web/src/components/dashboard/contactsHomePage/ContactHomePage.js index c55f9d0fd9..493cd20685 100644 --- a/services/core-web/src/components/dashboard/contactsHomePage/ContactHomePage.js +++ b/services/core-web/src/components/dashboard/contactsHomePage/ContactHomePage.js @@ -18,7 +18,7 @@ import * as FORM from "@/constants/forms"; import * as Permission from "@/constants/permissions"; import ContactSearch from "@/components/dashboard/contactsHomePage/ContactSearch"; import ContactList from "@/components/dashboard/contactsHomePage/ContactList"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; import AuthorizationWrapper from "@/components/common/wrappers/AuthorizationWrapper"; import * as routes from "@/constants/routes"; import { modalConfig } from "@/components/modalContent/config"; diff --git a/services/core-web/src/components/dashboard/customHomePage/VarianceTable.js b/services/core-web/src/components/dashboard/customHomePage/VarianceTable.js index 6773dae1b9..8dde634dae 100644 --- a/services/core-web/src/components/dashboard/customHomePage/VarianceTable.js +++ b/services/core-web/src/components/dashboard/customHomePage/VarianceTable.js @@ -2,7 +2,7 @@ import React from "react"; import PropTypes from "prop-types"; import * as Strings from "@mds/common/constants/strings"; import CustomPropTypes from "@/customPropTypes"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; import MineVarianceTable from "@/components/mine/Variances/MineVarianceTable"; /** diff --git a/services/core-web/src/components/dashboard/majorProjectHomePage/MajorProjectHomePage.js b/services/core-web/src/components/dashboard/majorProjectHomePage/MajorProjectHomePage.js index ab19b4ebe2..d411464646 100644 --- a/services/core-web/src/components/dashboard/majorProjectHomePage/MajorProjectHomePage.js +++ b/services/core-web/src/components/dashboard/majorProjectHomePage/MajorProjectHomePage.js @@ -18,7 +18,7 @@ import { import { getProjects, getProjectPageData } from "@mds/common/redux/selectors/projectSelectors"; import { bindActionCreators } from "redux"; import * as router from "@/constants/routes"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; import CustomPropTypes from "@/customPropTypes"; import MajorProjectSearch from "./MajorProjectSearch"; import MajorProjectTable from "./MajorProjectTable"; diff --git a/services/core-web/src/components/dashboard/minesHomePage/Dashboard.js b/services/core-web/src/components/dashboard/minesHomePage/Dashboard.js index 85126575a3..93c802011e 100755 --- a/services/core-web/src/components/dashboard/minesHomePage/Dashboard.js +++ b/services/core-web/src/components/dashboard/minesHomePage/Dashboard.js @@ -30,7 +30,7 @@ import { } from "@mds/common/redux/selectors/staticContentSelectors"; import * as Strings from "@mds/common/constants/strings"; import { PageTracker } from "@common/utils/trackers"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; import CustomPropTypes from "@/customPropTypes"; import MineList from "@/components/dashboard/minesHomePage/MineList"; import MineSearch from "@/components/dashboard/minesHomePage/MineSearch"; diff --git a/services/core-web/src/components/dashboard/noticeOfWorkHomePage/NoticeOfWorkHomePage.tsx b/services/core-web/src/components/dashboard/noticeOfWorkHomePage/NoticeOfWorkHomePage.tsx index 27360cd006..44687479b3 100644 --- a/services/core-web/src/components/dashboard/noticeOfWorkHomePage/NoticeOfWorkHomePage.tsx +++ b/services/core-web/src/components/dashboard/noticeOfWorkHomePage/NoticeOfWorkHomePage.tsx @@ -18,7 +18,7 @@ import { import * as routes from "@/constants/routes"; import NoticeOfWorkTable from "@/components/dashboard/noticeOfWorkHomePage/NoticeOfWorkTable"; import NoticeOfWorkSearch from "@/components/dashboard/noticeOfWorkHomePage/NoticeOfWorkSearch"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; import { PageTracker } from "@common/utils/trackers"; import { INoticeOfWorkApplication, IPageData, IOption, INoticeOfWork } from "@mds/common"; import { RootState } from "@/App"; diff --git a/services/core-web/src/components/dashboard/reportsHomePage/ReportsTable.tsx b/services/core-web/src/components/dashboard/reportsHomePage/ReportsTable.tsx index 7080108743..088c1b246c 100644 --- a/services/core-web/src/components/dashboard/reportsHomePage/ReportsTable.tsx +++ b/services/core-web/src/components/dashboard/reportsHomePage/ReportsTable.tsx @@ -1,5 +1,5 @@ import React, { FC } from "react"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; import MineReportTable from "@/components/mine/Reports/MineReportTable"; import { IMineReport, IPageData, MineReportParams } from "@mds/common"; diff --git a/services/core-web/src/components/mine/Reports/MineReportInfo.tsx b/services/core-web/src/components/mine/Reports/MineReportInfo.tsx index 7101f46f5c..b1be6a1b34 100644 --- a/services/core-web/src/components/mine/Reports/MineReportInfo.tsx +++ b/services/core-web/src/components/mine/Reports/MineReportInfo.tsx @@ -28,7 +28,7 @@ import { Feature, IMine, MINE_REPORTS_ENUM, MineReportParams, MineReportType } f import PlusOutlined from "@ant-design/icons/PlusOutlined"; import { useFeatureFlag } from "@mds/common/providers/featureFlags/useFeatureFlag"; import { RequestReportForm } from "@/components/Forms/reports/RequestReportForm"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; const defaultParams: MineReportParams = { report_name: undefined, diff --git a/services/core-web/src/components/mine/Tailings/MineTailingsInfoTabs.tsx b/services/core-web/src/components/mine/Tailings/MineTailingsInfoTabs.tsx index a816ed9731..be6140bac2 100644 --- a/services/core-web/src/components/mine/Tailings/MineTailingsInfoTabs.tsx +++ b/services/core-web/src/components/mine/Tailings/MineTailingsInfoTabs.tsx @@ -37,7 +37,7 @@ import { useFeatureFlag } from "@mds/common/providers/featureFlags/useFeatureFla import { Feature } from "@mds/common"; import { getUserAccessData } from "@mds/common/redux/selectors/authenticationSelectors"; import { USER_ROLES } from "@mds/common"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; /** * @class MineTailingsInfoTabs - all tenure information related to the mine. diff --git a/services/core-web/src/tests/components/common/ResponsivePagination.spec.js b/services/core-web/src/tests/components/common/ResponsivePagination.spec.js index c2c20f08e2..04a3af786c 100644 --- a/services/core-web/src/tests/components/common/ResponsivePagination.spec.js +++ b/services/core-web/src/tests/components/common/ResponsivePagination.spec.js @@ -1,6 +1,6 @@ import React from "react"; import { shallow } from "enzyme"; -import ResponsivePagination from "@/components/common/ResponsivePagination"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; let props = {}; let dispatchProps = {}; diff --git a/services/minespace-web/src/components/dashboard/mine/reports/Reports.tsx b/services/minespace-web/src/components/dashboard/mine/reports/Reports.tsx index b927035158..b19c6242f5 100644 --- a/services/minespace-web/src/components/dashboard/mine/reports/Reports.tsx +++ b/services/minespace-web/src/components/dashboard/mine/reports/Reports.tsx @@ -9,7 +9,7 @@ import { updateMineReport, } from "@mds/common/redux/actionCreators/reportActionCreator"; import { closeModal, openModal } from "@mds/common/redux/actions/modalActions"; -import { getMineReports } from "@mds/common/redux/selectors/reportSelectors"; +import { getMineReports, getReportsPageData } from "@mds/common/redux/selectors/reportSelectors"; import ReportsTable from "@/components/dashboard/mine/reports/ReportsTable"; import { modalConfig } from "@/components/modalContent/config"; import AuthorizationWrapper from "@/components/common/wrappers/AuthorizationWrapper"; @@ -19,6 +19,7 @@ import * as routes from "@/constants/routes"; import { useFeatureFlag } from "@mds/common/providers/featureFlags/useFeatureFlag"; import { Link as ScrollLink, Element } from "react-scroll"; import { SidebarContext } from "@mds/common/components/common/SidebarWrapper"; +import ResponsivePagination from "@mds/common/components/common/ResponsivePagination"; export const Reports: FC = () => { const dispatch = useDispatch(); @@ -26,6 +27,7 @@ export const Reports: FC = () => { const { isFeatureEnabled } = useFeatureFlag(); const { mine } = useContext<{ mine: IMine }>(SidebarContext); + const pageData = useSelector(getReportsPageData); const mineReports: IMineReport[] = useSelector(getMineReports); @@ -139,6 +141,15 @@ export const Reports: FC = () => { ); }; + const onPageChange = (page, per_page) => { + dispatch( + fetchMineReports(mine.mine_guid, null, { + page, + per_page, + }) + ); + }; + return ( @@ -201,7 +212,16 @@ export const Reports: FC = () => { openEditReportModal={openEditReportModal} mineReports={codeRequiredReports} isLoaded={isLoaded} + backendPaginated /> + + + Permit Required Reports diff --git a/services/minespace-web/src/components/dashboard/mine/reports/ReportsTable.tsx b/services/minespace-web/src/components/dashboard/mine/reports/ReportsTable.tsx index dc836f26cb..94c77e4410 100644 --- a/services/minespace-web/src/components/dashboard/mine/reports/ReportsTable.tsx +++ b/services/minespace-web/src/components/dashboard/mine/reports/ReportsTable.tsx @@ -32,6 +32,7 @@ interface ReportsTableProps { openEditReportModal: (event: React.MouseEvent, record: IMineReport) => void; openReport: (record: IMineReport) => void; isLoaded: boolean; + backendPaginated: boolean; } const DEFAULT_PAGE_SIZE = 10; @@ -67,7 +68,7 @@ export const ReportsTable: FC = (props) => { ]; let columns: ColumnsType = [ - renderTextColumn("report_name", "Report Name", true), + renderTextColumn("report_name", "Report Name", !props.backendPaginated), { title: "Code Section", key: "code_section", @@ -81,7 +82,7 @@ export const ReportsTable: FC = (props) => { ), }, - renderTextColumn("submission_year", "Compliance Year", true, null, 5), + renderTextColumn("submission_year", "Compliance Year", !props.backendPaginated, null, 5), renderTextColumn("due_date", "Due", true, null, 5), renderTextColumn(["latest_submission", "received_date"], "Submitted On", true), renderTextColumn("created_by_idir", "Requested By", true), @@ -166,7 +167,7 @@ export const ReportsTable: FC = (props) => { rowKey={(record) => record.mine_report_guid} emptyText="This mine has no report data." dataSource={props.mineReports} - pagination={pagination} + pagination={props.backendPaginated ? false : pagination} /> ); }; diff --git a/services/minespace-web/src/tests/components/dashboard/mine/reports/Reports.spec.tsx b/services/minespace-web/src/tests/components/dashboard/mine/reports/Reports.spec.tsx index 60c5d6e655..c355ae70b1 100644 --- a/services/minespace-web/src/tests/components/dashboard/mine/reports/Reports.spec.tsx +++ b/services/minespace-web/src/tests/components/dashboard/mine/reports/Reports.spec.tsx @@ -7,9 +7,7 @@ import { SidebarProvider } from "@mds/common/components/common/SidebarWrapper"; import { REPORTS, STATIC_CONTENT } from "@mds/common/constants/reducerTypes"; const initialState = { - [REPORTS]: { - mineReports: MOCK.MINE_REPORTS, - }, + [REPORTS]: { mineReports: MOCK.MINE_REPORTS, reportsPageData: MOCK.PAGE_DATA }, [STATIC_CONTENT]: { mineReportDefinitionOptions: MOCK.BULK_STATIC_CONTENT_RESPONSE.mineReportDefinitionOptions, }, diff --git a/services/minespace-web/src/tests/components/dashboard/mine/reports/__snapshots__/Reports.spec.tsx.snap b/services/minespace-web/src/tests/components/dashboard/mine/reports/__snapshots__/Reports.spec.tsx.snap index adeed64a41..6d809feb3f 100644 --- a/services/minespace-web/src/tests/components/dashboard/mine/reports/__snapshots__/Reports.spec.tsx.snap +++ b/services/minespace-web/src/tests/components/dashboard/mine/reports/__snapshots__/Reports.spec.tsx.snap @@ -128,65 +128,9 @@ exports[`Reports renders properly 1`] = ` > -
- - Report Name - - - - - - - - - - - -
+ Report Name -
- - Compliance Year - - - - - - - - - - - -
+ Compliance Year +
+
+