Skip to content

Commit c59e6ed

Browse files
authored
Clean up middleware signature (#5504)
* Clean up middleware signature * Cleaner ~types * Remove init and clean types * Use createMiddleware * Use createXXXMiddleware * Use createXXXMiddleware * Export schema * Move to props schema * Sort import * Add enhancer function check * Add more checks * Clean up * Add comment * Better middleware array check * Fix test * Fix flaky test * Better typing * Better types * Clean up * Update warning message * Clean up * Add entry * Remove comment * Typo * Mark middleware as readonly * Remove return
1 parent eab9284 commit c59e6ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+558
-450
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
3434
- If you customized `renderMarkdown` with a custom HTML sanitizer, please move the HTML sanitizer to the new HTML content transformer middleware
3535
- `useGroupActivities` hook is being deprecated in favor of the `useGroupActivitiesByName` hook. The hook will be removed on or after 2027-05-04
3636
- `useSuggestedActions()` hook is being deprecated in favor of the `useSuggestedActionsHooks().useSuggestedActions()` hook. The hook will be removed on or after 2027-05-30
37+
- The following middleware should be created using their respective factory function:
38+
- `activityBorderDecoratorMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
39+
- `activityGroupingDecoratorMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
40+
- `sendBoxMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
41+
- `sendBoxToolbarMiddleware`, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
3742

3843
### Added
3944

@@ -329,7 +334,8 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
329334
- `useSendMessage` hook is updated to support sending attachments with a message
330335
- `useSendBoxAttachments` hook is added to get/set attachments in the send box
331336
- Resolves [#5081](https://github.com/microsoft/BotFramework-WebChat/issues/5081). Added `uploadAccept` and `uploadMultiple` style options, by [@ms-jb](https://github.com/ms-jb), in PR [#5048](https://github.com/microsoft/BotFramework-WebChat/pull/5048)
332-
- Added `sendBoxMiddleware` and `sendBoxToolbarMiddleware`, by [@compulim](https://github.com/compulim), in PR [#5120](https://github.com/microsoft/BotFramework-WebChat/pull/5120)
337+
- Added `sendBoxMiddleware` and `sendBoxToolbarMiddleware`, by [@compulim](https://github.com/compulim), in PR [#5120](https://github.com/microsoft/BotFramework-WebChat/pull/5120) and [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
338+
- Instead of passing barebone middleware, use the `createSendBoxMiddleware()` and `createSendBoxToolbarMiddleware()` factory function correspondingly, related to PR [#5504](https://github.com/microsoft/BotFramework-WebChat/pull/5504)
333339
- (Experimental) Added `botframework-webchat-fluent-theme` package for applying Fluent UI theme to Web Chat, by [@compulim](https://github.com/compulim) and [@OEvgeny](https://github.com/OEvgeny)
334340
- Initial commit, in PR [#5120](https://github.com/microsoft/BotFramework-WebChat/pull/5120)
335341
- Inherits Fluent CSS palette if available, in PR [#5122](https://github.com/microsoft/BotFramework-WebChat/pull/5122)

__tests__/html/fluentTheme/withCustomDecorator.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
React,
2929
ReactDOM: { render },
3030
WebChat: {
31-
decorator: { DecoratorComposer },
31+
decorator: { createActivityBorderMiddleware, DecoratorComposer },
3232
FluentThemeProvider,
3333
ReactWebChat
3434
}
@@ -43,12 +43,12 @@
4343
}
4444

4545
const decoratorMiddleware = [
46-
init =>
47-
init === 'activity border' &&
48-
(next => request => (request.livestreamingState === 'completing' ? Flair : next(request))),
49-
init =>
50-
init === 'activity border' &&
51-
(next => request => (request.livestreamingState === 'preparing' ? Loader : next(request)))
46+
createActivityBorderMiddleware(
47+
next => request => (request.livestreamingState === 'completing' ? Flair : next(request))
48+
),
49+
createActivityBorderMiddleware(
50+
next => request => (request.livestreamingState === 'preparing' ? Loader : next(request))
51+
)
5252
];
5353

5454
const { directLine, store } = testHelpers.createDirectLineEmulator();

__tests__/html/sendBoxMiddleware/warnIfInvalid.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
await pageConditions.uiConnected();
1919

2020
// THEN: It should warn about the invalid middleware.
21-
await pageConditions.warnMessageLogged('"sendBoxMiddleware" prop is invalid.');
21+
await pageConditions.warnMessageLogged('must be an array of function');
2222

2323
// THEN: It should render the default send box.
2424
await host.snapshot();

__tests__/html/sendBoxToolbarMiddleware/warnIfInvalid.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
await pageConditions.uiConnected();
1919

2020
// THEN: It should warn about the invalid middleware.
21-
await pageConditions.warnMessageLogged('"sendBoxToolbarMiddleware" prop is invalid.');
21+
await pageConditions.warnMessageLogged('must be an array of function');
2222

2323
// THEN: It should render the default send box.
2424
await host.snapshot();

__tests__/html2/feedbackForm/behavior.resetByEscapeKey.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494
// WHEN: Feedback form is opened.
9595
document.querySelector(`[data-testid="${testIds.sendBoxTextBox}"]`).focus();
9696
await host.sendShiftTab(3);
97-
await host.sendKeys('UP', 'ENTER', 'RIGHT', 'SPACE');
97+
98+
// WHEN: Select the activity, then press right arrow key to select the dislike button (radio button).
99+
await host.sendKeys('UP', 'ENTER', 'RIGHT');
98100

99101
// THEN: The dislike button should be pressed.
100102
expect(Array.from(pageElements.allByTestId(testIds.feedbackButton)).map(element => element.checked)).toEqual([

__tests__/html2/feedbackForm/feedback.form.activity.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
// THEN: Should match snapshot.
9494
await host.snapshot('local');
9595

96-
// WHEN: Click on dislike button to re-open feedback form
97-
await host.sendKeys('RIGHT', 'SPACE');
96+
// WHEN: Press right arrow key to select the dislike button (radio button).
97+
await host.sendKeys('RIGHT');
9898

9999
await pageConditions.became(
100100
'feedback form is open',

__tests__/html2/grouping/customGrouping.html

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232

3333
const {
3434
React: { createElement },
35-
WebChat: { renderWebChat }
35+
WebChat: {
36+
decorator: { createActivityGroupingMiddleware },
37+
renderWebChat
38+
}
3639
} = window; // Imports in UMD fashion.
3740

3841
const clock = lolex.createClock();
@@ -62,22 +65,20 @@
6265
: undefined;
6366

6467
const decoratorMiddleware = [
65-
init =>
66-
init === 'activity grouping' &&
67-
(next => request => {
68-
const DownstreamComponent = next(request);
69-
70-
if (request.groupingName) {
71-
return ({ activities, children }) =>
72-
createElement(
73-
'div',
74-
{ className: `grouping grouping--${request.groupingName}` },
75-
createElement(DownstreamComponent, { activities }, children)
76-
);
77-
}
68+
createActivityGroupingMiddleware(next => request => {
69+
const DownstreamComponent = next(request);
70+
71+
if (request.groupingName) {
72+
return ({ activities, children }) =>
73+
createElement(
74+
'div',
75+
{ className: `grouping grouping--${request.groupingName}` },
76+
createElement(DownstreamComponent, { activities }, children)
77+
);
78+
}
7879

79-
return DownstreamComponent;
80-
})
80+
return DownstreamComponent;
81+
})
8182
];
8283

8384
renderWebChat(

__tests__/html2/grouping/disableAll.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,31 @@
1616
run(async function () {
1717
const {
1818
React: { createElement },
19-
WebChat: { renderWebChat }
19+
WebChat: {
20+
decorator: { createActivityGroupingMiddleware },
21+
renderWebChat
22+
}
2023
} = window; // Imports in UMD fashion.
2124

2225
const clock = lolex.createClock();
2326

2427
const { directLine, store } = testHelpers.createDirectLineEmulator({ ponyfill: clock });
2528

2629
const decoratorMiddleware = [
27-
init =>
28-
init === 'activity grouping' &&
29-
(next => request => {
30-
const DownstreamComponent = next(request);
31-
32-
if (request.groupingName) {
33-
return ({ activities, children }) =>
34-
createElement(
35-
'div',
36-
{ className: `grouping grouping--${request.groupingName}` },
37-
createElement(DownstreamComponent, { activities }, children)
38-
);
39-
}
40-
41-
return DownstreamComponent;
42-
})
30+
createActivityGroupingMiddleware(next => request => {
31+
const DownstreamComponent = next(request);
32+
33+
if (request.groupingName) {
34+
return ({ activities, children }) =>
35+
createElement(
36+
'div',
37+
{ className: `grouping grouping--${request.groupingName}` },
38+
createElement(DownstreamComponent, { activities }, children)
39+
);
40+
}
41+
42+
return DownstreamComponent;
43+
})
4344
];
4445

4546
renderWebChat(

__tests__/html2/grouping/disableSender.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,31 @@
1616
run(async function () {
1717
const {
1818
React: { createElement },
19-
WebChat: { renderWebChat }
19+
WebChat: {
20+
decorator: { createActivityGroupingMiddleware },
21+
renderWebChat
22+
}
2023
} = window; // Imports in UMD fashion.
2124

2225
const clock = lolex.createClock();
2326

2427
const { directLine, store } = testHelpers.createDirectLineEmulator({ ponyfill: clock });
2528

2629
const decoratorMiddleware = [
27-
init =>
28-
init === 'activity grouping' &&
29-
(next => request => {
30-
const DownstreamComponent = next(request);
31-
32-
if (request.groupingName) {
33-
return ({ activities, children }) =>
34-
createElement(
35-
'div',
36-
{ className: `grouping grouping--${request.groupingName}` },
37-
createElement(DownstreamComponent, { activities }, children)
38-
);
39-
}
40-
41-
return DownstreamComponent;
42-
})
30+
createActivityGroupingMiddleware(next => request => {
31+
const DownstreamComponent = next(request);
32+
33+
if (request.groupingName) {
34+
return ({ activities, children }) =>
35+
createElement(
36+
'div',
37+
{ className: `grouping grouping--${request.groupingName}` },
38+
createElement(DownstreamComponent, { activities }, children)
39+
);
40+
}
41+
42+
return DownstreamComponent;
43+
})
4344
];
4445

4546
renderWebChat(

__tests__/html2/grouping/disableStatus.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,31 @@
1616
run(async function () {
1717
const {
1818
React: { createElement },
19-
WebChat: { renderWebChat }
19+
WebChat: {
20+
decorator: { createActivityGroupingMiddleware },
21+
renderWebChat
22+
}
2023
} = window; // Imports in UMD fashion.
2124

2225
const clock = lolex.createClock();
2326

2427
const { directLine, store } = testHelpers.createDirectLineEmulator({ ponyfill: clock });
2528

2629
const decoratorMiddleware = [
27-
init =>
28-
init === 'activity grouping' &&
29-
(next => request => {
30-
const DownstreamComponent = next(request);
31-
32-
if (request.groupingName) {
33-
return ({ activities, children }) =>
34-
createElement(
35-
'div',
36-
{ className: `grouping grouping--${request.groupingName}` },
37-
createElement(DownstreamComponent, { activities }, children)
38-
);
39-
}
40-
41-
return DownstreamComponent;
42-
})
30+
createActivityGroupingMiddleware(next => request => {
31+
const DownstreamComponent = next(request);
32+
33+
if (request.groupingName) {
34+
return ({ activities, children }) =>
35+
createElement(
36+
'div',
37+
{ className: `grouping grouping--${request.groupingName}` },
38+
createElement(DownstreamComponent, { activities }, children)
39+
);
40+
}
41+
42+
return DownstreamComponent;
43+
})
4344
];
4445

4546
renderWebChat(

0 commit comments

Comments
 (0)