Skip to content

Commit

Permalink
[Release] Stage to Main (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
milo-pr-merge[bot] authored Jun 27, 2024
2 parents 32f61f0 + 5e2dd4c commit 2217784
Show file tree
Hide file tree
Showing 24 changed files with 2,076 additions and 343 deletions.
10 changes: 5 additions & 5 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ const CARD_TYPES = [

const CARD_SIZES = ['wide', 'super-wide'];

const TEXT_STYLES = {
H5: 'detail-m',
const SLOT_MAP_DEFAULT = {
H5: 'promo-text',
H4: 'body-xxs',
H3: 'heading-xs',
H2: 'heading-m',
};

const SLOT_MAP = { 'special-offers': { H5: 'detail-m' } };

const HEADING_MAP = {
'special-offers': {
H5: 'H4',
Expand Down Expand Up @@ -153,9 +155,7 @@ const parseContent = async (el, merchCard) => {

if (merchCard.variant === MINI_COMPARE_CHART) {
bodySlotName = 'body-m';
const promoText = el.querySelectorAll('h5');
const priceSmallType = el.querySelectorAll('h6');
appendSlot(promoText, 'promo-text', merchCard);
appendSlot(priceSmallType, 'price-commitment', merchCard);
}

Expand All @@ -171,7 +171,7 @@ const parseContent = async (el, merchCard) => {
innerElements.forEach((element) => {
let { tagName } = element;
if (isHeadingTag(tagName)) {
let slotName = TEXT_STYLES[tagName];
let slotName = SLOT_MAP[merchCard.variant]?.[tagName] || SLOT_MAP_DEFAULT[tagName];
if (slotName) {
if (['H2', 'H3', 'H4', 'H5'].includes(tagName)) {
element.classList.add('card-heading');
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/ost/ost.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const IMS_COMMERCE_CLIENT_ID = 'aos_milo_commerce';
const IMS_SCOPE = 'AdobeID,openid';
const IMS_ENV = 'prod';
const IMS_PROD_URL = 'https://auth.services.adobe.com/imslib/imslib.min.js';
const OST_VERSION = '1.18.2';
const OST_VERSION = '1.18.4';
const OST_BASE = `https://www.stage.adobe.com/special/tacocat/ost/lib/${OST_VERSION}`;
const OST_SCRIPT_URL = `${OST_BASE}/index.js`;
const OST_STYLE_URL = `${OST_BASE}/index.css`;
Expand Down
8 changes: 7 additions & 1 deletion libs/blocks/quiz-entry/quiz-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const App = ({
analyticsType = null,
questionData = { questions: { data: [] } },
stringsData = { questions: { data: [] } },
resultsData = {},
debug = false,
}) => {
const [dataLoaded, setDataLoaded] = useState(false);
const [quizState, setQuizState] = useState({ userFlow: [], userSelection: [] });
const [quizState, setQuizState] = useState({ userFlow: [], userSelection: [], results: {} });
const [quizLists, setQuizLists] = useState({});
const [quizData, setQuizData] = useState({});
const [hasMLData, setHasMLData] = useState(false);
Expand Down Expand Up @@ -117,6 +118,7 @@ const App = ({
setQuizState({
userFlow: [questionDataArray[0].questions],
userSelection: quizState.userSelection,
results: resultsData,
});
setSelectedQuestion(qLists.questions[questionDataArray[0].questions]);
}
Expand Down Expand Up @@ -260,6 +262,7 @@ const App = ({
const currentQuizState = {
userFlow: nextFlow,
userSelection: nextSelections,
results: resultsData,
};
localStorage.setItem('stored-quiz-state', JSON.stringify(currentQuizState));
setQuizState(currentQuizState);
Expand Down Expand Up @@ -390,6 +393,7 @@ export default async function init(
analyticsType: null,
questionData: null,
stringsData: null,
resultsData: null,
debug: false,
},
) {
Expand All @@ -408,6 +412,7 @@ export default async function init(
analyticsType: '',
questionData: { questions: { data: [] } },
stringsData: { questions: { data: [] } },
resultsData: {},
debug: false,
};
}
Expand All @@ -424,6 +429,7 @@ export default async function init(
analyticsType=${quizEntry.analyticsType || ''}
questionData=${quizEntry.questionData}
stringsData=${quizEntry.stringsData}
resultsData=${quizEntry.resultsData}
debug=${quizEntry.debug || false}
/>`, el);
}
26 changes: 19 additions & 7 deletions libs/blocks/quiz-entry/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ export async function fetchJson(path) {

export async function getQuizJson(path) {
try {
const [questions, strings] = await Promise.all(
[fetchJson(`${path}questions.json`), fetchJson(`${path}strings.json`)],
);
return [questions, strings];
// Fetch required files
const [questions, strings] = await Promise.all([
fetchJson(`${path}questions.json`),
fetchJson(`${path}strings.json`),
]);

// Try to fetch optional file, results.json
let results = [];
try {
results = await fetchJson(`${path}results.json`);
} catch (ex) {
window.lana?.log(`INFO: results.json not found or couldn't be fetched: ${ex}`, { tags: 'errorType=info,module=quiz-entry' });
}

return [questions, strings, results];
} catch (ex) {
window.lana?.log(`ERROR: Fetching data for quiz entry ${ex}`);
window.lana?.log(`ERROR: Fetching data for quiz entry: ${ex}`, { tags: 'errorType=error,module=quiz-entry' });
return [];
}
return [];
}

export const handleNext = (questionsData, selectedQuestion, userInputSelections, userFlow) => {
Expand Down Expand Up @@ -98,13 +109,14 @@ export async function getQuizEntryData(el) {
const maxQuestions = Number(blockData.maxquestions?.text) || 10;
const analyticsType = blockData.analyticstype?.text;
const analyticsQuiz = blockData.analyticsquiz?.text;
const [questionData, stringsData] = await getQuizJson(dataPath);
const [questionData, stringsData, resultsData] = await getQuizJson(dataPath);
return {
quizPath,
maxQuestions,
analyticsQuiz,
analyticsType,
questionData,
stringsData,
resultsData,
};
}
4 changes: 3 additions & 1 deletion libs/blocks/quiz/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const App = ({
const [userFlow, setUserFlow] = useState([]);
const validQuestions = useMemo(() => [], []);
const [debugBuild, setDebugBuild] = useState(null);
const [quizEntryData, setQuizEntryData] = useState({});

useEffect(() => {
(async () => {
Expand All @@ -62,6 +63,7 @@ const App = ({
&& !!storedQuizState?.userSelection.length) {
setUserFlow(storedQuizState.userFlow);
updateUserSelection(storedQuizState.userSelection);
setQuizEntryData(storedQuizState.results);
} else {
setUserFlow([questions.questions.data[0].questions]);
}
Expand Down Expand Up @@ -149,7 +151,7 @@ const App = ({
console.log(`Error copying URL: ${err} URL: ${debugURL}`);
});
}
handleResultFlow(transformToFlowData(userSelection));
handleResultFlow(transformToFlowData(userSelection), quizEntryData);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userSelection, nextQuizViewsExist]);
Expand Down
31 changes: 26 additions & 5 deletions libs/blocks/quiz/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ export const defaultRedirect = (url) => {

export const handleResultFlow = async (
answers = [],
quizEntryResults = {},
redirectFunc = defaultRedirect,
) => {
const { destinationPage } = await findAndStoreResultData(answers);
const { destinationPage } = await findAndStoreResultData(answers, quizEntryResults);
const redirectUrl = getRedirectUrl(destinationPage);
redirectFunc(redirectUrl);
};
Expand All @@ -74,8 +75,8 @@ export const handleResultFlow = async (
* Handling the result flow from here. Will need to make sure we capture all
* the data so that we can come back.
*/
export const findAndStoreResultData = async (answers = []) => {
const entireResultData = await parseResultData(answers);
export const findAndStoreResultData = async (answers = [], quizEntryResults = {}) => {
const entireResultData = await parseResultData(answers, quizEntryResults);
const resultData = entireResultData.filteredResults;
const { resultResources } = entireResultData;
let destinationPage = '';
Expand Down Expand Up @@ -265,8 +266,28 @@ export const getRedirectUrl = (destinationPage) => {
return `${destinationPage}${separator}quizkey=${quizKey}`;
};

export const parseResultData = async (answers) => {
const results = await fetchContentOfFile(RESULTS_EP_NAME);
export const parseResultData = async (answers, quizEntryResults) => {
// Initialize an empty object for the results
const results = {};

// Fetch the content of the file asynchronously
const quizResultsData = await fetchContentOfFile(RESULTS_EP_NAME);

// Destructure data from fetched content and the existing quizResultsData
const { result: { data: quizResultsDataArray } } = quizResultsData;
const { 'result-fragments': { data: quizFragmentsDataArray } } = quizResultsData;
const { 'result-destination': { data: quizDestinationDataArray } } = quizResultsData;

// Check if quizEntryResults is defined and extract data, otherwise use empty arrays
const quizEntryResultsDataArray = quizEntryResults?.result?.data || [];
const quizEntryFragmentsDataArray = quizEntryResults?.['result-fragments']?.data || [];
const quizEntryDestinationDataArray = quizEntryResults?.['result-destination']?.data || [];

// Merge the data arrays from both sources
results.result = { data: [...quizResultsDataArray, ...quizEntryResultsDataArray] };
results['result-fragments'] = { data: [...quizFragmentsDataArray, ...quizEntryFragmentsDataArray] };
results['result-destination'] = { data: [...quizDestinationDataArray, ...quizEntryDestinationDataArray] };

const filteredResults = results.result.data.reduce(
(resultObj, resultMap) => {
let hasMatch = false;
Expand Down
11 changes: 6 additions & 5 deletions libs/deps/commerce.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2217784

Please sign in to comment.