Skip to content

Commit bcb0074

Browse files
committed
feat(notifications)!: remove redux dependency from notifications package
Breaking changes are documented at packages/notifications/doc
1 parent 8f4011a commit bcb0074

33 files changed

+807
-1800
lines changed

config/setupTests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require('@testing-library/jest-dom');
66
const { expect } = require('@jest/globals');
77
const matchers = require('@testing-library/jest-dom/dist/matchers');
88
const MutationObserver = require('mutation-observer');
9+
const crypto = require('crypto');
910

1011
// ensure the expect is picked up from jest not cypress
1112
global.expect = expect;
@@ -15,6 +16,15 @@ global.SVGPathElement = function () {};
1516
// real MutationObserver polyfill for JSDOM
1617
global.MutationObserver = MutationObserver;
1718

19+
// Crypto object polyfill for JSDOM
20+
global.window.crypto = {
21+
...crypto,
22+
}
23+
// in case the cryto package is mangled and the method does not exist
24+
if(!global.window.crypto.randomUUID) {
25+
global.window.crypto.randomUUID = () => Date.now().toString(36) + Math.random().toString(36).slice(2);
26+
}
27+
1828

1929

2030
global.window.insights = {

package-lock.json

Lines changed: 46 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Migration
2+
3+
## V5 to V6 migration
4+
5+
In version 6, the notifications package was decoupled from redux. The package now uses only React api to manage its state.
6+
7+
### Using notifications middleware and redux store
8+
9+
Replace `NotificationsPortal` component with `NotificationsProvider`
10+
11+
```diff
12+
- <NotificationsPortal />
13+
+ <NotificationsProvider />
14+
# Provider can also render children
15+
- <NotificationsPortal />
16+
- {children}
17+
+ <NotificationsProvider>
18+
+ {children}
19+
+ </NotificationsProvider>
20+
```
21+
22+
Remove the notifications middleware from reducer from your store
23+
24+
```diff
25+
- import notificationsMiddleware from '@redhat-cloud-services/frontend-components-notifications/notificationsMiddleware';
26+
- import { notificationsReducer } from '@redhat-cloud-services/frontend-components-notifications/redux';
27+
28+
const middlewares = [
29+
thunk,
30+
promiseMiddleware,
31+
- notificationsMiddleware({
32+
- errorTitleKey: ['statusText', 'message', 'errors[0].status'],
33+
- errorDescriptionKey: ['errors[0].detail', 'errors', 'stack'],
34+
- }),
35+
reduxLogger,
36+
].filter((middleware) => typeof middleware === 'function');
37+
```
38+
39+
#### Notifications middleware
40+
41+
In v6, you can no longer dispatch automated notifications via redux middleware in combination with promise middleware. If you still need this functionality, you will have to implement your own middleware. You can take inspiration from the legacy version.
42+
43+
https://github.com/RedHatInsights/frontend-components/blob/pf4%405/packages/notifications/src/notificationsMiddleware/notificationsMiddleware.ts
44+
45+
In addition to custom integration, the internal notification store, has to be accessible from outside of the react context. You can create a store instance and pass it directly to your notifications provider. You can then use the store outside of react components.
46+
47+
```jsx
48+
import { createStore } from '@redhat-cloud-services/frontend-components-notifications/state';
49+
50+
const store = createStore()
51+
52+
<NotificationsProvider store={store} />
53+
54+
// use the store in your middleware integration
55+
56+
const customMiddleware = api => next => action => {
57+
// handle the action
58+
if(action.type.includes('_REJECTED')) {
59+
store.addNotification({
60+
title: action.error.title,
61+
description: action.error.description,
62+
variant: 'danger',
63+
})
64+
}
65+
66+
return next(action)
67+
}
68+
```

0 commit comments

Comments
 (0)