Skip to content

Commit def3bed

Browse files
committed
refactor: code review fixes
1 parent f2399fc commit def3bed

File tree

7 files changed

+29
-39
lines changed

7 files changed

+29
-39
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ export const CIStepperContent = ({
8585
(gitMaterialId: MaterialType['gitMaterialId']) => (selectedOption: CiPipelineSourceTypeOption) => {
8686
const { ci, cd } = structuredClone(ciCdPipeline)
8787

88-
// Determine if the previously selected source was a webhook
89-
const wasWebhookPreviously =
90-
ci.ciPipelineSourceTypeOptions.find((opt) => opt.isSelected)?.value === SourceTypeMap.WEBHOOK
91-
9288
// Find the material index to update
9389
const materialIndex = ci.materials.findIndex((mat) => mat.gitMaterialId === gitMaterialId)
9490

@@ -97,6 +93,10 @@ export const CIStepperContent = ({
9793
const newSourceType = selectedOption.value
9894
const isRegexType = newSourceType === SourceTypeMap.BranchRegex
9995

96+
// Determine if the previously selected source was a webhook
97+
const wasWebhookPreviously =
98+
ci.ciPipelineSourceTypeOptions.find((opt) => opt.isSelected)?.value === SourceTypeMap.WEBHOOK
99+
100100
// Update material with new type and adjusted values
101101
ci.materials[materialIndex] = {
102102
...currentMaterial,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ export const CreateCICDPipeline = ({
215215
])
216216

217217
setIsCreatingWorkflow(false)
218-
await getWorkflows()
219218

220219
if (cdNodeRes.status === 'rejected') {
221220
setCdNodeCreateError(cdNodeRes.reason)
@@ -238,6 +237,7 @@ export const CreateCICDPipeline = ({
238237
variant: ToastVariantType.success,
239238
description: CREATE_CI_CD_PIPELINE_TOAST_MESSAGES.CREATE_WORKFLOW_SUCCESS,
240239
})
240+
getWorkflows()
241241
onClose()
242242
}
243243
} catch {

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import {
22
DeploymentAppTypes,
33
DeploymentStrategy,
44
getEnvironmentListMinPublic,
5-
ModuleNameMap,
6-
ModuleStatus,
75
ReleaseMode,
86
SavedDeploymentStrategy,
97
showError,
@@ -15,7 +13,6 @@ import { getCDPipelineNameSuggestion, getDeploymentStrategyList } from '@Compone
1513
import { GeneratedHelmPush } from '@Components/cdPipeline/cdPipeline.types'
1614
import { getInitData } from '@Components/ciPipeline/ciPipeline.service'
1715
import { sortObjectArrayAlphabetically } from '@Components/common'
18-
import { getModuleInfo } from '@Components/v2/devtronStackManager/DevtronStackManager.service'
1916

2017
import { CreateCICDPipelineData } from './types'
2118

@@ -105,22 +102,14 @@ const getCDInitData = async (appId: string, isTemplateView: boolean): Promise<Cr
105102
}
106103

107104
const getCIInitData = async (appId: string, isTemplateView: boolean) => {
108-
const [
109-
{
110-
result: { form, isBlobStorageConfigured },
111-
},
112-
{
113-
result: { status },
114-
},
115-
] = await Promise.all([
116-
getInitData(appId.toString(), true, false, isTemplateView),
117-
getModuleInfo(ModuleNameMap.SECURITY),
118-
])
105+
const {
106+
result: { form, isBlobStorageConfigured, isSecurityModuleInstalled },
107+
} = await getInitData(appId.toString(), true, false, isTemplateView)
119108

120109
return {
121110
...form,
122111
isBlobStorageConfigured,
123-
isSecurityModuleInstalled: status === ModuleStatus.INSTALLED,
112+
isSecurityModuleInstalled,
124113
}
125114
}
126115

src/components/CIPipelineN/CIPipeline.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import {
2020
ServerErrors,
2121
showError,
2222
ConditionalWrap,
23-
VisibleModal,
2423
Drawer,
2524
VariableType,
2625
MandatoryPluginDataType,
27-
ButtonWithLoader,
2826
PluginDataStoreType,
2927
ProcessPluginDataReturnType,
3028
PluginDetailPayloadType,
@@ -34,11 +32,9 @@ import {
3432
getUpdatedPluginStore,
3533
TabProps,
3634
TabGroup,
37-
ModuleNameMap,
3835
SourceTypeMap,
3936
DEFAULT_ENV,
4037
getEnvironmentListMinPublic,
41-
ModuleStatus,
4238
PipelineFormType,
4339
ToastVariantType,
4440
ToastManager,
@@ -69,7 +65,6 @@ import { PreBuild } from './PreBuild'
6965
import { Sidebar } from './Sidebar'
7066
import { Build } from './Build'
7167
import { ReactComponent as WarningTriangle } from '../../assets/icons/ic-warning.svg'
72-
import { getModuleInfo } from '../v2/devtronStackManager/DevtronStackManager.service'
7368
import { LoadingState } from '../ciConfig/types'
7469
import { pipelineContext } from '../workflowEditor/workflowEditor'
7570
import { calculateLastStepDetailsLogic, checkUniqueness, validateTask } from '../cdPipeline/cdpipeline.util'
@@ -232,17 +227,6 @@ export default function CIPipeline({
232227
setAvailableTags(tags)
233228
}
234229

235-
const getSecurityModuleStatus = async (): Promise<void> => {
236-
try {
237-
const { result } = await getModuleInfo(ModuleNameMap.SECURITY)
238-
if (result?.status === ModuleStatus.INSTALLED) {
239-
setSecurityModuleInstalled(true)
240-
}
241-
} catch (error) {
242-
showError(error)
243-
}
244-
}
245-
246230
// mandatory plugins are applicable for job ci but not jobs
247231
const areMandatoryPluginPossible = !isJobView && !isTemplateView && !!processPluginData
248232

@@ -454,7 +438,6 @@ export default function CIPipeline({
454438
const handleOnMountAPICalls = async () => {
455439
try {
456440
setPageState(ViewType.LOADING)
457-
await getSecurityModuleStatus()
458441
if (ciPipelineId) {
459442
const ciPipelineResponse = await getInitDataWithCIPipeline(appId, ciPipelineId, true, isTemplateView)
460443
if (ciPipelineResponse) {
@@ -477,6 +460,7 @@ export default function CIPipeline({
477460
validateStage(BuildStageVariable.PostBuild, ciPipelineResponse.form)
478461
setFormData(ciPipelineResponse.form)
479462
setIsBlobStorageConfigured(ciPipelineResponse.isBlobStorageConfigured)
463+
setSecurityModuleInstalled(ciPipelineResponse.isSecurityModuleInstalled)
480464
setCIPipeline(ciPipelineResponse.ciPipeline)
481465
await getInitialPlugins(ciPipelineResponse.form)
482466
await getEnvironments(ciPipelineResponse.ciPipeline.environmentId)
@@ -486,6 +470,7 @@ export default function CIPipeline({
486470
const ciPipelineResponse = await getInitData(appId, true, isJobCard, isTemplateView)
487471
if (ciPipelineResponse) {
488472
setFormData(ciPipelineResponse.result.form)
473+
setSecurityModuleInstalled(ciPipelineResponse.result.isSecurityModuleInstalled)
489474
await getInitialPlugins(ciPipelineResponse.result.form)
490475
await getEnvironments(0)
491476
}
@@ -541,7 +526,7 @@ export default function CIPipeline({
541526

542527
const handleAdvancedOptions = () => {
543528
setIsAdvanced(true)
544-
handleAnalyticsEvent({category: 'CI Pipeline', action: 'DA_BUILD_ADVANCED'})
529+
handleAnalyticsEvent({ category: 'CI Pipeline', action: 'DA_BUILD_ADVANCED' })
545530
}
546531

547532
const renderSecondaryButton = () => {

src/components/ciPipeline/SourceMaterials.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const SourceMaterials = ({
5252
}
5353

5454
return initialMaterials
55-
}, [isMultiGit, initialMaterials])
55+
}, [initialMaterials])
5656

5757
// HANDLERS
5858
const onBlur = async () => {

src/components/ciPipeline/ciPipeline.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ import {
3232
GetTemplateAPIRouteType,
3333
getTemplateAPIRoute,
3434
SourceTypeMap,
35+
ModuleStatus,
3536
} from '@devtron-labs/devtron-fe-common-lib'
3637
import { Routes, ViewType } from '../../config'
3738
import { getSourceConfig, getWebhookDataMetaConfig } from '../../services/service'
3839
import { CiPipelineSourceTypeBaseOptions } from '../CIPipelineN/ciPipeline.utils'
3940
import { CIPipelineBuildType, CIPipelineInitData, PatchAction } from './types'
4041
import { safeTrim } from '../../util/Util'
42+
import { getModuleInfo } from '@Components/v2/devtronStackManager/DevtronStackManager.service'
4143

4244
const emptyStepsData = () => {
4345
return { id: 0, steps: [] }
@@ -68,13 +70,17 @@ export function getInitData(
6870
getCIPipelineNameSuggestion(appId, isTemplateView),
6971
getPipelineMetaConfiguration(appId.toString(), includeWebhookData, true, isJobCard, isTemplateView),
7072
getModuleConfigured(ModuleNameMap.BLOB_STORAGE),
73+
getModuleInfo(ModuleNameMap.SECURITY),
7174
]).then(
7275
([
7376
pipelineNameRes,
7477
pipelineMetaConfig,
7578
{
7679
result: { enabled: isBlobStorageConfigured },
7780
},
81+
{
82+
result: { status },
83+
},
7884
]) => {
7985
const scanEnabled =
8086
window._env_ && (window._env_.RECOMMEND_SECURITY_SCANNING || window._env_.FORCE_SECURITY_SCANNING)
@@ -102,6 +108,7 @@ export function getInitData(
102108
loadingData: false,
103109
isAdvanced: false,
104110
isBlobStorageConfigured,
111+
isSecurityModuleInstalled: status === ModuleStatus.INSTALLED,
105112
},
106113
}
107114
},
@@ -221,13 +228,17 @@ export function getInitDataWithCIPipeline(
221228
// by default BE will send global cache config for that pipelineType (JOB or CI_BUILD)
222229
getPipelineMetaConfiguration(appId, includeWebhookData, false, false, isTemplateView),
223230
getModuleConfigured(ModuleNameMap.BLOB_STORAGE),
231+
getModuleInfo(ModuleNameMap.SECURITY),
224232
]).then(
225233
([
226234
ciPipelineRes,
227235
pipelineMetaConfig,
228236
{
229237
result: { enabled: isBlobStorageConfigured },
230238
},
239+
{
240+
result: { status },
241+
},
231242
]) => {
232243
const ciPipeline = ciPipelineRes?.result
233244
const pipelineMetaConfigResult = pipelineMetaConfig?.result
@@ -239,6 +250,7 @@ export function getInitDataWithCIPipeline(
239250
pipelineMetaConfigResult.webhookEvents,
240251
pipelineMetaConfigResult.ciPipelineSourceTypeOptions,
241252
isBlobStorageConfigured,
253+
status === ModuleStatus.INSTALLED,
242254
)
243255
},
244256
)
@@ -324,6 +336,7 @@ export function saveCIPipeline(
324336
undefined,
325337
ciPipelineSourceTypeOptions,
326338
false,
339+
false,
327340
response.result.appWorkflowId ?? ciPipelineFromRes.appWorkflowId,
328341
)
329342
})
@@ -555,6 +568,7 @@ function parseCIResponse(
555568
webhookEvents,
556569
ciPipelineSourceTypeOptions,
557570
isBlobStorageConfigured?: boolean,
571+
isSecurityModuleInstalled?: boolean,
558572
appWorkflowId?: number,
559573
) {
560574
if (ciPipeline) {
@@ -628,6 +642,7 @@ function parseCIResponse(
628642
showPreBuild: ciPipeline.beforeDockerBuildScripts?.length > 0,
629643
showPostBuild: ciPipeline.afterDockerBuildScripts?.length > 0,
630644
isBlobStorageConfigured: isBlobStorageConfigured ?? false,
645+
isSecurityModuleInstalled: isSecurityModuleInstalled ?? false,
631646
}
632647
}
633648
}

src/components/ciPipeline/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,6 @@ export interface CIPipelineInitData {
430430
loadingData: boolean
431431
isAdvanced: boolean
432432
isBlobStorageConfigured: boolean
433+
isSecurityModuleInstalled: boolean
433434
}
434435
}

0 commit comments

Comments
 (0)