Skip to content

Commit 49f43ff

Browse files
committed
fix: node overlap hidden by calculating maxDepth
1 parent be5ce8e commit 49f43ff

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
@@ -18,6 +18,7 @@ import {
1818
CDMaterialResponseType,
1919
} from '@devtron-labs/devtron-fe-common-lib'
2020
import { Environment } from '../../../cdPipeline/cdPipeline.types'
21+
import { WorkflowDimensions } from './config'
2122

2223
export interface CDMaterialProps extends RouteComponentProps<{}> {
2324
material?: CDMaterialType[]
@@ -725,3 +726,10 @@ export interface MaterialSourceProps {
725726
fromTriggerInfo?: boolean
726727
clearSearch?: (e: any) => void
727728
}
729+
730+
export interface AddDimensionsToDownstreamDeploymentsParams {
731+
downstreams: NodeAttr[],
732+
dimensions: WorkflowDimensions,
733+
startX: number,
734+
startY: number,
735+
}

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
WorkflowResult,
1111
PipelineType,
1212
WorkflowNodeType,
13+
AddDimensionsToDownstreamDeploymentsParams,
1314
} from './types'
1415
import { WorkflowTrigger, WorkflowCreate, Offset, WorkflowDimensions, WorkflowDimensionType } from './config'
1516
import { TriggerType, DEFAULT_STATUS, GIT_BRANCH_NOT_CONFIGURED } from '../../../../config'
@@ -272,7 +273,7 @@ function addDimensions(workflows: WorkflowType[], workflowOffset: Offset, dimens
272273
ciNode.y = startY + workflowOffset.offsetY
273274

274275
if ((ciNode.downstreamNodes?.length ?? 0) > 0) {
275-
addDimensionsToDownstreamDeployments(ciNode.downstreamNodes, dimensions, ciNode.x, ciNode.y)
276+
addDimensionsToDownstreamDeployments({downstreams: ciNode.downstreamNodes, dimensions,startX: ciNode.x,startY: ciNode.y})
276277
}
277278

278279
const finalWorkflow = new Array<NodeAttr>()
@@ -360,16 +361,25 @@ function addDownstreams(workflows: WorkflowType[]) {
360361
})
361362
}
362363

363-
function addDimensionsToDownstreamDeployments(
364-
downstreams: Array<NodeAttr>,
365-
dimensions: WorkflowDimensions,
366-
startX: number,
367-
startY: number,
368-
) {
369-
let lastY = startY
364+
/**
365+
*
366+
* @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.
367+
* @returns maximum Y coordinate we have encountered so far
368+
*/
369+
const addDimensionsToDownstreamDeployments = ({
370+
downstreams,
371+
dimensions,
372+
startX,
373+
startY,
374+
}: AddDimensionsToDownstreamDeploymentsParams): number => {
375+
const cdNodesGap = dimensions.cDNodeSizes.nodeHeight + dimensions.cDNodeSizes.distanceY
376+
// 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
377+
let maxY = startY - cdNodesGap
370378
for (let index = 0; index < downstreams.length; index++) {
371379
const element = downstreams[index]
372-
let cdNodeY = lastY
380+
maxY = maxY + cdNodesGap
381+
const cdNodeY = maxY
382+
// From here onwards For Y value we will only change maxY for next iteration and wont need to change current cdNodeY
373383
let cdNodeX = startX + dimensions.cDNodeSizes.nodeWidth + dimensions.cDNodeSizes.distanceX
374384

375385
if (element.preNode) {
@@ -389,19 +399,11 @@ function addDimensionsToDownstreamDeployments(
389399
lastX = element.postNode.x
390400
}
391401

392-
lastY = cdNodeY + dimensions.cDNodeSizes.nodeHeight + dimensions.cDNodeSizes.distanceY
393-
394402
if ((element.downstreamNodes?.length ?? 0) > 0) {
395-
addDimensionsToDownstreamDeployments(element.downstreamNodes, dimensions, lastX, cdNodeY)
396-
lastY =
397-
element.downstreamNodes[element.downstreamNodes.length - 1].y +
398-
dimensions.cDNodeSizes.nodeHeight +
399-
dimensions.cDNodeSizes.distanceY
403+
maxY = addDimensionsToDownstreamDeployments({downstreams: element.downstreamNodes, dimensions, startX: lastX, startY: cdNodeY})
400404
}
401-
402-
//for next iteration use Y coordinate of the last element in downstreamNodes as it will have maximum Y coordinate
403-
startY = lastY
404405
}
406+
return maxY
405407
}
406408

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

0 commit comments

Comments
 (0)