Skip to content

Commit be01382

Browse files
committed
refactor: code optimization
1 parent 0edb381 commit be01382

File tree

8 files changed

+45
-64
lines changed

8 files changed

+45
-64
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ export const CreateCICDPipeline = ({
9292
const { deploymentAppType, selectedEnvironment } = cd
9393

9494
// HANDLERS
95+
const handleOnEscape = () => {
96+
onClose()
97+
}
98+
9599
const handleReloadNoGitOpsRepoConfiguredModalClose = () => {
96100
setReloadNoGitOpsRepoConfiguredModal(false)
97101
}
@@ -265,8 +269,7 @@ export const CreateCICDPipeline = ({
265269
}
266270
}
267271

268-
const handleCreateWorkflow = () =>
269-
cdNodeCreateError ? createWorkflow({ shouldCreateCINode: false }) : createWorkflow({ shouldCreateCINode: true })
272+
const handleCreateWorkflow = () => createWorkflow({ shouldCreateCINode: !cdNodeCreateError })
270273

271274
// RESET
272275
const resetStateToDefault = () => {
@@ -331,7 +334,7 @@ export const CreateCICDPipeline = ({
331334
open={open}
332335
width={800}
333336
onClose={onClose}
334-
onEscape={onClose}
337+
onEscape={handleOnEscape}
335338
>
336339
<GenericModal.Header title="Build and deploy from source code" />
337340
<GenericModal.Body>

src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
DeploymentAppTypes,
33
DeploymentStrategy,
44
getEnvironmentListMinPublic,
5-
getIsRequestAborted,
65
ModuleNameMap,
76
ModuleStatus,
87
ReleaseMode,
@@ -128,9 +127,7 @@ export const getCICDPipelineInitData = async (appId: string): Promise<CreateCICD
128127

129128
return { ci, cd }
130129
} catch (err) {
131-
if (!getIsRequestAborted(err)) {
132-
showError(err)
133-
}
130+
showError(err)
134131
throw err
135132
}
136133
}

src/Pages/App/Configurations/WorkflowEditor/SourceMaterialsSelector/SourceMaterialsSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const SourceMaterialsSelector = ({
1111
{repoName && (
1212
<div className="flex left dc__gap-8">
1313
<Icon name="ic-git" color={null} size={24} />
14-
<p className="m-0 fs-13 lh-20 fw-6 cn-9">{repoName}</p>
14+
<p className="m-0 fs-13 lh-20 fw-6 cn-9 dc__truncate">{repoName}</p>
1515
</div>
1616
)}
1717
<div className="dc__grid-cols-2 dc__gap-12">

src/components/ciPipeline/SourceMaterials.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Fragment, useEffect, useState } from 'react'
17+
import { Fragment, useMemo, useState } from 'react'
1818
import { Link, useLocation } from 'react-router-dom'
1919

2020
import {
2121
CiPipelineSourceTypeOption,
2222
InfoBlock,
23-
MaterialType,
2423
SelectPickerProps,
2524
SourceTypeMap,
2625
} from '@devtron-labs/devtron-fe-common-lib'
@@ -44,24 +43,22 @@ export const SourceMaterials = ({
4443
}: SourceMaterialsProps) => {
4544
// STATES
4645
const [isProviderChanged, setProviderChanged] = useState(false)
47-
const [materials, setMaterials] = useState<MaterialType[]>(initialMaterials)
4846

4947
// HOOKS
5048
const location = useLocation()
5149

5250
// CONSTANTS
5351
const isLinkedCI = location.pathname.includes('linked-ci')
54-
const isMultiGit = materials.length > 1
55-
56-
useEffect(() => {
52+
const isMultiGit = initialMaterials.length > 1
53+
const materials = useMemo(() => {
5754
const webhookTypeMaterial = initialMaterials.find((material) => material.type === SourceTypeMap.WEBHOOK)
5855

5956
if (isMultiGit && webhookTypeMaterial) {
60-
setMaterials([webhookTypeMaterial])
61-
} else {
62-
setMaterials(initialMaterials)
57+
return [webhookTypeMaterial]
6358
}
64-
}, [initialMaterials])
59+
60+
return initialMaterials
61+
}, [isMultiGit, initialMaterials])
6562

6663
// HANDLERS
6764
const onBlur = async () => {
@@ -127,7 +124,7 @@ export const SourceMaterials = ({
127124
<div className="flexbox-col dc__gap-16">
128125
<h3 className="m-0 fs-14 lh-20 fw-6 cn-9">Select code source</h3>
129126
{materials.map((material, index) => {
130-
const mat = material
127+
const mat = structuredClone(material)
131128
const isBranchRegex = mat.type === SourceTypeMap.BranchRegex || mat.isRegex
132129
const isBranchFixed = mat.type === SourceTypeMap.BranchFixed && !mat.isRegex
133130
const _selectedWebhookEvent =

src/components/ciPipeline/ciPipeline.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
import { Routes, ViewType } from '../../config'
3838
import { getSourceConfig, getWebhookDataMetaConfig } from '../../services/service'
3939
import { CiPipelineSourceTypeBaseOptions } from '../CIPipelineN/ciPipeline.utils'
40-
import { CIPipelineBuildType, PatchAction } from './types'
40+
import { CIPipelineBuildType, CIPipelineInitData, PatchAction } from './types'
4141
import { safeTrim } from '../../util/Util'
4242

4343
const emptyStepsData = () => {
@@ -64,9 +64,7 @@ export function getInitData(
6464
includeWebhookData: boolean = false,
6565
isJobCard: boolean,
6666
isTemplateView: AppConfigProps['isTemplateView'],
67-
): Promise<{
68-
result: { form: PipelineFormType; loadingData: boolean; isAdvanced: boolean; isBlobStorageConfigured: boolean }
69-
}> {
67+
): Promise<CIPipelineInitData> {
7068
return Promise.all([
7169
getCIPipelineNameSuggestion(appId, isTemplateView),
7270
getPipelineMetaConfiguration(appId.toString(), includeWebhookData, true, isJobCard, isTemplateView),

src/components/ciPipeline/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,12 @@ export interface WebhookConditionType {
423423
deleteWebhookCondition: (index: number) => void
424424
canEditSelectorCondition: boolean
425425
}
426+
427+
export interface CIPipelineInitData {
428+
result: {
429+
form: PipelineFormType
430+
loadingData: boolean
431+
isAdvanced: boolean
432+
isBlobStorageConfigured: boolean
433+
}
434+
}

src/css/mixins.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,17 @@
4949
}
5050
}
5151
}
52+
53+
@mixin divider($name, $color) {
54+
&__#{$name} {
55+
width: 1px;
56+
min-height: 16px;
57+
background-color: var(#{$color});
58+
59+
&--horizontal {
60+
width: 100%;
61+
min-height: 1px;
62+
background-color: var(#{$color});
63+
}
64+
}
65+
}

src/css/themeUtils.scss

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -150,45 +150,8 @@
150150
}
151151

152152
.divider {
153-
&__primary {
154-
width: 1px;
155-
min-height: 16px;
156-
background-color: var(--divider-primary);
157-
158-
&--horizontal {
159-
width: 100%;
160-
min-height: 1px;
161-
background-color: var(--divider-primary);
162-
}
163-
}
164-
165-
&__primary-translucent {
166-
width: 1px;
167-
min-height: 16px;
168-
background-color: var(--divider-primary-translucent);
169-
}
170-
171-
&__secondary {
172-
width: 1px;
173-
min-height: 16px;
174-
background-color: var(--divider-secondary);
175-
176-
&--horizontal {
177-
width: 100%;
178-
min-height: 1px;
179-
background-color: var(--divider-secondary);
180-
}
181-
}
182-
183-
&__secondary-translucent {
184-
width: 1px;
185-
min-height: 16px;
186-
background-color: var(--divider-secondary-translucent);
187-
188-
&--horizontal {
189-
width: 100%;
190-
min-height: 1px;
191-
background-color: var(--divider-secondary-translucent);
192-
}
193-
}
153+
@include divider("primary", "--divider-primary");
154+
@include divider("primary-translucent", "--divider-primary-translucent");
155+
@include divider("secondary", "--divider-secondary");
156+
@include divider("secondary-translucent", "--divider-secondary-translucent");
194157
}

0 commit comments

Comments
 (0)