-
Notifications
You must be signed in to change notification settings - Fork 14
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
NETOBSERV-1097 react-router-dom upgrade with dynamic loader #350
Merged
openshift-merge-robot
merged 4 commits into
netobserv:main
from
jpinsonneau:1097_dynamic
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import * as React from 'react'; | ||
import * as reactRouterDom from 'react-router-dom'; | ||
|
||
/** | ||
* useHistory is deprecated and not available anymore in react-router 6+ | ||
* This function allow retro compatibility between useHistory and useNavigate | ||
* by switching from one to the other | ||
*/ | ||
type NavFunc = (to: string, opts?: any) => void; | ||
let navFunc: NavFunc | null = null; | ||
|
||
export const setNavFunction = (f: NavFunc) => { | ||
navFunc = f; | ||
}; | ||
|
||
export const navigate = (to: string, opts?: any) => { | ||
if (navFunc) { | ||
navFunc(to, opts); | ||
} else { | ||
console.error('navigate error; navFunc is not initialized', navFunc); | ||
} | ||
}; | ||
|
||
export const DynamicLoader: React.FC<{}> = ({ children }) => { | ||
const genericReactRouterDom = reactRouterDom as any; | ||
if (genericReactRouterDom['useNavigate']) { | ||
console.log('loading nav function from react-router useNavigate'); | ||
setNavFunction(genericReactRouterDom['useNavigate']()); | ||
} else if (genericReactRouterDom['useHistory']) { | ||
console.log('loading nav function from react-router useHistory'); | ||
setNavFunction(genericReactRouterDom['useHistory']().push); | ||
} else { | ||
console.error("can't load nav function from react-router"); | ||
} | ||
return <>{!!children ? children : ''}</>; | ||
}; | ||
|
||
export default DynamicLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { clearURLParams } from '../utils/url'; | |
import { clearLocalStorage } from '../utils/local-storage-hook'; | ||
import NetflowTraffic from './netflow-traffic'; | ||
import AlertFetcher from './alerts/fetcher'; | ||
import DynamicLoader from './dynamic-loader/dynamic-loader'; | ||
|
||
type Props = {}; | ||
type State = { | ||
|
@@ -52,9 +53,11 @@ class NetflowTrafficParent extends React.Component<Props, State> { | |
// else render default NetworkTraffic | ||
|
||
return ( | ||
<AlertFetcher> | ||
<NetflowTraffic forcedFilters={null} /> | ||
</AlertFetcher> | ||
<DynamicLoader> | ||
<AlertFetcher> | ||
<NetflowTraffic forcedFilters={null} /> | ||
</AlertFetcher> | ||
</DynamicLoader> | ||
Comment on lines
+56
to
+60
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.
|
||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
useNavigate
is the preferred hook and will be taken from the import if available.If not,
reactRouterDom.useNavigate
equals0
and it fallback onuseHistory.push
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.
Just tested on my 4.13 cluster and it uses
useHistory
. I guess I should spin up a 4.14 to test useNavigate?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.
useNavigate
will be used only when console plugin team will finish the migration introducing v6 API.react-router-dom-v5-compat
with v6 capabilities using this compat lib. Since we don't import it it will still rely on v5 apiuseNavigate
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.
https://redhat-internal.slack.com/archives/C011BL0FEKZ/p1687957240461039