Merge pull request #2116 from Safelite/feature/routerLogs

conditional logging in router
This commit is contained in:
CarlNation 2024-11-15 09:37:53 -05:00 committed by GitHub
commit 579beb937a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,15 +50,23 @@ const routes = [
async beforeEnter(to, from, next) {
// If we have no query string, or we don't have the FmgPage query string.
try {
log("------------- router index.js beforeEnter start -----------------");
log(" --to: ", JSON.stringify(to));
log(" --from: ", JSON.stringify(from));
log(" --next: ", JSON.stringify(next));
log(" --cookie: ", JSON.stringify(getFunnelCookie()));
await analyticsMixin.methods.validateSession();
if (getFunnelCookie()?.SuppressConceptFunnel) {
log(" --go to heritage suppressConceptFunnel: ");
await navigateToHeritageFunnel({ shouldSaveSession: false });
return next(false);
}
// If the saved session has timed out, clear the session, execute 404 logic.
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
log(" --save session timeout go to start");
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
deleteFunnelCookie();
GoToFunnelStartOn404(next);
@ -68,6 +76,7 @@ const routes = [
if (window.sessionStorage.getItem("submittedOrder") !== null) {
if (to.query.fmgPage !== funnelStartPageName) {
to.query.fmgPage = fmgPageValues.CONFIRMATION;
log(" --has submittedOrder go to confirmation");
}
}
// On entering the funnel "fresh", read cookie information, decide what to do next.
@ -130,12 +139,15 @@ const routes = [
// This logic may determine that the user should be sent to heritage -- if so, do that here.
if (pageToRedirectTo === fmgPageValues.HERITAGE) {
// prettier-ignore
log(" --go to heritage pageToRedirectTo ", JSON.stringify(pageToRedirectTo));
await navigateToHeritageFunnel({ shouldSaveSession: false });
return next(false);
}
// Assign our fmgPage so it will load normally like the other pages.
to.query.fmgPage = pageToRedirectTo;
log(" --assign to: ", JSON.stringify(pageToRedirectTo));
}
}
@ -149,6 +161,7 @@ const routes = [
to.query.fmgPage === fmgPageValues.QUOTE ||
to.query.fmgPage === fmgPageValues.INSURANCE_COMPANY
) {
log(" --block quote page for integrated clients - go to heritage");
// Push to heritage if going to quote & integrated.
await navigateToHeritageFunnel({ shouldSaveSession: false });
return next(false);
@ -183,6 +196,7 @@ const routes = [
GoToFunnelStartOn404(next);
}
log(" --has route:", to.query.fmgPage);
return next({ name: to.query.fmgPage, query: to.query, params: to.params });
}
@ -210,12 +224,13 @@ const routes = [
.components.default();
if (!arePagePrerequisitesValid(nextComponent)) {
console.log(
"Page Prereqs not valid for next component: " + nextComponent.default.name
);
// prettier-ignore
console.log("Page Prereqs not valid for next component: " + nextComponent.default.name);
GoToFunnelStartOn404(next);
}
log("------------- router index.js beforeEnter end -----------------");
// Assign current query string parameters, as well as our fmgPage one.
next({
name: routeData[0].name,
@ -230,6 +245,8 @@ const routes = [
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
}
console.log(new Date() + " Exception in beforeEnter:" + JSON.stringify(error));
// If we don't have a route, go to our 404 page.
GoToFunnelStartOn404(next);
}
@ -441,7 +458,16 @@ async function navigate(
const zip = getQuerystringParameter(queryStrings.ZIP_CODE);
const promo = getQuerystringParameter(queryStrings.PROMO);
const pageError = getQuerystringParameter(queryStrings.PAGE_ERROR);
const log = getQuerystringParameter(queryStrings.LOG);
const logQs = getQuerystringParameter(queryStrings.LOG);
log("------------- router index.js navigate start -----------------");
log(" --scenario: ", scenario);
log(" --currentRoute: ", JSON.stringify(currentRoute));
log(" --isSavingNavigation: ", isSavingNavigation);
log(" --optionalQuery: ", JSON.stringify(optionalQuery));
log(" --optionalParams: ", JSON.stringify(optionalParams));
log(" --optionalPageData: ", JSON.stringify(optionalPageData));
log(" --nextPageName: ", nextPageName);
if (
hasZip &&
@ -461,10 +487,13 @@ async function navigate(
queryStringsObject[queryStrings.PAGE_ERROR] = pageError;
}
if (log) {
queryStringsObject[queryStrings.LOG] = log;
if (logQs) {
queryStringsObject[queryStrings.LOG] = logQs;
}
log(" querystrings: ", JSON.stringify(queryStringsObject));
log("------------- router index.js navigate end -----------------");
router.push({
name: "root",
query: Object.assign(optionalQuery, queryStringsObject),
@ -490,6 +519,15 @@ function getNavigationMap(scenario, currentRoute) {
return matchedQueryValue[0];
}
function log(message, data) {
const log = getQuerystringParameter(queryStrings.LOG);
data = data ?? "";
if (eval(log)) {
console.log(new Date() + message + data);
}
}
//---------------------------------------------------------- Private Functions ----------------------------------------------------------
// Navigate to an external url.