From b26957cac5bda2ce3b469195a943cb3ddf5fb09a Mon Sep 17 00:00:00 2001 From: Roger Leung <60829068+rogerlcleung@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:28:04 -0800 Subject: [PATCH] Add URI encoding and code clean-up --- frontend/src/app/routes/Compliance.js | 3 ++- .../src/compliance/AssessmentContainer.js | 3 +-- .../ComplianceObligationContainer.js | 3 +-- .../ComplianceReportSummaryContainer.js | 24 +++++++++---------- .../src/compliance/ConsumerSalesContainer.js | 3 +-- .../SupplierInformationContainer.js | 3 +-- .../ComplianceObligationDetailsPage.js | 3 +-- .../components/ComplianceReportTabs.js | 10 ++++---- .../components/ComplianceReportsTable.js | 3 +-- .../components/ConsumerSalesDetailsPage.js | 3 +-- .../SupplierInformationDetailsPage.js | 3 +-- 11 files changed, 25 insertions(+), 36 deletions(-) diff --git a/frontend/src/app/routes/Compliance.js b/frontend/src/app/routes/Compliance.js index 92285842f..531d11f69 100644 --- a/frontend/src/app/routes/Compliance.js +++ b/frontend/src/app/routes/Compliance.js @@ -38,5 +38,6 @@ const COMPLIANCE = { export default COMPLIANCE export const insertIdAndYear = (route, id, modelYear) => { - return `${route.replace(":id", id)}?year=${modelYear}`; + const encode = (str) => encodeURIComponent(str); + return `${route.replace(":id", encode(id))}?year=${encode(modelYear)}`; } \ No newline at end of file diff --git a/frontend/src/compliance/AssessmentContainer.js b/frontend/src/compliance/AssessmentContainer.js index 302388b73..763497dbe 100644 --- a/frontend/src/compliance/AssessmentContainer.js +++ b/frontend/src/compliance/AssessmentContainer.js @@ -6,8 +6,7 @@ import Big from "big.js"; import Loading from "../app/components/Loading"; import CONFIG from "../app/config"; import history from "../app/History"; -import ROUTES_COMPLIANCE from "../app/routes/Compliance"; -import { insertIdAndYear } from "../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../app/routes/Compliance"; import CustomPropTypes from "../app/utilities/props"; import AssessmentDetailsPage from "./components/AssessmentDetailsPage"; import calculateCreditReductionBig from "../app/utilities/calculateCreditReductionBig"; diff --git a/frontend/src/compliance/ComplianceObligationContainer.js b/frontend/src/compliance/ComplianceObligationContainer.js index 24138b7ff..3a1dcc707 100644 --- a/frontend/src/compliance/ComplianceObligationContainer.js +++ b/frontend/src/compliance/ComplianceObligationContainer.js @@ -6,8 +6,7 @@ import ComplianceReportTabs from "./components/ComplianceReportTabs"; import ComplianceObligationDetailsPage from "./components/ComplianceObligationDetailsPage"; import history from "../app/History"; import ROUTES_SIGNING_AUTHORITY_ASSERTIONS from "../app/routes/SigningAuthorityAssertions"; -import ROUTES_COMPLIANCE from "../app/routes/Compliance"; -import { insertIdAndYear } from "../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../app/routes/Compliance"; import CONFIG from "../app/config"; import calculateCreditReduction from "../app/utilities/calculateCreditReduction"; import getClassAReduction from "../app/utilities/getClassAReduction"; diff --git a/frontend/src/compliance/ComplianceReportSummaryContainer.js b/frontend/src/compliance/ComplianceReportSummaryContainer.js index f2d17ce32..1e4951f8f 100644 --- a/frontend/src/compliance/ComplianceReportSummaryContainer.js +++ b/frontend/src/compliance/ComplianceReportSummaryContainer.js @@ -1,16 +1,14 @@ -import axios from 'axios' -import React, { useEffect, useState } from 'react' -import { useParams, useLocation } from 'react-router-dom' -import CONFIG from '../app/config' -import history from '../app/History' -import Loading from '../app/components/Loading' -import ROUTES_COMPLIANCE from '../app/routes/Compliance' -import { insertIdAndYear } from '../app/routes/Compliance' -import CustomPropTypes from '../app/utilities/props' -import ComplianceReportTabs from './components/ComplianceReportTabs' -import ComplianceReportSummaryDetailsPage from './components/ComplianceReportSummaryDetailsPage' -import ROUTES_SIGNING_AUTHORITY_ASSERTIONS from '../app/routes/SigningAuthorityAssertions' -import deleteModelYearReport from '../app/utilities/deleteModelYearReport' +import axios from "axios"; +import React, { useEffect, useState } from "react"; +import { useParams, useLocation } from "react-router-dom"; +import CONFIG from "../app/config"; +import history from "../app/History"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../app/routes/Compliance"; +import CustomPropTypes from "../app/utilities/props"; +import ComplianceReportTabs from "./components/ComplianceReportTabs"; +import ComplianceReportSummaryDetailsPage from "./components/ComplianceReportSummaryDetailsPage"; +import ROUTES_SIGNING_AUTHORITY_ASSERTIONS from "../app/routes/SigningAuthorityAssertions"; +import deleteModelYearReport from "../app/utilities/deleteModelYearReport"; import qs from "qs"; const ComplianceReportSummaryContainer = (props) => { diff --git a/frontend/src/compliance/ConsumerSalesContainer.js b/frontend/src/compliance/ConsumerSalesContainer.js index f20146217..ed9d3ce5e 100644 --- a/frontend/src/compliance/ConsumerSalesContainer.js +++ b/frontend/src/compliance/ConsumerSalesContainer.js @@ -6,8 +6,7 @@ import history from "../app/History"; import CustomPropTypes from "../app/utilities/props"; import ComplianceReportTabs from "./components/ComplianceReportTabs"; import ConsumerSalesDetailsPage from "./components/ConsumerSalesDetailsPage"; -import ROUTES_COMPLIANCE from "../app/routes/Compliance"; -import { insertIdAndYear } from "../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../app/routes/Compliance"; import ROUTES_SIGNING_AUTHORITY_ASSERTIONS from "../app/routes/SigningAuthorityAssertions"; import deleteModelYearReport from "../app/utilities/deleteModelYearReport"; import FORECAST_ROUTES from "../salesforecast/constants/routes"; diff --git a/frontend/src/compliance/SupplierInformationContainer.js b/frontend/src/compliance/SupplierInformationContainer.js index 9a3f225ca..12b466617 100644 --- a/frontend/src/compliance/SupplierInformationContainer.js +++ b/frontend/src/compliance/SupplierInformationContainer.js @@ -5,8 +5,7 @@ import { useParams } from "react-router-dom"; import { withRouter } from "react-router"; import CONFIG from "../app/config"; import history from "../app/History"; -import ROUTES_COMPLIANCE from "../app/routes/Compliance"; -import { insertIdAndYear } from "../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../app/routes/Compliance"; import ROUTES_VEHICLES from "../app/routes/Vehicles"; import CustomPropTypes from "../app/utilities/props"; import ComplianceReportTabs from "./components/ComplianceReportTabs"; diff --git a/frontend/src/compliance/components/ComplianceObligationDetailsPage.js b/frontend/src/compliance/components/ComplianceObligationDetailsPage.js index cb6ff1ea8..4ea6faca3 100644 --- a/frontend/src/compliance/components/ComplianceObligationDetailsPage.js +++ b/frontend/src/compliance/components/ComplianceObligationDetailsPage.js @@ -13,8 +13,7 @@ import ComplianceReportDeleteModal from "./ComplianceReportDeleteModal"; import Modal from "../../app/components/Modal"; import history from "../../app/History"; -import ROUTES_COMPLIANCE from "../../app/routes/Compliance"; -import { insertIdAndYear } from "../../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../../app/routes/Compliance"; const ComplianceObligationDetailsPage = (props) => { const { diff --git a/frontend/src/compliance/components/ComplianceReportTabs.js b/frontend/src/compliance/components/ComplianceReportTabs.js index 7c6f287db..630b32c86 100644 --- a/frontend/src/compliance/components/ComplianceReportTabs.js +++ b/frontend/src/compliance/components/ComplianceReportTabs.js @@ -1,9 +1,7 @@ -import PropTypes from 'prop-types' -import React from 'react' -import { Link, useParams } from 'react-router-dom' - -import ROUTES_COMPLIANCE from '../../app/routes/Compliance' -import { insertIdAndYear } from "../../app/routes/Compliance"; +import PropTypes from "prop-types"; +import React from "react"; +import { Link, useParams } from "react-router-dom"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../../app/routes/Compliance"; const ComplianceReportTabs = (props) => { const { active, reportStatuses, user, modelYear } = props diff --git a/frontend/src/compliance/components/ComplianceReportsTable.js b/frontend/src/compliance/components/ComplianceReportsTable.js index ed39cf9c9..80061e9a3 100644 --- a/frontend/src/compliance/components/ComplianceReportsTable.js +++ b/frontend/src/compliance/components/ComplianceReportsTable.js @@ -4,8 +4,7 @@ import React from "react"; import ReactTable from "../../app/components/ReactTable"; import CustomPropTypes from "../../app/utilities/props"; import history from "../../app/History"; -import ROUTES_COMPLIANCE from "../../app/routes/Compliance"; -import { insertIdAndYear } from "../../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../../app/routes/Compliance"; import ROUTES_SUPPLEMENTARY from "../../app/routes/SupplementaryReport"; import formatNumeric from "../../app/utilities/formatNumeric"; import getClassAReduction from "../../app/utilities/getClassAReduction"; diff --git a/frontend/src/compliance/components/ConsumerSalesDetailsPage.js b/frontend/src/compliance/components/ConsumerSalesDetailsPage.js index 45a3617ac..c834a1b7f 100644 --- a/frontend/src/compliance/components/ConsumerSalesDetailsPage.js +++ b/frontend/src/compliance/components/ConsumerSalesDetailsPage.js @@ -8,8 +8,7 @@ import Modal from "../../app/components/Modal"; import history from "../../app/History"; import ComplianceReportSignOff from "./ComplianceReportSignOff"; import ConsumerSalesLDVModalTable from "./ConsumerSalesLDVModelTable"; -import ROUTES_COMPLIANCE from "../../app/routes/Compliance"; -import { insertIdAndYear } from "../../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../../app/routes/Compliance"; import ComplianceReportDeleteModal from "./ComplianceReportDeleteModal"; import RecordsUpload from "../../salesforecast/components/RecordsUpload"; import RecordsTable from "../../salesforecast/components/RecordsTable"; diff --git a/frontend/src/compliance/components/SupplierInformationDetailsPage.js b/frontend/src/compliance/components/SupplierInformationDetailsPage.js index e6126ad23..eb56a4cd3 100644 --- a/frontend/src/compliance/components/SupplierInformationDetailsPage.js +++ b/frontend/src/compliance/components/SupplierInformationDetailsPage.js @@ -7,8 +7,7 @@ import Loading from "../../app/components/Loading"; import Modal from "../../app/components/Modal"; import history from "../../app/History"; import CustomPropTypes from "../../app/utilities/props"; -import ROUTES_COMPLIANCE from "../../app/routes/Compliance"; -import { insertIdAndYear } from "../../app/routes/Compliance"; +import ROUTES_COMPLIANCE, { insertIdAndYear } from "../../app/routes/Compliance"; import FormatNumeric from "../../app/utilities/formatNumeric"; import ComplianceReportAlert from "./ComplianceReportAlert"; import ComplianceReportSignOff from "./ComplianceReportSignOff";