Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a7b831c
MWPW-147601: sending ML field text to Analytics
JackySun9 May 20, 2024
6f9d73a
unifided send ML field analytics event
JackySun9 May 21, 2024
df61901
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 May 23, 2024
0748c59
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 3, 2024
b1ff35b
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 4, 2024
128a911
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 4, 2024
67a9cc5
MWPW-147989 and MWPW-151786: handle localized path for quiz spreadshe…
JackySun9 Jun 4, 2024
b859a15
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 5, 2024
2ad6c83
update code according to feedbacks
JackySun9 Jun 5, 2024
841a407
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 6, 2024
f46432d
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 10, 2024
a02b4b7
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 11, 2024
54573c5
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 13, 2024
a3f17a8
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 17, 2024
ae5d280
MWPW-150705: De-couple Result Spreadsheet for Interactive Front Door …
JackySun9 Jun 17, 2024
3e2bf9c
add unit tests
JackySun9 Jun 18, 2024
5652302
fix lint errors
JackySun9 Jun 18, 2024
bba27a6
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 18, 2024
051d1e4
update lana with tags
JackySun9 Jun 18, 2024
7e11e5f
Merge branch 'stage' of https://github.com/adobecom/milo into stage
JackySun9 Jun 20, 2024
4194fb1
Update self hosted dependency
actions-user Jun 24, 2024
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
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
2 changes: 1 addition & 1 deletion libs/deps/imslib.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading