Skip to content

Commit 462905d

Browse files
committed
feat: refactor BranchRegexModal to use utility function for initial regex value and improve BuildImageHeader layout
1 parent e651d6e commit 462905d

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/components/app/details/triggerView/BranchRegexModal.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { getGitProviderIcon } from '@Components/common'
3838
import { REQUIRED_FIELD_MSG } from '../../../../config/constantMessaging'
3939
import { BRANCH_REGEX_MODAL_MESSAGING } from './Constants'
4040
import { BranchRegexModalProps, RegexValueType } from './types'
41+
import { getInitialRegexValue } from './utils'
4142

4243
const renderRegexInfo = () => (
4344
<InfoBlock
@@ -65,19 +66,8 @@ const BranchRegexModal = ({
6566
workflowId,
6667
handleReload,
6768
}: BranchRegexModalProps) => {
68-
const getInitialRegexValue = () => {
69-
const initialValue: Record<number, RegexValueType> = {}
70-
material.forEach((mat) => {
71-
initialValue[mat.gitMaterialId] = {
72-
value: mat.value,
73-
isInvalid: mat.regex && !new RegExp(mat.regex).test(mat.value),
74-
}
75-
})
76-
return initialValue
77-
}
78-
7969
const [isSavingRegexValue, setIsSavingRegexValue] = useState(false)
80-
const [regexValue, setRegexValue] = useState<Record<number, RegexValueType>>(getInitialRegexValue)
70+
const [regexValue, setRegexValue] = useState<Record<number, RegexValueType>>(getInitialRegexValue(material))
8171

8272
const isRegexValueInvalid = (_cm): void => {
8373
const regExp = new RegExp(_cm.source.regex)

src/components/app/details/triggerView/BuildImageModal/BuildImageHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ const BuildImageHeader = ({
3737
</div>
3838
) : (
3939
<h2 className="m-0 fs-16 fw-6 lh-24 cn-9 dc__truncate">
40-
{isJobView ? 'Job Pipeline' : 'Build Pipeline'}{' '}
41-
{pipelineName && !isBulkTrigger ? `'${pipelineName}'` : ''}
40+
{`${isJobView ? 'Job' : 'Build'} Pipeline ${pipelineName && !isBulkTrigger ? `'${pipelineName}'` : ''}`}
4241
</h2>
4342
)}
4443

src/components/app/details/triggerView/BuildImageModal/BulkBuildImageModal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ const BulkBuildImageModal = ({
107107
initialDataAbortControllerRef,
108108
)
109109

110-
setNumberOfAppsLoading(validWorkflows.length)
111-
112110
if (ciMaterialPromiseList.length === 0) {
113111
return []
114112
}
115113

114+
setNumberOfAppsLoading(validWorkflows.length)
115+
116116
const ciMaterialList =
117117
await ApiQueuingWithBatch<Awaited<ReturnType<typeof getCIMaterials>>>(ciMaterialPromiseList)
118118
const runtimeParamsList = await ApiQueuingWithBatch<RuntimePluginVariables[]>(runtimeParamsPromiseList)
@@ -456,10 +456,7 @@ const BulkBuildImageModal = ({
456456
className="flexbox-col dc__content-space h-100 bg__modal--primary shadow__modal dc__overflow-auto bulk-ci-trigger-container"
457457
onClick={stopPropagation}
458458
>
459-
<div
460-
className="flexbox-col dc__content-space h-100 bg__modal--primary shadow__modal dc__overflow-auto bulk-ci-trigger"
461-
onClick={stopPropagation}
462-
>
459+
<div className="flexbox-col dc__content-space h-100 dc__overflow-auto bulk-ci-trigger">
463460
<div className="flexbox-col dc__overflow-auto flex-grow-1">
464461
<BuildImageHeader
465462
showWebhookModal={showWebhookModal}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { CIMaterialType } from '@devtron-labs/devtron-fe-common-lib'
2+
3+
import { RegexValueType } from './types'
4+
5+
export const getInitialRegexValue = (materials: CIMaterialType[]) => {
6+
const initialValue: Record<number, RegexValueType> = {}
7+
materials.forEach((mat) => {
8+
initialValue[mat.gitMaterialId] = {
9+
value: mat.value,
10+
isInvalid: mat.regex && !new RegExp(mat.regex).test(mat.value),
11+
}
12+
})
13+
return initialValue
14+
}

0 commit comments

Comments
 (0)