Skip to content

Commit 430ee9e

Browse files
authored
Merge pull request #2402 from devtron-labs/feat/approval-policy-discovery
feat: add support for redirection from protect config
2 parents b799944 + c79896f commit 430ee9e

File tree

7 files changed

+111
-17
lines changed

7 files changed

+111
-17
lines changed

src/Pages/Applications/DevtronApps/Details/AppConfigurations/AppConfig.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import { ENV_CONFIG_PATH_REG } from './AppConfig.constants'
5353

5454
const getApprovalPolicyConfigForApp: (appId: number) => Promise<ResourceIdToResourceApprovalPolicyConfigMapType> =
5555
importComponentFromFELibrary('getApprovalPolicyConfigForApp', null, 'function')
56+
const isFELibAvailable: (appId: number) => Promise<ResourceIdToResourceApprovalPolicyConfigMapType> =
57+
importComponentFromFELibrary('isFELibAvailable', null, 'function')
5658

5759
export const AppConfig = ({ appName, resourceKind, filteredEnvIds }: AppConfigProps) => {
5860
// HOOKS
@@ -463,7 +465,9 @@ export const AppConfig = ({ appName, resourceKind, filteredEnvIds }: AppConfigPr
463465
: 'app-compose-with-no-gitops-config__nav'
464466
} ${isJob ? 'job-compose__side-nav' : ''} ${
465467
!showCannotDeleteTooltip ? 'dc__position-rel' : ''
466-
} ${hideConfigHelp ? 'hide-app-config-help' : ''} ${!canShowExternalLinks ? 'hide-external-links' : ''}`
468+
} ${hideConfigHelp ? 'hide-app-config-help' : ''} ${!canShowExternalLinks ? 'hide-external-links' : ''} ${
469+
state.isUnlocked.workflowEditor && isFELibAvailable && !isJob ? 'config-protection__side-nav' : ''
470+
}`
467471
}
468472

469473
const toggleRepoSelectionTippy = () => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export enum STAGE_NAME {
4444
SECRETS = 'SECRETS',
4545
ENV_OVERRIDE = 'ENV_OVERRIDE',
4646
EXTERNAL_LINKS = 'EXTERNAL_LINKS',
47+
PROTECT_CONFIGURATION = 'PROTECT_CONFIGURATION',
4748
REDIRECT_ITEM = 'REDIRECT_ITEM',
4849
}
4950

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
BASE_CONFIGURATION_ENV_ID,
2222
} from '@devtron-labs/devtron-fe-common-lib'
2323

24-
import { DOCUMENTATION } from '@Config/index'
24+
import { URLS, DOCUMENTATION } from '@Config/index'
2525

2626
import { AppConfigStatusItemType, EnvConfigDTO } from '../../service.types'
2727
import { AppConfigState, AppStageUnlockedType, CustomNavItemsType, EnvConfigType, STAGE_NAME } from './AppConfig.types'
@@ -282,6 +282,12 @@ export const getNavItems = ({
282282
flowCompletionPercent: completedPercent,
283283
currentStep: completedSteps,
284284
},
285+
{
286+
title: 'Protect Configuration',
287+
href: URLS.GLOBAL_CONFIG_APPROVAL_POLICY,
288+
stage: STAGE_NAME.PROTECT_CONFIGURATION,
289+
isLocked: false,
290+
},
285291
{
286292
title: 'Environment Override',
287293
href: `/app/${appId}/edit/env-override`,

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
TippyCustomized,
2828
TippyTheme,
2929
} from '@devtron-labs/devtron-fe-common-lib'
30+
import { importComponentFromFELibrary } from '@Components/common'
31+
import { ReactComponent as ICArrowSquareOut } from '@Icons/ic-arrow-square-out.svg'
3032
import { DEVTRON_APPS_STEPS, STAGE_NAME } from '../AppConfig.types'
3133
import { URLS } from '../../../../../../config'
3234
import AppConfigurationCheckBox from './AppConfigurationCheckBox'
@@ -38,6 +40,8 @@ import { useAppConfigurationContext } from '../AppConfiguration.provider'
3840
import { renderNavItem } from './Navigation.helper'
3941
import { EnvConfigurationsNav } from './EnvConfigurationsNav'
4042

43+
const isFELibAvailable = importComponentFromFELibrary('isFELibAvailable', null, 'function')
44+
4145
export const AppNavigation = () => {
4246
// HOOKS
4347
const { path } = useRouteMatch()
@@ -49,6 +53,7 @@ export const AppNavigation = () => {
4953
deleteApp,
5054
canShowExternalLinks,
5155
showCannotDeleteTooltip,
56+
isWorkflowEditorUnlocked,
5257
toggleRepoSelectionTippy,
5358
getRepo,
5459
isJobView,
@@ -172,6 +177,23 @@ export const AppNavigation = () => {
172177
)
173178
}
174179

180+
if (item.stage === STAGE_NAME.PROTECT_CONFIGURATION) {
181+
return (
182+
isWorkflowEditorUnlocked &&
183+
isFELibAvailable && (
184+
<div key={item.stage}>
185+
{!canShowExternalLinks && <div className="dc__border-bottom-n1 mt-8 mb-8" />}
186+
{renderNavItem(item, null, {
187+
target: '_blank',
188+
icon: <ICArrowSquareOut className="icon-dim-16 dc__no-shrink scn-8" />,
189+
tooltipContent:
190+
'Configuration change approval has been moved to Global Configuration',
191+
})}
192+
</div>
193+
)
194+
)
195+
}
196+
175197
if (
176198
item.stage !== STAGE_NAME.ENV_OVERRIDE ||
177199
(item.stage === STAGE_NAME.ENV_OVERRIDE && item.isLocked)

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

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import {
44
ApprovalConfigDataKindType,
55
ApprovalConfigDataType,
66
CollapsibleListItem,
7+
ConditionalWrap,
78
EnvResourceType,
89
getIsApprovalPolicyConfigured,
910
ResourceIdToResourceApprovalPolicyConfigMapType,
11+
Tooltip,
1012
} from '@devtron-labs/devtron-fe-common-lib'
1113

1214
import { ReactComponent as Lock } from '@Icons/ic-locked.svg'
1315
import { ReactComponent as ICStamp } from '@Icons/ic-stamp.svg'
1416
import { ResourceConfigStage, ResourceConfigState } from '@Pages/Applications/DevtronApps/service.types'
1517

18+
import { AnchorHTMLAttributes, ReactElement } from 'react'
1619
import {
1720
CustomNavItemsType,
1821
EnvConfigRouteParams,
@@ -32,29 +35,51 @@ const renderNavItemIcon = (isLocked: boolean, isApprovalPolicyConfigured: boolea
3235
return null
3336
}
3437

38+
const wrapWithTooltip = (content: string) => (children: ReactElement) => (
39+
<Tooltip content={content} alwaysShowTippyOnHover placement="right">
40+
{children}
41+
</Tooltip>
42+
)
43+
3544
/**
3645
*
3746
* @param item
3847
* @param hideApprovalPolicyIcon Used to hide the policy icon (applicable for jobs atm)
3948
*/
40-
export const renderNavItem = (item: CustomNavItemsType, hideApprovalPolicyIcon?: boolean) => {
49+
export const renderNavItem = (
50+
item: CustomNavItemsType,
51+
hideApprovalPolicyIcon?: boolean,
52+
options?: {
53+
target?: AnchorHTMLAttributes<HTMLAnchorElement>['target']
54+
icon?: ReactElement
55+
tooltipContent?: string
56+
},
57+
) => {
4158
const linkDataTestName = item.title.toLowerCase().split(' ').join('-')
4259

4360
return (
44-
<NavLink
45-
data-testid={`${linkDataTestName}-link`}
46-
key={item.title}
47-
onClick={(event) => {
48-
if (item.isLocked) {
49-
event.preventDefault()
50-
}
51-
}}
52-
className="dc__nav-item cursor fs-13 lh-32 cn-7 w-100 br-4 px-8 flexbox dc__align-items-center dc__content-space dc__no-decor"
53-
to={item.href}
54-
>
55-
<span className="dc__truncate nav-text">{item.title}</span>
56-
{renderNavItemIcon(item.isLocked, !hideApprovalPolicyIcon && item.isProtectionAllowed, linkDataTestName)}
57-
</NavLink>
61+
<ConditionalWrap condition={!!options?.tooltipContent} wrap={wrapWithTooltip(options?.tooltipContent)}>
62+
<NavLink
63+
data-testid={`${linkDataTestName}-link`}
64+
key={item.title}
65+
onClick={(event) => {
66+
if (item.isLocked) {
67+
event.preventDefault()
68+
}
69+
}}
70+
className="dc__nav-item cursor fs-13 lh-32 cn-9 w-100 br-4 px-8 flexbox dc__align-items-center dc__content-space dc__no-decor"
71+
to={item.href}
72+
target={options?.target}
73+
>
74+
<span className="dc__truncate nav-text">{item.title}</span>
75+
{options?.icon ??
76+
renderNavItemIcon(
77+
item.isLocked,
78+
!hideApprovalPolicyIcon && item.isProtectionAllowed,
79+
linkDataTestName,
80+
)}
81+
</NavLink>
82+
</ConditionalWrap>
5883
)
5984
}
6085

src/Pages/Applications/DevtronApps/Details/AppConfigurations/appConfig.scss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@
6161
grid-template-rows: repeat(3, 32px) 1fr;
6262
}
6363
}
64+
65+
&.config-protection__side-nav {
66+
grid-template-rows: 110px repeat(4, 32px) 54px 32px 1fr auto;
67+
68+
&.hide-external-links {
69+
grid-template-rows: 110px repeat(4, 32px) 54px 1fr auto;
70+
}
71+
72+
&.hide-app-config-help {
73+
grid-template-rows: repeat(4, 32px) 54px 32px 1fr auto;
74+
75+
&.hide-external-links {
76+
grid-template-rows: repeat(4, 32px) 54px 1fr auto;
77+
}
78+
}
79+
}
6480
}
6581

6682
&.app-compose-with-gitops-config__nav {
@@ -73,6 +89,22 @@
7389
grid-template-rows: repeat(5, 32px) 1fr auto;
7490
}
7591
}
92+
93+
&.config-protection__side-nav {
94+
grid-template-rows: 110px repeat(5, 32px) 54px 32px 1fr auto;
95+
96+
&.hide-external-links {
97+
grid-template-rows: 110px repeat(5, 32px) 54px 1fr auto;
98+
}
99+
100+
&.hide-app-config-help {
101+
grid-template-rows: repeat(5, 32px) 54px 32px 1fr auto;
102+
103+
&.hide-external-links {
104+
grid-template-rows: repeat(5, 32px) 54px 1fr auto;
105+
}
106+
}
107+
}
76108
}
77109

78110
.help-container {

src/components/cdPipeline/BuildCD.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { BuildCDProps } from './types'
6464
const VirtualEnvSelectionInfoText = importComponentFromFELibrary('VirtualEnvSelectionInfoText')
6565
const HelmManifestPush = importComponentFromFELibrary('HelmManifestPush')
6666
const MigrateHelmReleaseBody = importComponentFromFELibrary('MigrateHelmReleaseBody', null, 'function')
67+
const ApprovalPolicyRedirectCard = importComponentFromFELibrary('ApprovalPolicyRedirectCard', null, 'function')
6768

6869
export default function BuildCD({
6970
isAdvanced,
@@ -775,6 +776,9 @@ export default function BuildCD({
775776
!noGitOpsModuleInstalledAndConfigured &&
776777
renderDeploymentAppType()}
777778
{isAdvanced ? renderAdvancedDeploymentStrategy() : renderBasicDeploymentStrategy()}
779+
{isAdvanced &&
780+
ApprovalPolicyRedirectCard &&
781+
<ApprovalPolicyRedirectCard />}
778782
{isAdvanced && (
779783
<>
780784
<CustomImageTags

0 commit comments

Comments
 (0)