Skip to content

Commit

Permalink
[Release] Stage to Main (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
milo-pr-merge[bot] authored Jun 12, 2024
2 parents e8300af + 5a932b9 commit 2350bd0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 28 deletions.
3 changes: 2 additions & 1 deletion libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@ let fedsPlaceholderConfig;
export const getFedsPlaceholderConfig = ({ useCache = true } = {}) => {
if (useCache && fedsPlaceholderConfig) return fedsPlaceholderConfig;

const { locale } = getConfig();
const { locale, placeholders } = getConfig();
const libOrigin = getFederatedContentRoot();

fedsPlaceholderConfig = {
locale: {
...locale,
contentRoot: `${libOrigin}${locale.prefix}/federal/globalnav`,
},
placeholders,
};

return fedsPlaceholderConfig;
Expand Down
42 changes: 19 additions & 23 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ const checkForParamMatch = (paramStr) => {
};

async function getPersonalizationVariant(manifestPath, variantNames = [], variantLabel = null) {
const config = getConfig();
if (config.mep?.variantOverride?.[manifestPath]) {
return config.mep.variantOverride[manifestPath];
}

const variantInfo = variantNames.reduce((acc, name) => {
let nameArr = [name];
if (!name.startsWith(TARGET_EXP_PREFIX)) nameArr = name.split(',');
Expand All @@ -572,7 +577,6 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian

let userEntitlements = [];
if (hasEntitlementTag) {
const config = getConfig();
userEntitlements = await config.entitlements();
}

Expand Down Expand Up @@ -608,7 +612,7 @@ const createDefaultExperiment = (manifest) => ({
variants: {},
});

export async function getPersConfig(info, override = false) {
export async function getPersConfig(info, variantOverride = false) {
const {
name,
manifestData,
Expand All @@ -620,7 +624,7 @@ export async function getPersConfig(info, override = false) {
disabled,
event,
} = info;
if (disabled && !override) {
if (disabled && !variantOverride) {
return createDefaultExperiment(info);
}
let data = manifestData;
Expand Down Expand Up @@ -743,26 +747,19 @@ export async function categorizeActions(experiment) {
};
}

function overridePersonalizationVariant(manifest, config) {
const { manifestPath, variantNames } = manifest;
if (!config.mep?.override) return;
let selectedVariant;
config.mep?.override?.split('---').some((item) => {
function parseMepParam(mepParam) {
if (!mepParam) return false;
const mepObject = Object.create(null);
const decodedParam = decodeURIComponent(mepParam);
decodedParam.split('---').forEach((item) => {
const pair = item.trim().split('--');
if (pair[0] === manifestPath && pair.length > 1) {
[, selectedVariant] = pair;
return true;
if (pair.length > 1) {
const [manifestPath, selectedVariant] = pair;
mepObject[manifestPath] = selectedVariant;
}
return false;
});
if (!selectedVariant) return;
if (variantNames.includes(selectedVariant)) {
manifest.selectedVariantName = selectedVariant;
manifest.selectedVariant = manifest.variants[selectedVariant];
return;
}
manifest.selectedVariantName = selectedVariant;
manifest.selectedVariant = manifest.variants[selectedVariant];

return mepObject;
}

function compareExecutionOrder(a, b) {
Expand Down Expand Up @@ -793,7 +790,6 @@ export function cleanAndSortManifestList(manifests) {
} else {
manifestObj[manifest.manifestPath] = manifest;
}
if (config.mep?.override) overridePersonalizationVariant(manifest, config);
} catch (e) {
console.warn(e);
window.lana?.log(`MEP Error parsing manifests: ${e.toString()}`);
Expand Down Expand Up @@ -832,7 +828,7 @@ export async function applyPers(manifests, postLCP = false) {
handleFragmentCommand,
preview: (mepButton !== 'off'
&& (config.env?.name !== 'prod' || mepParam || mepParam === '' || mepButton)),
override: mepParam ? decodeURIComponent(mepParam) : '',
variantOverride: parseMepParam(mepParam),
highlight: (mepHighlight !== undefined && mepHighlight !== 'false'),
mepParam,
targetEnabled: config.mep?.targetEnabled,
Expand All @@ -842,7 +838,7 @@ export async function applyPers(manifests, postLCP = false) {
if (!manifests?.length) return;
let experiments = manifests;
for (let i = 0; i < experiments.length; i += 1) {
experiments[i] = await getPersConfig(experiments[i], config.mep?.override);
experiments[i] = await getPersConfig(experiments[i], config.mep?.variantOverride);
}

experiments = cleanAndSortManifestList(experiments);
Expand Down
4 changes: 3 additions & 1 deletion libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,9 @@ function decorateHeader() {
const baseBreadcrumbs = getMetadata('breadcrumbs-base')?.length;
const breadcrumbs = document.querySelector('.breadcrumbs');
const autoBreadcrumbs = getMetadata('breadcrumbs-from-url') === 'on';
if (baseBreadcrumbs || breadcrumbs || autoBreadcrumbs) header.classList.add('has-breadcrumbs');
const dynamicNavActive = getMetadata('dynamic-nav') === 'on'
&& window.sessionStorage.getItem('gnavSource') !== null;
if (!dynamicNavActive && (baseBreadcrumbs || breadcrumbs || autoBreadcrumbs)) header.classList.add('has-breadcrumbs');
if (breadcrumbs) header.append(breadcrumbs);
const promo = getMetadata('gnav-promo-source');
if (promo?.length) header.classList.add('has-promo');
Expand Down
8 changes: 7 additions & 1 deletion test/blocks/caas/send-to-caas.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';

import { checkUrl } from '../../../tools/send-to-caas/send-utils.js';
import { checkUrl, getOrigin, setConfig } from '../../../tools/send-to-caas/send-utils.js';

document.body.innerHTML = await readFile({ path: './mocks/body.html' });

Expand All @@ -18,4 +18,10 @@ describe('checkUrl function', () => {
const result = checkUrl(inputUrl, 'Error message');
expect(result).to.equal(inputUrl);
});

it('should return consumer mapping when set', () => {
setConfig({ project: 'dc' });
const result = getOrigin('someFloodgateColor');
expect(result).to.equal('doccloud');
});
});
15 changes: 15 additions & 0 deletions test/blocks/global-navigation/global-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,4 +1437,19 @@ describe('global navigation', () => {
).to.be.true;
});
});

describe('Dynamic nav', () => {
describe('Breadcrumbs', () => {
it('should not decorate breadcrumbs when dynamic nav is active', async () => {
const dynamicNavOn = toFragment`<meta name="dynamic-nav" content="on">`;
document.head.append(dynamicNavOn);
document.body.replaceChildren(toFragment`<header class="global-navigation"></header>`);
window.sessionStorage.setItem('dynamicNavKey', 'milo');
window.sessionStorage.setItem('gnavSource', '/some-path');
await initGnav(document.body.querySelector('header'));
const breadcrumbs = document.querySelector('.feds-breadcrumbs');
expect(breadcrumbs).to.be.null;
});
});
});
});
4 changes: 2 additions & 2 deletions tools/send-to-caas/send-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ const processRepoForFloodgate = (repo, fgColor) => {
return repo;
};

const getOrigin = (fgColor) => {
export const getOrigin = (fgColor) => {
const { project, repo } = getConfig();
const origin = project || processRepoForFloodgate(repo, fgColor);

const mappings = {
cc: 'hawks',
dc: 'doccloud',
};
const originLC = (mappings[origin] || origin).toLowerCase();
const originLC = mappings[origin.toLowerCase()] || origin;
if (originLC) {
return originLC;
}
Expand Down

0 comments on commit 2350bd0

Please sign in to comment.