All files / modules/70-pipeline/components/ExecutionStageDiagram ExecutionStageDiagramUtils.ts

56% Statements 182/325
49.84% Branches 154/309
93.33% Functions 28/30
53.64% Lines 162/302

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569              23x   23x 23x     23x             23x                     23x   23x 23x 23x   23x 4x 4x 8x 8x   4x     23x           74x 74x 74x 4x   4x       4x 4x 4x 8x 8x     8x                 8x   8x     4x       74x     23x 4x   4x 8x 8x       8x             4x     23x           108x   108x 108x 108x   108x 108x   108x 108x 108x                                                                                                             108x 28x     108x     23x           14x                     14x         14x 74x   74x                                     14x             23x 10x   10x 70x   70x 70x                             10x     23x           207x   207x   207x   207x     207x       23x                 108x 108x 108x 108x 108x                                         108x 108x 108x 108x                                                                                                             108x     23x         108x 108x 5x   108x       108x       108x     23x       6x 6x 33x 6x 3x 3x 3x             6x                       23x 10x 10x 50x 4x 4x 46x 2x               2x 2x 2x   44x 2x                 10x     23x 4x     23x 4x 4x 4x 4x 3x 3x 6x 3x 3x 3x 3x   3x   3x   3x               3x       3x 3x       3x           23x       3x 3x 3x 3x     23x 22x 22x 107x 107x   107x 8x 99x 5x       22x     23x 9x 9x                                       23x 108x 108x     108x     23x 113x 103x 103x 103x 103x   10x      
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import { defaultTo, delay } from 'lodash-es'
import type { DiagramEngine } from '@projectstorm/react-diagrams-core'
import { IconName, Utils } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import type { IconProps } from '@wings-software/uicore/dist/icons/Icon'
import type { CSSProperties } from 'react'
import {
  ExecutionStatusEnum,
  ExecutionStatus,
  isExecutionRunning,
  isExecutionNotStarted,
  isExecutionFinishedAnyhow
} from '@pipeline/utils/statusHelpers'
import {
  PipelineOrStageStatus,
  statusToStatusMapping
} from '@pipeline/components/PipelineSteps/AdvancedSteps/ConditionalExecutionPanel/ConditionalExecutionPanelUtils'
import type { NodeRunInfo } from 'services/pipeline-ng'
import type {
  ExecutionPipeline,
  ExecutionPipelineGroupInfo,
  ExecutionPipelineItem,
  ExecutionPipelineNode
} from './ExecutionPipelineModel'
import * as Diagram from '../Diagram'
import type { DefaultNodeModel } from '../Diagram'
import { ExecutionPipelineNodeType } from './ExecutionPipelineModel'
import { StepType } from '../PipelineSteps/PipelineStepInterface'
import css from './ExecutionStageDiagram.module.scss'
 
export const containGroup = <T>(nodes: Array<ExecutionPipelineNode<T>>): boolean => {
  let contain = false
  nodes.forEach(node => {
    Iif (node.group) contain = true
    else Iif (node.parallel) contain = contain || containGroup(node.parallel)
  })
  return contain
}
 
export const calculateDepth = <T>(
  node: ExecutionPipelineNode<T>,
  groupStatesMap: Map<string, GroupState<T>>,
  spaceAfterGroup: number,
  SPACE_AFTER_GROUP: number
): number => {
  const depth = 1
  let groupMaxDepth = 0
  if (node?.group) {
    const stepState = groupStatesMap.get(node.group.identifier)
    // collapsed group
    Iif (stepState?.collapsed) {
      return 1
    }
    // expanded group
    Eif (node.group.items?.length > 0) {
      groupMaxDepth = 0
      node.group.items.forEach(nodeG => {
        let depthInner = 0
        Iif (nodeG?.group) {
          // group
          depthInner = calculateDepth(nodeG, groupStatesMap, SPACE_AFTER_GROUP, SPACE_AFTER_GROUP) + SPACE_AFTER_GROUP
        } else Iif (nodeG?.parallel) {
          // parallel
          nodeG?.parallel.forEach(nodeP => {
            depthInner += calculateDepth(nodeP, groupStatesMap, SPACE_AFTER_GROUP, SPACE_AFTER_GROUP)
          })
          // NOTE: adjustment for parallel stage
          depthInner += nodeG?.parallel?.find(item => item.group) ? SPACE_AFTER_GROUP : 0
        } else {
          // step
          depthInner = 1
        }
        groupMaxDepth = Math.max(groupMaxDepth, depthInner)
      })
    }
    groupMaxDepth += spaceAfterGroup
  }
 
  // NOTE: condition "groupMaxDepth < depth" makes empty group height equal to group with one step
  return groupMaxDepth < depth ? groupMaxDepth + depth : groupMaxDepth
}
 
export const calculateGroupHeaderDepth = <T>(items: Array<ExecutionPipelineNode<T>>, HEADER_DEPTH: number): number => {
  let maxNum = 0
 
  items.forEach(node => {
    let num = 0
    Iif (node.group) {
      num = HEADER_DEPTH
      num += calculateGroupHeaderDepth(node.group.items, HEADER_DEPTH)
      maxNum = Math.max(maxNum, num)
    } else Iif (node.parallel && node.parallel[0]?.group) {
      num = HEADER_DEPTH
      num += calculateGroupHeaderDepth(node.parallel[0].group.items, HEADER_DEPTH)
      maxNum = Math.max(maxNum, num)
    }
  })
 
  return maxNum
}
 
export const getNodeStyles = (
  isSelected: boolean,
  status: ExecutionStatus,
  type: ExecutionPipelineNodeType,
  nodeHasBorder: boolean
): React.CSSProperties => {
  const style = {} as React.CSSProperties
 
  style.borderColor = 'var(--execution-pipeline-color-grey)'
  style.borderWidth = '2px'
  style.borderStyle = 'solid'
 
  /* istanbul ignore else */ if (status) {
    switch (status) {
      case ExecutionStatusEnum.Success:
        style.borderColor = 'var(--execution-pipeline-color-blue)'
        style.backgroundColor = isSelected ? 'var(--execution-pipeline-color-blue)' : Utils.getRealCSSColor(Color.WHITE)
        break
      case ExecutionStatusEnum.Expired:
        style.borderColor = isSelected ? 'var(--execution-pipeline-color-blue)' : Utils.getRealCSSColor(Color.WHITE)
        break
 
      case ExecutionStatusEnum.Running:
      case ExecutionStatusEnum.AsyncWaiting:
      case ExecutionStatusEnum.TaskWaiting:
      case ExecutionStatusEnum.TimedWaiting:
        style.borderColor = 'var(--execution-pipeline-color-blue)'
        style.backgroundColor = isSelected ? 'var(--execution-pipeline-color-blue)' : Utils.getRealCSSColor(Color.WHITE)
        break
      case ExecutionStatusEnum.Paused:
        style.borderColor = 'var(--execution-pipeline-color-orange)'
        style.backgroundColor = isSelected
          ? 'var(--execution-pipeline-color-orange)'
          : Utils.getRealCSSColor(Color.WHITE)
        break
      case ExecutionStatusEnum.InterventionWaiting:
      case ExecutionStatusEnum.ApprovalWaiting:
      case ExecutionStatusEnum.ResourceWaiting:
        style.borderColor = 'var(--execution-pipeline-color-orange2)'
        style.backgroundColor = isSelected
          ? 'var(--execution-pipeline-color-orange)'
          : Utils.getRealCSSColor(Color.WHITE)
        break
      case ExecutionStatusEnum.NotStarted:
        style.borderColor = 'var(--execution-pipeline-color-dark-grey)'
        style.backgroundColor = Utils.getRealCSSColor(Color.WHITE)
        break
      case ExecutionStatusEnum.Aborted:
        if (type === ExecutionPipelineNodeType.DIAMOND) {
          style.borderColor = 'var(--execution-pipeline-color-dark-grey2)'
          style.backgroundColor = isSelected ? 'var(--execution-pipeline-color-red)' : 'var(--red-50)'
        } else {
          style.borderColor = 'var(--execution-pipeline-color-dark-grey2)'
          style.backgroundColor = isSelected
            ? 'var(--execution-pipeline-color-dark-grey2)'
            : Utils.getRealCSSColor(Color.WHITE)
        }
 
        break
      case ExecutionStatusEnum.ApprovalRejected:
      case ExecutionStatusEnum.Failed:
        style.borderColor =
          type === ExecutionPipelineNodeType.DIAMOND
            ? 'var(--execution-pipeline-color-blue)'
            : 'var(--execution-pipeline-color-red)'
        style.backgroundColor = isSelected ? 'var(--execution-pipeline-color-red)' : Utils.getRealCSSColor(Color.WHITE)
        break
      default:
        break
    }
  }
 
  if (!nodeHasBorder) {
    style.borderWidth = '0px'
  }
 
  return style
}
 
export const getParallelNodesStatusForOutLines = <T>(
  parallel: ExecutionPipelineNode<T>[]
): {
  displayLines: boolean
  status: ExecutionStatus
} => {
  Iif (parallel.length === 0) {
    return {
      displayLines: false,
      status: ExecutionStatusEnum.NotStarted
    }
  }
 
  // Success like status. This will be overwrite if status is not success like
  const ret: {
    displayLines: boolean
    status: ExecutionStatus
  } = {
    displayLines: true,
    status: ExecutionStatusEnum.Success
  }
 
  parallel.forEach(pItem => {
    Eif (pItem.item) {
      // if status set and node status is deferent than not started
      Iif (!isExecutionFinishedAnyhow(pItem.item.status)) {
        ret.displayLines = false
        ret.status = pItem.item.status
      }
    } else if (pItem.group) {
      // if status set and node status is deferent than not started
      if (!isExecutionFinishedAnyhow(pItem.group.status)) {
        ret.displayLines = false
        ret.status = pItem.group.status
      }
    } else if (pItem.parallel) {
      const parallelRet = getParallelNodesStatusForOutLines(pItem.parallel)
      if (!isExecutionFinishedAnyhow(parallelRet.status)) {
        ret.displayLines = false
        ret.status = parallelRet.status
      }
    }
  })
 
  return ret
}
 
/**
 * return ExecutionStatusEnum.NotStarted or one of the other
 * Used for line on right side
 */
export const getParallelNodesStatusForInLine = <T>(parallel: ExecutionPipelineNode<T>[]) => {
  let status = ExecutionStatusEnum.NotStarted
 
  parallel.forEach(pItem => {
    Eif (pItem.item) {
      // if status set and node status is deferent than not started
      Eif (pItem.item.status && !isExecutionNotStarted(pItem.item.status)) {
        status = pItem.item.status
      }
    } else if (pItem.group) {
      // if status set and node status is deferent than not started
      if (pItem.group.status && !isExecutionNotStarted(pItem.group.status)) {
        status = pItem.group.status
      }
    } else if (pItem.parallel) {
      const parallelStatus = getParallelNodesStatusForInLine(pItem.parallel)
      if (!isExecutionNotStarted(parallelStatus)) {
        status = parallelStatus
      }
    }
  })
 
  return status
}
 
export const getArrowsColor = (
  status: ExecutionStatus,
  isParallel = false,
  hideLines = false,
  isLast = false
): string => {
  Iif (hideLines) {
    return 'var(--pipeline-transparent-border)'
  } else Iif (status === ExecutionStatusEnum.NotStarted) {
    return 'var(--execution-pipeline-color-arrow-not-started)'
  } else Iif (isParallel && isExecutionRunning(status)) {
    return 'var(--execution-pipeline-color-arrow-not-started)'
  } else Iif (isLast && isExecutionRunning(status)) {
    return 'var(--execution-pipeline-color-arrow-not-started)'
  } else {
    return 'var(--execution-pipeline-color-arrow-complete)'
  }
}
 
export const getStatusProps = (
  status: ExecutionStatus,
  stepType: ExecutionPipelineNodeType
): {
  secondaryIcon?: IconName
  secondaryIconProps: Omit<IconProps, 'name'>
  secondaryIconStyle: CSSProperties
} => {
  const secondaryIconStyle: React.CSSProperties =
    stepType === ExecutionPipelineNodeType.DIAMOND ? {} : { top: -7, right: -7 }
  let secondaryIcon: IconName | undefined = undefined
  const secondaryIconProps: Omit<IconProps, 'name'> = { size: 16 }
  /* istanbul ignore else */ if (status) {
    switch (status) {
      case ExecutionStatusEnum.IgnoreFailed:
        secondaryIcon = 'warning-outline'
        secondaryIconProps.size = 18
        secondaryIconStyle.color = 'var(--execution-pipeline-color-dark-red)'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        break
      case ExecutionStatusEnum.Failed:
        secondaryIcon = 'execution-warning'
        secondaryIconProps.size = 18
        secondaryIconStyle.color = 'var(--execution-pipeline-color-dark-red)'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        secondaryIconStyle.paddingBottom = `2px`
        break
      case ExecutionStatusEnum.ResourceWaiting:
        secondaryIcon = 'execution-warning'
        secondaryIconProps.size = 20
        secondaryIconStyle.color = 'var(--execution-pipeline-color-orange)'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        break
      case ExecutionStatusEnum.Success:
        secondaryIcon = 'execution-success'
        secondaryIconProps.color = Color.GREEN_450
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        break
      case ExecutionStatusEnum.Running:
      case ExecutionStatusEnum.AsyncWaiting:
      case ExecutionStatusEnum.TaskWaiting:
      case ExecutionStatusEnum.TimedWaiting:
        secondaryIcon = 'spinner'
        secondaryIconStyle.animation = `${css.rotate} 2s`
        secondaryIconStyle.color = Utils.getRealCSSColor(Color.WHITE)
        secondaryIconStyle.backgroundColor = 'var(--primary-7)'
        secondaryIconStyle.borderRadius = '50%'
        secondaryIconStyle.height = '15px'
        secondaryIconStyle.padding = '1px'
        secondaryIconStyle.boxShadow = '0px 0px 0px 0.6px rgba(255,255,255,1)'
        secondaryIconProps.size = 13
        break
      case ExecutionStatusEnum.Aborted:
        secondaryIcon = 'stop'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        secondaryIconStyle.color = 'var(--grey-700)'
        secondaryIconStyle.backgroundColor = Utils.getRealCSSColor(Color.WHITE)
        secondaryIconStyle.borderRadius = '50%'
        secondaryIconStyle.border = '1px solid var(--grey-700)'
        secondaryIconStyle.height = '16px'
        secondaryIconStyle.padding = '3px'
        secondaryIconStyle.boxShadow = '0px 0px 0px 0.6px rgba(255,255,255,1)'
        secondaryIconProps.size = 8
 
        break
      case ExecutionStatusEnum.Expired:
        secondaryIcon = 'execution-abort'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        secondaryIconStyle.color = 'var(--execution-pipeline-color-dark-grey2)'
        break
      case ExecutionStatusEnum.Paused:
      case ExecutionStatusEnum.Pausing:
        secondaryIcon = 'execution-input'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        secondaryIconStyle.color = 'var(--execution-pipeline-color-orange)'
        break
      case ExecutionStatusEnum.ApprovalWaiting:
      case ExecutionStatusEnum.InterventionWaiting:
        secondaryIcon = 'waiting'
        secondaryIconStyle.animation = `${css.fadeIn} 1s`
        secondaryIconStyle.color = Utils.getRealCSSColor(Color.WHITE)
        secondaryIconStyle.backgroundColor = 'var(--execution-pipeline-color-orange2)'
        secondaryIconStyle.borderRadius = '50%'
        secondaryIconStyle.height = '16px'
        secondaryIconStyle.padding = '2px'
        secondaryIconProps.size = 12
        secondaryIconStyle.boxShadow = '0px 0px 0px 0.6px rgba(255,255,255,1)'
        break
      default:
        break
    }
  }
  return { secondaryIconStyle, secondaryIcon: secondaryIcon, secondaryIconProps }
}
 
export const getIconStyleBasedOnStatus = (
  status: ExecutionStatus,
  isSelected: boolean,
  data: any
): React.CSSProperties => {
  let toReturn: CSSProperties = {}
  if (isSelected && status !== ExecutionStatusEnum.NotStarted) {
    toReturn = { color: Utils.getRealCSSColor(Color.WHITE) }
  }
  Iif (!isSelected && (status === ExecutionStatusEnum.Skipped || status === ExecutionStatusEnum.Expired)) {
    toReturn = { color: Utils.getRealCSSColor(Color.GREY_500) }
  }
 
  Iif (data.stepType === StepType.HarnessApproval && !isSelected) {
    toReturn = { color: Utils.getRealCSSColor(Color.PRIMARY_5) }
  }
 
  return toReturn
}
 
export const getStageFromExecutionPipeline = <T>(
  data: ExecutionPipeline<T>,
  identifier = '-1'
): ExecutionPipelineItem<T> | undefined => {
  let stage: ExecutionPipelineItem<T> | undefined = undefined
  data.items?.forEach(node => {
    if (!stage) {
      if (node?.item?.identifier === identifier) {
        stage = node?.item
      } else Eif (node?.parallel) {
        stage = getStageFromExecutionPipeline({ items: node.parallel, identifier: '', allNodes: [] }, identifier)
      } else if (node?.group) {
        stage = getStageFromExecutionPipeline({ items: node.group.items, identifier: '', allNodes: [] }, identifier)
      }
    }
  })
 
  return stage
}
 
export interface GroupState<T> {
  data?: T
  group?: ExecutionPipelineGroupInfo<T>
  collapsed: boolean
  name: string
  status: ExecutionStatus
  identifier: string
}
 
export const getGroupsFromData = <T>(items: Array<ExecutionPipelineNode<T>>): Map<string, GroupState<T>> => {
  let groupState = new Map<string, GroupState<T>>()
  items.forEach(node => {
    if (node.parallel) {
      const itemsGroupState = getGroupsFromData(node.parallel)
      groupState = new Map([...groupState, ...itemsGroupState])
    } else if (node.group) {
      groupState.set(node.group.identifier, {
        collapsed: false,
        name: node.group.name,
        status: node.group.status,
        identifier: node.group.identifier,
        data: node.group.data,
        group: node.group
      })
      Eif (node.group.items.length > 0) {
        const itemsGroupState = getGroupsFromData(node.group.items)
        groupState = new Map([...groupState, ...itemsGroupState])
      }
    } else if (node.item?.showInLabel) {
      groupState.set(node.item.identifier, {
        collapsed: false,
        name: node.item.name,
        status: node.item.status,
        identifier: node.item.identifier,
        data: node.item.data
      })
    }
  })
  return groupState
}
 
export const moveStageToFocusDelayed = (engine: DiagramEngine, identifier: string, focusOnVisibility = false): void => {
  delay(() => moveStageToFocus(engine, identifier, focusOnVisibility), 1)
}
 
export const moveStageToFocus = (engine: DiagramEngine, identifier: string, focusOnVisibility = false): void => {
  const model = engine.getModel() as Diagram.DiagramModel
  const layer = model.getGroupLayer(identifier) || model.getNodeFromId(identifier)
  const canvas = engine.getCanvas()
  /* istanbul ignore else */ if (layer && canvas) {
    const rect = canvas.getBoundingClientRect()
    const zoom = engine.getModel().getZoomLevel()
    const s = (num: number): number => num * (1 / (100 / zoom))
    const offsetX = engine.getModel().getOffsetX()
    const offsetY = engine.getModel().getOffsetY()
    let newOffsetX = engine.getModel().getOffsetX()
    let newOffsetY = engine.getModel().getOffsetY()
 
    const node = (engine.getModel() as Diagram.DiagramModel).getNodeFromId(identifier)
 
    Iif (focusOnVisibility && node && rect.width < offsetX + s(node.getPosition().x) + s(node.width) + s(40)) {
      newOffsetX = (rect.width - s(node.width)) * 0.8 - s(node.getPosition().x)
    } else Iif (!focusOnVisibility) {
      if (layer instanceof Diagram.StepGroupNodeLayerModel) {
        newOffsetX = rect.width * 0.2 - s(layer.startNode.getPosition().x)
      } else {
        newOffsetX = rect.width * 0.2 - s(layer.getPosition().x)
      }
    }
 
    Iif (node && rect.height < offsetY + s(node.getPosition().y) + s(node.height) + s(40)) {
      newOffsetY = (rect.height - s(node.height)) * 0.7 - s(node.getPosition().y)
    }
 
    let shouldRepaint = false
    Iif (newOffsetX !== offsetX || newOffsetY !== offsetY) {
      engine.getModel().setOffset(newOffsetX, newOffsetY)
      shouldRepaint = true
    }
    Iif (shouldRepaint) {
      engine.repaintCanvas()
    }
  }
}
 
export const getStageFromDiagramEvent = <T>(
  event: Diagram.DefaultNodeEvent,
  data: ExecutionPipeline<T>
): ExecutionPipelineItem<T> | undefined => {
  const entity = event.entity as DefaultNodeModel
  const id = entity.getOptions().identifier
  const stage = getStageFromExecutionPipeline(data, id)
  return stage
}
 
export const getRunningNode = <T>(data: ExecutionPipeline<T>): ExecutionPipelineItem<T> | undefined => {
  let stage: ExecutionPipelineItem<T> | undefined = undefined
  data.items?.forEach(node => {
    Eif (!stage) {
      Iif (isExecutionRunning(node?.item?.status)) {
        stage = node?.item
      } else if (node?.parallel) {
        stage = getRunningNode({ items: node.parallel, identifier: '', allNodes: [] })
      } else if (node?.group) {
        stage = getRunningNode({ items: node.group.items, identifier: '', allNodes: [] })
      }
    }
  })
  return stage
}
 
export const focusRunningNode = <T>(engine: DiagramEngine, data: ExecutionPipeline<T>): void => {
  const runningStage = getRunningNode(data)
  /* istanbul ignore else */ Iif (runningStage) {
    const node = (engine.getModel() as Diagram.DiagramModel).getNodeFromId(runningStage.identifier)
    const canvas = engine.getCanvas()
    if (canvas && node) {
      const rect = canvas.getBoundingClientRect()
      const nodePosition = node.getPosition()
      const nodeWidth = node.width
      /* istanbul ignore else */ Iif (rect.width < nodePosition.x + nodeWidth + 40) {
        const newOffsetX = (rect.width - node.width) * 0.8 - nodePosition.x
        if (newOffsetX !== engine.getModel().getOffsetX()) {
          const offsetY = engine.getModel().getOffsetY()
          engine.getModel().setOffset(newOffsetX, offsetY)
          //engine.getModel().setZoomLevel(100)
          engine.repaintCanvas()
        }
      }
    }
  }
}
 
export const getTertiaryIconProps = <T>(stage: ExecutionPipelineItem<T>): { tertiaryIcon?: IconName } => {
  const tertiaryIconProps: { tertiaryIcon?: IconName } = {}
  Iif (stage?.barrierFound) {
    tertiaryIconProps.tertiaryIcon = 'barrier-open-with-links'
  }
  return tertiaryIconProps
}
 
export const getConditionalExecutionFlag = (when?: NodeRunInfo): boolean => {
  if (when?.whenCondition) {
    const conditionArr = when.whenCondition.split(' && ')
    const status = statusToStatusMapping[defaultTo(conditionArr.shift()?.replace(/[^a-zA-Z]/g, ''), '')]
    const condition = conditionArr.join(' && ')
    return !(status === PipelineOrStageStatus.SUCCESS && !condition?.trim())
  } else {
    return false
  }
}