Skip to content

Commit 59ac703

Browse files
committed
fix: enhance navigation redirection logic
1 parent 869c834 commit 59ac703

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

src/components/common/navigation/NavRoutes.components.tsx

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { lazy, useEffect, useMemo, useState } from 'react'
17+
import { lazy, useMemo, useState } from 'react'
1818
import { generatePath, Navigate, Route, Routes, useLocation } from 'react-router-dom'
1919
import * as Sentry from '@sentry/browser'
2020

@@ -23,9 +23,12 @@ import {
2323
InfrastructureManagementAppListType,
2424
ROUTER_URLS,
2525
SERVER_MODE,
26+
URLS as COMMON_URLS,
2627
useMainContext,
2728
} from '@devtron-labs/devtron-fe-common-lib'
2829

30+
import { URLS } from '@Config/index'
31+
2932
import { ExternalFluxAppDetailsRoute } from '../../../Pages/App/Details/ExternalFlux'
3033
import { AppContext } from '../Contexts'
3134
import ErrorBoundary from '../errorBoundary'
@@ -40,7 +43,7 @@ const Jobs = lazy(() => import('../../Jobs/Jobs'))
4043

4144
const NetworkStatusInterface = importComponentFromFELibrary('NetworkStatusInterface', null, 'function')
4245

43-
const getDefaultRedirectPath = (isFirstLoginUser: boolean, serverMode: SERVER_MODE) => {
46+
const getDefaultRedirectPath = (isFirstLoginUser: boolean, serverMode: SERVER_MODE, pathname: string) => {
4447
if (window._env_.K8S_CLIENT) {
4548
return ROUTER_URLS.RESOURCE_BROWSER.ROOT
4649
}
@@ -53,21 +56,42 @@ const getDefaultRedirectPath = (isFirstLoginUser: boolean, serverMode: SERVER_MO
5356
if (window._env_.FEATURE_DEFAULT_LANDING_RB_ENABLE) {
5457
return ROUTER_URLS.RESOURCE_BROWSER.ROOT
5558
}
56-
return serverMode === SERVER_MODE.EA_ONLY
57-
? ROUTER_URLS.INFRASTRUCTURE_MANAGEMENT_APPS
58-
: ROUTER_URLS.DEVTRON_APP_LIST
59+
if (serverMode === SERVER_MODE.EA_ONLY) {
60+
return ROUTER_URLS.INFRASTRUCTURE_MANAGEMENT_APPS
61+
}
62+
63+
const parts = pathname.split('/').filter((part) => part)
64+
65+
if (parts?.[0] === 'app') {
66+
if (Number.isNaN(Number(parts?.[1]))) {
67+
Sentry.captureMessage(`redirecting to ${ROUTER_URLS.DEVTRON_APP_LIST} from ${pathname}`, 'warning')
68+
return ROUTER_URLS.DEVTRON_APP_LIST
69+
}
70+
71+
const pageHeaderTab = parts?.[2]
72+
73+
if (
74+
pageHeaderTab === COMMON_URLS.APP_DETAILS ||
75+
pageHeaderTab === URLS.APP_TRIGGER ||
76+
pageHeaderTab === URLS.APP_CI_DETAILS ||
77+
pageHeaderTab === URLS.APP_CD_DETAILS ||
78+
pageHeaderTab === URLS.APP_DEPLOYMENT_METRICS ||
79+
pageHeaderTab === COMMON_URLS.APP_CONFIG
80+
) {
81+
parts[0] = `${BASE_ROUTES.APPLICATION_MANAGEMENT.ROOT}/${BASE_ROUTES.APPLICATION_MANAGEMENT.DEVTRON_APP}`
82+
const newPath = parts.join('/')
83+
return newPath
84+
}
85+
}
86+
87+
Sentry.captureMessage(`redirecting to ${ROUTER_URLS.DEVTRON_APP_LIST} from ${pathname}`, 'warning')
88+
return ROUTER_URLS.DEVTRON_APP_LIST
5989
}
6090

6191
export const RedirectUserWithSentry = ({ isFirstLoginUser }: { isFirstLoginUser: boolean }) => {
6292
const { pathname } = useLocation()
6393
const { serverMode } = useMainContext()
64-
const redirectPath = getDefaultRedirectPath(isFirstLoginUser, serverMode)
65-
66-
useEffect(() => {
67-
if (pathname !== '/') {
68-
Sentry.captureMessage(`redirecting to ${redirectPath} from ${pathname}`, 'warning')
69-
}
70-
}, [])
94+
const redirectPath = getDefaultRedirectPath(isFirstLoginUser, serverMode, pathname)
7195

7296
return <Navigate to={redirectPath} replace />
7397
}

src/config/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const URLS = {
3333
APP_CI_DETAILS: 'ci-details',
3434
APP_CD_DETAILS: 'cd-details',
3535
APP_GIT_CONFIG: 'materials',
36+
APP_DEPLOYMENT_METRICS: 'deployment-metrics',
3637
APP_DOCKER_CONFIG: 'docker-build-config',
3738
APP_GITOPS_CONFIG: 'gitops-config',
3839
APP_DEPLOYMENT_CONFIG: EnvResourceType.DeploymentTemplate,

0 commit comments

Comments
 (0)