Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Priority Resolution #1193

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 15 additions & 2 deletions src/components/DecisioningEngine/createDecisionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,23 @@ export default ({ eventRegistry }) => {
}
};

const evaluate = (context = {}) =>
Object.values(payloadsBasedOnActivityId)
const evaluate = (context = {}) => {
const sortedPayloadsBasedOnActivityId = Object.values(
payloadsBasedOnActivityId,
).sort(({ rank: rankA }, { rank: rankB }) => {
if (rankA < rankB) {
return -1;
}
if (rankA > rankB) {
return 1;
}
return 0;
});

return sortedPayloadsBasedOnActivityId
.map((payload) => payload.evaluate(context))
.filter((payload) => payload.items.length > 0);
};

const addPayloads = (personalizationPayloads) => {
personalizationPayloads.forEach(addPayload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default (payload, eventRegistry, decisionHistory) => {
}

return {
rank: payload?.scopeDetails?.rank || Infinity,
evaluate,
isEvaluable: items.length > 0,
};
Expand Down
19 changes: 18 additions & 1 deletion src/components/Personalization/createNotificationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
import { defer } from "../../utils/index.js";
import { SUPPRESS } from "../../constants/eventType.js";

export default (collect, renderedPropositions) => {
return (isRenderDecisions, isSendDisplayEvent, viewName) => {
Expand All @@ -24,13 +25,29 @@ export default (collect, renderedPropositions) => {
return renderedPropositionsDeferred.resolve;
}

return (decisionsMeta) => {
return (suppressedPropositions, decisionsMeta) => {
if (decisionsMeta.length > 0) {
collect({
decisionsMeta,
viewName,
});
}

if (suppressedPropositions && suppressedPropositions.length > 0) {
const suppressedMeta = suppressedPropositions.map(
({ id, scope, scopeDetails }) => ({
id,
scope,
scopeDetails,
}),
);

collect({
decisionsMeta: suppressedMeta,
eventType: SUPPRESS,
viewName,
});
}
};
};
};
8 changes: 7 additions & 1 deletion src/components/Personalization/createOnDecisionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
const { render, returnedPropositions } = processPropositions(
propositionsToExecute,
);
debugger;

Check failure on line 33 in src/components/Personalization/createOnDecisionHandler.js

View workflow job for this annotation

GitHub Actions / Linting files

Unexpected 'debugger' statement
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove this


const handleNotifications = notificationHandler(
renderDecisions,
sendDisplayEvent,
viewName,
);
render().then(handleNotifications);
render().then(
handleNotifications.bind(
null,
returnedPropositions.filter((p) => p.isSuppressedDisplay),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these params are in the wrong order. See createNotificationHandler.js#L28

),
);

return Promise.resolve({
propositions: returnedPropositions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const isValidInAppMessage = (data, logger) => {
};

export default ({ modules, logger }) => {
return (item) => {
return (item, firstItemInBatch) => {
const data = item.getData();
const meta = { ...item.getProposition().getNotification() };

Expand All @@ -73,14 +73,16 @@ export default ({ modules, logger }) => {
}

return {
render: () => {
return modules[type]({
...data,
meta,
});
},
setRenderAttempted: true,
includeInNotification: true,
render: firstItemInBatch
? () =>
modules[type]({
...data,
meta,
})
: null,
setRenderAttempted: firstItemInBatch,
setSuppressedDisplay: !firstItemInBatch,
includeInNotification: firstItemInBatch,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that we should only be rendering the last item.

};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
return meta;
});

const processItem = (item) => {
const processItem = (item, firstItemInBatch) => {
const processor = schemaProcessors[item.getSchema()];
if (!processor) {
return {};
}
return processor(item);
return processor(item, firstItemInBatch);
};

const processItems = ({
Expand All @@ -64,6 +64,7 @@
returnedDecisions: existingReturnedDecisions,
items,
proposition,
firstItemInBatch = false,
}) => {
let renderers = [...existingRenderers];
let returnedPropositions = [...existingReturnedPropositions];
Expand All @@ -74,15 +75,22 @@
let atLeastOneWithNotification = false;
let render;
let setRenderAttempted;
let setSuppressedDisplay;
let includeInNotification;
let onlyRenderThis = false;
let i = 0;
let item;

while (items.length > i) {
item = items[i];
({ render, setRenderAttempted, includeInNotification, onlyRenderThis } =
processItem(item));
({
render,
setRenderAttempted,
setSuppressedDisplay,
includeInNotification,
onlyRenderThis,
} = processItem(item, firstItemInBatch));

if (onlyRenderThis) {
returnedPropositions = [];
returnedDecisions = [];
Expand All @@ -98,6 +106,7 @@
atLeastOneWithNotification = includeInNotification;
break;
}

if (render) {
itemRenderers.push(wrapRenderWithLogging(render, item));
}
Expand Down Expand Up @@ -125,6 +134,7 @@
returnedDecisions,
renderedItems,
true,
setSuppressedDisplay,
);
}
if (nonRenderedItems.length > 0) {
Expand All @@ -133,9 +143,11 @@
returnedDecisions,
nonRenderedItems,
false,
setSuppressedDisplay,
);
}

debugger;

Check failure on line 150 in src/components/Personalization/handlers/createProcessPropositions.js

View workflow job for this annotation

GitHub Actions / Linting files

Unexpected 'debugger' statement
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove

return {
renderers,
returnedPropositions,
Expand Down Expand Up @@ -163,6 +175,7 @@
returnedDecisions,
items,
proposition,
firstItemInBatch: i === 0,
}));
if (onlyRenderThis) {
break;
Expand Down Expand Up @@ -194,6 +207,7 @@
false,
);
});

const render = () => {
return Promise.all(renderers.map((renderer) => renderer())).then(
(metas) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ export default ({ preprocess, isPageWideSurface }) => {
decisions,
includedItems,
renderAttempted,
isSuppressedDisplay = false,
) {
if (visibleInReturnedItems) {
propositions.push({
...payload,
items: includedItems.map((i) => i.getOriginalItem()),
renderAttempted,
isSuppressedDisplay,
});
if (!renderAttempted) {
decisions.push({
Expand Down
1 change: 1 addition & 0 deletions src/constants/eventType.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const DISPLAY = "decisioning.propositionDisplay";
export const INTERACT = "decisioning.propositionInteract";
export const TRIGGER = "decisioning.propositionTrigger";
export const DISMISS = "decisioning.propositionDismiss";
export const SUPPRESS = "decisioning.propositionSuppressDisplay";
export const EVENT_TYPE_TRUE = 1;
6 changes: 5 additions & 1 deletion src/constants/propositionEventType.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import { DISPLAY, INTERACT, TRIGGER, DISMISS } from "./eventType.js";
import { DISPLAY, INTERACT, TRIGGER, DISMISS, SUPPRESS } from "./eventType.js";

export const PropositionEventType = {
DISPLAY: "display",
INTERACT: "interact",
TRIGGER: "trigger",
DISMISS: "dismiss",
SUPPRESS: "suppressDisplay",
};

const eventTypeToPropositionEventTypeMapping = {
[DISPLAY]: PropositionEventType.DISPLAY,
[INTERACT]: PropositionEventType.INTERACT,
[TRIGGER]: PropositionEventType.TRIGGER,
[DISMISS]: PropositionEventType.DISMISS,
[SUPPRESS]: PropositionEventType.SUPPRESS,
};

const propositionEventTypeToEventTypeMapping = {
[PropositionEventType.DISPLAY]: DISPLAY,
[PropositionEventType.INTERACT]: INTERACT,
[PropositionEventType.TRIGGER]: TRIGGER,
[PropositionEventType.DISMISS]: DISMISS,
[PropositionEventType.SUPPRESS]: SUPPRESS,
};

export const getPropositionEventType = (eventType) =>
Expand Down
Loading