CONSOLE-4990: Replace history object navigation with useNavigate hook#15959
CONSOLE-4990: Replace history object navigation with useNavigate hook#15959rhamilto wants to merge 8 commits intoopenshift:mainfrom
Conversation
|
Skipping CI for Draft Pull Request. |
|
@rhamilto: This pull request references CONSOLE-4990 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhamilto The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
frontend/packages/console-app/src/actions/providers/cronjob-provider.ts
Outdated
Show resolved
Hide resolved
frontend/packages/console-shared/src/components/dynamic-form/index.tsx
Outdated
Show resolved
Hide resolved
frontend/packages/console-shared/src/components/quick-search/QuickSearchContent.tsx
Outdated
Show resolved
Hide resolved
frontend/packages/console-shared/src/components/quick-search/QuickSearchDetails.tsx
Show resolved
Hide resolved
frontend/packages/dev-console/src/components/edit-application/EditApplication.tsx
Outdated
Show resolved
Hide resolved
frontend/packages/operator-lifecycle-manager/src/components/operator-hub/operator-hub-items.tsx
Outdated
Show resolved
Hide resolved
fab6845 to
4c78f4b
Compare
|
@rhamilto: This pull request references CONSOLE-4990 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
738897a to
b7a45bf
Compare
Test File RemovedRemoved
The test file has been reverted to its original state and is no longer part of this PR. |
|
/retest |
|
It looks like we should not reload everything when switching between resource tabs(this issue is not reproducible on 4.22.0-0.ci-2026-02-09-205844) console-reload-on-switching-tabs.mov |
Replace history object usage with useNavigate hook in console-shared package. Changes: - ActionMenuItem.tsx: Replace history.push with navigate - CatalogTile.tsx: Replace history.push with navigate - CatalogView.tsx: Replace history.push with navigate - catalog-utils.tsx: Accept NavigateFunction as parameter - dynamic-form/index.tsx: Replace history.goBack with navigate(-1) - error-boundary.tsx: Use componentDidUpdate instead of key prop for location-based reset - DeleteResourceModal.tsx: Replace history.push with navigate - MultiTabListPage.tsx: Replace history.push with navigate Migration patterns: - Components: Added useNavigate() hook - Utilities: Parameter injection for NavigateFunction - ErrorBoundary: Pass locationPathname as prop and use componentDidUpdate to reset error state only when there's an active error AND location changes. This avoids unnecessary component remounting during tab navigation. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
057efc3 to
3f29d8e
Compare
|
@rhamilto: This pull request references CONSOLE-4990 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Bug Fix AppliedI've fixed the issue reported by @yapei where switching between resource tabs was causing everything to reload. Root Cause: The Fix: Changed the implementation to pass
This preserves the error reset behavior while avoiding unnecessary component remounting. Changes: The fix has been squashed into commit All tests pass ✅ |
|
/retest |
|
@yapei: This PR has been marked as verified by DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Replace history object usage with useNavigate hook in dev-console package. Changes: - AddCardItem.tsx: Pass navigate to navigateTo utility - EditBuildConfig.tsx: Replace history.push with navigate - EditDeployment.tsx: Replace history.push with navigate - EditApplication.tsx: Replace history.goBack with navigate(-1) - AddHealthChecks.tsx: Replace history.push with navigate - AddHealthChecksForm.tsx: Replace history.goBack with navigate(-1) - HPAFormikForm.tsx: Replace history.goBack with navigate(-1) - DeployImage.tsx: Pass navigate to handleRedirect - ImportForm.tsx: Pass navigate to handleRedirect - ImportSamplePage.tsx: Pass navigate to handleRedirect - import-submit-utils.ts: Accept NavigateFunction parameter - UploadJar.tsx: Replace history.goBack with navigate(-1) - useUploadJarFormToast.ts: Accept navigate as parameter - AddServerlessFunction.tsx: Replace history.goBack with navigate(-1) - jar-file-upload-utils.ts: Accept navigate as parameter - MonitoringPage.tsx: Replace history.push with navigate - ProjectDetailsPage.tsx: Replace history.push with navigate - add-page-utils.ts: Accept navigate as parameter All utility functions updated to use dependency injection pattern. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace history object usage with useNavigate hook in knative-plugin package. Changes: - EventSink.tsx: Replace history.goBack with navigate(-1) - EventSource.tsx: Replace history.goBack with navigate(-1) - AddBroker.tsx: Replace history.goBack with navigate(-1) - AddChannel.tsx: Replace history.goBack with navigate(-1) - Subscribe.tsx: Replace history.push with navigate - FunctionDetailsPage.tsx: Replace history.push with navigate - CreateKnatifyPage.tsx: Replace history.goBack with navigate(-1) - create-eventsources-utils.ts: Accept NavigateFunction parameter All components updated to use useNavigate() hook. Utility function updated to use dependency injection pattern. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace history object usage with useNavigate hook in helm-plugin package. Changes: - HelmReleaseDetailsPage.tsx: Replace history.push with navigate - CreateHelmChartRepository.tsx: Replace history.goBack with navigate(-1) - CreateHelmChartRepositoryPage.tsx: Replace history.push with navigate - HelmInstallUpgradePage.tsx: Replace history.push/goBack with navigate - HelmReleaseRollbackPage.tsx: Replace history.push/goBack with navigate All components updated to use useNavigate() hook from react-router-dom-v5-compat. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace history object usage with useNavigate hook in operator-lifecycle-manager package. Changes: - create-catalog-source.tsx: Replace history.goBack with navigate(-1) - operator-hub-items.tsx: Replace history.replace with navigate - operator-hub-subscribe.tsx: Replace history.push with navigate - install-plan.tsx: Replace history.push with navigate - uninstall-operator-modal.tsx: Replace history.push with navigate - operand-form.tsx: Replace history.push/replace/goBack with navigate - DEPRECATED_operand-form.tsx: Replace history.push/goBack with navigate - subscription.tsx: Replace history.push with navigate All components updated to use useNavigate() hook from react-router-dom-v5-compat. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace history object usage with useNavigate hook in remaining packages. Changes: - topology/ExportViewLogButton.tsx: Replace history.push with navigate - shipwright-plugin/EditBuild.tsx: Replace history.push/goBack with navigate - metal3-plugin/AddBareMetalHost.tsx: Replace history.push with navigate - metal3-plugin/AddBareMetalHostForm.tsx: Replace history.goBack with navigate(-1) - public/QuickCreate.tsx: Replace history.push with navigate - public/attach-storage.tsx: Remove unused history type definition All components updated to use useNavigate() hook from react-router-dom-v5-compat. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace `LocationDescriptor` and `Location` types from the history package with `To` and `Location` types from react-router-dom-v5-compat. This is part of the migration to programmatic navigation using React Router hooks instead of the history object. Changes: - Replace LocationDescriptor with To in console-types.ts (SDK) - Replace LocationDescriptor with To in delete-modal.tsx - Replace History.LocationDescriptor with To in LinkStatus.tsx - Replace Location import in telemetry.ts Breaking Change: The UseDeleteModal hook's redirectTo parameter type has changed from LocationDescriptor (history) to To (react-router-dom). Plugin developers should update their imports accordingly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3f29d8e to
2f4ced5
Compare
|
Pushed a test fix. |
|
@rhamilto: The DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/verified by @rhamilto |
|
@rhamilto: This PR has been marked as verified by DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/retest |
|
@rhamilto: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
tech debt |
Summary
This PR completes the migration from the deprecated
historyobject to React Router'suseNavigatehook across all remaining packages in the OpenShift Console frontend.Changes
This PR migrates all remaining instances of the deprecated
historyobject to use theuseNavigatehook fromreact-router-dom-v5-compat, except for:public/components/app.tsx(will be handled in CONSOLE-4392)public/components/factory/modal.tsx(will be handled in CONSOLE-5012)Packages Migrated
console-app
useNavigatehookconsole-shared
useNavigatehooklocation.pathnameas akeyprop (which caused component remounting on every URL change) to passing it as a regular prop and usingcomponentDidUpdateto reset error state only when there's an active error AND the location changes. This prevents unnecessary component remounting during tab navigation.dev-console
ProjectAccess.tsx: Replacehistory.goBackwithnavigate(-1)ProjectAccess.spec.tsx: Updated test mocks (removed obsoletehistorymock, addeduseNavigatemock)knative-plugin
DeleteRevisionModalController.tsx: Replacehistory.push()withnavigate()helm-plugin
useNavigatehookoperator-lifecycle-manager
create-catalog-source.tsx: Replacehistory.goBackwithnavigate(-1)operator-hub-items.tsx: Replacehistory.replacewithnavigateoperator-hub-subscribe.tsx: Replacehistory.pushwithnavigateinstall-plan.tsx: Replacehistory.pushwithnavigateuninstall-operator-modal.tsx: Replacehistory.pushwithnavigateoperand-form.tsx: Replacehistory.push/replace/goBackwith navigate equivalentsDEPRECATED_operand-form.tsx: Replacehistory.push/goBackwith navigate equivalentssubscription.tsx: Replacehistory.pushwithnavigatemetal3-plugin
AddBareMetalHost.tsx: Replacehistory.push()withnavigate()public/components
attach-storage.tsx: Removed unusedhistory: Historytype definitionTest Updates
ProjectAccess.spec.tsxto remove the obsoletehistorymock and add properuseNavigatemockMigration Patterns Used
All migrations follow the established patterns:
history.push(path)→navigate(path)history.replace(path)→navigate(path, { replace: true })history.goBack()→navigate(-1)useNavigate()hook imports fromreact-router-dom-v5-compatCommit Structure
The commits are organized by package for easier review:
CONSOLE-4990: Migrate console-app to useNavigate hookCONSOLE-4990: Migrate console-shared to useNavigate hookCONSOLE-4990: Migrate dev-console to useNavigate hookCONSOLE-4990: Migrate knative-plugin to useNavigate hookCONSOLE-4990: Migrate helm-plugin to useNavigate hookCONSOLE-4990: Migrate operator-lifecycle-manager to useNavigate hookCONSOLE-4990: Migrate remaining packages to useNavigate hookCONSOLE-4990: Replace history types with React Router typesBug Fix
Fixed resource tab navigation causing full page reloads (#15959 (comment))
The ErrorBoundary component was using
location.pathnameas akeyprop, which caused the entire component tree to remount whenever the URL changed. This resulted in:Solution: Changed to pass
locationPathnameas a prop and usecomponentDidUpdateto reset error state only when there's an active error AND the location changes. This preserves the error reset behavior while avoiding unnecessary remounts.Related Issues
Testing
useNavigate()hookCo-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com