Skip to content

Commit ed0c059

Browse files
authored
Merge pull request #569 from devtron-labs/workflow__esc
ci workflow esacpe fixed
2 parents 9f6c265 + a69d5de commit ed0c059

File tree

5 files changed

+77
-17
lines changed

5 files changed

+77
-17
lines changed

src/components/CIPipelineN/CIPipeline.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect, createContext } from 'react'
22
import { NavLink } from 'react-router-dom'
3-
import { ButtonWithLoader, ConditionalWrap, DeleteDialog, showError, VisibleModal } from '../common'
3+
import { ButtonWithLoader, ConditionalWrap, DeleteDialog, showError, useKeyDown, VisibleModal } from '../common'
44
import { Redirect, Route, Switch, useParams, useRouteMatch, useLocation, useHistory } from 'react-router'
55
import { BuildStageVariable, BuildTabText, ModuleNameMap, SourceTypeMap, TriggerType, ViewType } from '../../config'
66
import {
@@ -200,11 +200,11 @@ export default function CIPipeline({
200200
})
201201
}, [])
202202

203-
const getSecurityModuleStatus = async(): Promise<void> => {
203+
const getSecurityModuleStatus = async (): Promise<void> => {
204204
try {
205205
const { result } = await getModuleInfo(ModuleNameMap.SECURITY)
206206
if (result?.status === ModuleStatus.INSTALLED) {
207-
setSecurityModuleInstalled(true)
207+
setSecurityModuleInstalled(true)
208208
}
209209
} catch (error) {}
210210
}
@@ -354,7 +354,8 @@ export default function CIPipeline({
354354
validateStage(BuildStageVariable.PreBuild, formData)
355355
validateStage(BuildStageVariable.Build, formData)
356356
validateStage(BuildStageVariable.PostBuild, formData)
357-
const scanValidation = !isSecurityModuleInstalled || (formData.scanEnabled || !window._env_.FORCE_SECURITY_SCANNING)
357+
const scanValidation =
358+
!isSecurityModuleInstalled || formData.scanEnabled || !window._env_.FORCE_SECURITY_SCANNING
358359
if (!scanValidation) {
359360
setLoadingData(false)
360361
toast.error('Scanning is mandatory, please enable scanning')
@@ -377,7 +378,7 @@ export default function CIPipeline({
377378
}
378379

379380
saveCIPipeline(
380-
{...formData, scanEnabled: isSecurityModuleInstalled ? formData.scanEnabled: false },
381+
{ ...formData, scanEnabled: isSecurityModuleInstalled ? formData.scanEnabled : false },
381382
ciPipeline,
382383
formData.materials,
383384
+appId,
@@ -511,9 +512,7 @@ export default function CIPipeline({
511512
_formDataErrorObj.name = validationRules.name(_formData.name)
512513
_formDataErrorObj[BuildStageVariable.Build].isValid = _formDataErrorObj.name.isValid
513514
let valid = _formData.materials.reduce((isValid, mat) => {
514-
isValid =
515-
isValid &&
516-
validationRules.sourceValue( mat.regex || mat.value).isValid
515+
isValid = isValid && validationRules.sourceValue(mat.regex || mat.value).isValid
517516
return isValid
518517
}, true)
519518
_formDataErrorObj[BuildStageVariable.Build].isValid = _formDataErrorObj.name.isValid && valid
@@ -639,6 +638,7 @@ export default function CIPipeline({
639638
const addNewTask = () => {
640639
const _formData = { ...formData }
641640
const detailsFromLastStep = calculateLastStepDetail(true, _formData, activeStageName)
641+
642642
const stage = {
643643
id: detailsFromLastStep.index,
644644
index: detailsFromLastStep.index,
@@ -677,6 +677,14 @@ export default function CIPipeline({
677677
)
678678
}
679679

680+
const keys = useKeyDown()
681+
682+
useEffect(() => {
683+
if (keys.join('') === 'Escape' && typeof close === 'function') {
684+
close()
685+
}
686+
}, [keys])
687+
680688
return (
681689
<VisibleModal className="">
682690
<div

src/components/cdPipeline/CDPipeline.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,22 @@ export default class CDPipeline extends Component<CDPipelineProps, CDPipelineSta
119119
this.handleRunInEnvCheckbox = this.handleRunInEnvCheckbox.bind(this)
120120
this.savePipeline = this.savePipeline.bind(this)
121121
this.selectEnvironment = this.selectEnvironment.bind(this)
122+
this.escFunction = this.escFunction.bind(this)
122123
}
123124

124125
componentDidMount() {
125126
this.getDeploymentStrategies()
127+
document.addEventListener('keydown', this.escFunction)
128+
}
129+
130+
componentWillUnmount() {
131+
document.removeEventListener('keydown', this.escFunction)
132+
}
133+
134+
escFunction(event) {
135+
if ((event.keyCode === 27 || event.key === 'Escape') && typeof this.props.close === 'function') {
136+
this.props.close()
137+
}
126138
}
127139

128140
getDeploymentStrategies(): void {

src/components/ciPipeline/ExternalCIPipeline.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ export default class ExternalCIPipeline extends Component<CIPipelineProps, Exter
6767
this.copyToClipboard = this.copyToClipboard.bind(this);
6868
this.validationRules = new ValidationRules();
6969
this.handleSourceChange = this.handleSourceChange.bind(this);
70-
70+
this.escFunction = this.escFunction.bind(this);
7171
}
7272

7373
componentDidMount() {
7474
this.getHostURLConfig();
7575
if (this.props.match.params.ciPipelineId) {
76+
document.addEventListener("keydown", this.escFunction);
7677
getInitDataWithCIPipeline(this.props.match.params.appId, this.props.match.params.ciPipelineId).then((response) => {
7778
this.setState({ ...response });
7879
}).catch((error: ServerErrors) => {
@@ -96,6 +97,16 @@ export default class ExternalCIPipeline extends Component<CIPipelineProps, Exter
9697
}
9798
}
9899

100+
componentWillUnmount() {
101+
document.removeEventListener('keydown', this.escFunction)
102+
}
103+
104+
escFunction(event) {
105+
if ((event.keyCode === 27 || event.key === 'Escape') && typeof this.props.close === 'function') {
106+
this.props.close()
107+
}
108+
}
109+
99110
getHostURLConfig() {
100111
getHostURLConfiguration().then((response) => {
101112
this.setState({ hostURLConfig: response.result, })

src/components/ciPipeline/LinkedCIPipelineEdit.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ export default class LinkedCIPipeline extends Component<CIPipelineProps, LinkedC
5252
this.selectApp = this.selectApp.bind(this)
5353
this.handleName = this.handleName.bind(this)
5454
this.validationRules = new ValidationRules()
55+
this.escFunction = this.escFunction.bind(this);
56+
}
57+
58+
componentDidMount() {
59+
document.addEventListener('keydown', this.escFunction)
60+
}
61+
62+
componentWillUnmount() {
63+
document.removeEventListener('keydown', this.escFunction)
64+
}
65+
66+
escFunction(event) {
67+
if (event.keyCode === 27 || event.key === 'Escape') {
68+
this.props.close()
69+
}
5570
}
5671

5772
selectApp({ value }): void {

src/components/ciPipeline/LinkedCIPipelineView.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,31 @@ export default class LinkedCIPipelineView extends Component<CIPipelineProps, CIP
5858
}
5959
this.deletePipeline = this.deletePipeline.bind(this);
6060
this.closeCIDeleteModal = this.closeCIDeleteModal.bind(this);
61+
this.escFunction = this.escFunction.bind(this)
6162
}
6263

6364
componentDidMount() {
64-
getInitDataWithCIPipeline(this.props.match.params.appId, this.props.match.params.ciPipelineId, true).then((response) => {
65-
this.setState({ ...response, loadingData: false }, () => {
66-
this.generateSourceUrl();
67-
});
68-
}).catch((error: ServerErrors) => {
69-
showError(error);
70-
this.setState({ loadingData: false });
71-
})
65+
document.addEventListener('keydown', this.escFunction)
66+
getInitDataWithCIPipeline(this.props.match.params.appId, this.props.match.params.ciPipelineId, true)
67+
.then((response) => {
68+
this.setState({ ...response, loadingData: false }, () => {
69+
this.generateSourceUrl()
70+
})
71+
})
72+
.catch((error: ServerErrors) => {
73+
showError(error)
74+
this.setState({ loadingData: false })
75+
})
76+
}
77+
78+
componentWillUnmount() {
79+
document.removeEventListener('keydown', this.escFunction)
80+
}
81+
82+
escFunction(event) {
83+
if ((event.keyCode === 27 || event.key === 'Escape') && typeof this.props.close === 'function') {
84+
this.props.close()
85+
}
7286
}
7387

7488
async generateSourceUrl() {

0 commit comments

Comments
 (0)