diff --git a/apps/assisted-ui/package.json b/apps/assisted-ui/package.json index 3a8d5b2020..c8eebc537e 100644 --- a/apps/assisted-ui/package.json +++ b/apps/assisted-ui/package.json @@ -22,6 +22,7 @@ "react-monaco-editor": "^0.55.0", "react-redux": "^8.0.5", "react-router-dom": "^5.3.3", + "react-router-dom-v5-compat": "^6.21.2", "react-tagsinput": "^3.20", "redux": "^4", "uuid": "^8.1", @@ -31,7 +32,6 @@ "devDependencies": { "@tsconfig/vite-react": "^1.0.1", "@types/react": "17.0.x", - "@types/react-router-dom": "^5.3.3", "@vitejs/plugin-react-swc": "^3.0.1", "vite": "^4.5.3", "vite-plugin-environment": "^1.1.3" diff --git a/apps/assisted-ui/src/components/App.tsx b/apps/assisted-ui/src/components/App.tsx index 5c789c7726..d7df97cf23 100755 --- a/apps/assisted-ui/src/components/App.tsx +++ b/apps/assisted-ui/src/components/App.tsx @@ -1,19 +1,22 @@ import type React from 'react'; -import { BrowserRouter, Route } from 'react-router-dom'; +import { BrowserRouter } from 'react-router-dom'; +import { CompatRouter, Route } from 'react-router-dom-v5-compat'; import { Page } from '@patternfly/react-core'; import * as OCM from '@openshift-assisted/ui-lib/ocm'; import { Header } from './Header'; import '../i18n'; -const { HostsClusterDetailTabMock, Routes, Features, Config } = OCM; +const { HostsClusterDetailTabMock, UILibRoutes, Features, Config } = OCM; window.__app__ = { OCM }; export const App: React.FC = () => ( - } isManagedSidebar defaultManagedSidebarIsOpen={false}> - - - - + + } isManagedSidebar defaultManagedSidebarIsOpen={false}> + + } /> + + + ); diff --git a/libs/ui-lib/lib/cim/components/Agent/NoAgentsAlert.tsx b/libs/ui-lib/lib/cim/components/Agent/NoAgentsAlert.tsx index 14dce25c26..2da665f1fd 100644 --- a/libs/ui-lib/lib/cim/components/Agent/NoAgentsAlert.tsx +++ b/libs/ui-lib/lib/cim/components/Agent/NoAgentsAlert.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { Alert, AlertVariant, List, ListComponent, ListItem } from '@patternfly/react-core'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router-dom-v5-compat'; import { useTranslation } from '../../../common/hooks/use-translation-wrapper'; import { Trans } from 'react-i18next'; import { CpuArchitecture } from '../../../common'; diff --git a/libs/ui-lib/lib/cim/components/Agent/tableUtils.tsx b/libs/ui-lib/lib/cim/components/Agent/tableUtils.tsx index e9e00d2c3f..0c1025cc88 100644 --- a/libs/ui-lib/lib/cim/components/Agent/tableUtils.tsx +++ b/libs/ui-lib/lib/cim/components/Agent/tableUtils.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { sortable, expandable, breakWord } from '@patternfly/react-table'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router-dom-v5-compat'; import { HostsTableActions, diff --git a/libs/ui-lib/lib/cim/components/Hypershift/DetailsPage/NodePoolsTable.tsx b/libs/ui-lib/lib/cim/components/Hypershift/DetailsPage/NodePoolsTable.tsx index 94ac8eb68d..a78a6bbcf3 100644 --- a/libs/ui-lib/lib/cim/components/Hypershift/DetailsPage/NodePoolsTable.tsx +++ b/libs/ui-lib/lib/cim/components/Hypershift/DetailsPage/NodePoolsTable.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router-dom-v5-compat'; import { Button, Label, Popover, Stack, StackItem } from '@patternfly/react-core'; import { PlusCircleIcon } from '@patternfly/react-icons/dist/js/icons/plus-circle-icon'; import { diff --git a/libs/ui-lib/lib/cim/components/InfraEnv/AddHostDropdown.tsx b/libs/ui-lib/lib/cim/components/InfraEnv/AddHostDropdown.tsx index 9cb5b7fc18..5eb812fad5 100644 --- a/libs/ui-lib/lib/cim/components/InfraEnv/AddHostDropdown.tsx +++ b/libs/ui-lib/lib/cim/components/InfraEnv/AddHostDropdown.tsx @@ -14,7 +14,7 @@ import { AddHostDropdownProps } from './types'; import './AddHostDropdown.css'; import { PopoverIcon } from '../../../common'; import { Trans } from 'react-i18next'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router-dom-v5-compat'; type ModalType = 'iso' | 'bmc' | 'yaml' | 'ipxe' | undefined; diff --git a/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimConfigProgressAlert.tsx b/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimConfigProgressAlert.tsx index 0ee0becccb..b9b9bddac2 100644 --- a/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimConfigProgressAlert.tsx +++ b/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimConfigProgressAlert.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { useHistory } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom-v5-compat'; import { Alert, AlertVariant, @@ -26,7 +26,7 @@ export const CimConfigProgressAlert: React.FC = ({ assistedServiceDeploymentUrl, }) => { const { t } = useTranslation(); - const history = useHistory(); + const navigate = useNavigate(); const [hideSuccess, setHideSuccess] = React.useState(true); React.useEffect( @@ -68,7 +68,7 @@ export const CimConfigProgressAlert: React.FC = ({ variant={ButtonVariant.link} isInline key="assisted-service-deployment" - onClick={() => history.push(assistedServiceDeploymentUrl)} + onClick={() => navigate(assistedServiceDeploymentUrl)} > {t('ai:Troubleshoot in the assisted service deployment')} diff --git a/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimStorageMissingAlert.tsx b/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimStorageMissingAlert.tsx index c003176d5c..3358f50205 100644 --- a/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimStorageMissingAlert.tsx +++ b/libs/ui-lib/lib/cim/components/modals/CimConfiguration/CimStorageMissingAlert.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { useHistory } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom-v5-compat'; import { Alert, AlertActionLink, AlertVariant } from '@patternfly/react-core'; import { ExternalLinkAltIcon } from '@patternfly/react-icons/dist/js/icons/external-link-alt-icon'; @@ -10,7 +10,7 @@ export const CimStorageMissingAlert: React.FC<{ storageOperatorUrl: string; }> = ({ docStorageUrl, storageOperatorUrl }) => { const { t } = useTranslation(); - const history = useHistory(); + const navigate = useNavigate(); const contentWorkaround = ( <> @@ -20,10 +20,7 @@ export const CimStorageMissingAlert: React.FC<{ ); const actionLinks: React.ReactNode[] = [ - history.push(storageOperatorUrl)} - > + navigate(storageOperatorUrl)}> {t('ai:Install storage operator')} , window.open(docStorageUrl, '_blank')}> diff --git a/libs/ui-lib/lib/cim/components/modals/MassDeleteAgentModal.tsx b/libs/ui-lib/lib/cim/components/modals/MassDeleteAgentModal.tsx index ce2a83f302..42daf6455a 100644 --- a/libs/ui-lib/lib/cim/components/modals/MassDeleteAgentModal.tsx +++ b/libs/ui-lib/lib/cim/components/modals/MassDeleteAgentModal.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { Button, Flex, FlexItem, Popover } from '@patternfly/react-core'; import { InfoCircleIcon } from '@patternfly/react-icons/dist/js/icons/info-circle-icon'; -import { Link } from 'react-router-dom'; +import { Link } from 'react-router-dom-v5-compat'; import { sortable } from '@patternfly/react-table'; import { global_palette_blue_300 as blueInfoColor } from '@patternfly/react-tokens/dist/js/global_palette_blue_300'; import { diff --git a/libs/ui-lib/lib/ocm/components/HostsClusterDetailTab/HostsClusterDetailTabMock.tsx b/libs/ui-lib/lib/ocm/components/HostsClusterDetailTab/HostsClusterDetailTabMock.tsx index bd95a35d31..53f95a3cfe 100644 --- a/libs/ui-lib/lib/ocm/components/HostsClusterDetailTab/HostsClusterDetailTabMock.tsx +++ b/libs/ui-lib/lib/ocm/components/HostsClusterDetailTab/HostsClusterDetailTabMock.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { RouteComponentProps } from 'react-router-dom'; import { ButtonVariant, EmptyState, @@ -9,7 +8,6 @@ import { PageSectionVariants, EmptyStateHeader, } from '@patternfly/react-core'; -import { HostsClusterDetailTabProps } from './types'; import { OcmCpuArchitecture, STANDALONE_DEPLOYMENT_ENABLED_FEATURES, @@ -44,9 +42,7 @@ const getCluster = (type: string) => { } }; -export const HostsClusterDetailTabMock: React.FC< - RouteComponentProps & HostsClusterDetailTabProps -> = () => { +export const HostsClusterDetailTabMock = () => { const [tabShown, setTabShown] = React.useState(''); const [isMocked, setIsMocked] = React.useState(false); diff --git a/libs/ui-lib/lib/ocm/components/Routes.tsx b/libs/ui-lib/lib/ocm/components/Routes.tsx index c5224d9ac4..78c270e54a 100644 --- a/libs/ui-lib/lib/ocm/components/Routes.tsx +++ b/libs/ui-lib/lib/ocm/components/Routes.tsx @@ -1,29 +1,33 @@ import React from 'react'; import { Provider } from 'react-redux'; -import { Switch, Route, Redirect } from 'react-router-dom'; +import { Routes, Route, Navigate, Outlet } from 'react-router-dom-v5-compat'; import { Clusters, ClusterPage, NewClusterPage } from './clusters'; import type { FeatureListType } from '../../common/features/featureGate'; -import { routeBasePath } from '../config'; import { AssistedUILibVersion } from './ui'; import { storeDay1 } from '../store'; import { useFeatureDetection } from '../hooks/use-feature-detection'; -export const Routes: React.FC<{ allEnabledFeatures: FeatureListType }> = ({ +export const UILibRoutes = ({ allEnabledFeatures, children, +}: { + allEnabledFeatures: FeatureListType; + children?: React.ReactNode; }) => { useFeatureDetection(allEnabledFeatures); return ( - - - - + + }> + } /> + } /> + } /> + {children} - - + } /> + ); }; diff --git a/libs/ui-lib/lib/ocm/components/clusterDetail/AssistedInstallerDetailCard.tsx b/libs/ui-lib/lib/ocm/components/clusterDetail/AssistedInstallerDetailCard.tsx index fea2a67fb1..363d2b7aaf 100644 --- a/libs/ui-lib/lib/ocm/components/clusterDetail/AssistedInstallerDetailCard.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterDetail/AssistedInstallerDetailCard.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { Provider } from 'react-redux'; import { Card, CardBody, CardHeader, Title } from '@patternfly/react-core'; import { storeDay1 } from '../../store'; -import { OCM_CLUSTER_LIST_LINK } from '../../config'; import { AlertsContextProvider, AssistedInstallerOCMPermissionTypesListType, @@ -29,8 +28,8 @@ import { NewFeatureSupportLevelProvider } from '../featureSupportLevels'; import { usePullSecret } from '../../hooks'; import { Cluster } from '@openshift-assisted/types/assisted-installer-service'; import { useFeatureDetection } from '../../hooks/use-feature-detection'; -import { BrowserRouter } from 'react-router-dom'; import { OpenshiftVersionsContextProvider } from '../clusterWizard/OpenshiftVersionsContext'; +import { BrowserRouter } from 'react-router-dom-v5-compat'; type AssistedInstallerDetailCardProps = { aiClusterId: string; @@ -65,7 +64,7 @@ const ClusterLoadFailed = ({ clusterId, error }: { clusterId: Cluster['id']; err ]} + actions={[]} content={error} /> @@ -85,7 +84,7 @@ const LoadingDefaultConfigFailedCard = () => ( ]} + actions={[]} /> diff --git a/libs/ui-lib/lib/ocm/components/clusterDetail/ClusterDetail.tsx b/libs/ui-lib/lib/ocm/components/clusterDetail/ClusterDetail.tsx index 3633bdfd10..7ad8e5caf7 100644 --- a/libs/ui-lib/lib/ocm/components/clusterDetail/ClusterDetail.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterDetail/ClusterDetail.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useHistory } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom-v5-compat'; import { Stack, StackItem, @@ -40,7 +40,7 @@ const ClusterDetail: React.FC = ({ cluster }) => { const isSNOExpansionAllowed = featureSupportLevelContext.isFeatureSupported('SINGLE_NODE_EXPANSION'); const isSingleClusterFeatureEnabled = useFeature('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE'); - const history = useHistory(); + const navigate = useNavigate(); const canAddHosts = (!isSNO(cluster) || isSNOExpansionAllowed) && cluster.status === 'installed' && !isInOcm; @@ -49,13 +49,13 @@ const ClusterDetail: React.FC = ({ cluster }) => { try { const { data } = await ClustersAPI.allowAddHosts(cluster.id); updateCluster(data); - history.push(`${routeBasePath}/clusters/${cluster.id}`); + navigate(`${routeBasePath}/clusters/${cluster.id}`); } catch (e) { handleApiError(e); } }; void doItAsync(); - }, [cluster.id, history]); + }, [cluster.id, navigate]); return ( @@ -112,7 +112,7 @@ const ClusterDetail: React.FC = ({ cluster }) => { {!isSingleClusterFeatureEnabled && ( history.push(`${routeBasePath}/clusters`)} + onClick={() => navigate('..')} id={getClusterDetailId('button-back-to-all-clusters')} > Back to all clusters diff --git a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetails.tsx b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetails.tsx index 4f461c23d6..ae91f6f579 100644 --- a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetails.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetails.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useHistory } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom-v5-compat'; import { useDispatch } from 'react-redux'; import { useAlerts, LoadingState, ClusterWizardStep, ErrorState } from '../../../common'; import { usePullSecret } from '../../hooks'; @@ -11,7 +11,6 @@ import { useManagedDomains, useUsedClusterNames } from '../../hooks'; import { useOpenshiftVersionsContext } from './OpenshiftVersionsContext'; import ClusterDetailsForm from './ClusterDetailsForm'; import ClusterWizardNavigation from './ClusterWizardNavigation'; -import { routeBasePath } from '../../config'; import { ClusterDetailsUpdateParams, ClustersService, @@ -29,7 +28,7 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => { const clusterWizardContext = useClusterWizardContext(); const managedDomains = useManagedDomains(); const { addAlert, clearAlerts } = useAlerts(); - const history = useHistory(); + const navigate = useNavigate(); const dispatch = useDispatch(); const { usedClusterNames } = useUsedClusterNames(cluster?.id || ''); const pullSecret = usePullSecret(); @@ -74,7 +73,7 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => { clearAlerts(); try { const cluster = await ClustersService.create(params); - history.push(`${routeBasePath}/clusters/${cluster.id}`, ClusterWizardFlowStateNew); + navigate(`../${cluster.id}`, { state: ClusterWizardFlowStateNew }); await UISettingService.update(cluster.id, { addCustomManifests }); } catch (e) { handleApiError(e, () => @@ -85,7 +84,7 @@ const ClusterDetails = ({ cluster, infraEnv }: ClusterDetailsProps) => { } } }, - [clearAlerts, history, addAlert, dispatch], + [clearAlerts, navigate, addAlert, dispatch], ); const navigation = ; diff --git a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetailsForm.tsx b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetailsForm.tsx index ebd255bef4..9ee39a528b 100644 --- a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetailsForm.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterDetailsForm.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { useSelector } from 'react-redux'; -import { useLocation } from 'react-router-dom'; +import { useLocation } from 'react-router-dom-v5-compat'; import { Grid, GridItem } from '@patternfly/react-core'; import isUndefined from 'lodash-es/isUndefined.js'; import { Formik, FormikHelpers } from 'formik'; diff --git a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardContextProvider.tsx b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardContextProvider.tsx index 514e2f5ce5..d4e16fcc23 100644 --- a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardContextProvider.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardContextProvider.tsx @@ -1,5 +1,5 @@ import React, { PropsWithChildren } from 'react'; -import { useLocation } from 'react-router-dom'; +import { useLocation } from 'react-router-dom-v5-compat'; import { ClusterWizardContextType, ClusterWizardContext } from './ClusterWizardContext'; import { ClusterWizardFlowStateType, @@ -91,7 +91,8 @@ const ClusterWizardContextProvider = ({ const [wizardStepIds, setWizardStepIds] = React.useState(); const [wizardPerPage, setWizardPerPage] = React.useState(10); const [customManifestsStep, setCustomManifestsStep] = React.useState(false); - const { state: locationState } = useLocation(); + const location = useLocation(); + const locationState = location.state as ClusterWizardFlowStateType | undefined; const { uiSettings, updateUISettings, diff --git a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardFooter.tsx b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardFooter.tsx index 7401b19285..d0027b2dba 100644 --- a/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardFooter.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterWizard/ClusterWizardFooter.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useHistory } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom-v5-compat'; import { Alert, AlertGroup, AlertVariant } from '@patternfly/react-core'; import { WizardFooter, @@ -9,7 +9,6 @@ import { clusterFieldLabels, selectClusterValidationsInfo, } from '../../../common'; -import { routeBasePath } from '../../config'; import { wizardStepsValidationsMap } from './wizardTransition'; import { useClusterWizardContext } from './ClusterWizardContext'; import ClusterWizardStepValidationsAlert from '../../../common/components/clusterWizard/ClusterWizardStepValidationsAlert'; @@ -80,12 +79,9 @@ const ClusterWizardFooter = ({ ...rest }: ClusterWizardFooterProps) => { const { alerts } = useAlerts(); - const history = useHistory(); + const navigate = useNavigate(); - const handleCancel = React.useCallback( - () => history.push(`${routeBasePath}/clusters/`), - [history], - ); + const handleCancel = React.useCallback(() => navigate('..'), [navigate]); const alertsSection = alerts.length ? : undefined; diff --git a/libs/ui-lib/lib/ocm/components/clusterWizard/Operators.tsx b/libs/ui-lib/lib/ocm/components/clusterWizard/Operators.tsx index 425eadc233..7eae861628 100644 --- a/libs/ui-lib/lib/ocm/components/clusterWizard/Operators.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterWizard/Operators.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { useDispatch } from 'react-redux'; -import { useHistory, useLocation } from 'react-router-dom'; +import { useLocation, useNavigate } from 'react-router-dom-v5-compat'; import { Formik, FormikConfig, useFormikContext } from 'formik'; import { ClusterWizardStep, @@ -42,7 +42,7 @@ const OperatorsForm = ({ cluster }: { cluster: Cluster }) => { const clusterWizardContext = useClusterWizardContext(); const isAutoSaveRunning = useFormikAutoSave(); const { errors, touched, isSubmitting, isValid } = useFormikContext(); - const history = useHistory(); + const navigate = useNavigate(); const { pathname } = useLocation(); const isNextDisabled = @@ -54,7 +54,7 @@ const OperatorsForm = ({ cluster }: { cluster: Cluster }) => { const handleNext = () => { if (window.location.pathname.indexOf('assisted-installer') > -1) { - history.replace(pathname, undefined); + navigate(pathname, { state: undefined, replace: true }); } clusterWizardContext.moveNext(); }; diff --git a/libs/ui-lib/lib/ocm/components/clusters/ClusterBreadcrumbs.tsx b/libs/ui-lib/lib/ocm/components/clusters/ClusterBreadcrumbs.tsx index 711e2e5aef..c709c4dac2 100644 --- a/libs/ui-lib/lib/ocm/components/clusters/ClusterBreadcrumbs.tsx +++ b/libs/ui-lib/lib/ocm/components/clusters/ClusterBreadcrumbs.tsx @@ -5,8 +5,7 @@ import { BreadcrumbItem, PageSection, } from '@patternfly/react-core'; -import { Link } from 'react-router-dom'; -import { routeBasePath } from '../../config'; +import { Link } from 'react-router-dom-v5-compat'; import { isInOcm } from '../../../common/api'; const ClusterBreadcrumbs = ({ clusterName }: { clusterName?: string }) => ( @@ -16,9 +15,9 @@ const ClusterBreadcrumbs = ({ clusterName }: { clusterName?: string }) => ( Clusters} /> {clusterName ? ( - Assisted Clusters} - /> + + Assisted Clusters + ) : ( Assisted Clusters )} diff --git a/libs/ui-lib/lib/ocm/components/clusters/ClusterPage.tsx b/libs/ui-lib/lib/ocm/components/clusters/ClusterPage.tsx index 6560b04be3..2d510deec5 100644 --- a/libs/ui-lib/lib/ocm/components/clusters/ClusterPage.tsx +++ b/libs/ui-lib/lib/ocm/components/clusters/ClusterPage.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Redirect, RouteComponentProps } from 'react-router-dom'; +import { useParams, Navigate } from 'react-router-dom-v5-compat'; import { useDispatch } from 'react-redux'; import { PageSection, PageSectionVariants, Text, TextContent } from '@patternfly/react-core'; import { @@ -35,13 +35,12 @@ import { Cluster, InfraEnv } from '@openshift-assisted/types/assisted-installer- import { AssistedInstallerHeader } from './AssistedInstallerHeader'; import { OpenshiftVersionsContextProvider } from '../clusterWizard/OpenshiftVersionsContext'; -type MatchParams = { - clusterId: string; -}; - -const ClusterPageGeneric: React.FC<{ clusterId: string; showBreadcrumbs?: boolean }> = ({ +const ClusterPageGeneric = ({ clusterId, showBreadcrumbs = false, +}: { + clusterId: string; + showBreadcrumbs?: boolean; }) => { if (!clusterId) { // console.error('ClusterPageGeneric: missing clusterId'); @@ -132,7 +131,7 @@ const ClusterPageGeneric: React.FC<{ clusterId: string; showBreadcrumbs?: boolea if (uiState === ResourceUIState.POLLING_ERROR && !cluster) { if (Number(errorDetail?.code) === 404) { - return ; + return ; } return ( @@ -141,7 +140,7 @@ const ClusterPageGeneric: React.FC<{ clusterId: string; showBreadcrumbs?: boolea fetchData={ Number(errorDetail?.code) === 401 ? () => window.location.reload() : fetchCluster } - actions={[]} + actions={[]} /> ); @@ -152,7 +151,7 @@ const ClusterPageGeneric: React.FC<{ clusterId: string; showBreadcrumbs?: boolea ]} + actions={[]} content={ 'Check to make sure the cluster-ID is valid. Otherwise, the cluster details may have been deleted.' } @@ -198,16 +197,20 @@ const ClusterPageGeneric: React.FC<{ clusterId: string; showBreadcrumbs?: boolea ); } - return ; + return ; }; -export const SingleClusterPage: React.FC<{ clusterId: string }> = ({ clusterId }) => ( +export const SingleClusterPage = ({ clusterId }: { clusterId: string }) => ( ); -export const ClusterPage: React.FC> = ({ match }) => ( - - - -); + +export const ClusterPage = () => { + const { clusterId } = useParams<{ clusterId: string }>(); + return ( + + + + ); +}; diff --git a/libs/ui-lib/lib/ocm/components/clusters/ClusterPageErrors.tsx b/libs/ui-lib/lib/ocm/components/clusters/ClusterPageErrors.tsx index 0a2f1ed512..b92358111d 100644 --- a/libs/ui-lib/lib/ocm/components/clusters/ClusterPageErrors.tsx +++ b/libs/ui-lib/lib/ocm/components/clusters/ClusterPageErrors.tsx @@ -1,14 +1,13 @@ import React from 'react'; import { PageSection, PageSectionVariants } from '@patternfly/react-core'; import { ErrorState } from '../../../common'; -import { routeBasePath } from '../../config'; import { BackButton } from '../ui/Buttons/BackButton'; export const ClusterUiError = () => ( ]} + actions={[]} /> ); diff --git a/libs/ui-lib/lib/ocm/components/clusters/Clusters.tsx b/libs/ui-lib/lib/ocm/components/clusters/Clusters.tsx index f1ad8141d2..b794f54db0 100644 --- a/libs/ui-lib/lib/ocm/components/clusters/Clusters.tsx +++ b/libs/ui-lib/lib/ocm/components/clusters/Clusters.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { RouteComponentProps } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom-v5-compat'; import { Button, ButtonVariant, @@ -22,7 +22,6 @@ import ClustersTable from './ClustersTable'; import { fetchClustersAsync, deleteCluster } from '../../store/slices/clusters/slice'; import { handleApiError, getApiErrorMessage } from '../../../common/api'; import ClusterBreadcrumbs from './ClusterBreadcrumbs'; -import { routeBasePath } from '../../config'; import { ClustersService } from '../../services'; import { useTranslation } from '../../../common/hooks/use-translation-wrapper'; import ClusterPollingErrorModal from '../clusterDetail/ClusterPollingErrorModal'; @@ -33,9 +32,8 @@ import { selectClusterTableRows, } from '../../store/slices/clusters/selectors'; -type ClustersProps = RouteComponentProps; - -const Clusters: React.FC = ({ history }) => { +const Clusters = () => { + const navigate = useNavigate(); const { LOADING, EMPTY, POLLING_ERROR, RELOADING } = ResourceUIState; const { addAlert } = useAlerts(); const { t } = useTranslation(); @@ -85,7 +83,7 @@ const Clusters: React.FC = ({ history }) => { primaryAction={