From 22dab6644861e52865ab288c0149d91b912823b3 Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Wed, 4 Dec 2024 01:18:24 -0800 Subject: [PATCH] MWPW-155723 - Adds group metadata to ensure dyanmic nav continuity (#3124) * Adding dynamic-nav-group setting to allow distinction between dynamic-nav user journeys * Utils change * Ensuring status shows correctly dispite group * Making metadata case insensative --- .../dynamic-navigation/dynamic-navigation.js | 14 ++++ libs/features/dynamic-navigation/status.js | 8 ++- test/features/dynamic-nav/dynamicNav.test.js | 30 ++++++++ test/features/dynamic-nav/status.test.js | 70 ++++++++++++++++++- 4 files changed, 120 insertions(+), 2 deletions(-) diff --git a/libs/features/dynamic-navigation/dynamic-navigation.js b/libs/features/dynamic-navigation/dynamic-navigation.js index 7354518a58..7d943cc597 100644 --- a/libs/features/dynamic-navigation/dynamic-navigation.js +++ b/libs/features/dynamic-navigation/dynamic-navigation.js @@ -14,16 +14,30 @@ export function foundDisableValues() { return foundValues.length ? foundValues : false; } +function dynamicNavGroupMatches(groupMetaData) { + const storedGroup = window.sessionStorage.getItem('dynamicNavGroup'); + if (groupMetaData && storedGroup) { + return storedGroup.toLowerCase() === groupMetaData.toLowerCase(); + } + return false; +} + export default function dynamicNav(url, key) { if (foundDisableValues()) return url; const metadataContent = getMetadata('dynamic-nav'); + const dynamicNavGroup = getMetadata('dynamic-nav-group'); if (metadataContent === 'entry') { window.sessionStorage.setItem('gnavSource', url); window.sessionStorage.setItem('dynamicNavKey', key); + if (dynamicNavGroup) window.sessionStorage.setItem('dynamicNavGroup', dynamicNavGroup); return url; } + if (metadataContent === 'on' && dynamicNavGroup) { + if (!dynamicNavGroupMatches(dynamicNavGroup)) return url; + } + if (metadataContent !== 'on' || key !== window.sessionStorage.getItem('dynamicNavKey')) return url; return window.sessionStorage.getItem('gnavSource') || url; diff --git a/libs/features/dynamic-navigation/status.js b/libs/features/dynamic-navigation/status.js index 792f586765..3321459581 100644 --- a/libs/features/dynamic-navigation/status.js +++ b/libs/features/dynamic-navigation/status.js @@ -80,7 +80,11 @@ const createStatusWidget = (dynamicNavKey) => { const currentSource = getCurrentSource(dynamicNavSetting, storedSource, authoredSource); const dynamicNavDisableValues = getMetadata('dynamic-nav-disable'); const foundValues = foundDisableValues(); - const status = getStatus(dynamicNavSetting, foundValues.length >= 1, storedSource); + const groupMetaSetting = getMetadata('dynamic-nav-group') || 'Group not set'; + const groupsMatch = groupMetaSetting.toLowerCase() === window.sessionStorage.getItem('dynamicNavGroup').toLowerCase(); + const groupsMatchMessage = groupsMatch ? 'Yes' : 'No'; + const isDisabled = foundValues.length >= 1 || (!groupsMatch && groupMetaSetting !== 'Group not set'); + const status = getStatus(dynamicNavSetting, isDisabled, storedSource); const statusWidget = createTag('div', { class: 'dynamic-nav-status' }); statusWidget.innerHTML = ` @@ -94,6 +98,8 @@ const createStatusWidget = (dynamicNavKey) => {

Status: ${status}

Setting: ${dynamicNavSetting}

+

Group: ${groupMetaSetting}

+

Group matches stored group: ${groupsMatchMessage}

Consumer key: ${dynamicNavKey}