Skip to content

Commit 67fd9d8

Browse files
Merge pull request #2462 from devtron-labs/feat/add-base-config-route
feat: add base-config path segment for base configurations
2 parents a0687a6 + b2d770c commit 67fd9d8

File tree

11 files changed

+75
-92
lines changed

11 files changed

+75
-92
lines changed

src/Pages/Applications/DevtronApps/Details/AppConfigurations/AppConfig.types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ export interface EnvConfigurationsNavProps {
223223
isCMSecretLocked?: boolean
224224
hideEnvSelector?: boolean
225225
appOrEnvIdToResourceApprovalConfigurationMap: AppConfigState['envIdToEnvApprovalConfigurationMap']
226-
/**
227-
* @default false
228-
*/
229-
removeBaseConfigPath?: boolean
230226
}
231227

232228
export interface EnvConfigRouteParams {

src/Pages/Applications/DevtronApps/Details/AppConfigurations/AppConfig.utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ import {
1919
stringComparatorBySortOrder,
2020
ConfigResourceType,
2121
BASE_CONFIGURATION_ENV_ID,
22-
EnvResourceType,
2322
} from '@devtron-labs/devtron-fe-common-lib'
2423

25-
import { URLS, DOCUMENTATION } from '@Config/index'
24+
import { URLS, DOCUMENTATION, getAppComposeURL, APP_COMPOSE_STAGE } from '@Config/index'
2625
import { AppConfigStatusItemType, EnvConfigDTO } from '../../service.types'
2726
import { AppConfigState, AppStageUnlockedType, CustomNavItemsType, EnvConfigType, STAGE_NAME } from './AppConfig.types'
2827

@@ -145,15 +144,15 @@ export const getNavItems = ({
145144
},
146145
{
147146
title: 'ConfigMaps & Secrets',
148-
href: `/job/${appId}/edit/${EnvResourceType.ConfigMap}`,
147+
href: getAppComposeURL(appId, APP_COMPOSE_STAGE.CONFIG_MAPS, true),
149148
stage: STAGE_NAME.REDIRECT_ITEM,
150149
isLocked: !_isUnlocked.configmap,
151150
isProtectionAllowed: true,
152151
required: true,
153152
},
154153
{
155154
title: 'ConfigMaps',
156-
href: `/job/${appId}/edit/configmap`,
155+
href: getAppComposeURL(appId, APP_COMPOSE_STAGE.CONFIG_MAPS, true),
157156
stage: STAGE_NAME.CONFIGMAP,
158157
isLocked: !_isUnlocked.configmap,
159158
supportDocumentURL: DOCUMENTATION.APP_CREATE_CONFIG_MAP,
@@ -165,7 +164,7 @@ export const getNavItems = ({
165164
},
166165
{
167166
title: 'Secrets',
168-
href: `/job/${appId}/edit/secrets`,
167+
href: getAppComposeURL(appId, APP_COMPOSE_STAGE.SECRETS, true),
169168
stage: STAGE_NAME.SECRETS,
170169
isLocked: !_isUnlocked.secret,
171170
supportDocumentURL: DOCUMENTATION.APP_CREATE_SECRET,
@@ -220,7 +219,7 @@ export const getNavItems = ({
220219
},
221220
{
222221
title: 'Deployment Template',
223-
href: `/app/${appId}/edit/deployment-template`,
222+
href: getAppComposeURL(appId, APP_COMPOSE_STAGE.DEPLOYMENT_TEMPLATE),
224223
stage: STAGE_NAME.DEPLOYMENT_TEMPLATE,
225224
isLocked: !_isUnlocked.deploymentTemplate,
226225
supportDocumentURL: DOCUMENTATION.APP_DEPLOYMENT_TEMPLATE,
@@ -251,7 +250,7 @@ export const getNavItems = ({
251250
},
252251
{
253252
title: 'ConfigMaps',
254-
href: `/app/${appId}/edit/configmap`,
253+
href: getAppComposeURL(appId, APP_COMPOSE_STAGE.CONFIG_MAPS),
255254
stage: STAGE_NAME.CONFIGMAP,
256255
isLocked: !_isUnlocked.configmap,
257256
supportDocumentURL: DOCUMENTATION.APP_CREATE_CONFIG_MAP,
@@ -263,7 +262,7 @@ export const getNavItems = ({
263262
},
264263
{
265264
title: 'Secrets',
266-
href: `/app/${appId}/edit/secrets`,
265+
href: getAppComposeURL(appId, APP_COMPOSE_STAGE.SECRETS),
267266
stage: STAGE_NAME.SECRETS,
268267
isLocked: !_isUnlocked.secret,
269268
supportDocumentURL: DOCUMENTATION.APP_CREATE_SECRET,

src/Pages/Applications/DevtronApps/Details/AppConfigurations/MainContent/AppComposeRouter.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ const AppComposeRouter = () => {
134134
reloadEnvironments={reloadEnvironments}
135135
/>
136136
</Route>,
137-
<Route key={`${path}/${URLS.APP_CM_CONFIG}`} path={`${path}/${URLS.APP_CM_CONFIG}/:name?`}>
137+
<Route
138+
key={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CM_CONFIG}`}
139+
path={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CM_CONFIG}/:name?`}
140+
>
138141
<ConfigMapSecretWrapper
139142
isJob
140143
isApprovalPolicyConfigured={false}
@@ -146,7 +149,10 @@ const AppComposeRouter = () => {
146149
envName=""
147150
/>
148151
</Route>,
149-
<Route key={`${path}/${URLS.APP_CS_CONFIG}`} path={`${path}/${URLS.APP_CS_CONFIG}/:name?`}>
152+
<Route
153+
key={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CS_CONFIG}`}
154+
path={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CS_CONFIG}/:name?`}
155+
>
150156
<ConfigMapSecretWrapper
151157
isJob
152158
isApprovalPolicyConfigured={false}
@@ -208,13 +214,13 @@ const AppComposeRouter = () => {
208214
)}
209215

210216
{(isUnlocked.deploymentTemplate || isUnlocked.workflowEditor) && (
211-
<Route path={`${path}/${URLS.BASE_CONFIG}`}>
217+
<Route path={`${path}/${URLS.BASE_CONFIG}`} exact>
212218
<Progressing pageLoader />
213219
</Route>
214220
)}
215221

216222
{isUnlocked.deploymentTemplate && (
217-
<Route path={`${path}/${URLS.APP_DEPLOYMENT_CONFIG}`}>
223+
<Route path={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_DEPLOYMENT_CONFIG}`}>
218224
<DeploymentTemplate
219225
respondOnSuccess={respondOnSuccess}
220226
isCiPipeline={isCiPipeline}
@@ -255,7 +261,10 @@ const AppComposeRouter = () => {
255261
reloadAppConfig={reloadAppConfig}
256262
/>
257263
</Route>,
258-
<Route key={`${path}/${URLS.APP_CM_CONFIG}`} path={`${path}/${URLS.APP_CM_CONFIG}/:name?`}>
264+
<Route
265+
key={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CM_CONFIG}`}
266+
path={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CM_CONFIG}/:name?`}
267+
>
259268
<ConfigMapSecretWrapper
260269
isApprovalPolicyConfigured={getIsApprovalPolicyConfigured(
261270
approvalConfigMapForBaseConfiguration?.[ApprovalConfigDataKindType.configMap],
@@ -268,7 +277,10 @@ const AppComposeRouter = () => {
268277
envName=""
269278
/>
270279
</Route>,
271-
<Route key={`${path}/${URLS.APP_CS_CONFIG}`} path={`${path}/${URLS.APP_CS_CONFIG}/:name?`}>
280+
<Route
281+
key={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CS_CONFIG}`}
282+
path={`${path}/${URLS.BASE_CONFIG}/${URLS.APP_CS_CONFIG}/:name?`}
283+
>
272284
<ConfigMapSecretWrapper
273285
isApprovalPolicyConfigured={getIsApprovalPolicyConfigured(
274286
approvalConfigMapForBaseConfiguration?.[ApprovalConfigDataKindType.configSecret],
@@ -307,7 +319,7 @@ const AppComposeRouter = () => {
307319
const basePath = generatePath(path, match.params)
308320
const envOverridePath = match.params.envId
309321
? `/${URLS.APP_ENV_OVERRIDE_CONFIG}/${match.params.envId}`
310-
: ''
322+
: `/${URLS.BASE_CONFIG}`
311323
// Set the resourceTypePath based on the resourceType from the URL parameters.
312324
// If the resourceType is 'Manifest' or 'PipelineStrategy', use 'deployment-template' as the back URL.
313325
// Otherwise, use the actual resourceType from the URL, which could be 'deployment-template', 'configmap', or 'secrets'.

src/Pages/Applications/DevtronApps/Details/AppConfigurations/MainContent/DeploymentTemplate/DeploymentTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import { Prompt, useLocation, useParams } from 'react-router-dom'
6565
import YAML from 'yaml'
6666
import { importComponentFromFELibrary } from '@Components/common'
6767
import { getModuleInfo } from '@Components/v2/devtronStackManager/DevtronStackManager.service'
68-
import { URLS } from '@Config/routes'
68+
import { APP_COMPOSE_STAGE, getAppComposeURL } from '@Config/routes'
6969
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
7070
import { ReactComponent as ICInfoOutlineGrey } from '@Icons/ic-info-outline-grey.svg'
7171
import deleteOverrideEmptyStateImage from '@Images/no-artifact.webp'
@@ -255,7 +255,7 @@ const DeploymentTemplate = ({
255255

256256
const isGuiSupported = isEditMode && !showDeleteOverrideDraftEmptyState
257257

258-
const baseDeploymentTemplateURL = `${URLS.APP}/${appId}/${URLS.APP_CONFIG}/${URLS.APP_DEPLOYMENT_CONFIG}`
258+
const baseDeploymentTemplateURL = getAppComposeURL(appId, APP_COMPOSE_STAGE.DEPLOYMENT_TEMPLATE)
259259

260260
/**
261261
* Means has no global config

src/Pages/Applications/DevtronApps/Details/AppConfigurations/Navigation/AppNavigation.tsx

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333

3434
import { ReactNode } from 'react'
35-
import { match as matchType, Route, Switch, useLocation, useRouteMatch } from 'react-router-dom'
35+
import { Route, Switch, useLocation, useRouteMatch } from 'react-router-dom'
3636
import {
3737
Button,
3838
ButtonStyleType,
@@ -114,9 +114,11 @@ export const AppNavigation = () => {
114114
)
115115

116116
const getValidBackURL = () => {
117-
const isBackURLLocked = location.pathname === lastUnlockedStage
118-
const secondLastUnlockedStage = isBackURLLocked
119-
? navItems.reduce(
117+
const isCurrentPathLastUnlockedStage = location.pathname === lastUnlockedStage
118+
const eligibleNavItems = navItems.filter((navItem) => navItem.stage !== STAGE_NAME.REDIRECT_ITEM)
119+
120+
const secondLastUnlockedStage = isCurrentPathLastUnlockedStage
121+
? eligibleNavItems.reduce(
120122
(acc, curr) => {
121123
if (curr.href === lastUnlockedStage) {
122124
acc.found = true
@@ -140,39 +142,32 @@ export const AppNavigation = () => {
140142
return secondLastUnlockedStage || lastUnlockedStage
141143
}
142144

143-
const renderEnvConfigurationsNav = (match: matchType, isBaseConfig?: boolean) => (
144-
<EnvConfigurationsNav
145-
key={`env-configurations-nav-${'envId' in match.params ? match.params.envId : ''}`}
146-
envConfig={envConfig}
147-
fetchEnvConfig={fetchEnvConfig}
148-
environments={environments.map(({ environmentName, environmentId }) => ({
149-
id: environmentId,
150-
name: environmentName,
151-
}))}
152-
showBaseConfigurations
153-
showDeploymentTemplate={!isJobView}
154-
goBackURL={getValidBackURL()}
155-
compareWithURL={`${path}/:envId(\\d+)?`}
156-
showComparison={!isJobView && isUnlocked.workflowEditor}
157-
isCMSecretLocked={!isUnlocked.workflowEditor}
158-
appOrEnvIdToResourceApprovalConfigurationMap={envIdToEnvApprovalConfigurationMap}
159-
removeBaseConfigPath={isBaseConfig}
160-
/>
161-
)
162-
163145
return (
164146
<Switch>
165147
<Route
166148
path={[
167-
`${path}/${DEPLOYMENT_CONFIGURATION_RESOURCE_TYPE_ROUTE}`,
149+
`${path}/${URLS.BASE_CONFIG}/${DEPLOYMENT_CONFIGURATION_RESOURCE_TYPE_ROUTE}?`,
168150
`${path}/${URLS.APP_ENV_OVERRIDE_CONFIG}/:envId(\\d+)/${DEPLOYMENT_CONFIGURATION_RESOURCE_TYPE_ROUTE}?`,
169151
]}
170152
>
171-
{({ match }) => renderEnvConfigurationsNav(match)}
172-
</Route>
173-
174-
<Route path={`${path}/${URLS.BASE_CONFIG}`} key={URLS.BASE_CONFIG}>
175-
{({ match }) => renderEnvConfigurationsNav(match, true)}
153+
{({ match }) => (
154+
<EnvConfigurationsNav
155+
key={`env-configurations-nav-${'envId' in match.params ? match.params.envId : ''}`}
156+
envConfig={envConfig}
157+
fetchEnvConfig={fetchEnvConfig}
158+
environments={environments.map(({ environmentName, environmentId }) => ({
159+
id: environmentId,
160+
name: environmentName,
161+
}))}
162+
showBaseConfigurations
163+
showDeploymentTemplate={!isJobView}
164+
goBackURL={getValidBackURL()}
165+
compareWithURL={`${path}/:envId(\\d+)?`}
166+
showComparison={!isJobView && isUnlocked.workflowEditor}
167+
isCMSecretLocked={!isUnlocked.workflowEditor}
168+
appOrEnvIdToResourceApprovalConfigurationMap={envIdToEnvApprovalConfigurationMap}
169+
/>
170+
)}
176171
</Route>
177172

178173
<Route key="default-navigation">

src/Pages/Applications/DevtronApps/Details/AppConfigurations/Navigation/EnvConfigurationsNav.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const EnvConfigurationsNavContent = ({
135135
if (resourceData.id === BASE_CONFIGURATIONS.id && envId) {
136136
// Removing `/env-override/:envId` from pathname, resulting path will be base configuration path.
137137
const [basePath, resourcePath] = pathname.split(`/${URLS.APP_ENV_OVERRIDE_CONFIG}/${envId}`)
138-
history.push(`${basePath}${resourcePath}`)
138+
history.push(`${basePath}${URLS.BASE_CONFIG}/${resourcePath}`)
139139
}
140140
}, [resourceData, envId])
141141

@@ -299,7 +299,6 @@ export const EnvConfigurationsNav = ({
299299
hideEnvSelector,
300300
compareWithURL,
301301
appOrEnvIdToResourceApprovalConfigurationMap,
302-
removeBaseConfigPath = false,
303302
}: EnvConfigurationsNavProps) => {
304303
const history = useHistory()
305304
const { isSuperAdmin } = useMainContext()
@@ -319,8 +318,7 @@ export const EnvConfigurationsNav = ({
319318
}
320319
: null)
321320

322-
const [expandedIds, setExpandedIds] =
323-
useState<Record<Extract<EnvResourceType, EnvResourceType.ConfigMap | EnvResourceType.Secret>, boolean>>()
321+
const [expandedIds, setExpandedIds] = useState<ExpandedIdsType>()
324322

325323
const isResourceTypeValid = Object.values(EnvResourceType).includes(resourceType as EnvResourceType)
326324
const resourceName = isResourceTypeValid ? pathname.split(`${resourceType}/`)[1] : null
@@ -332,16 +330,10 @@ export const EnvConfigurationsNav = ({
332330
isSuperAdmin || !areCMsPresent ? EnvResourceType.DeploymentTemplate : EnvResourceType.ConfigMap
333331

334332
history.replace(
335-
generatePath(
336-
// Here resourceType is mandatory since we are navigating to a specific resource type
337-
removeBaseConfigPath
338-
? `${pathname.split(URLS.BASE_CONFIG)[0]}${DEPLOYMENT_CONFIGURATION_RESOURCE_TYPE_ROUTE}`
339-
: path,
340-
{
341-
...params,
342-
resourceType: validResourceType,
343-
},
344-
),
333+
generatePath(path, {
334+
...params,
335+
resourceType: validResourceType,
336+
}),
345337
)
346338
}
347339
}
@@ -385,7 +377,7 @@ export const EnvConfigurationsNav = ({
385377

386378
// Build the new app path, conditionally adding the environment override config when switching to environment
387379
const appPath = `${truncatedPath}${
388-
value !== BASE_CONFIGURATIONS.id ? `/${URLS.APP_ENV_OVERRIDE_CONFIG}/:envId(\\d+)?` : ''
380+
value !== BASE_CONFIGURATIONS.id ? `/${URLS.APP_ENV_OVERRIDE_CONFIG}/:envId(\\d+)?` : `/${URLS.BASE_CONFIG}`
389381
}/${DEPLOYMENT_CONFIGURATION_RESOURCE_TYPE_ROUTE}?` // Dynamically set valid resource types
390382

391383
// Generate the final path

src/Pages/Applications/DevtronApps/Details/AppConfigurations/Navigation/EnvironmentOverrideRouter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const JobEnvOverrideRoute = ({ envOverride, ciPipelines, reload, isEnvProtected
183183
<div className="flexbox dc__align-items-center dc__content-space pr-8">
184184
<NavLink
185185
data-testid="env-deployment-template"
186-
className="app-compose__nav-item app-compose__nav-item--job cursor dc__gap-8"
186+
className="app-compose__nav-item app-compose__nav-item--job cursor dc__gap-8"
187187
to={`${URLS.APP_ENV_OVERRIDE_CONFIG}/${envOverride.environmentId}/${EnvResourceType.ConfigMap}`}
188188
>
189189
<span className="dc__truncate">{envOverride.environmentName}</span>

src/Pages/Shared/ConfigMapSecret/ConfigMapSecretContainer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {
5656
isNullOrUndefined,
5757
} from '@devtron-labs/devtron-fe-common-lib'
5858

59-
import { URLS } from '@Config/routes'
59+
import { APP_COMPOSE_STAGE, getAppComposeURL } from '@Config/routes'
6060
import { ConfigHeader, ConfigToolbar, ConfigToolbarProps, NoOverrideEmptyState } from '@Pages/Applications'
6161
import { getConfigToolbarPopupConfig } from '@Pages/Applications/DevtronApps/Details/AppConfigurations/MainContent/utils'
6262
import { importComponentFromFELibrary } from '@Components/common'
@@ -187,7 +187,11 @@ export const ConfigMapSecretContainer = ({
187187
const gaEventCategory = `devtronapp-configuration-${isSecret ? 'secret' : 'cm'}`
188188

189189
// COMPONENT PROP CONSTANTS
190-
const baseConfigurationURL = `${isJob ? URLS.JOB : URLS.APP}/${appId}/${URLS.APP_CONFIG}/${isSecret ? URLS.APP_CS_CONFIG : URLS.APP_CM_CONFIG}/${name}`
190+
const baseConfigurationURL = getAppComposeURL(
191+
appId,
192+
isSecret ? APP_COMPOSE_STAGE.SECRETS : APP_COMPOSE_STAGE.CONFIG_MAPS,
193+
isJob,
194+
)
191195
const headerMessage =
192196
cmSecretStateLabel === CM_SECRET_STATE.ENV ||
193197
cmSecretStateLabel === CM_SECRET_STATE.UNPUBLISHED ||

src/Pages/Shared/EnvironmentOverride/EnvironmentOverrides.types.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
AppConfigState,
2020
EnvConfigurationState,
2121
} from '@Pages/Applications/DevtronApps/Details/AppConfigurations/AppConfig.types'
22-
import { DOCUMENTATION, URLS } from '../../../config'
2322
import { ConfigAppList } from '../../../components/ApplicationGroup/AppGroup.types'
2423

2524
export enum ComponentStates {
@@ -36,20 +35,6 @@ export interface SectionHeadingType {
3635
learnMoreLink: string
3736
}
3837

39-
export const SECTION_HEADING_INFO: Record<string, SectionHeadingType> = {
40-
[URLS.APP_CM_CONFIG]: {
41-
title: 'ConfigMaps',
42-
subtitle:
43-
'ConfigMap is used to store common configuration variables, allowing users to unify environment variables for different modules in a distributed system into one object.',
44-
learnMoreLink: DOCUMENTATION.APP_CREATE_CONFIG_MAP,
45-
},
46-
[URLS.APP_CS_CONFIG]: {
47-
title: 'Secrets',
48-
subtitle: 'A Secret is an object that contains sensitive data such as passwords, OAuth tokens, and SSH keys.',
49-
learnMoreLink: DOCUMENTATION.APP_CREATE_SECRET,
50-
},
51-
}
52-
5338
export interface EnvironmentOverrideComponentProps {
5439
appList?: ConfigAppList[]
5540
environments: AppConfigState['environmentList']

0 commit comments

Comments
 (0)