-
Notifications
You must be signed in to change notification settings - Fork 701
CONSOLE-4989: bump to react-redux 8
#15854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { useMemo, useEffect } from 'react'; | ||
| import { Map as ImmutableMap } from 'immutable'; | ||
| import { useSelector, useDispatch } from 'react-redux'; | ||
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we update to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don't work in the dynamic plugin SDK package because for some reason that package holds its own redux selectors. IIRC when we build SDK packages, type only imports to internal console code (like for console redux store) become broken because it doesn't get automatically copied over. Typically SDK consumers only access console code via dynamic require imports I considered adding a |
||
| import * as k8sActions from '../../../app/k8s/actions/k8s'; | ||
| import { getReduxIdPayload } from '../../../app/k8s/reducers/k8sSelector'; | ||
| import { SDKStoreState } from '../../../app/redux-types'; | ||
| import type { SDKDispatch, SDKStoreState } from '../../../app/redux-types'; | ||
| import { UseK8sWatchResource } from '../../../extensions/console-types'; | ||
| import { getIDAndDispatch, getReduxData, NoModelError } from './k8s-watcher'; | ||
| import { useDeepCompareMemoize } from './useDeepCompareMemoize'; | ||
|
|
@@ -33,7 +33,7 @@ export const useK8sWatchResource: UseK8sWatchResource = (initResource) => { | |
|
|
||
| const reduxID = useMemo(() => getIDAndDispatch(resource, k8sModel), [k8sModel, resource]); | ||
|
|
||
| const dispatch = useDispatch(); | ||
| const dispatch = useDispatch<SDKDispatch>(); | ||
|
|
||
| useEffect(() => { | ||
| if (reduxID) { | ||
|
|
@@ -46,9 +46,9 @@ export const useK8sWatchResource: UseK8sWatchResource = (initResource) => { | |
| }; | ||
| }, [dispatch, reduxID]); | ||
|
|
||
| const resourceK8s = useSelector<SDKStoreState, ImmutableMap<string, any>>((state) => | ||
| const resourceK8s = useSelector<SDKStoreState>((state) => | ||
| reduxID ? getReduxIdPayload(state, reduxID.id) : null, | ||
| ); | ||
| ) as ImmutableMap<string, any>; | ||
|
|
||
| return useMemo(() => { | ||
| if (!resource) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import { useRef, useMemo, useEffect } from 'react'; | ||
| import { Map as ImmutableMap, Iterable as ImmutableIterable } from 'immutable'; | ||
| import { useSelector, useDispatch } from 'react-redux'; | ||
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent with migration pattern: still using react-redux's useSelector. Despite the past review comment being marked as addressed, lines 3 and 141 still import and use 🔎 Apply the migration patternRemove the react-redux import and use console-specific hooks: -import { useDispatch, useSelector } from 'react-redux';
+import { useDispatch } from 'react-redux';
+import { useConsoleSelector } from '@console/shared/src/hooks/useConsoleSelector';Then update line 141: - const resourceK8s = useSelector(resourceK8sSelector);
+ const resourceK8s = useConsoleSelector(resourceK8sSelector);Also applies to: 141-141 🤖 Prompt for AI Agents |
||
| import { createSelectorCreator, defaultMemoize } from 'reselect'; | ||
| import { K8sModel } from '../../../api/common-types'; | ||
| import * as k8sActions from '../../../app/k8s/actions/k8s'; | ||
| import type { SDKDispatch, SDKStoreState } from '../../../app/redux-types'; | ||
| import { UseK8sWatchResources } from '../../../extensions/console-types'; | ||
| import { | ||
| transformGroupVersionKindToReference, | ||
|
|
@@ -38,9 +39,9 @@ export const useK8sWatchResources: UseK8sWatchResources = (initResources) => { | |
| const resources = useDeepCompareMemoize(initResources, true); | ||
| const modelsLoaded = useModelsLoaded(); | ||
|
|
||
| const allK8sModels = useSelector<OpenShiftReduxRootState, ImmutableMap<string, K8sModel>>( | ||
| (state: OpenShiftReduxRootState) => state.k8s.getIn(['RESOURCES', 'models']), | ||
| ); | ||
| const allK8sModels = useSelector<SDKStoreState>((state) => | ||
| state.k8s.getIn(['RESOURCES', 'models']), | ||
| ) as ImmutableMap<string, K8sModel>; | ||
|
|
||
| const prevK8sModels = usePrevious(allK8sModels); | ||
| const prevResources = usePrevious(resources); | ||
|
|
@@ -98,7 +99,7 @@ export const useK8sWatchResources: UseK8sWatchResources = (initResources) => { | |
| [k8sModels, modelsLoaded, resources], | ||
| ); | ||
|
|
||
| const dispatch = useDispatch(); | ||
| const dispatch = useDispatch<SDKDispatch>(); | ||
| useEffect(() => { | ||
| const reduxIDKeys = Object.keys(reduxIDs || {}); | ||
| reduxIDKeys.forEach((k) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { useDispatch } from 'react-redux'; | ||
| import type { AnyAction } from 'redux'; | ||
| import type { ThunkDispatch } from 'redux-thunk'; | ||
| import type { RootState } from '@console/internal/redux'; | ||
|
|
||
| // TODO: When upgrading to react-redux v9, use the built-in `withTypes` method. | ||
| // See: https://github.com/reduxjs/react-redux/releases/tag/v9.1.0 | ||
|
|
||
| /** | ||
| * A hook to access the console redux `dispatch` function. | ||
| * | ||
| * See {@link useDispatch} for more details. | ||
| */ | ||
| export const useConsoleDispatch: () => ThunkDispatch<RootState, undefined, AnyAction> = useDispatch; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { TypedUseSelectorHook, useSelector } from 'react-redux'; | ||
| import type { RootState } from '@console/internal/redux'; | ||
|
|
||
| // TODO: When upgrading to react-redux v9, use the built-in `withTypes` method. | ||
| // See: https://github.com/reduxjs/react-redux/releases/tag/v9.1.0 | ||
|
|
||
| /** | ||
| * A hook to access the console redux state. | ||
| * | ||
| * See {@link useSelector} for more details. | ||
| */ | ||
| export const useConsoleSelector: TypedUseSelectorHook<RootState> = useSelector; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { useStore } from 'react-redux'; | ||
| import type store from '@console/internal/redux'; | ||
|
|
||
| // TODO: When upgrading to react-redux v9, use the built-in `withTypes` method. | ||
| // See: https://github.com/reduxjs/react-redux/releases/tag/v9.1.0 | ||
|
|
||
| /** | ||
| * A hook to access the console redux store. | ||
| * | ||
| * See {@link useStore} for more details. | ||
| */ | ||
| export const useConsoleStore = useStore as () => typeof store; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
react-reduxis Console provided shared module, using the default configi.e. plugins are built with the assumption that Console provides v7 impl. without plugin provided fallback.
So this is effectively a breaking change in Console provided shared modules.