|
5 | 5 | parsers, |
6 | 6 | reusable, |
7 | 7 | Workflow, |
8 | | - WorkflowJob, |
| 8 | + workflow, |
9 | 9 | } from '@circleci/circleci-config-sdk'; |
10 | 10 | import { CustomCommand } from '@circleci/circleci-config-sdk/dist/src/lib/Components/Commands/exports/Reusable'; |
11 | 11 | import { CustomParameter } from '@circleci/circleci-config-sdk/dist/src/lib/Components/Parameters'; |
@@ -379,28 +379,37 @@ const Actions: StoreActions = { |
379 | 379 | const nodeWidth = 250; // Make this dynamic |
380 | 380 | const nodeHeight = 60; // Make this dynamic |
381 | 381 |
|
| 382 | + const getJobName = (workflowJob: workflow.WorkflowJobAbstract) => { |
| 383 | + const baseName = |
| 384 | + workflowJob instanceof workflow.WorkflowJob |
| 385 | + ? workflowJob.job.name |
| 386 | + : (workflowJob as workflow.WorkflowJobApproval).name; |
| 387 | + |
| 388 | + return workflowJob.parameters?.name || baseName; |
| 389 | + }; |
| 390 | + |
382 | 391 | state.workflows = config.workflows.map(({ name, jobs }) => { |
383 | | - const jobTable: Record<string, WorkflowJob> = {}; |
| 392 | + const jobTable: Record<string, workflow.WorkflowJobAbstract> = {}; |
384 | 393 |
|
385 | 394 | jobs.forEach((workflowJob) => { |
386 | | - const jobName = workflowJob.parameters.name || workflowJob.job.name; |
| 395 | + const jobName = getJobName(workflowJob); |
387 | 396 | jobTable[jobName] = workflowJob; |
388 | 397 | }); |
389 | 398 |
|
390 | 399 | const elements: Elements = []; |
391 | 400 | const columns: Array<number> = []; |
392 | 401 | const solved: Record<ElementId, number> = {}; |
393 | 402 |
|
394 | | - const solve = (workflowJob: WorkflowJob) => { |
395 | | - const jobName = workflowJob.parameters.name || workflowJob.job.name; |
| 403 | + const solve = (workflowJob: workflow.WorkflowJobAbstract) => { |
| 404 | + const jobName = getJobName(workflowJob); |
396 | 405 |
|
397 | 406 | if (solved[jobName] !== undefined) { |
398 | 407 | return solved[jobName]; |
399 | 408 | } |
400 | 409 |
|
401 | 410 | let column = 0; |
402 | 411 |
|
403 | | - if (workflowJob.parameters.requires) { |
| 412 | + if (workflowJob.parameters?.requires) { |
404 | 413 | let greatestColumn = 0; |
405 | 414 |
|
406 | 415 | workflowJob.parameters.requires.forEach((requiredJob) => { |
|
0 commit comments