From 0998285fd857251feecc43a6e17ca4b95aff049a Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Mon, 18 Dec 2023 15:25:38 -0500 Subject: [PATCH 1/3] Remove calls to RouteInfo and GetHomePage in router. --- src/router/index.js | 52 +++++++++++-------- src/router/router-constants/fmgPage-values.js | 4 +- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 06879ae34..512c44b13 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -9,6 +9,7 @@ import { queryStrings } from "@/constants/query-strings"; import { getQuerystringParameter } from "@/helpers/querystring-helper"; import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper"; import { showFmgLoadingModal } from "@/helpers/loading-modal-helper"; +import { fmgPageValues, homepageName } from "@/router/router-constants/fmgPage-values"; // Heritage integration import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper"; @@ -48,7 +49,7 @@ const routes = [ // If the saved session has timed out, clear the session, execute 404 logic. if (getFunnelCookie() !== null && !isSavedSessionStillActive()) { await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE); - await GoToFunnelStartOn404(next); + GoToFunnelStartOn404(next); } // Intercept all navigation if a submitted order exists in storage @@ -100,14 +101,18 @@ const routes = [ } if (!arePagePrerequisitesValid(component)) { - await GoToFunnelStartOn404(next); + GoToFunnelStartOn404(next); } return next({ name: to.query.fmgPage, query: to.query, params: to.params }); } + if (!isExistingFmgPageName(to.query.fmgPage)) { + GoToFunnelStartOn404(next); + } + // Get route info for the given url. Names will have a 1:1 relationship with names in the Cms. - const routeData = await GetRouteInfoFromPageName(to.query.fmgPage); + const routeData = GetRouteInfoFromPageName(to.query.fmgPage); // Add our dynamic route. router.addRoute({ @@ -124,7 +129,7 @@ const routes = [ .components.default(); if (!arePagePrerequisitesValid(nextComponent)) { - await GoToFunnelStartOn404(next); + GoToFunnelStartOn404(next); } // Assign current query string parameters, as well as our fmgPage one. @@ -137,7 +142,7 @@ const routes = [ console.log(error); // If we don't have a route, go to our 404 page. - await GoToFunnelStartOn404(next); + GoToFunnelStartOn404(next); } }, }, @@ -355,31 +360,26 @@ function navigateToUrl(url, optionalQuery = {}) { } // Get route information by page name. -// This will reach out to the Cms and there is a 1:1 relationship between page names and route names. -async function GetRouteInfoFromPageName(pageName) { - const response = await store.dispatch(storeActions.GET_ROUTE_INFO_ACTION, { - pageName: pageName, - }); - const jsonFromResponse = JSON.parse(response.data.Result); - let routeData = []; +// This will no longer reach out to the Cms. There is a 1:1 relationship between page names and route names and layouts. +function GetRouteInfoFromPageName(pageName) { + // check if pagename is a valid route/component + if (!isExistingFmgPageName(pageName)) { + return []; + } - // Add our route data and return our array. - Object.keys(jsonFromResponse).forEach((key) => { - routeData.push({ + const routeData = [ + { path: "/", - name: `${key}`, - component: lazyLoadComponent(jsonFromResponse[key].LayoutName), - }); - }); + name: pageName, + component: lazyLoadComponent(pageName), + }, + ]; return routeData; } // Go to our start page on a 404. -async function GoToFunnelStartOn404(next) { - const apiResponse = await store.dispatch(storeActions.GET_HOMEPAGE_NAME); - const homepageName = apiResponse.data.Result; - +function GoToFunnelStartOn404(next) { // Put item on the bus eventBus.addEventToBus( globalEvents.Categories.GLOBAL_ALERT, @@ -398,6 +398,12 @@ async function GoToFunnelStartOn404(next) { }); } +function isExistingFmgPageName(pageName) { + const names = Object.values(fmgPageValues); + + return names.some((name) => name === pageName); +} + // Checks arePagePrerequisitesValid on the component passed in. function arePagePrerequisitesValid(component) { return component.default.methods.arePagePrerequisitesValid(); diff --git a/src/router/router-constants/fmgPage-values.js b/src/router/router-constants/fmgPage-values.js index 8a0a47fc0..7b840ce18 100644 --- a/src/router/router-constants/fmgPage-values.js +++ b/src/router/router-constants/fmgPage-values.js @@ -22,4 +22,6 @@ const fmgPageValues = { CONFIRMATION: "confirmation", }; -export { fmgPageValues }; +const homepageName = fmgPageValues.VEHICLE; + +export { fmgPageValues, homepageName }; From 1b5db2c4cfea8d89958dffa26723865809b5c910 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Mon, 18 Dec 2023 15:46:46 -0500 Subject: [PATCH 2/3] Cleanup now unused code --- src/constants/endpoints.js | 10 ---------- src/constants/store-actions.js | 2 -- src/store/index.js | 20 -------------------- src/store/store.spec.js | 28 ---------------------------- 4 files changed, 60 deletions(-) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 320952b4d..ea40af19d 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -1,14 +1,4 @@ const endpoints = { - GetRouteInfo: { - url: (applicationAbbreviation) => - `/content/api/v1/content/${applicationAbbreviation}/RouteInfo`, - method: "POST", - }, - GetHomepageInfo: { - url: (applicationAbbreviation) => - `/content/api/v1/content/${applicationAbbreviation}/HomepageInfo`, - method: "GET", - }, GetPageData: { url: (applicationAbbreviation, pageName) => `/content/api/v1/content/${applicationAbbreviation}/${pageName}`, diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index daa65d2cf..9b6fdb865 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -1,7 +1,5 @@ const storeActions = { // Content Actions - GET_ROUTE_INFO_ACTION: "getRouteInfo", - GET_HOMEPAGE_NAME: "getHomepageName", GET_PAGE_DATA: "getPageData", // Vehicle Actions diff --git a/src/store/index.js b/src/store/index.js index 673c4dfa1..910ffba66 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -956,26 +956,6 @@ export const actions = { context.commit(storeMutations.RESET_SAVE_SESSION_PROMISE); }, - // Content API Actions - getRouteInfo(context, { pageName }) { - return globalMethods.callHttpClient({ - method: endpoints.GetRouteInfo.method, - endpoint: endpoints.GetRouteInfo.url(applicationConfig.APPLICATION_ABBREVIATION), - payload: { - pageName: pageName, - }, - logApiCall: true, - pageNameToLog: pageName, - }); - }, - - getHomepageName(context) { - return globalMethods.callHttpClient({ - method: endpoints.GetHomepageInfo.method, - endpoint: endpoints.GetHomepageInfo.url(applicationConfig.APPLICATION_ABBREVIATION), - }); - }, - getPageData(context, { pageName }) { return globalMethods.callHttpClient({ method: endpoints.GetPageData.method, diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 8353ec0d8..2d5d4578c 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -659,34 +659,6 @@ describe("Actions", () => { expect(commit).toBeCalledWith(storeMutations.RESET_STATE); }); - it("getRouteInfo action, returns route info", async () => { - // Arrange - const context = state; - - globalMethods.callHttpClient.mockImplementation(() => { - return Promise.resolve({ data: { Widget: "Data" } }); - }); - - // Act - const response = await actions.getRouteInfo(context, "vehicle-year"); - - expect(response.data).toEqual({ Widget: "Data" }); - }); - - it("getHomepageName action, returns homepage name", async () => { - // Arrange - const context = state; - - globalMethods.callHttpClient.mockImplementation(() => { - return Promise.resolve({ data: { Name: "vehicle-year" } }); - }); - - // Act - const response = await actions.getHomepageName(context); - - expect(response.data).toEqual({ Name: "vehicle-year" }); - }); - it("getPageData action, returns page data", async () => { // Arrange const context = state; From 345265ca17b63bc45244a4ebacc58f4cd6e625a4 Mon Sep 17 00:00:00 2001 From: Chloe Herd Date: Mon, 18 Dec 2023 16:30:56 -0500 Subject: [PATCH 3/3] Change some magic values to constants --- src/router/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 512c44b13..377652a95 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -54,8 +54,8 @@ const routes = [ // Intercept all navigation if a submitted order exists in storage if (store.getters.hasSubmittedOrder) { - if (to.query.fmgPage !== "vehicle") { - to.query.fmgPage = "confirmation"; + if (to.query.fmgPage !== homepageName) { + to.query.fmgPage = fmgPageValues.CONFIRMATION; } } // On entering the funnel "fresh", read cookie information, decide what to do next. @@ -180,7 +180,7 @@ router.beforeEach(async (to, from, next) => { // Refresh page if navigating to self to prevent locking. // For now only carved out for vehicle; all modals are opened through anchor tags at the moment, // which also self navigate, but relied on the page remaining the same on self-navigation. - } else if (toQueryPage === fromQueryPage && toQueryPage === "vehicle") { + } else if (toQueryPage === fromQueryPage && toQueryPage === homepageName) { router.go(0); } else { next();