Merge branch 'develop' into feature/CSR-76

This commit is contained in:
Max 2021-12-17 15:58:37 -05:00
commit 77e8fd1d34

View file

@ -30,23 +30,31 @@ export function fetchCmsContentForPage(fmgPage) {
// Function to convert a string, into a matching global state item. // Function to convert a string, into a matching global state item.
function mapStringToState(str) { function mapStringToState(str) {
// Pull the state string out of our dynamic string from the CMS // Pull all matches out of the string.
const regexExp = new RegExp('{(.*?):(.*?)}', 'g'); const regexExp = new RegExp('{(.*?):(.*?)}', 'g');
const matches = [...str.matchAll(regexExp)]; const matches = [...str.matchAll(regexExp)];
const stateString = matches.map(m => m[2]).toString();
// Convert the state string to a state object // Our final string value that will be built from the matches.
let storeState = store.state; let stringBuilder = '';
for (const s of stateString.split('.')) { for (const match of matches) {
if (storeState[s] != undefined) {
storeState = storeState[s]; // Reset store state for each match.
} else { let storeState = store.state;
return false; // If we can't find our state variable, break our loop. Don't break our code.
for (const s of match[2].split('.')) {
if (storeState[s] != undefined) {
storeState = storeState[s];
} else {
return false;
}
} }
// Concatenate the string.
stringBuilder = `${stringBuilder} ${storeState}`;
} }
return storeState; return stringBuilder.trimStart();
} }
// Parent function for processWidgetItemForReplacement. This will loop through the parent // Parent function for processWidgetItemForReplacement. This will loop through the parent