Skip to content

Commit 269ab19

Browse files
Move pipeline studio to ui package (#851)
* move pipeline nodes to ui; add pipeline-graph to design-system; small improvements --------- Co-authored-by: Kevin Nagurski <[email protected]>
1 parent fd74912 commit 269ab19

File tree

81 files changed

+5966
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5966
-295
lines changed

apps/design-system/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
"typecheck": "tsc -b"
1414
},
1515
"dependencies": {
16+
"@harnessio/pipeline-graph": "workspace:*",
1617
"@harnessio/ui": "workspace:*",
1718
"@harnessio/yaml-editor": "workspace:*",
19+
"@types/lodash-es": "^4.17.12",
1820
"clsx": "^2.1.1",
21+
"lodash-es": "^4.17.21",
1922
"monaco-editor": "0.50.0",
2023
"react": "^17.0.2",
2124
"react-dom": "^17.0.2",
2225
"react-live": "^4.1.8",
23-
"react-router-dom": "^6.26.0"
26+
"react-router-dom": "^6.26.0",
27+
"vite-plugin-monaco-editor": "^1.1.0"
2428
},
2529
"devDependencies": {
2630
"@types/react": "^17.0.3",

apps/design-system/src/pages/view-preview/view-preview.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { RepoSettingsViewWrapper } from '@/pages/view-preview/repo-settings-view
88
import ExecutionListWrapper from '@subjects/views/execution-list/execution-list'
99
import { ProjectLabelsList } from '@subjects/views/labels/project-labels-list'
1010
import { RepoLabelsList } from '@subjects/views/labels/repo-labels-list'
11+
import PipelineStudioWrapper from '@subjects/views/pipeline-edit/pipeline-edit'
12+
import PipelineGraphWrapper from '@subjects/views/pipeline-graph/pipeline-graph'
13+
import PipelineGraphMinimalWrapper from '@subjects/views/pipeline-graph/pipeline-graph-minimal'
1114
import PipelineListWrapper from '@subjects/views/pipeline-list/pipeline-list'
1215
import PullRequestCompareWrapper from '@subjects/views/pull-request-compare/pull-request-compare'
1316
import PullRequestChangesWrapper from '@subjects/views/pull-request-conversation/pull-request-changes-wrapper'
@@ -148,6 +151,17 @@ export const viewPreviews: Record<string, ReactNode> = {
148151
<PipelineListWrapper />
149152
</RepoViewWrapper>
150153
),
154+
'pipeline-studio': <PipelineStudioWrapper />,
155+
'pipeline-graph': (
156+
<RepoViewWrapper>
157+
<PipelineGraphWrapper />
158+
</RepoViewWrapper>
159+
),
160+
'pipeline-graph-minimal': (
161+
<RepoViewWrapper>
162+
<PipelineGraphMinimalWrapper />
163+
</RepoViewWrapper>
164+
),
151165
'execution-list': (
152166
<RepoViewWrapper>
153167
<ExecutionListWrapper />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const pipelineYaml1 = `pipeline:
2+
stages:
3+
- group:
4+
stages:
5+
- parallel:
6+
stages:
7+
- steps:
8+
- run: go build
9+
- run: go test
10+
- steps:
11+
- run: npm test
12+
- group:
13+
stages:
14+
- steps:
15+
- run: go build
16+
- steps:
17+
- run: npm run
18+
- run: npm test
19+
`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const pipelineYaml2 = `
2+
pipeline:
3+
stages:
4+
- group:
5+
stages: []
6+
- group:
7+
stages:
8+
- steps: []
9+
- parallel:
10+
stages: []
11+
`
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { useState } from 'react'
2+
3+
import { Button, ButtonGroup } from '@harnessio/ui/components'
4+
import {
5+
CommonNodeDataType,
6+
deleteItemInArray,
7+
injectItemInArray,
8+
PipelineEdit,
9+
YamlEntityType
10+
} from '@harnessio/ui/views'
11+
12+
import { pipelineYaml1 } from './mocks/pipelineYaml1'
13+
14+
const PipelineStudioWrapper = () => {
15+
const [yamlRevision, setYamlRevision] = useState({ yaml: pipelineYaml1 })
16+
const [view, setView] = useState<'graph' | 'yaml'>('graph')
17+
18+
const processAddIntention = (
19+
nodeData: CommonNodeDataType,
20+
position: 'after' | 'before' | 'in',
21+
yamlEntityTypeToAdd?: YamlEntityType | undefined
22+
) => {
23+
let newYaml = yamlRevision.yaml
24+
25+
switch (yamlEntityTypeToAdd) {
26+
case YamlEntityType.SerialStageGroup:
27+
// NOTE: if we are adding in the array we have to provide path to children array
28+
newYaml = injectItemInArray(yamlRevision.yaml, {
29+
path: position === 'in' && nodeData.yamlChildrenPath ? nodeData.yamlChildrenPath : nodeData.yamlPath,
30+
position,
31+
item: { group: { stages: [] } }
32+
})
33+
break
34+
35+
case YamlEntityType.ParallelStageGroup:
36+
// NOTE: if we are adding in the array we have to provide path to children array
37+
newYaml = injectItemInArray(yamlRevision.yaml, {
38+
path: position === 'in' && nodeData.yamlChildrenPath ? nodeData.yamlChildrenPath : nodeData.yamlPath,
39+
position,
40+
item: { parallel: { stages: [] } }
41+
})
42+
break
43+
44+
case YamlEntityType.Stage:
45+
// NOTE: if we are adding in the array we have to provide path to children array
46+
newYaml = injectItemInArray(yamlRevision.yaml, {
47+
path: position === 'in' && nodeData.yamlChildrenPath ? nodeData.yamlChildrenPath : nodeData.yamlPath,
48+
position,
49+
item: { steps: [] }
50+
})
51+
break
52+
53+
default:
54+
if (nodeData.yamlEntityType === YamlEntityType.Stage) {
55+
// TODO: set addIntent state and open drawer....
56+
}
57+
break
58+
}
59+
60+
setYamlRevision({ yaml: newYaml })
61+
}
62+
63+
return (
64+
<div className="flex h-screen flex-col">
65+
<ButtonGroup className="m-2 flex gap-2">
66+
<Button onClick={() => setView('graph')} variant={'secondary'}>
67+
Visual
68+
</Button>
69+
<Button onClick={() => setView('yaml')} variant={'secondary'}>
70+
Yaml
71+
</Button>
72+
</ButtonGroup>
73+
74+
<PipelineEdit
75+
yamlRevision={yamlRevision}
76+
onYamlRevisionChange={setYamlRevision}
77+
view={view}
78+
onAddIntention={(nodeData, position, yamlEntityTypeToAdd) => {
79+
console.log('onAddIntention')
80+
processAddIntention(nodeData, position, yamlEntityTypeToAdd)
81+
}}
82+
onDeleteIntention={data => {
83+
console.log('onDeleteIntention')
84+
const updatedYaml = deleteItemInArray(yamlRevision.yaml, { path: data.yamlPath })
85+
setYamlRevision({ yaml: updatedYaml })
86+
}}
87+
onEditIntention={() => {
88+
console.log('onEditIntention')
89+
}}
90+
onSelectIntention={() => {
91+
console.log('onSelectIntention')
92+
}}
93+
onRevealInYaml={() => {
94+
console.log('onSelectIntention')
95+
}}
96+
/>
97+
</div>
98+
)
99+
}
100+
101+
export default PipelineStudioWrapper

0 commit comments

Comments
 (0)