Skip to content

Commit 8ee929b

Browse files
committed
Patch attachmentLayout instead of via activityMiddleware
1 parent d5c6b46 commit 8ee929b

2 files changed

Lines changed: 16 additions & 31 deletions

File tree

packages/test/page-object/src/globals/testHelpers/activityGrouping/ActivityGroupingSurface.js

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types';
22

3-
import ActivityGroupingContext from './ActivityGroupingContext';
43
import createDirectLineWithTranscript from '../createDirectLineWithTranscript';
4+
import ActivityGroupingContext from './ActivityGroupingContext';
55

66
// Use React from window (UMD) instead of import.
77
const { React: { useEffect, useMemo, useState } = {} } = window;
@@ -23,22 +23,6 @@ const URL_QUERY_MAPPING = {
2323
wd: 'hide'
2424
};
2525

26-
function createCustomActivityMiddleware(attachmentLayout) {
27-
return () =>
28-
next =>
29-
(arg0, ...args) =>
30-
next(
31-
{
32-
...arg0,
33-
activity: {
34-
...arg0.activity,
35-
...(attachmentLayout && arg0.activity.from.role === 'bot' ? { attachmentLayout } : {})
36-
}
37-
},
38-
...args
39-
);
40-
}
41-
4226
function generateURL(state) {
4327
const params = {};
4428

@@ -143,7 +127,15 @@ const ActivityGroupingSurface = ({ children }) => {
143127
let directLine;
144128

145129
(async function () {
146-
directLine = await createDirectLineWithTranscript(transcriptName);
130+
directLine = await createDirectLineWithTranscript(transcriptName, {
131+
patchActivity: activity => {
132+
if ((attachmentLayout === 'carousel' || attachmentLayout === 'stacked') && activity.from?.role === 'bot') {
133+
return Object.freeze({ ...activity, attachmentLayout });
134+
}
135+
136+
return activity;
137+
}
138+
});
147139

148140
aborted || setDirectLine(directLine);
149141
})();
@@ -152,15 +144,7 @@ const ActivityGroupingSurface = ({ children }) => {
152144
aborted = true;
153145
directLine && directLine.end();
154146
};
155-
}, [setDirectLine, transcriptName]);
156-
157-
const activityMiddleware = useMemo(
158-
() =>
159-
attachmentLayout === 'carousel' || attachmentLayout === 'stacked'
160-
? createCustomActivityMiddleware(attachmentLayout)
161-
: undefined,
162-
[attachmentLayout]
163-
);
147+
}, [attachmentLayout, setDirectLine, transcriptName]);
164148

165149
const styleOptions = useMemo(
166150
() => ({
@@ -223,7 +207,6 @@ const ActivityGroupingSurface = ({ children }) => {
223207
const context = useMemo(
224208
() => ({
225209
...contextState,
226-
activityMiddleware,
227210
directLine,
228211
setAttachmentLayout,
229212
setBotAvatarInitials,
@@ -242,7 +225,6 @@ const ActivityGroupingSurface = ({ children }) => {
242225
url
243226
}),
244227
[
245-
activityMiddleware,
246228
contextState,
247229
directLine,
248230
setAttachmentLayout,

packages/test/page-object/src/globals/testHelpers/createDirectLineWithTranscript.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ function createUpdateRelativeTimestamp(now, { Date }) {
3636

3737
export default function createDirectLineWithTranscript(
3838
activitiesOrFilename,
39-
{ overridePostActivity, ponyfill: { Date } = { Date: window.Date } } = {}
39+
{ overridePostActivity, patchActivity: patchActivityFromOptions, ponyfill: { Date } = { Date: window.Date } } = {}
4040
) {
4141
const now = Date.now();
42-
const patchActivity = createUpdateRelativeTimestamp(now, { Date });
42+
const patchActivity = activity =>
43+
createUpdateRelativeTimestamp(now, { Date })(
44+
patchActivityFromOptions ? patchActivityFromOptions(activity) : activity
45+
);
4346
const connectionStatusDeferredObservable = createDeferredObservable(() => {
4447
connectionStatusDeferredObservable.next(0);
4548
});

0 commit comments

Comments
 (0)