From a464e91803e3677dd46d3bb4bd71b298c90bd27a Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Wed, 18 Dec 2024 15:26:32 -0800 Subject: [PATCH] fix: Disable navigating unless report is draft * Only execute navigate if report is in Draft status to prevent draft clicks from going to edit --- .../AllocationAgreementSummary.jsx | 17 ++++++++------- .../components/ReportDetails.jsx | 21 +++++++++++++------ .../FinalSupplyEquipmentSummary.jsx | 19 ++++++++++------- .../views/FuelExports/FuelExportSummary.jsx | 19 ++++++++++------- .../views/FuelSupplies/FuelSupplySummary.jsx | 19 ++++++++++------- .../NotionalTransferSummary.jsx | 20 ++++++++++-------- .../src/views/OtherUses/OtherUsesSummary.jsx | 19 ++++++++++------- 7 files changed, 80 insertions(+), 54 deletions(-) diff --git a/frontend/src/views/AllocationAgreements/AllocationAgreementSummary.jsx b/frontend/src/views/AllocationAgreements/AllocationAgreementSummary.jsx index 30b1a9f02..70a536d18 100644 --- a/frontend/src/views/AllocationAgreements/AllocationAgreementSummary.jsx +++ b/frontend/src/views/AllocationAgreements/AllocationAgreementSummary.jsx @@ -8,8 +8,9 @@ import { useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { useLocation, useParams, useNavigate } from 'react-router-dom' import { v4 as uuid } from 'uuid' +import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses.js' -export const AllocationAgreementSummary = ({ data }) => { +export const AllocationAgreementSummary = ({ data, status }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') const [gridKey, setGridKey] = useState(`allocation-agreements-grid`) @@ -137,12 +138,14 @@ export const AllocationAgreementSummary = ({ data }) => { } const handleRowClicked = (params) => { - navigate( - ROUTES.REPORTS_ADD_ALLOCATION_AGREEMENTS.replace( - ':compliancePeriod', - compliancePeriod - ).replace(':complianceReportId', complianceReportId) - ) + if (status === COMPLIANCE_REPORT_STATUSES.DRAFT) { + navigate( + ROUTES.REPORTS_ADD_ALLOCATION_AGREEMENTS.replace( + ':compliancePeriod', + compliancePeriod + ).replace(':complianceReportId', complianceReportId) + ) + } } return ( diff --git a/frontend/src/views/ComplianceReports/components/ReportDetails.jsx b/frontend/src/views/ComplianceReports/components/ReportDetails.jsx index bf7d562ec..351110c15 100644 --- a/frontend/src/views/ComplianceReports/components/ReportDetails.jsx +++ b/frontend/src/views/ComplianceReports/components/ReportDetails.jsx @@ -81,7 +81,9 @@ const ReportDetails = ({ currentStatus = 'Draft' }) => { ), useFetch: useGetFuelSupplies, component: (data) => - data.fuelSupplies.length > 0 && + data.fuelSupplies.length > 0 && ( + + ) }, { name: t('finalSupplyEquipment:fseTitle'), @@ -95,7 +97,7 @@ const ReportDetails = ({ currentStatus = 'Draft' }) => { useFetch: useGetFinalSupplyEquipments, component: (data) => data.finalSupplyEquipments.length > 0 && ( - + ) }, { @@ -110,7 +112,7 @@ const ReportDetails = ({ currentStatus = 'Draft' }) => { useFetch: useGetAllocationAgreements, component: (data) => data.allocationAgreements.length > 0 && ( - + ) }, { @@ -124,7 +126,9 @@ const ReportDetails = ({ currentStatus = 'Draft' }) => { ), useFetch: useGetAllNotionalTransfers, component: (data) => - data.length > 0 && + data.length > 0 && ( + + ) }, { name: t('otherUses:summaryTitle'), @@ -136,7 +140,10 @@ const ReportDetails = ({ currentStatus = 'Draft' }) => { ).replace(':complianceReportId', complianceReportId) ), useFetch: useGetAllOtherUses, - component: (data) => data.length > 0 && + component: (data) => + data.length > 0 && ( + + ) }, { name: t('fuelExport:fuelExportTitle'), @@ -149,7 +156,9 @@ const ReportDetails = ({ currentStatus = 'Draft' }) => { ), useFetch: useGetFuelExports, component: (data) => - !isArrayEmpty(data) && + !isArrayEmpty(data) && ( + + ) } ], [ diff --git a/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx b/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx index 1869f3c63..a8c7935a1 100644 --- a/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx +++ b/frontend/src/views/FinalSupplyEquipments/FinalSupplyEquipmentSummary.jsx @@ -9,8 +9,9 @@ import { useTranslation } from 'react-i18next' import { useLocation, useParams, useNavigate } from 'react-router-dom' import { v4 as uuid } from 'uuid' import { numberFormatter } from '@/utils/formatters.js' +import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses.js' -export const FinalSupplyEquipmentSummary = ({ data }) => { +export const FinalSupplyEquipmentSummary = ({ data, status }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') const [gridKey, setGridKey] = useState('final-supply-equipments-grid') @@ -187,13 +188,15 @@ export const FinalSupplyEquipmentSummary = ({ data }) => { setGridKey(`final-supply-equipments-grid-${uuid()}`) } - const handleRowClicked = (params) => { - navigate( - ROUTES.REPORTS_ADD_FINAL_SUPPLY_EQUIPMENTS.replace( - ':compliancePeriod', - compliancePeriod - ).replace(':complianceReportId', complianceReportId) - ) + const handleRowClicked = () => { + if (status === COMPLIANCE_REPORT_STATUSES.DRAFT) { + navigate( + ROUTES.REPORTS_ADD_FINAL_SUPPLY_EQUIPMENTS.replace( + ':compliancePeriod', + compliancePeriod + ).replace(':complianceReportId', complianceReportId) + ) + } } return ( diff --git a/frontend/src/views/FuelExports/FuelExportSummary.jsx b/frontend/src/views/FuelExports/FuelExportSummary.jsx index 4cab9c377..76898317f 100644 --- a/frontend/src/views/FuelExports/FuelExportSummary.jsx +++ b/frontend/src/views/FuelExports/FuelExportSummary.jsx @@ -9,8 +9,9 @@ import { useTranslation } from 'react-i18next' import { useLocation, useParams, useNavigate } from 'react-router-dom' import i18n from '@/i18n' import { ROUTES } from '@/constants/routes' +import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses.js' -export const FuelExportSummary = ({ data }) => { +export const FuelExportSummary = ({ data, status }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') const { complianceReportId, compliancePeriod } = useParams() @@ -124,13 +125,15 @@ export const FuelExportSummary = ({ data }) => { return params.data.fuelExportId.toString() } - const handleRowClicked = (params) => { - navigate( - ROUTES.REPORTS_ADD_FUEL_EXPORTS.replace( - ':compliancePeriod', - compliancePeriod - ).replace(':complianceReportId', complianceReportId) - ) + const handleRowClicked = () => { + if (status === COMPLIANCE_REPORT_STATUSES.DRAFT) { + navigate( + ROUTES.REPORTS_ADD_FUEL_EXPORTS.replace( + ':compliancePeriod', + compliancePeriod + ).replace(':complianceReportId', complianceReportId) + ) + } } return ( diff --git a/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx b/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx index 2e913d8dd..6944b0383 100644 --- a/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx +++ b/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx @@ -10,8 +10,9 @@ import { useLocation, useNavigate, useParams } from 'react-router-dom' import { v4 as uuid } from 'uuid' import i18n from '@/i18n' import { StandardCellWarningAndErrors } from '@/utils/grid/errorRenderers' +import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses.js' -export const FuelSupplySummary = ({ data }) => { +export const FuelSupplySummary = ({ data, status }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') const [gridKey, setGridKey] = useState(`fuel-supplies-grid`) @@ -126,13 +127,15 @@ export const FuelSupplySummary = ({ data }) => { setGridKey(`fuel-supplies-grid-${uuid()}`) } - const handleRowClicked = (params) => { - navigate( - ROUTES.REPORTS_ADD_SUPPLY_OF_FUEL.replace( - ':compliancePeriod', - compliancePeriod - ).replace(':complianceReportId', complianceReportId) - ) + const handleRowClicked = () => { + if (status === COMPLIANCE_REPORT_STATUSES.DRAFT) { + navigate( + ROUTES.REPORTS_ADD_SUPPLY_OF_FUEL.replace( + ':compliancePeriod', + compliancePeriod + ).replace(':complianceReportId', complianceReportId) + ) + } } return ( diff --git a/frontend/src/views/NotionalTransfers/NotionalTransferSummary.jsx b/frontend/src/views/NotionalTransfers/NotionalTransferSummary.jsx index e93d2502f..daa71fae1 100644 --- a/frontend/src/views/NotionalTransfers/NotionalTransferSummary.jsx +++ b/frontend/src/views/NotionalTransfers/NotionalTransferSummary.jsx @@ -8,8 +8,9 @@ import { useTranslation } from 'react-i18next' import { useLocation, useParams, useNavigate } from 'react-router-dom' import { formatNumberWithCommas as valueFormatter } from '@/utils/formatters' import { ROUTES } from '@/constants/routes' +import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses.js' -export const NotionalTransferSummary = ({ data }) => { +export const NotionalTransferSummary = ({ data, status }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') const { complianceReportId, compliancePeriod } = useParams() @@ -34,14 +35,15 @@ export const NotionalTransferSummary = ({ data }) => { [] ) - const handleRowClicked = (params) => { - console.log('Row clicked', params) - navigate( - ROUTES.REPORTS_ADD_NOTIONAL_TRANSFERS.replace( - ':compliancePeriod', - compliancePeriod - ).replace(':complianceReportId', complianceReportId) - ) + const handleRowClicked = () => { + if (status === COMPLIANCE_REPORT_STATUSES.DRAFT) { + navigate( + ROUTES.REPORTS_ADD_NOTIONAL_TRANSFERS.replace( + ':compliancePeriod', + compliancePeriod + ).replace(':complianceReportId', complianceReportId) + ) + } } const columns = [ diff --git a/frontend/src/views/OtherUses/OtherUsesSummary.jsx b/frontend/src/views/OtherUses/OtherUsesSummary.jsx index 797ff8476..4c6a203ed 100644 --- a/frontend/src/views/OtherUses/OtherUsesSummary.jsx +++ b/frontend/src/views/OtherUses/OtherUsesSummary.jsx @@ -11,8 +11,9 @@ import { } from '@/utils/formatters' import { useTranslation } from 'react-i18next' import { ROUTES } from '@/constants/routes' +import { COMPLIANCE_REPORT_STATUSES } from '@/constants/statuses.js' -export const OtherUsesSummary = ({ data }) => { +export const OtherUsesSummary = ({ data, status }) => { const [alertMessage, setAlertMessage] = useState('') const [alertSeverity, setAlertSeverity] = useState('info') const { t } = useTranslation(['common', 'otherUses']) @@ -86,13 +87,15 @@ export const OtherUsesSummary = ({ data }) => { const getRowId = (params) => params.data.otherUsesId - const handleRowClicked = (params) => { - navigate( - ROUTES.REPORTS_ADD_OTHER_USE_FUELS.replace( - ':compliancePeriod', - compliancePeriod - ).replace(':complianceReportId', complianceReportId) - ) + const handleRowClicked = () => { + if (status === COMPLIANCE_REPORT_STATUSES.DRAFT) { + navigate( + ROUTES.REPORTS_ADD_OTHER_USE_FUELS.replace( + ':compliancePeriod', + compliancePeriod + ).replace(':complianceReportId', complianceReportId) + ) + } } return (