Skip to content

Commit b52626b

Browse files
committed
refactor: common out SourceMaterials - SourceType Selector Footer
1 parent 619cf1e commit b52626b

File tree

4 files changed

+84
-137
lines changed

4 files changed

+84
-137
lines changed

src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/CIStepperContent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { createWebhookConditionList } from '@Components/ciPipeline/ciPipeline.se
1212
import { ValidationRules } from '@Components/ciPipeline/validationRules'
1313

1414
import { SourceMaterialsSelector } from '../SourceMaterialsSelector'
15-
import { getSelectedWebhookEvent } from '../utils'
15+
import { getCIPipelineBranchSelectorFooterConfig, getSelectedWebhookEvent } from '../utils'
1616
import { ConfigureWebhookWrapper } from './ConfigureWebhookWrapper'
1717
import { CIStepperContentProps } from './types'
18-
import { getBranchValue, getMenuListFooterConfig, getSelectedMaterial } from './utils'
18+
import { getBranchValue, getSelectedMaterial } from './utils'
1919

2020
const validationRules = new ValidationRules()
2121

@@ -179,7 +179,7 @@ export const CIStepperContent = ({
179179
value: selectedMaterial,
180180
onChange: handleSourceTypeChange(gitMaterialId),
181181
getOptionValue: (option) => `${option.value}-${option.label}`,
182-
menuListFooterConfig: getMenuListFooterConfig(materials),
182+
menuListFooterConfig: getCIPipelineBranchSelectorFooterConfig(materials),
183183
isDisabled: isFormDisabled || isMultiGitAndWebhook,
184184
disabledTippyContent: isMultiGitAndWebhook
185185
? `Cannot change source type ${selectedWebhookEvent.name} for multi-git applications`

src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/utils.tsx renamed to src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/utils.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { Link } from 'react-router-dom'
2-
31
import {
42
DeploymentAppTypes,
53
MaterialType,
64
ReleaseMode,
7-
SelectPickerProps,
85
SourceTypeMap,
96
TriggerType,
107
} from '@devtron-labs/devtron-fe-common-lib'
@@ -13,7 +10,6 @@ import { GeneratedHelmPush } from '@Components/cdPipeline/cdPipeline.types'
1310
import { ValidationRules } from '@Components/ciPipeline/validationRules'
1411
import { createClusterEnvGroup, getDeploymentAppType } from '@Components/common'
1512
import { ENV_ALREADY_EXIST_ERROR } from '@Config/constants'
16-
import { URLS } from '@Config/routes'
1713

1814
import { CreateCICDPipelineData, CreateCICDPipelineFormError } from './types'
1915

@@ -271,69 +267,3 @@ export const getSaveCDPipelinesPayload = ({
271267

272268
return [pipeline]
273269
}
274-
275-
export const getMenuListFooterConfig = (materials: MaterialType[]): SelectPickerProps['menuListFooterConfig'] => {
276-
if (!materials) {
277-
return null
278-
}
279-
280-
const isMultiGit = materials.length > 1
281-
const type: SelectPickerProps['menuListFooterConfig']['type'] = 'text'
282-
283-
if (isMultiGit) {
284-
return {
285-
type,
286-
value: (
287-
<span>
288-
If you need webhook based CI for apps with multiple code sources,&nbsp;
289-
<a
290-
className="anchor"
291-
rel="noreferrer"
292-
href="https://github.com/devtron-labs/devtron/issues"
293-
target="_blank"
294-
>
295-
Create a GitHub issue
296-
</a>
297-
</span>
298-
),
299-
}
300-
}
301-
302-
if (!materials[0].gitHostId) {
303-
return {
304-
type,
305-
value: (
306-
<span>
307-
Select git host for this git account to view all supported options.&nbsp;
308-
<Link className="anchor" to={URLS.GLOBAL_CONFIG_GIT}>
309-
Select git host
310-
</Link>
311-
</span>
312-
),
313-
}
314-
}
315-
316-
if (materials[0].gitHostId > 0) {
317-
return {
318-
type,
319-
value: (
320-
<span>
321-
If you want to trigger CI using any other mechanism,&nbsp;
322-
<a
323-
className="anchor"
324-
rel="noreferrer"
325-
href="https://github.com/devtron-labs/devtron/issues"
326-
target="_blank"
327-
>
328-
Create a GitHub issue
329-
</a>
330-
</span>
331-
),
332-
}
333-
}
334-
335-
return {
336-
type,
337-
value: null,
338-
}
339-
}

src/Pages/App/Configurations/WorkflowEditor/utils.ts renamed to src/Pages/App/Configurations/WorkflowEditor/utils.tsx

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { Dispatch, SetStateAction } from 'react'
2+
import { Link } from 'react-router-dom'
23

3-
import { DeploymentAppTypes, MaterialType, PipelineFormType } from '@devtron-labs/devtron-fe-common-lib'
4+
import {
5+
DeploymentAppTypes,
6+
MaterialType,
7+
PipelineFormType,
8+
SelectPickerProps,
9+
} from '@devtron-labs/devtron-fe-common-lib'
10+
11+
import { URLS } from '@Config/routes'
412

513
const gitOpsRepoNotConfiguredWithOptionsHidden =
614
'Deployment via GitOps requires a repository to save deployment manifests. Please configure and try again.'
@@ -77,3 +85,71 @@ export const getSelectedWebhookEvent = (material: MaterialType, webhookEvents: P
7785
return null
7886
}
7987
}
88+
89+
export const getCIPipelineBranchSelectorFooterConfig = (
90+
materials: MaterialType[],
91+
): SelectPickerProps['menuListFooterConfig'] => {
92+
if (!materials) {
93+
return null
94+
}
95+
96+
const isMultiGit = materials.length > 1
97+
const type: SelectPickerProps['menuListFooterConfig']['type'] = 'text'
98+
99+
if (isMultiGit) {
100+
return {
101+
type,
102+
value: (
103+
<span>
104+
If you need webhook based CI for apps with multiple code sources,&nbsp;
105+
<a
106+
className="anchor"
107+
rel="noreferrer"
108+
href="https://github.com/devtron-labs/devtron/issues"
109+
target="_blank"
110+
>
111+
Create a GitHub issue
112+
</a>
113+
</span>
114+
),
115+
}
116+
}
117+
118+
if (!materials[0].gitHostId) {
119+
return {
120+
type,
121+
value: (
122+
<span>
123+
Select git host for this git account to view all supported options.&nbsp;
124+
<Link className="anchor" to={URLS.GLOBAL_CONFIG_GIT}>
125+
Select git host
126+
</Link>
127+
</span>
128+
),
129+
}
130+
}
131+
132+
if (materials[0].gitHostId > 0) {
133+
return {
134+
type,
135+
value: (
136+
<span>
137+
If you want to trigger CI using any other mechanism,&nbsp;
138+
<a
139+
className="anchor"
140+
rel="noreferrer"
141+
href="https://github.com/devtron-labs/devtron/issues"
142+
target="_blank"
143+
>
144+
Create a GitHub issue
145+
</a>
146+
</span>
147+
),
148+
}
149+
}
150+
151+
return {
152+
type,
153+
value: null,
154+
}
155+
}

src/components/ciPipeline/SourceMaterials.tsx

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@
1515
*/
1616

1717
import { Fragment, useMemo, useState } from 'react'
18-
import { Link, useLocation } from 'react-router-dom'
18+
import { useLocation } from 'react-router-dom'
1919

20-
import {
21-
CiPipelineSourceTypeOption,
22-
InfoBlock,
23-
SelectPickerProps,
24-
SourceTypeMap,
25-
} from '@devtron-labs/devtron-fe-common-lib'
20+
import { CiPipelineSourceTypeOption, InfoBlock, SourceTypeMap } from '@devtron-labs/devtron-fe-common-lib'
2621

27-
import { URLS } from '@Config/routes'
28-
import { SourceMaterialsSelector } from '@Pages/App/Configurations'
22+
import { getCIPipelineBranchSelectorFooterConfig, SourceMaterialsSelector } from '@Pages/App/Configurations'
2923

3024
import { ConfigureWebhook } from './ConfigureWebhook'
3125
import { SourceMaterialsProps } from './types'
@@ -67,59 +61,6 @@ export const SourceMaterials = ({
6761
}
6862
}
6963

70-
const getMenuListFooterConfig = (): SelectPickerProps['menuListFooterConfig'] => {
71-
const _isMultiGit = includeWebhookEvents && isMultiGit
72-
const _isSingleGit = includeWebhookEvents && !isMultiGit
73-
74-
let value: SelectPickerProps['menuListFooterConfig']['value'] = null
75-
76-
if (_isMultiGit) {
77-
value = (
78-
<span>
79-
If you need webhook based CI for apps with multiple code sources,&nbsp;
80-
<a
81-
className="anchor"
82-
rel="noreferrer"
83-
href="https://github.com/devtron-labs/devtron/issues"
84-
target="_blank"
85-
>
86-
Create a GitHub issue
87-
</a>
88-
</span>
89-
)
90-
} else if (_isSingleGit) {
91-
if (!materials[0].gitHostId) {
92-
value = (
93-
<span>
94-
Select git host for this git account to view all supported options.&nbsp;
95-
<Link className="anchor" to={URLS.GLOBAL_CONFIG_GIT}>
96-
Select git host
97-
</Link>
98-
</span>
99-
)
100-
} else if (materials[0].gitHostId > 0) {
101-
value = (
102-
<span>
103-
If you want to trigger CI using any other mechanism,&nbsp;
104-
<a
105-
className="anchor"
106-
rel="noreferrer"
107-
href="https://github.com/devtron-labs/devtron/issues"
108-
target="_blank"
109-
>
110-
Create a GitHub issue
111-
</a>
112-
</span>
113-
)
114-
}
115-
}
116-
117-
return {
118-
type: 'text',
119-
value,
120-
}
121-
}
122-
12364
return (
12465
<div className="flexbox-col dc__gap-16">
12566
<h3 className="m-0 fs-14 lh-20 fw-6 cn-9">Select code source</h3>
@@ -170,7 +111,7 @@ export const SourceMaterials = ({
170111
isDisabled: isLinkedCI || isMultiGitAndWebhook,
171112
value: selectedMaterial,
172113
onChange: (selected) => selectSourceType(selected, mat.gitMaterialId),
173-
menuListFooterConfig: getMenuListFooterConfig(),
114+
menuListFooterConfig: getCIPipelineBranchSelectorFooterConfig(materials),
174115
getOptionValue: (option) => `${option.value}-${option.label}`,
175116
disabledTippyContent: isMultiGitAndWebhook
176117
? `Cannot change source type ${_selectedWebhookEvent.name} for multi-git applications`

0 commit comments

Comments
 (0)