Skip to content

Commit

Permalink
add response tokens to rendering-succeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
Nina Ciocanu committed Sep 17, 2024
1 parent 30eea3a commit a3a70df
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
16 changes: 10 additions & 6 deletions src/components/Personalization/createFetchDataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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(),
),
},
});
}
Expand All @@ -94,7 +96,9 @@ export default ({
logLevel: "info",
detail: {
scope: personalizationDetails.getViewName(),
propositions: currentViewPropositions.map(proposition => proposition.toJSON())
propositions: currentViewPropositions.map((proposition) =>
proposition.toJSON(),
),
},
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Personalization/createViewChangeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
},
});

Expand Down
10 changes: 5 additions & 5 deletions src/components/Personalization/flicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export const showElements = (prehidingSelector) => {
}
};

export const createHideContainers = ( logger ) => {
return ( prehidingStyle ) => {
export const createHideContainers = (logger) => {
return (prehidingStyle) => {
if (!prehidingStyle) {
return;
}
Expand All @@ -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
Expand All @@ -102,5 +102,5 @@ export const createShowContainers = ( logger ) => {
logLevel: "info",
});
removeNode(node);
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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) => () => {
Expand All @@ -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;
Expand All @@ -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) => {
Expand Down Expand Up @@ -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;
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

0 comments on commit a3a70df

Please sign in to comment.