Skip to content

Commit d8322c7

Browse files
committed
WIP: bd7d3d2 Merge pull request #1269 from devtron-labs/feat(scoped-variables)/floater-suggestions
1 parent 1660448 commit d8322c7

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import { CustomInput, Drawer, InfoColourBar, Progressing } from '@devtron-labs/devtron-fe-common-lib'
2+
import React, { useEffect, useRef, useState } from 'react'
3+
import { ReactComponent as Close } from '../../../../assets/icons/ic-cross.svg'
4+
import { ReactComponent as Warn } from '../../../../assets/icons/ic-warning.svg'
5+
import SourceUpdateResponseModal from './SourceUpdateResponseModal'
6+
7+
export default function BulkSourceChange({ closePopup, responseList, changeBranch, loading, selectedAppCount }) {
8+
const sourceChangeDetailRef = useRef<HTMLDivElement>(null)
9+
10+
const [showResponseModal, setShowResponseModal] = useState(false)
11+
const [inputError, setInputError] = useState('')
12+
const [branchName, setBranchName] = useState('')
13+
14+
const closeBulkCIModal = (evt) => {
15+
closePopup(evt)
16+
}
17+
18+
const escKeyPressHandler = (evt): void => {
19+
if (evt && evt.key === 'Escape' && typeof closePopup === 'function') {
20+
evt.preventDefault()
21+
closeBulkCIModal(evt)
22+
}
23+
}
24+
const outsideClickHandler = (evt): void => {
25+
if (
26+
sourceChangeDetailRef.current &&
27+
!sourceChangeDetailRef.current.contains(evt.target) &&
28+
typeof closePopup === 'function'
29+
) {
30+
closeBulkCIModal(evt)
31+
}
32+
}
33+
34+
useEffect(() => {
35+
document.addEventListener('keydown', escKeyPressHandler)
36+
return (): void => {
37+
document.removeEventListener('keydown', escKeyPressHandler)
38+
}
39+
}, [escKeyPressHandler])
40+
41+
useEffect(() => {
42+
document.addEventListener('click', outsideClickHandler)
43+
return (): void => {
44+
document.removeEventListener('click', outsideClickHandler)
45+
}
46+
}, [outsideClickHandler])
47+
48+
useEffect(() => {
49+
setShowResponseModal(responseList.length > 0)
50+
}, [responseList])
51+
52+
const updateBranch = () => {
53+
if (branchName.length === 0) {
54+
setInputError('This is required')
55+
return
56+
}
57+
changeBranch(branchName)
58+
}
59+
60+
const renderHeaderSection = (): JSX.Element | null => {
61+
return (
62+
<div className="flex flex-align-center flex-justify dc__border-bottom bcn-0 pt-16 pr-20 pb-16 pl-20">
63+
<h2 className="fs-16 fw-6 lh-1-43 m-0">Change branch for {selectedAppCount} applications</h2>
64+
<button
65+
type="button"
66+
className="dc__transparent flex icon-dim-24"
67+
disabled={loading}
68+
onClick={closeBulkCIModal}
69+
>
70+
<Close className="icon-dim-24" />
71+
</button>
72+
</div>
73+
)
74+
}
75+
76+
const renderInfoBar = (): JSX.Element => {
77+
return (
78+
<InfoColourBar
79+
message="Branch will be changed only for build pipelines with source type as ‘Branch Fixed’ or ‘Branch Regex’."
80+
classname="warn dc__no-border-radius dc__no-top-border dc__no-left-border dc__no-right-border"
81+
Icon={Warn}
82+
iconClass="warning-icon"
83+
/>
84+
)
85+
}
86+
87+
const checkInput = (): boolean => {
88+
return branchName === ''
89+
}
90+
91+
const handleInputChange = (e): void => {
92+
setBranchName(e.target.value)
93+
setInputError('')
94+
}
95+
96+
const renderForm = (): JSX.Element => {
97+
const isDisabled = checkInput()
98+
99+
return (
100+
<div className="p-20">
101+
<div className="form__row">
102+
<CustomInput
103+
labelClassName="dc__required-field"
104+
autoComplete="off"
105+
name="branch_name"
106+
disabled={false}
107+
value={branchName}
108+
error={inputError}
109+
onChange={handleInputChange}
110+
label="Change to branch"
111+
placeholder="Enter branch name"
112+
/>
113+
</div>
114+
<div className="flexbox">
115+
<button
116+
data-testid="cancel_button"
117+
className="cta cancel h-36 lh-36"
118+
type="button"
119+
onClick={closeBulkCIModal}
120+
>
121+
Cancel
122+
</button>
123+
<button
124+
data-testid="save_cluster_after_entering_cluster_details"
125+
className="cta ml-12 h-36 lh-36"
126+
onClick={updateBranch}
127+
disabled={isDisabled}
128+
>
129+
{loading ? <Progressing /> : 'Update branch'}
130+
</button>
131+
</div>
132+
</div>
133+
)
134+
}
135+
return (
136+
<Drawer position="right" width="75%" minWidth={showResponseModal ? '1024px' : '600px'} maxWidth={showResponseModal ? '1200px' : '600px'}>
137+
<div className="dc__window-bg h-100 bcn-0 bulk-ci-trigger-container" ref={sourceChangeDetailRef}>
138+
{renderHeaderSection()}
139+
{showResponseModal ? (
140+
<SourceUpdateResponseModal closePopup={closePopup} isLoading={false} responseList={responseList} />
141+
) : (
142+
<>
143+
{renderInfoBar()}
144+
{renderForm()}
145+
</>
146+
)}
147+
</div>
148+
</Drawer>
149+
)
150+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react'
2+
import { Progressing } from '@devtron-labs/devtron-fe-common-lib'
3+
import { TriggerModalRow } from './TriggerModalTableRow'
4+
5+
export default function SourceUpdateResponseModal({ closePopup, responseList, isLoading }) {
6+
const renderResponseBodySection = (): JSX.Element => {
7+
if (isLoading) {
8+
return <Progressing pageLoader />
9+
}
10+
return (
11+
<div className="response-list-container bcn-0 dc__height-inherit dc__overflow-auto pr-20 pb-16 pl-20">
12+
<div
13+
className="dc__position-sticky dc__top-0 bcn-0 dc__border-bottom response-row dc__border-bottom pt-24 pb-8 dc__uppercase"
14+
style={{ zIndex: 1 }}
15+
>
16+
<div className="fs-12 fw-6 cn-7 ">Application</div>
17+
<div className="fs-12 fw-6 cn-7 ">Branch Change status</div>
18+
<div className="fs-12 fw-6 cn-7 ">Message</div>
19+
</div>
20+
{responseList
21+
.map((response, index) => (
22+
<TriggerModalRow key={response.appId} rowData={response} index={index} />
23+
))}
24+
</div>
25+
)
26+
}
27+
28+
const renderFooterSection = (): JSX.Element => {
29+
return (
30+
<div
31+
className={`dc__border-top flex bcn-0 pt-16 pr-20 pb-16 pl-20 dc__position-fixed dc__bottom-0 env-modal-width right`}
32+
>
33+
<button className="cta cancel flex h-36" data-testid="close-popup" onClick={closePopup}>
34+
Close
35+
</button>
36+
</div>
37+
)
38+
}
39+
40+
return (
41+
<>
42+
{renderResponseBodySection()}
43+
{renderFooterSection()}
44+
</>
45+
)
46+
}

0 commit comments

Comments
 (0)