Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release] Stage to Main #2340

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function replaceDotMedia(path, doc) {
}

export default async function init(a) {
const { expFragments, decorateArea, mep } = getConfig();
const { decorateArea, mep } = getConfig();
let relHref = localizeLink(a.href);
let inline = false;

Expand All @@ -79,8 +79,8 @@ export default async function init(a) {
}

const path = new URL(a.href).pathname;
if (expFragments?.[path] && mep) {
relHref = mep.handleFragmentCommand(expFragments[path], a);
if (mep?.fragments?.[path] && mep) {
relHref = mep.handleFragmentCommand(mep?.fragments[path], a);
if (!relHref) return;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export async function fetchAndProcessPlainHtml({ url, shouldDecorateLinks = true
const commands = mepGnav?.commands;
if (commands?.length) {
const { handleCommands, deleteMarkedEls } = await import('../../../features/personalization/personalization.js');
handleCommands(commands, commands[0].manifestId, body, true);
handleCommands(commands, body, true);
deleteMarkedEls(body);
}
const inlineFrags = [...body.querySelectorAll('a[href*="#_inline"]')];
Expand Down
1 change: 0 additions & 1 deletion libs/blocks/quiz-entry/quiz-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ const App = ({
if (debug) console.log(currentQuizState);
if (questionCount.current === maxQuestions || currentQuizState.userFlow.length === 1) {
if (!debug) {
setSelectedQuestion(null);
locationWrapper.redirect(quizPath);
}
} else {
Expand Down
5 changes: 1 addition & 4 deletions libs/blocks/quiz-entry/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ export const handleSelections = (prevSelections, selectedQuestion, selections) =
// de-dup any existing data if they use the ml field and cards.
if (prevSelections.length > 0) {
prevSelections.forEach((selection) => {
const jsonSelectionSelectedQustion = JSON.stringify(selection.selectedQuestion);
const jsonSelectedQuesion = JSON.stringify(selectedQuestion[0].selectedQuestion);
const isSameQuestion = jsonSelectionSelectedQustion === jsonSelectedQuesion;
if (isSameQuestion) {
if (JSON.stringify(selection.selectedQuestion) === JSON.stringify(selectedQuestion)) {
selection.selectedCards = selections;
isNewQuestion = false;
}
Expand Down
1 change: 1 addition & 0 deletions libs/blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ function applyStylesBasedOnScreenSize(table, originTable) {
};

const mobileRenderer = () => {
table.dispatchEvent(tableHighlightLoadedEvent);
const headings = table.querySelectorAll('.row-heading .col');
const headingsLength = headings.length;

Expand Down
1 change: 1 addition & 0 deletions libs/features/jarvis-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
[language, region] = config.locale.ietf.split('-');
} else {
[region, language] = config.locale.prefix.replace('/', '').split('_');
if (region === 'africa') region = 'ZA';

Check warning on line 218 in libs/features/jarvis-chat.js

View check run for this annotation

Codecov / codecov/patch

libs/features/jarvis-chat.js#L218

Added line #L218 was not covered by tests
}

window.AdobeMessagingExperienceClient.initialize({
Expand Down
2 changes: 2 additions & 0 deletions libs/features/personalization/add-preview-to-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default async function addPreviewToConfig({
pageUrl,
mepEnabled,
persManifests,
targetEnabled,
}) {
const { mep: mepOverride, mepHighlight, mepButton } = Object.fromEntries(pageUrl.searchParams);
const config = updateConfig({
Expand All @@ -12,6 +13,7 @@ export default async function addPreviewToConfig({
preview: (mepButton !== 'off' && (mepOverride !== undefined || mepEnabled)),
override: mepOverride ? decodeURIComponent(mepOverride) : '',
highlight: (mepHighlight !== undefined && mepHighlight !== 'false'),
targetEnabled,
},
});

Expand Down
6 changes: 4 additions & 2 deletions libs/features/personalization/entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ const ENTITLEMENT_MAP = {
'08216aa4-4a0f-4136-8b27-182212764a7c': 'free-dc',
// PEP segments
'6cb0d58c-3a65-47e2-b459-c52bb158d5b6': 'lightroom-web-usage',
'caa3de84-6336-4fa8-8db2-240fc88106cc': 'photoshop-web-usage',
'5c6a4bb8-a2f3-4202-8cca-f5e918b969dc': 'firefly-web-usage',
'caa3de84-6336-4fa8-8db2-240fc88106cc': 'photoshop-signup-source',
'ef82408e-1bab-4518-b655-a88981515d6b': 'photoshop-web-usage',
'5c6a4bb8-a2f3-4202-8cca-f5e918b969dc': 'firefly-signup-source',
'20106303-e88c-4b15-93e5-f6a1c3215a12': 'firefly-web-usage',
'3df0b0b0-d06e-4fcc-986e-cc97f54d04d8': 'acrobat-web-usage',
};

Expand Down
94 changes: 62 additions & 32 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ const getBlockProps = (fVal) => {
return { blockSelector, blockTarget: val };
};

const consolidateObjects = (arr, prop) => arr.reduce((propMap, item) => {
const consolidateArray = (arr, prop, existing = []) => arr
.reduce((results, i) => [...results, ...i[prop] || []], existing);

const consolidateObjects = (arr, prop, existing = {}) => arr.reduce((propMap, item) => {
item[prop]?.forEach((i) => {
const { selector, val } = i;
if (prop === 'blocks') {
Expand All @@ -210,17 +213,19 @@ const consolidateObjects = (arr, prop) => arr.reduce((propMap, item) => {

if (selector in propMap) return;
const action = {
action: i.action,
fragment: val,
selector,
manifestPath: item.manifestPath,
action: i.action,
manifestId: i.manifestId,
};
// eslint-disable-next-line no-restricted-syntax
for (const key in propMap) {
if (propMap[key].fragment === selector) propMap[key] = action;
}
propMap[selector] = action;
});
return propMap;
return { ...existing, ...propMap };
}, {});

export const matchGlob = (searchStr, inputStr) => {
Expand Down Expand Up @@ -410,8 +415,9 @@ const addHash = (url, newHash) => {
}
};

export function handleCommands(commands, manifestId, rootEl = document, forceInline = false) {
export function handleCommands(commands, rootEl = document, forceInline = false) {
commands.forEach((cmd) => {
const { manifestId } = cmd;
const { action, selector, target: trgt } = cmd;
const target = forceInline ? addHash(trgt, INLINE_HASH) : trgt;
if (selector.startsWith(IN_BLOCK_SELECTOR_PREFIX)) {
Expand All @@ -435,7 +441,7 @@ export function handleCommands(commands, manifestId, rootEl = document, forceInl
});
}

const getVariantInfo = (line, variantNames, variants) => {
const getVariantInfo = (line, variantNames, variants, manifestId) => {
const action = line.action?.toLowerCase().replace('content', '').replace('fragment', '');
const { selector } = line;
const pageFilter = line['page filter'] || line['page filter optional'];
Expand All @@ -451,13 +457,15 @@ const getVariantInfo = (line, variantNames, variants) => {
pageFilter,
target: line[vn],
selectorType: checkSelectorType(selector),
manifestId,
};

if (action in COMMANDS && variantInfo.selectorType === 'fragment') {
variants[vn].fragments.push({
selector: normalizePath(variantInfo.selector),
val: normalizePath(line[vn]),
action,
manifestId,
});
} else if (GLOBAL_CMDS.includes(action)) {
variants[vn][action] = variants[vn][action] || [];
Expand All @@ -468,12 +476,14 @@ const getVariantInfo = (line, variantNames, variants) => {
selector: blockSelector,
val: blockTarget,
pageFilter,
manifestId,
});
} else {
variants[vn][action].push({
selector: normalizePath(selector),
val: normalizePath(line[vn]),
pageFilter,
manifestId,
});
}
} else if (action in COMMANDS || action in CREATE_CMDS) {
Expand All @@ -485,7 +495,7 @@ const getVariantInfo = (line, variantNames, variants) => {
});
};

export function parseConfig(data) {
export function parseConfig(data, manifestId) {
if (!data?.length) return null;

const config = {};
Expand All @@ -500,7 +510,7 @@ export function parseConfig(data) {
variants[vn] = { commands: [], fragments: [] };
});

experiences.forEach((line) => getVariantInfo(line, variantNames, variants));
experiences.forEach((line) => getVariantInfo(line, variantNames, variants, manifestId));

config.variants = variants;
config.variantNames = variantNames;
Expand Down Expand Up @@ -621,7 +631,15 @@ export async function getPersConfig(info, override = false) {

const persData = data?.experiences?.data || data?.data || data;
if (!persData) return null;
const config = parseConfig(persData);

let manifestId = getFileName(manifestPath);
const globalConfig = getConfig();
if (!globalConfig.mep?.preview) {
manifestId = false;
} else if (name) {
manifestId = `${name}: ${manifestId}`;
}
const config = parseConfig(persData, manifestId);

if (!config) {
/* c8 ignore next 3 */
Expand Down Expand Up @@ -700,7 +718,7 @@ const normalizeFragPaths = ({ selector, val, action }) => ({
action,
});

export async function runPersonalization(experiment, config) {
export async function categorizeActions(experiment) {
if (!experiment) return null;
const { manifestPath, selectedVariant } = experiment;
if (!selectedVariant || selectedVariant === 'default') return { experiment };
Expand All @@ -714,21 +732,14 @@ export async function runPersonalization(experiment, config) {
selectedVariant.insertscript?.map((script) => loadScript(script.val));
selectedVariant.updatemetadata?.map((metadata) => setMetadata(metadata));

let manifestId = getFileName(experiment.manifest);
if (!config.mep?.preview) {
manifestId = false;
} else if (experiment.name) {
manifestId = `${experiment.name}: ${manifestId}`;
}
handleCommands(selectedVariant.commands, manifestId);

selectedVariant.fragments &&= selectedVariant.fragments.map(normalizeFragPaths);

return {
manifestPath,
experiment,
blocks: selectedVariant.useblockcode,
fragments: selectedVariant.fragments,
commands: selectedVariant.commands,
};
}

Expand Down Expand Up @@ -760,9 +771,11 @@ function compareExecutionOrder(a, b) {
}

export function cleanAndSortManifestList(manifests) {
const manifestObj = {};
const config = getConfig();
manifests.forEach((manifest) => {
const manifestObj = {};
let allManifests = manifests;
if (config.mep?.experiments) allManifests = [...manifests, ...config.mep.experiments];
allManifests.forEach((manifest) => {
try {
if (!manifest?.manifest) return;
if (!manifest.manifestPath) manifest.manifestPath = normalizePath(manifest.manifest);
Expand Down Expand Up @@ -790,30 +803,43 @@ export function cleanAndSortManifestList(manifests) {
}

export function handleFragmentCommand(command, a) {
const config = getConfig();
const { action, fragment, manifestPath } = command;
const { action, fragment, manifestId } = command;
if (action === 'replace') {
a.href = fragment;
if (config.mep.preview) a.dataset.manifestId = manifestPath;
if (manifestId) a.dataset.manifestId = manifestId;
return fragment;
}
if (action === 'remove') {
if (config.mep.preview) {
a.parentElement.dataset.removedManifestId = manifestPath;
if (manifestId) {
a.parentElement.dataset.removedManifestId = manifestId;
} else {
a.parentElement.remove();
}
}
return false;
}

export async function applyPers(manifests) {
export async function applyPers(manifests, postLCP = false) {
try {
const config = getConfig();
if (!postLCP) {
const {
mep: mepParam,
mepHighlight,
mepButton,
target,
} = Object.fromEntries(PAGE_URL.searchParams);
config.mep = {
handleFragmentCommand,
preview: (mepButton !== 'off' && (config.env?.name !== 'prod' || mepButton)),
override: mepParam ? decodeURIComponent(mepParam) : '',
highlight: (mepHighlight !== undefined && mepHighlight !== 'false'),
mepParam,
targetEnabled: target,
};
}

if (!manifests?.length) return;
config.mep ??= {};
config.mep.handleFragmentCommand = handleFragmentCommand;
let experiments = manifests;
for (let i = 0; i < experiments.length; i += 1) {
experiments[i] = await getPersConfig(experiments[i], config.mep?.override);
Expand All @@ -824,17 +850,21 @@ export async function applyPers(manifests) {
let results = [];

for (const experiment of experiments) {
const result = await runPersonalization(experiment, config);
const result = await categorizeActions(experiment);
if (result) {
results.push(result);
}
}
results = results.filter(Boolean);
deleteMarkedEls();

config.experiments = experiments;
config.expBlocks = consolidateObjects(results, 'blocks');
config.expFragments = consolidateObjects(results, 'fragments');
config.mep.experiments ??= [];
config.mep.experiments = experiments;
config.mep.blocks = consolidateObjects(results, 'blocks', config.mep.blocks);
config.mep.fragments = consolidateObjects(results, 'fragments', config.mep.fragments);
config.mep.commands = consolidateArray(results, 'commands', config.mep.commands);

if (!postLCP) handleCommands(config.mep.commands);
deleteMarkedEls();

const pznList = results.filter((r) => (r.experiment?.manifestType === TRACKED_MANIFEST_TYPE));
if (!pznList.length) return;
Expand Down
15 changes: 7 additions & 8 deletions libs/features/personalization/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createTag, getConfig, getMetadata, loadStyle, MILO_EVENTS } from '../../utils/utils.js';
import { createTag, getConfig, getMetadata, loadStyle } from '../../utils/utils.js';
import { TRACKED_MANIFEST_TYPE, getFileName } from './personalization.js';

function updatePreviewButton() {
Expand Down Expand Up @@ -199,13 +199,14 @@ function createPreviewPill(manifests) {
<div class="mep-manifest-variants">${radio}</div>
</div>`;
});
const targetOnText = getMetadata('target') === 'on' ? 'on' : 'off';
const config = getConfig();
let targetOnText = config.mep.targetEnabled ? 'on' : 'off';
if (config.mep.targetEnabled === 'gnav') targetOnText = 'on for gnav only';
const personalizationOn = getMetadata('personalization');
const personalizationOnText = personalizationOn && personalizationOn !== '' ? 'on' : 'off';
const simulateHref = new URL(window.location.href);
simulateHref.searchParams.set('mep', manifestParameter.join('---'));

const config = getConfig();
let mepHighlightChecked = '';
if (config.mep?.highlight) {
mepHighlightChecked = 'checked="checked"';
Expand Down Expand Up @@ -287,10 +288,8 @@ function addHighlightData(manifests) {
}

export default async function decoratePreviewMode() {
const { miloLibs, codeRoot, experiments } = getConfig();
const { miloLibs, codeRoot, mep } = getConfig();
loadStyle(`${miloLibs || codeRoot}/features/personalization/preview.css`);
document.addEventListener(MILO_EVENTS.DEFERRED, () => {
createPreviewPill(experiments);
if (experiments) addHighlightData(experiments);
}, { once: true });
createPreviewPill(mep?.experiments);
if (mep?.experiments) addHighlightData(mep.experiments);
}
6 changes: 4 additions & 2 deletions libs/features/personalization/stage-entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const STAGE_ENTITLEMENTS = {
'4ec7b469-42c9-4367-a7da-39f11a32d880': '3d-substance-texturing',
// PEP segments
'9202b767-77dc-4e6e-8d74-488d9ef08900': 'lightroom-web-usage',
'3a7ffcce-11b8-4242-8cdf-8c8d059ae1cd': 'photoshop-web-usage',
'cbe1d7ab-db7d-49cb-969e-a6a2bbe8c660': 'firefly-web-usage',
'3a7ffcce-11b8-4242-8cdf-8c8d059ae1cd': 'photoshop-signup-source',
'81541746-1564-46d5-8787-02c3cd4bf548': 'photoshop-web-usage',
'cbe1d7ab-db7d-49cb-969e-a6a2bbe8c660': 'firefly-signup-source',
'49033b54-1c02-4640-840d-3c5fd6174992': 'firefly-web-usage',
'96adf81f-97ca-4943-81ff-c41fbe8f3af7': 'acrobat-web-usage',
};

Expand Down
Loading
Loading