Skip to content

Commit 69d46e9

Browse files
committed
chore: extract components to other file
1 parent d2c2657 commit 69d46e9

File tree

3 files changed

+151
-129
lines changed

3 files changed

+151
-129
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import { lazy, useEffect, useMemo, useState } from 'react'
2+
import { Route, Switch, useHistory, useLocation, useRouteMatch } from 'react-router-dom'
3+
import * as Sentry from '@sentry/browser'
4+
5+
import {
6+
AppListConstants,
7+
ModuleNameMap,
8+
ModuleStatus,
9+
SERVER_MODE,
10+
URLS as CommonURLS,
11+
useAsync,
12+
useMainContext,
13+
} from '@devtron-labs/devtron-fe-common-lib'
14+
15+
import { getModuleInfo } from '@Components/v2/devtronStackManager/DevtronStackManager.service'
16+
import { URLS } from '@Config/routes'
17+
import { AppRouterType } from '@Services/service.types'
18+
19+
import { ExternalFluxAppDetailsRoute } from '../../../Pages/App/Details/ExternalFlux'
20+
import { AppContext } from '../Contexts'
21+
import ErrorBoundary from '../errorBoundary'
22+
import { importComponentFromFELibrary } from '../helpers/Helpers'
23+
24+
const ExternalApps = lazy(() => import('../../external-apps/ExternalApps'))
25+
const ExternalArgoApps = lazy(() => import('../../externalArgoApps/ExternalArgoApp'))
26+
const AppDetailsPage = lazy(() => import('../../app/details/main'))
27+
const NewAppList = lazy(() => import('../../app/list-new/AppList'))
28+
const DevtronChartRouter = lazy(() => import('../../v2/index'))
29+
30+
const NetworkStatusInterface = importComponentFromFELibrary('NetworkStatusInterface', null, 'function')
31+
32+
export const RedirectUserWithSentry = ({ isFirstLoginUser }: { isFirstLoginUser: boolean }) => {
33+
const { push } = useHistory()
34+
const { pathname } = useLocation()
35+
const { serverMode } = useMainContext()
36+
useEffect(() => {
37+
if (pathname && pathname !== '/') {
38+
Sentry.captureMessage(
39+
`redirecting to ${window._env_.HIDE_NETWORK_STATUS_INTERFACE ? 'app-list' : 'network status interface'} from ${pathname}`,
40+
'warning',
41+
)
42+
}
43+
44+
if (!window._env_.HIDE_NETWORK_STATUS_INTERFACE && !!NetworkStatusInterface) {
45+
push(CommonURLS.NETWORK_STATUS_INTERFACE)
46+
return
47+
}
48+
49+
if (window._env_.K8S_CLIENT) {
50+
push(URLS.RESOURCE_BROWSER)
51+
} else if (isFirstLoginUser) {
52+
push(URLS.GETTING_STARTED)
53+
} else if (serverMode === SERVER_MODE.EA_ONLY && window._env_.FEATURE_DEFAULT_LANDING_RB_ENABLE) {
54+
push(URLS.RESOURCE_BROWSER)
55+
} else {
56+
push(`${URLS.APP}/${URLS.APP_LIST}`)
57+
}
58+
}, [])
59+
return null
60+
}
61+
62+
const RedirectToAppList = () => {
63+
const { replace } = useHistory()
64+
const { serverMode } = useMainContext()
65+
useEffect(() => {
66+
const baseUrl = `${URLS.APP}/${URLS.APP_LIST}`
67+
if (serverMode === SERVER_MODE.FULL) {
68+
replace(`${baseUrl}/${AppListConstants.AppType.DEVTRON_APPS}`)
69+
} else {
70+
replace(`${baseUrl}/${AppListConstants.AppType.HELM_APPS}`)
71+
}
72+
}, [])
73+
return null
74+
}
75+
76+
const AppListRouter = ({ isSuperAdmin, appListCount, loginCount }: AppRouterType) => {
77+
const { path } = useRouteMatch()
78+
const [, argoInfoData] = useAsync(() => getModuleInfo(ModuleNameMap.ARGO_CD))
79+
const isArgoInstalled: boolean = argoInfoData?.result?.status === ModuleStatus.INSTALLED
80+
81+
return (
82+
<ErrorBoundary>
83+
<Switch>
84+
<Route path={`${path}/:appType`} render={() => <NewAppList isArgoInstalled={isArgoInstalled} />} />
85+
<Route exact path="">
86+
<RedirectToAppList />
87+
</Route>
88+
<Route>
89+
<RedirectUserWithSentry isFirstLoginUser={isSuperAdmin && loginCount === 0 && appListCount === 0} />
90+
</Route>
91+
</Switch>
92+
</ErrorBoundary>
93+
)
94+
}
95+
96+
export const AppRouter = ({ isSuperAdmin, appListCount, loginCount }: AppRouterType) => {
97+
const { path } = useRouteMatch()
98+
const [environmentId, setEnvironmentId] = useState(null)
99+
const [currentAppName, setCurrentAppName] = useState<string>('')
100+
101+
const appContextValue = useMemo(
102+
() => ({ environmentId, setEnvironmentId, currentAppName, setCurrentAppName }),
103+
[environmentId, currentAppName],
104+
)
105+
106+
return (
107+
<ErrorBoundary>
108+
<AppContext.Provider value={appContextValue}>
109+
<Switch>
110+
<Route
111+
path={`${path}/${URLS.APP_LIST}`}
112+
render={() => (
113+
<AppListRouter
114+
isSuperAdmin={isSuperAdmin}
115+
appListCount={appListCount}
116+
loginCount={loginCount}
117+
/>
118+
)}
119+
/>
120+
<Route path={`${path}/${URLS.EXTERNAL_APPS}/:appId/:appName`} render={() => <ExternalApps />} />
121+
<Route
122+
path={`${path}/${URLS.EXTERNAL_ARGO_APP}/:clusterId(\\d+)/:appName/:namespace`}
123+
render={() => <ExternalArgoApps />}
124+
/>
125+
{window._env_.FEATURE_EXTERNAL_FLUX_CD_ENABLE && (
126+
<Route path={`${path}/${URLS.EXTERNAL_FLUX_APP}/:clusterId/:appName/:namespace/:templateType`}>
127+
<ExternalFluxAppDetailsRoute />
128+
</Route>
129+
)}
130+
<Route
131+
path={`${path}/${URLS.DEVTRON_CHARTS}/deployments/:appId(\\d+)/env/:envId(\\d+)`}
132+
render={() => <DevtronChartRouter />}
133+
/>
134+
<Route path={`${path}/:appId(\\d+)`} render={() => <AppDetailsPage />} />
135+
136+
<Route exact path="">
137+
<RedirectToAppList />
138+
</Route>
139+
<Route>
140+
<RedirectUserWithSentry
141+
isFirstLoginUser={isSuperAdmin && loginCount === 0 && appListCount === 0}
142+
/>
143+
</Route>
144+
</Switch>
145+
</AppContext.Provider>
146+
</ErrorBoundary>
147+
)
148+
}

src/components/common/navigation/NavigationRoutes.tsx

Lines changed: 3 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as Sentry from '@sentry/browser'
2323
import {
2424
AboutDevtronDialog,
2525
animate,
26-
AppListConstants,
2726
AppThemeType,
2827
BaseConfirmationModal,
2928
ConfirmationModalProvider,
@@ -54,8 +53,6 @@ import {
5453
ToastManager,
5554
ToastVariantType,
5655
URLS as CommonURLS,
57-
useAsync,
58-
useMainContext,
5956
useMotionTemplate,
6057
useMotionValue,
6158
UserPreferencesType,
@@ -69,15 +66,14 @@ import { getUserRole } from '@Pages/GlobalConfigurations/Authorization/authoriza
6966
import { Configurations } from '@Pages/Releases/Detail'
7067

7168
import { SERVER_MODE, URLS, ViewType } from '../../../config'
72-
import { ExternalFluxAppDetailsRoute } from '../../../Pages/App/Details/ExternalFlux'
7369
import {
7470
dashboardLoggedIn,
7571
getAppListMin,
7672
getClusterListMinWithoutAuth,
7773
getLoginData,
7874
updateLoginCount,
7975
} from '../../../services/service'
80-
import { AppRouterType, LoginCountType } from '../../../services/service.types'
76+
import { LoginCountType } from '../../../services/service.types'
8177
import { HelmAppListResponse } from '../../app/list-new/AppListType'
8278
import { LOGIN_COUNT, MAX_LOGIN_COUNT } from '../../onboardingGuide/onboarding.utils'
8379
import { Security } from '../../security/Security'
@@ -94,14 +90,11 @@ import { SidePanel } from '../SidePanel'
9490
import { AppContext, ErrorBoundary } from '..'
9591
import { ENVIRONMENT_DATA_FALLBACK, INITIAL_ENV_DATA_STATE, NAVBAR_WIDTH } from './constants'
9692
import Navigation from './Navigation'
93+
import { AppRouter, RedirectUserWithSentry } from './NavRoutes.components'
9794
import { EnvironmentDataStateType, NavigationRoutesTypes } from './types'
9895

9996
const Charts = lazy(() => import('../../charts/Charts'))
100-
const ExternalApps = lazy(() => import('../../external-apps/ExternalApps'))
101-
const ExternalArgoApps = lazy(() => import('../../externalArgoApps/ExternalArgoApp'))
102-
const AppDetailsPage = lazy(() => import('../../app/details/main'))
103-
const NewAppList = lazy(() => import('../../app/list-new/AppList'))
104-
const DevtronChartRouter = lazy(() => import('../../v2/index'))
97+
10598
const GlobalConfig = lazy(() => import('../../globalConfigurations/GlobalConfiguration'))
10699
const BulkEdit = lazy(() => import('../../bulkEdits/BulkEdits'))
107100
const ResourceBrowser = lazy(() => import('../../ResourceBrowser/ResourceBrowserRouter'))
@@ -130,124 +123,6 @@ const ViewIsPipelineRBACConfigured: FunctionComponent<{
130123
const LicenseInfoDialog = importComponentFromFELibrary('LicenseInfoDialog', null, 'function')
131124
const AIResponseWidget = importComponentFromFELibrary('AIResponseWidget', null, 'function')
132125

133-
const RedirectUserWithSentry = ({ isFirstLoginUser }: { isFirstLoginUser: boolean }) => {
134-
const { push } = useHistory()
135-
const { pathname } = useLocation()
136-
const { serverMode } = useMainContext()
137-
useEffect(() => {
138-
if (pathname && pathname !== '/') {
139-
Sentry.captureMessage(
140-
`redirecting to ${window._env_.HIDE_NETWORK_STATUS_INTERFACE ? 'app-list' : 'network status interface'} from ${pathname}`,
141-
'warning',
142-
)
143-
}
144-
145-
if (!window._env_.HIDE_NETWORK_STATUS_INTERFACE && !!NetworkStatusInterface) {
146-
push(CommonURLS.NETWORK_STATUS_INTERFACE)
147-
return
148-
}
149-
150-
if (window._env_.K8S_CLIENT) {
151-
push(URLS.RESOURCE_BROWSER)
152-
} else if (isFirstLoginUser) {
153-
push(URLS.GETTING_STARTED)
154-
} else if (serverMode === SERVER_MODE.EA_ONLY && window._env_.FEATURE_DEFAULT_LANDING_RB_ENABLE) {
155-
push(URLS.RESOURCE_BROWSER)
156-
} else {
157-
push(`${URLS.APP}/${URLS.APP_LIST}`)
158-
}
159-
}, [])
160-
return null
161-
}
162-
163-
const RedirectToAppList = () => {
164-
const { replace } = useHistory()
165-
const { serverMode } = useMainContext()
166-
useEffect(() => {
167-
const baseUrl = `${URLS.APP}/${URLS.APP_LIST}`
168-
if (serverMode === SERVER_MODE.FULL) {
169-
replace(`${baseUrl}/${AppListConstants.AppType.DEVTRON_APPS}`)
170-
} else {
171-
replace(`${baseUrl}/${AppListConstants.AppType.HELM_APPS}`)
172-
}
173-
}, [])
174-
return null
175-
}
176-
177-
const AppListRouter = ({ isSuperAdmin, appListCount, loginCount }: AppRouterType) => {
178-
const { path } = useRouteMatch()
179-
const [, argoInfoData] = useAsync(() => getModuleInfo(ModuleNameMap.ARGO_CD))
180-
const isArgoInstalled: boolean = argoInfoData?.result?.status === ModuleStatus.INSTALLED
181-
182-
return (
183-
<ErrorBoundary>
184-
<Switch>
185-
<Route path={`${path}/:appType`} render={() => <NewAppList isArgoInstalled={isArgoInstalled} />} />
186-
<Route exact path="">
187-
<RedirectToAppList />
188-
</Route>
189-
<Route>
190-
<RedirectUserWithSentry isFirstLoginUser={isSuperAdmin && loginCount === 0 && appListCount === 0} />
191-
</Route>
192-
</Switch>
193-
</ErrorBoundary>
194-
)
195-
}
196-
197-
const AppRouter = ({ isSuperAdmin, appListCount, loginCount }: AppRouterType) => {
198-
const { path } = useRouteMatch()
199-
const [environmentId, setEnvironmentId] = useState(null)
200-
const [currentAppName, setCurrentAppName] = useState<string>('')
201-
202-
const appContextValue = useMemo(
203-
() => ({ environmentId, setEnvironmentId, currentAppName, setCurrentAppName }),
204-
[environmentId, currentAppName],
205-
)
206-
207-
return (
208-
<ErrorBoundary>
209-
<AppContext.Provider value={appContextValue}>
210-
<Switch>
211-
<Route
212-
path={`${path}/${URLS.APP_LIST}`}
213-
render={() => (
214-
<AppListRouter
215-
isSuperAdmin={isSuperAdmin}
216-
appListCount={appListCount}
217-
loginCount={loginCount}
218-
/>
219-
)}
220-
/>
221-
<Route path={`${path}/${URLS.EXTERNAL_APPS}/:appId/:appName`} render={() => <ExternalApps />} />
222-
<Route
223-
path={`${path}/${URLS.EXTERNAL_ARGO_APP}/:clusterId(\\d+)/:appName/:namespace`}
224-
render={() => <ExternalArgoApps />}
225-
/>
226-
{window._env_.FEATURE_EXTERNAL_FLUX_CD_ENABLE && (
227-
<Route path={`${path}/${URLS.EXTERNAL_FLUX_APP}/:clusterId/:appName/:namespace/:templateType`}>
228-
<ExternalFluxAppDetailsRoute />
229-
</Route>
230-
)}
231-
<Route
232-
path={`${path}/${URLS.DEVTRON_CHARTS}/deployments/:appId(\\d+)/env/:envId(\\d+)`}
233-
render={() => <DevtronChartRouter />}
234-
/>
235-
<Route path={`${path}/:appId(\\d+)`} render={() => <AppDetailsPage />} />
236-
237-
<Route exact path="">
238-
<RedirectToAppList />
239-
</Route>
240-
<Route>
241-
<RedirectUserWithSentry
242-
isFirstLoginUser={isSuperAdmin && loginCount === 0 && appListCount === 0}
243-
/>
244-
</Route>
245-
</Switch>
246-
</AppContext.Provider>
247-
</ErrorBoundary>
248-
)
249-
}
250-
251126
const NavigationRoutes = ({ reloadVersionConfig }: Readonly<NavigationRoutesTypes>) => {
252127
const history = useHistory()
253128
const location = useLocation()

src/components/v2/values/chartValuesDiff/ChartValuesView.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
InfoBlock,
4444
ButtonVariantType,
4545
handleAnalyticsEvent,
46-
Button,
4746
Icon,
4847
AnimatedDeployButton,
4948
} from '@devtron-labs/devtron-fe-common-lib'

0 commit comments

Comments
 (0)