|
| 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