Skip to content

Commit 161a2e8

Browse files
Merge pull request #1538 from devtron-labs/fix/workflow-node-overlap
fix: node overlap hidden by calculating maxDepth
2 parents 7ea41a4 + 2039e57 commit 161a2e8

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/components/app/details/triggerView/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
PipelineType,
2020
} from '@devtron-labs/devtron-fe-common-lib'
2121
import { Environment } from '../../../cdPipeline/cdPipeline.types'
22+
import { WorkflowDimensions } from './config'
2223

2324
export interface CDMaterialProps extends RouteComponentProps<{}> {
2425
material?: CDMaterialType[]
@@ -710,3 +711,10 @@ export interface MaterialSourceProps {
710711
fromTriggerInfo?: boolean
711712
clearSearch?: (e: any) => void
712713
}
714+
715+
export interface AddDimensionsToDownstreamDeploymentsParams {
716+
downstreams: NodeAttr[],
717+
dimensions: WorkflowDimensions,
718+
startX: number,
719+
startY: number,
720+
}

src/components/app/details/triggerView/workflow.service.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
CiPipelineResult,
99
Workflow,
1010
WorkflowResult,
11+
AddDimensionsToDownstreamDeploymentsParams,
1112
} from './types'
1213
import { WorkflowTrigger, WorkflowCreate, Offset, WorkflowDimensions, WorkflowDimensionType } from './config'
1314
import { TriggerType, DEFAULT_STATUS, GIT_BRANCH_NOT_CONFIGURED } from '../../../../config'
@@ -270,7 +271,7 @@ function addDimensions(workflows: WorkflowType[], workflowOffset: Offset, dimens
270271
ciNode.y = startY + workflowOffset.offsetY
271272

272273
if ((ciNode.downstreamNodes?.length ?? 0) > 0) {
273-
addDimensionsToDownstreamDeployments(ciNode.downstreamNodes, dimensions, ciNode.x, ciNode.y)
274+
addDimensionsToDownstreamDeployments({downstreams: ciNode.downstreamNodes, dimensions,startX: ciNode.x,startY: ciNode.y})
274275
}
275276

276277
const finalWorkflow = new Array<NodeAttr>()
@@ -367,16 +368,25 @@ function addDownstreams(workflows: WorkflowType[]) {
367368
})
368369
}
369370

370-
function addDimensionsToDownstreamDeployments(
371-
downstreams: Array<NodeAttr>,
372-
dimensions: WorkflowDimensions,
373-
startX: number,
374-
startY: number,
375-
) {
376-
let lastY = startY
371+
/**
372+
*
373+
* @description This function is used to add dimensions to downstream deployments, we are recursively traversing the downstream deployments and adding dimensions to them, on each iteration we are updating the lastY coordinate which is used to calculate the Y coordinate of the next deployment, this value is going to be maximum Y coordinate we have encountered so far.
374+
* @returns maximum Y coordinate we have encountered so far
375+
*/
376+
const addDimensionsToDownstreamDeployments = ({
377+
downstreams,
378+
dimensions,
379+
startX,
380+
startY,
381+
}: AddDimensionsToDownstreamDeploymentsParams): number => {
382+
const cdNodesGap = dimensions.cDNodeSizes.nodeHeight + dimensions.cDNodeSizes.distanceY
383+
// Shifting the Y coordinates here since, we are anyways adding cdNodesGap to maxY on start of each iteration and dont want to add that in the end of iteration
384+
let maxY = startY - cdNodesGap
377385
for (let index = 0; index < downstreams.length; index++) {
378386
const element = downstreams[index]
379-
let cdNodeY = lastY
387+
maxY = maxY + cdNodesGap
388+
const cdNodeY = maxY
389+
// From here onwards For Y value we will only change maxY for next iteration and wont need to change current cdNodeY
380390
let cdNodeX = startX + dimensions.cDNodeSizes.nodeWidth + dimensions.cDNodeSizes.distanceX
381391

382392
if (element.preNode) {
@@ -396,19 +406,11 @@ function addDimensionsToDownstreamDeployments(
396406
lastX = element.postNode.x
397407
}
398408

399-
lastY = cdNodeY + dimensions.cDNodeSizes.nodeHeight + dimensions.cDNodeSizes.distanceY
400-
401409
if ((element.downstreamNodes?.length ?? 0) > 0) {
402-
addDimensionsToDownstreamDeployments(element.downstreamNodes, dimensions, lastX, cdNodeY)
403-
lastY =
404-
element.downstreamNodes[element.downstreamNodes.length - 1].y +
405-
dimensions.cDNodeSizes.nodeHeight +
406-
dimensions.cDNodeSizes.distanceY
410+
maxY = addDimensionsToDownstreamDeployments({downstreams: element.downstreamNodes, dimensions, startX: lastX, startY: cdNodeY})
407411
}
408-
409-
//for next iteration use Y coordinate of the last element in downstreamNodes as it will have maximum Y coordinate
410-
startY = lastY
411412
}
413+
return maxY
412414
}
413415

414416
function toWorkflowType(workflow: Workflow, ciResponse: CiPipelineResult): WorkflowType {

0 commit comments

Comments
 (0)