Skip to content

Commit a4a2a95

Browse files
committed
feat: add util for getting workflows which can be triggered
1 parent 0dc27e2 commit a4a2a95

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

src/components/ApplicationGroup/AppGroup.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export interface BulkCDTriggerType extends BulkRuntimeParamsType {
157157
setLoading: React.Dispatch<React.SetStateAction<boolean>>
158158
isVirtualEnv?: boolean
159159
uniqueReleaseTags: string[]
160+
feasiblePipelineIds: Set<number>
160161
}
161162

162163
export interface ProcessWorkFlowStatusType {

src/components/ApplicationGroup/Details/TriggerView/BulkCDTrigger.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ import { BulkCDDetailType, BulkCDTriggerType } from '../../AppGroup.types'
7474
import { BULK_CD_DEPLOYMENT_STATUS, BULK_CD_MATERIAL_STATUS, BULK_CD_MESSAGING, BUTTON_TITLE } from '../../Constants'
7575
import { BULK_ERROR_MESSAGES } from './constants'
7676
import TriggerResponseModalBody, { TriggerResponseModalFooter } from './TriggerResponseModal'
77-
import { getIsImageApprovedByDeployerSelected, getIsNonApprovedImageSelected, getSelectedAppListForBulkStrategy } from './utils'
77+
import {
78+
getIsImageApprovedByDeployerSelected,
79+
getIsNonApprovedImageSelected,
80+
getSelectedAppListForBulkStrategy,
81+
} from './utils'
7882

7983
const DeploymentWindowInfoBar = importComponentFromFELibrary('DeploymentWindowInfoBar')
8084
const BulkDeployResistanceTippy = importComponentFromFELibrary('BulkDeployResistanceTippy')
@@ -111,6 +115,7 @@ const BulkCDTrigger = ({
111115
updateBulkInputMaterial,
112116
// NOTE: Should trigger the bulk cd here only but since its also calling another parent function not refactoring right now
113117
onClickTriggerBulkCD,
118+
feasiblePipelineIds,
114119
responseList,
115120
isLoading,
116121
setLoading,
@@ -1002,7 +1007,7 @@ const BulkCDTrigger = ({
10021007
bulkDeploymentStrategy={bulkDeploymentStrategy}
10031008
pipelineIdVsStrategyMap={pipelineIdVsStrategyMap}
10041009
setPipelineIdVsStrategyMap={setPipelineIdVsStrategyMap}
1005-
appList={getSelectedAppListForBulkStrategy(appList)}
1010+
appList={getSelectedAppListForBulkStrategy(appList, feasiblePipelineIds)}
10061011
/>
10071012
) : (
10081013
<>

src/components/ApplicationGroup/Details/TriggerView/EnvTriggerView.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,33 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
14371437
return true
14381438
}
14391439

1440+
// Helper to get selected CD nodes
1441+
const getSelectedCDNodesWithArtifacts = (selectedWorkflows: WorkflowType[]): { node: CommonNodeAttr; wf: WorkflowType }[] =>
1442+
selectedWorkflows
1443+
.filter((wf) => wf.isSelected)
1444+
.map((wf) => {
1445+
const _cdNode = wf.nodes.find(
1446+
(node) => node.type === WorkflowNodeType.CD && node.environmentId === +envId,
1447+
)
1448+
if (!_cdNode) return null
1449+
1450+
let _selectedNode: CommonNodeAttr | undefined
1451+
if (bulkTriggerType === DeploymentNodeType.PRECD) {
1452+
_selectedNode = _cdNode.preNode
1453+
} else if (bulkTriggerType === DeploymentNodeType.CD) {
1454+
_selectedNode = _cdNode
1455+
} else if (bulkTriggerType === DeploymentNodeType.POSTCD) {
1456+
_selectedNode = _cdNode.postNode
1457+
}
1458+
1459+
const selectedArtifacts = _selectedNode?.[materialType]?.filter((artifact) => artifact.isSelected) || []
1460+
if (_selectedNode && selectedArtifacts.length > 0) {
1461+
return { node: _selectedNode, wf }
1462+
}
1463+
return null
1464+
})
1465+
.filter(Boolean)
1466+
14401467
const onClickTriggerBulkCD = (
14411468
skipIfHibernated: boolean,
14421469
pipelineIdVsStrategyMap: PipelineIdsVsDeploymentStrategyMap,
@@ -1452,27 +1479,14 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
14521479
const nodeList: CommonNodeAttr[] = []
14531480
const triggeredAppList: { appId: number; envId?: number; appName: string }[] = []
14541481

1455-
for (const _wf of filteredWorkflows) {
1456-
if (_wf.isSelected && (!appsToRetry || appsToRetry[_wf.appId])) {
1457-
const _cdNode = _wf.nodes.find(
1458-
(node) => node.type === WorkflowNodeType.CD && node.environmentId === +envId,
1459-
)
1460-
let _selectedNode: CommonNodeAttr
1461-
if (bulkTriggerType === DeploymentNodeType.PRECD) {
1462-
_selectedNode = _cdNode.preNode
1463-
} else if (bulkTriggerType === DeploymentNodeType.CD) {
1464-
_selectedNode = _cdNode
1465-
} else if (bulkTriggerType === DeploymentNodeType.POSTCD) {
1466-
_selectedNode = _cdNode.postNode
1467-
}
1468-
1469-
if (_selectedNode?.[materialType]?.length) {
1470-
nodeList.push(_selectedNode)
1471-
_appIdMap.set(_selectedNode.id, _wf.appId.toString())
1472-
triggeredAppList.push({ appId: _wf.appId, appName: _wf.name, envId: _selectedNode.environmentId })
1473-
}
1474-
}
1475-
}
1482+
const eligibleNodes = getSelectedCDNodesWithArtifacts(
1483+
filteredWorkflows.filter((wf) => !appsToRetry || appsToRetry[wf.appId]),
1484+
)
1485+
eligibleNodes.forEach(({ node: eligibleNode, wf }) => {
1486+
nodeList.push(eligibleNode)
1487+
_appIdMap.set(eligibleNode.id, wf.appId.toString())
1488+
triggeredAppList.push({ appId: wf.appId, appName: wf.name, envId: eligibleNode.environmentId })
1489+
})
14761490

14771491
const _CDTriggerPromiseFunctionList = []
14781492
nodeList.forEach((node, index) => {
@@ -2067,12 +2081,15 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
20672081

20682082
const { uniqueReleaseTags } = bulkCDDetailTypeResponse
20692083

2084+
const feasiblePipelineIds = new Set(getSelectedCDNodesWithArtifacts(filteredWorkflows).map(({ node }) => +node.id))
2085+
20702086
// Have to look for its each prop carefully
20712087
// No need to send uniqueReleaseTags will get those in BulkCDTrigger itself
20722088
return (
20732089
<BulkCDTrigger
20742090
stage={bulkTriggerType}
20752091
appList={_selectedAppWorkflowList}
2092+
feasiblePipelineIds={feasiblePipelineIds}
20762093
closePopup={hideBulkCDModal}
20772094
updateBulkInputMaterial={updateBulkCDInputMaterial}
20782095
onClickTriggerBulkCD={onClickTriggerBulkCD}

src/components/ApplicationGroup/Details/TriggerView/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ export const getIsImageApprovedByDeployerSelected = (appList: BulkCDDetailType[]
4646
)
4747
})
4848

49-
export const getSelectedAppListForBulkStrategy = (appList: BulkCDDetailType[]) =>
50-
appList.map((app) => ({ pipelineId: +app.cdPipelineId, appName: app.name }))
49+
export const getSelectedAppListForBulkStrategy = (appList: BulkCDDetailType[], feasiblePipelineIds: Set<number>) =>
50+
appList
51+
.map((app) => ({ pipelineId: +app.cdPipelineId, appName: app.name }))
52+
.filter(({ pipelineId }) => feasiblePipelineIds.has(pipelineId))

0 commit comments

Comments
 (0)