Skip to content

Commit

Permalink
Merge pull request #1061 from adobe/miscFetchPRComments
Browse files Browse the repository at this point in the history
Misc fetch pr comments
  • Loading branch information
jonsnyder authored Oct 23, 2023
2 parents 76dda60 + 0019f4f commit 33288d6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 20 deletions.
15 changes: 9 additions & 6 deletions src/components/Personalization/createComponent.js
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 { noop, flatMap } from "../../utils";
import { noop, flatMap, isNonEmptyArray } from "../../utils";
import createPersonalizationDetails from "./createPersonalizationDetails";
import { AUTHORING_ENABLED } from "./constants/loggerMessage";
import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
Expand Down Expand Up @@ -102,11 +102,14 @@ export default ({
return Promise.all(decisionsMetaPromises).then(decisionsMetas => {
// We only want to call mergeDecisionsMeta once, but we can get the propositions
// from two places: the pending display notifications and the view change handler.
mergeDecisionsMeta(
event,
flatMap(decisionsMetas, dms => dms),
PropositionEventType.DISPLAY
);
const decisionsMeta = flatMap(decisionsMetas, dms => dms);
if (isNonEmptyArray(decisionsMeta)) {
mergeDecisionsMeta(
event,
decisionsMeta,
PropositionEventType.DISPLAY
);
}
});
},
onClick({ event, clickedElement }) {
Expand Down
13 changes: 13 additions & 0 deletions src/components/Personalization/dom-actions/createRedirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

export default window => url => window.location.replace(url);
5 changes: 0 additions & 5 deletions src/components/Personalization/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export const mergeDecisionsMeta = (
eventType,
eventLabel = ""
) => {
// Do not send a display notification with no decisions. Even empty view changes
// should include a proposition.
if (decisionsMeta.length === 0) {
return;
}
const xdm = {
_experience: {
decisioning: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export default ({ logger, executeRedirect, collect }) => item => {
}

const render = () => {
return collect({ decisionsMeta: [item.getMeta()] }).then(() => {
return collect({
decisionsMeta: [item.getMeta()],
documentMayUnload: true
}).then(() => {
executeRedirect(content);
// We've already sent the display notification, so don't return anything
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/Personalization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import createProcessDomAction from "./handlers/createProcessDomAction";
import createProcessHtmlContent from "./handlers/createProcessHtmlContent";
import createProcessRedirect from "./handlers/createProcessRedirect";
import createProcessPropositions from "./handlers/createProcessPropositions";
import createRedirect from "./dom-actions/createRedirect";

const createPersonalization = ({ config, logger, eventManager }) => {
const { targetMigrationEnabled, prehidingStyle } = config;
Expand All @@ -58,6 +59,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
});
const viewCache = createViewCacheManager({ createProposition });

const executeRedirect = createRedirect(window);
const schemaProcessors = {
[schema.DEFAULT_CONTENT_ITEM]: processDefaultContent,
[schema.DOM_ACTION]: createProcessDomAction({
Expand All @@ -68,7 +70,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
[schema.HTML_CONTENT_ITEM]: createProcessHtmlContent({ modules, logger }),
[schema.REDIRECT_ITEM]: createProcessRedirect({
logger,
executeRedirect: url => window.location.replace(url),
executeRedirect,
collect
})
};
Expand Down
7 changes: 1 addition & 6 deletions src/core/createEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,7 @@ export default () => {
return shouldSendEvent;
},
getViewName() {
if (
!userXdm ||
!userXdm.web ||
!userXdm.web.webPageDetails ||
!userXdm.web.webPageDetails.viewName
) {
if (!userXdm || !userXdm.web || !userXdm.web.webPageDetails) {
return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import createRedirect from "../../../../../../src/components/Personalization/dom-actions/createRedirect";

describe("createRedirect", () => {
it("redirects", () => {
const window = {
location: {
replace: jasmine.createSpy()
}
};
const redirect = createRedirect(window);
redirect("myurl");
expect(window.location.replace).toHaveBeenCalledWith("myurl");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ describe("createProcessRedirect", () => {
expect(executeRedirect).not.toHaveBeenCalled();
const renderPromise = result.render();
await flushPromiseChains();
expect(collect).toHaveBeenCalledWith({ decisionsMeta: ["mymetavalue"] });
expect(collect).toHaveBeenCalledWith({
decisionsMeta: ["mymetavalue"],
documentMayUnload: true
});
expect(executeRedirect).not.toHaveBeenCalled();
collectDefer.resolve();
await flushPromiseChains();
Expand Down

0 comments on commit 33288d6

Please sign in to comment.