diff --git a/src/helpers/cms-content-helper.js b/src/helpers/cms-content-helper.js index b0aa9bed2..1c795aab2 100644 --- a/src/helpers/cms-content-helper.js +++ b/src/helpers/cms-content-helper.js @@ -10,16 +10,20 @@ export function fetchCmsContentForPage(fmgPage) { response.data.Result.forEach((widget) => { - let widgetWithReplacements = findAndReplaceGlobalStateValues(widget.Model, widget.Type); + let widgetWithReplacements = findAndReplaceGlobalStateValues(widget.Model, widget.Name); - if (Object.values(widgetNames).includes(widgetWithReplacements.Type)) { - // If we already have this widget, push it on the collection - if (widgetWithReplacements.Type in pageDataFromCms) { - pageDataFromCms[widgetWithReplacements.Type].push(widgetWithReplacements.Model); - return; - } + // If we already have this widget, push it on the collection + if (widgetWithReplacements.Name in pageDataFromCms) { + pageDataFromCms[widgetWithReplacements.Name].push(widgetWithReplacements.Model); + return; + } - pageDataFromCms[widgetWithReplacements.Type] = [widgetWithReplacements.Model]; + pageDataFromCms[widgetWithReplacements.Name] = [widgetWithReplacements.Model]; + }); + + Object.keys(pageDataFromCms).forEach((key) => { + if (pageDataFromCms[key].length === 1){ + pageDataFromCms[key] = pageDataFromCms[key][0]; } }); @@ -66,10 +70,10 @@ function mapStringToState(str) { // Parent function for processWidgetItemForReplacement. This will loop through the parent // object and pass any objects that need additional processing to the processWidgetItemForReplacement function. -function findAndReplaceGlobalStateValues(widgetModel, widgetType) { +function findAndReplaceGlobalStateValues(widgetModel, widgetName) { const objWithReplacements = { - Type: widgetType, + Name: widgetName, Model: {} }; diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index e9fdb7686..e641c4c73 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -55,10 +55,10 @@ export default { settleAllPromises(promiseResultMap).then((resultMap) => { // Call the "next" function to complete the transition to this page. next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget[0]); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget[0]); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget[0]); - vm.$refs.makeQuestion.initializeComponent(resultMap.cmsContent.RadioQuestionWidget[0], resultMap.makeQuestionInitialData); + vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); + vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); + vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); + vm.$refs.makeQuestion.initializeComponent(resultMap.cmsContent.VehicleMakeQuestion, resultMap.makeQuestionInitialData); }); }); }, diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index e10d51fa7..c682e9e24 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -55,10 +55,10 @@ export default { settleAllPromises(promiseResultMap).then((resultMap) => { // Call the "next" function to complete the transition to this page. next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget[0]); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget[0]); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget[0]); - vm.$refs.modelQuestion.initializeComponent(resultMap.cmsContent.RadioQuestionWidget[0], resultMap.modelQuestionInitialData); + vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); + vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); + vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); + vm.$refs.modelQuestion.initializeComponent(resultMap.cmsContent.VehicleModelQuestion, resultMap.modelQuestionInitialData); }); }); }, diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index e258254d4..9a1706b97 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -55,10 +55,10 @@ export default { settleAllPromises(promiseResultMap).then((resultMap) => { // Call the "next" function to complete the transition to this page. next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget[0]); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget[0]); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget[0]); - vm.$refs.styleQuestion.initializeComponent(resultMap.cmsContent.RadioQuestionWidget[0], resultMap.styleQuestionInitialData); + vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); + vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); + vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); + vm.$refs.styleQuestion.initializeComponent(resultMap.cmsContent.VehicleStyleQuestion, resultMap.styleQuestionInitialData); }); }); }, diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index 8456c3275..c5c85675e 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -53,10 +53,10 @@ export default { settleAllPromises(promiseResultMap).then((resultMap) => { // Call the "next" function to complete the transition to this page. next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget[0]); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget[0]); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget[0]); - vm.$refs.yearQuestion.initializeComponent(resultMap.cmsContent.RadioQuestionWidget[0], resultMap.yearQuestionInitialData); + vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); + vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); + vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); + vm.$refs.yearQuestion.initializeComponent(resultMap.cmsContent.VehicleYearQuestion, resultMap.yearQuestionInitialData); }); }); },