Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 7652cb5

Browse files
authored
feat: generate job requires connections #106
feat: generate job requires connections
2 parents 11a6449 + 52f4e2e commit 7652cb5

4 files changed

Lines changed: 69 additions & 20 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"homepage": "https://circleci-public.github.io/visual-config-editor/",
55
"dependencies": {
6-
"@circleci/circleci-config-sdk": "0.6.0-alpha.2",
6+
"@circleci/circleci-config-sdk": "0.6.0",
77
"@craco/craco": "^6.3.0",
88
"@monaco-editor/react": "^4.3.1",
99
"@testing-library/jest-dom": "^5.11.4",

src/components/containers/WorkflowContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Job } from '@circleci/circleci-config-sdk';
21
import { WorkflowJobParameters } from '@circleci/circleci-config-sdk/dist/src/lib/Components/Workflow/types/WorkflowJob.types';
32
import { useEffect, useState } from 'react';
43
import ReactFlow, {

src/state/Store.tsx

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PipelineParameterLiteral } from '@circleci/circleci-config-sdk/dist/src
1212
import { Action, action } from 'easy-peasy';
1313
import { MutableRefObject } from 'react';
1414
import {
15+
ElementId,
1516
Elements,
1617
FlowElement,
1718
isNode,
@@ -371,28 +372,55 @@ const Actions: StoreActions = {
371372
commands: config.commands || [],
372373
};
373374

374-
config.workflows.forEach(({ name, jobs }) => {
375-
state.workflows = state.workflows.concat({
376-
name,
377-
id: v4(),
378-
elements: [],
379-
});
380-
const workflow = state.workflows[state.selectedWorkflow];
381-
const nodeWidth = 120; // Make this dynamic
382-
const elements: Node<any>[] = [];
375+
state.workflows = config.workflows.map(({ name, jobs }) => {
376+
const nodeWidth = 200; // Make this dynamic
377+
const elements: Elements = [];
378+
const requireTable: Record<ElementId, ElementId[]> = {};
383379

380+
// Build workflow and prep requirement connection generation
384381
jobs.forEach((workflowJob, i) => {
382+
const jobName = workflowJob.job.name;
383+
385384
elements.push({
386-
id: v4(),
385+
id: jobName,
387386
data: { job: workflowJob.job, parameters: workflowJob.parameters },
388387
connectable: true,
389388
dragHandle: '.node',
390389
type: 'jobs',
391390
position: { x: i * nodeWidth, y: 0 },
392391
});
392+
393+
workflowJob.parameters.requires?.forEach((requiredJob) => {
394+
if (!requireTable[requiredJob]) {
395+
requireTable[requiredJob] = [jobName];
396+
return;
397+
}
398+
399+
requireTable[requiredJob].push(jobName);
400+
});
401+
});
402+
403+
// Generate connections
404+
Object.entries(requireTable).forEach(([jobName, requiredBy]) => {
405+
requiredBy.forEach((requiredId) => {
406+
elements.push({
407+
id: v4(),
408+
source: jobName,
409+
target: requiredId,
410+
type: 'requires',
411+
sourceHandle: `${jobName}_source`,
412+
targetHandle: `${requiredId}_target`,
413+
animated: false,
414+
style: { stroke: '#A3A3A3', strokeWidth: '2px' },
415+
});
416+
});
393417
});
394418

395-
workflow.elements = elements;
419+
return {
420+
name,
421+
id: v4(),
422+
elements,
423+
};
396424
});
397425

398426
state.config = config.generate();

yarn.lock

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
dependencies:
2525
"@babel/highlight" "^7.10.4"
2626

27-
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.5.5":
27+
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.16.0", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.5.5":
2828
version "7.16.7"
2929
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.7.tgz#44416b6bd7624b998f5b1af5d470856c40138789"
3030
integrity sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==
@@ -1081,13 +1081,14 @@
10811081
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
10821082
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
10831083

1084-
"@circleci/circleci-config-sdk@0.6.0-alpha.2":
1085-
version "0.6.0-alpha.2"
1086-
resolved "https://registry.yarnpkg.com/@circleci/circleci-config-sdk/-/circleci-config-sdk-0.6.0-alpha.2.tgz#deb98f2e2e7a0d97b703c4c380dc4a3343d16523"
1087-
integrity sha512-DqT9/cYpLnz+HoIoQw/xK+1siBGN4DZ+MHPj7f2VhKl20ogvPt8b9Prb7+qDdX5nz2gAA9ADGnyNBXQWen018Q==
1084+
"@circleci/circleci-config-sdk@0.6.0":
1085+
version "0.6.0"
1086+
resolved "https://registry.yarnpkg.com/@circleci/circleci-config-sdk/-/circleci-config-sdk-0.6.0.tgz#7374b92282a29aaef3efdf5868116f9034c39dcc"
1087+
integrity sha512-AHWL1h+nwZvqttjIDNsIaenJ5V0Gkc3bj9LCBv9dRJ2325T+XmntIauO5cy9JFYgv9v9GOXlpo/C6cFMHWjOAA==
10881088
dependencies:
10891089
ajv "^8.8.2"
10901090
ajv-merge-patch "^5.0.1"
1091+
better-ajv-errors "^1.2.0"
10911092
yaml "2.0.0-9"
10921093

10931094
"@cnakazawa/watch@^1.0.3":
@@ -1193,6 +1194,11 @@
11931194
debug "^4.1.1"
11941195
minimatch "^3.0.4"
11951196

1197+
"@humanwhocodes/momoa@^2.0.2":
1198+
version "2.0.4"
1199+
resolved "https://registry.yarnpkg.com/@humanwhocodes/momoa/-/momoa-2.0.4.tgz#8b9e7a629651d15009c3587d07a222deeb829385"
1200+
integrity sha512-RE815I4arJFtt+FVeU1Tgp9/Xvecacji8w/V6XtXsWWH/wz/eNkNbhb+ny/+PlVZjV0rxQpRSQKNKE3lcktHEA==
1201+
11961202
"@humanwhocodes/object-schema@^1.2.0":
11971203
version "1.2.1"
11981204
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
@@ -2896,6 +2902,17 @@ batch@0.6.1:
28962902
resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16"
28972903
integrity sha1-3DQxT05nkxgJP8dgJyUl+UvyXBY=
28982904

2905+
better-ajv-errors@^1.2.0:
2906+
version "1.2.0"
2907+
resolved "https://registry.yarnpkg.com/better-ajv-errors/-/better-ajv-errors-1.2.0.tgz#6412d58fa4d460ff6ccbd9e65c5fef9781cc5286"
2908+
integrity sha512-UW+IsFycygIo7bclP9h5ugkNH8EjCSgqyFB/yQ4Hqqa1OEYDtb0uFIkYE0b6+CjkgJYVM5UKI/pJPxjYe9EZlA==
2909+
dependencies:
2910+
"@babel/code-frame" "^7.16.0"
2911+
"@humanwhocodes/momoa" "^2.0.2"
2912+
chalk "^4.1.2"
2913+
jsonpointer "^5.0.0"
2914+
leven "^3.1.0 < 4"
2915+
28992916
bfj@^7.0.2:
29002917
version "7.0.2"
29012918
resolved "https://registry.yarnpkg.com/bfj/-/bfj-7.0.2.tgz#1988ce76f3add9ac2913fd8ba47aad9e651bfbb2"
@@ -7195,6 +7212,11 @@ jsonfile@^6.0.1:
71957212
optionalDependencies:
71967213
graceful-fs "^4.1.6"
71977214

7215+
jsonpointer@^5.0.0:
7216+
version "5.0.0"
7217+
resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-5.0.0.tgz#f802669a524ec4805fa7389eadbc9921d5dc8072"
7218+
integrity sha512-PNYZIdMjVIvVgDSYKTT63Y+KZ6IZvGRNNWcxwD+GNnUz1MKPfv30J8ueCjdwcN0nDx2SlshgyB7Oy0epAzVRRg==
7219+
71987220
"jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.2.1:
71997221
version "3.3.0"
72007222
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.3.0.tgz#e624f259143b9062c92b6413ff92a164c80d3ccb"
@@ -7262,7 +7284,7 @@ last-call-webpack-plugin@^3.0.0:
72627284
lodash "^4.17.5"
72637285
webpack-sources "^1.1.0"
72647286

7265-
leven@^3.1.0:
7287+
leven@^3.1.0, "leven@^3.1.0 < 4":
72667288
version "3.1.0"
72677289
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"
72687290
integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==
@@ -8029,7 +8051,7 @@ nwsapi@^2.2.0:
80298051
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
80308052
version "4.1.1"
80318053
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
8032-
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
8054+
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
80338055

80348056
object-copy@^0.1.0:
80358057
version "0.1.0"

0 commit comments

Comments
 (0)