diff --git a/src/components/Personalization/createFetchDataHandler.js b/src/components/Personalization/createFetchDataHandler.js index dfef58a46..587d50447 100644 --- a/src/components/Personalization/createFetchDataHandler.js +++ b/src/components/Personalization/createFetchDataHandler.js @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import {groupBy, isNonEmptyArray} from "../../utils/index.js"; +import { groupBy, isNonEmptyArray } from "../../utils/index.js"; import PAGE_WIDE_SCOPE from "../../constants/pageWideScope.js"; const DECISIONS_HANDLE = "personalization:decisions"; @@ -46,14 +46,14 @@ export default ({ onResponse(({ response }) => { const handles = response.getPayloadsByType(DECISIONS_HANDLE); - if(!isNonEmptyArray(handles)){ + if (!isNonEmptyArray(handles)) { logger.logOnContentRendering({ status: "no-offers", message: "No offers were returned.", logLevel: "info", detail: { - query: personalizationDetails.createQueryDetails() - } + query: personalizationDetails.createQueryDetails(), + }, }); } const propositions = handles.map((handle) => createProposition(handle)); @@ -82,7 +82,9 @@ export default ({ logLevel: "info", detail: { scope: PAGE_WIDE_SCOPE, - propositions: pagePropositions.map(proposition => proposition.toJSON()) + propositions: pagePropositions.map((proposition) => + proposition.toJSON(), + ), }, }); } @@ -94,7 +96,9 @@ export default ({ logLevel: "info", detail: { scope: personalizationDetails.getViewName(), - propositions: currentViewPropositions.map(proposition => proposition.toJSON()) + propositions: currentViewPropositions.map((proposition) => + proposition.toJSON(), + ), }, }); } diff --git a/src/components/Personalization/createViewChangeHandler.js b/src/components/Personalization/createViewChangeHandler.js index 10dad9e7f..9b379429a 100644 --- a/src/components/Personalization/createViewChangeHandler.js +++ b/src/components/Personalization/createViewChangeHandler.js @@ -35,7 +35,9 @@ export default ({ processPropositions, viewCache, logger }) => { logLevel: "info", detail: { scope: viewName, - propositions: propositions.map(proposition => proposition.toJSON()) + propositions: propositions.map((proposition) => + proposition.toJSON(), + ), }, }); diff --git a/src/components/Personalization/flicker/index.js b/src/components/Personalization/flicker/index.js index 3caf6985e..9638a4e48 100644 --- a/src/components/Personalization/flicker/index.js +++ b/src/components/Personalization/flicker/index.js @@ -56,8 +56,8 @@ export const showElements = (prehidingSelector) => { } }; -export const createHideContainers = ( logger ) => { - return ( prehidingStyle ) => { +export const createHideContainers = (logger) => { + return (prehidingStyle) => { if (!prehidingStyle) { return; } @@ -84,9 +84,9 @@ export const createHideContainers = ( logger ) => { appendNode(document.head, styleNode); }; -} +}; -export const createShowContainers = ( logger ) => { +export const createShowContainers = (logger) => { return () => { // If containers prehiding style exists // we will remove it @@ -102,5 +102,5 @@ export const createShowContainers = ( logger ) => { logLevel: "info", }); removeNode(node); - } + }; }; diff --git a/src/components/Personalization/handlers/createProcessPropositions.js b/src/components/Personalization/handlers/createProcessPropositions.js index 6c47136a2..dcb4a8ec9 100644 --- a/src/components/Personalization/handlers/createProcessPropositions.js +++ b/src/components/Personalization/handlers/createProcessPropositions.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import { groupBy } from "../../../utils/index.js"; +import { groupBy, isNonEmptyArray } from "../../../utils/index.js"; export default ({ schemaProcessors, logger }) => { const wrapRenderWithLogging = (render, item) => () => { @@ -20,7 +20,7 @@ export default ({ schemaProcessors, logger }) => { if (logger.enabled) { logger.info(`Action ${item.toString()} executed.`); } - return true; + return item.toJSON(); }) .catch((error) => { const { message, stack } = error; @@ -36,18 +36,19 @@ export default ({ schemaProcessors, logger }) => { logLevel: "warn", }); - return false; + return undefined; }); }; const renderItems = (renderers, meta) => - Promise.all(renderers.map((renderer) => renderer())).then((successes) => { + Promise.all(renderers.map((renderer) => renderer())).then((results) => { + const successes = results.filter((result) => result); // as long as at least one renderer succeeds, we want to add the notification // to the display notifications - if (!successes.includes(true)) { - return undefined; + if (isNonEmptyArray(successes)) { + return { meta, successes }; } - return meta; + return undefined; }); const processItem = (item) => { @@ -197,15 +198,24 @@ export default ({ schemaProcessors, logger }) => { const render = () => { return Promise.all(renderers.map((renderer) => renderer())).then( (metas) => { - const renderedPropositions = metas.filter((meta) => meta); - const propsByScope = groupBy(renderedPropositions, (p) => p.scope); - logger.logOnContentRendering({ - status: "rendering-succeeded", - detail: { ...propsByScope }, - message: `Scopes: ${JSON.stringify(propsByScope)} successfully executed.`, - logLevel: "info", + const propositions = metas + .filter((meta) => meta) + .map((meta) => { + return { items: meta.successes, ...meta.meta }; + }); + const renderedPropositions = propositions.map((prop) => { + const { id, scope, scopeDetails } = prop; + return { id, scope, scopeDetails }; }); - + if (isNonEmptyArray(propositions)) { + const propsByScope = groupBy(propositions, (p) => p.scope); + logger.logOnContentRendering({ + status: "rendering-succeeded", + detail: { ...propsByScope }, + message: `Scopes: ${JSON.stringify(propsByScope)} successfully executed.`, + logLevel: "info", + }); + } return renderedPropositions; }, ); diff --git a/src/components/Personalization/handlers/processDefaultContent.js b/src/components/Personalization/handlers/processDefaultContent.js index d697ea123..8c0f1887f 100644 --- a/src/components/Personalization/handlers/processDefaultContent.js +++ b/src/components/Personalization/handlers/processDefaultContent.js @@ -9,6 +9,12 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +import noop from "../../../utils/noop.js"; + export default () => { - return { setRenderAttempted: true, includeInNotification: true }; + return { + render: noop, + setRenderAttempted: true, + includeInNotification: true, + }; };