1
1
import React , { Component } from 'react'
2
- import { AddCDPositions , WorkflowNodeType , PipelineType , AddPipelineType } from '@devtron-labs/devtron-fe-common-lib'
2
+ import {
3
+ AddCDPositions ,
4
+ WorkflowNodeType ,
5
+ PipelineType ,
6
+ AddPipelineType ,
7
+ AddCDButton ,
8
+ Point ,
9
+ EdgeNodeType ,
10
+ } from '@devtron-labs/devtron-fe-common-lib'
3
11
import { nodeColors } from './colors'
4
12
5
- interface Point {
6
- x : number
7
- y : number
8
- }
9
-
10
13
interface Line {
11
14
startNode : Point
12
15
endNode : Point
13
16
}
14
17
15
18
interface EdgeProps {
16
19
// type should not be any but WorkflowNodeType, but node type is something else have to look into it
17
- startNode : Point & { height : number ; width : number ; type ?: any ; id ?: number | string }
18
- endNode : Point & { height : number ; width : number ; type ?: any ; id ?: number | string }
20
+ startNode : Point & EdgeNodeType
21
+ endNode : Point & EdgeNodeType
19
22
onClickEdge : ( event : any ) => void
20
23
deleteEdge : ( ) => void
21
24
onMouseOverEdge : ( startID : any , endID : any ) => void
@@ -44,49 +47,6 @@ interface LineDots {
44
47
midPointY : number
45
48
}
46
49
47
- interface AddCDButtonProps {
48
- position : AddCDPositions
49
- addCDButtons : AddCDPositions [ ]
50
- endNode : Point & { height : number ; width : number ; type ?: any ; id ?: number | string }
51
- startNode : Point & { height : number ; width : number ; type ?: any ; id ?: number | string }
52
- handleAddCD : ( position : AddCDPositions ) => void
53
- }
54
-
55
- function AddCDButton ( { position, addCDButtons, endNode, startNode, handleAddCD } : Readonly < AddCDButtonProps > ) {
56
- const referenceNode = position === AddCDPositions . RIGHT ? endNode : startNode
57
- const handleAddCDClick = ( ) => {
58
- handleAddCD ( position )
59
- }
60
-
61
- if ( addCDButtons ?. includes ( position ) ) {
62
- return (
63
- < svg
64
- x = { referenceNode . x + ( position === AddCDPositions . RIGHT ? - 20 - 5 : referenceNode . width + 5 ) }
65
- // Here 10 is the height of the button / 2
66
- y = { referenceNode . y + referenceNode . height / 2 - 10 }
67
- width = "20"
68
- height = "20"
69
- viewBox = "0 0 20 20"
70
- fill = "none"
71
- xmlns = "http://www.w3.org/2000/svg"
72
- data-testid = { `add-cd-to-${ position } ` }
73
- onClick = { handleAddCDClick }
74
- >
75
- < rect width = "20" height = "20" rx = "10" fill = "#664BEE" className = "add-cd-edge-btn" />
76
- < path
77
- d = "M6.5 10H13.5M10 6.5V13.5"
78
- stroke = "white"
79
- strokeWidth = "1.5"
80
- strokeLinecap = "round"
81
- strokeLinejoin = "round"
82
- />
83
- </ svg >
84
- )
85
- }
86
-
87
- return null
88
- }
89
-
90
50
export default class Edge extends Component < EdgeProps > {
91
51
getLineDots ( ) : LineDots {
92
52
let lineStartX = this . props . startNode . x + this . props . startNode . width
@@ -192,44 +152,13 @@ export default class Edge extends Component<EdgeProps> {
192
152
}
193
153
const { handleCDSelect, startNode, endNode, workflowId, ciPipelineId, isWebhookCD } = this . props
194
154
const pipelineType = this . getPipelineType ( )
155
+ const addPipelineType =
156
+ this . props . isParallelEdge && position === AddCDPositions . RIGHT
157
+ ? AddPipelineType . PARALLEL
158
+ : AddPipelineType . SEQUENTIAL
159
+ const endNodeId = ! this . props . isParallelEdge && position === AddCDPositions . RIGHT ? endNode . id : null
195
160
196
- if ( this . props . isParallelEdge && position === AddCDPositions . RIGHT ) {
197
- handleCDSelect (
198
- workflowId ,
199
- ciPipelineId ,
200
- pipelineType ,
201
- startNode . id ,
202
- isWebhookCD ,
203
- null ,
204
- AddPipelineType . PARALLEL ,
205
- )
206
- return
207
- }
208
-
209
- if ( position === AddCDPositions . LEFT ) {
210
- handleCDSelect (
211
- workflowId ,
212
- ciPipelineId ,
213
- pipelineType ,
214
- startNode . id ,
215
- isWebhookCD ,
216
- null ,
217
- AddPipelineType . SEQUENTIAL ,
218
- )
219
- return
220
- }
221
-
222
- if ( position === AddCDPositions . RIGHT ) {
223
- handleCDSelect (
224
- workflowId ,
225
- ciPipelineId ,
226
- pipelineType ,
227
- startNode . id ,
228
- isWebhookCD ,
229
- endNode . id ,
230
- AddPipelineType . SEQUENTIAL ,
231
- )
232
- }
161
+ handleCDSelect ( workflowId , ciPipelineId , pipelineType , startNode . id , isWebhookCD , endNodeId , addPipelineType )
233
162
}
234
163
235
164
render ( ) {
@@ -238,9 +167,8 @@ export default class Edge extends Component<EdgeProps> {
238
167
239
168
return (
240
169
< g
241
- style = { { cursor : 'pointer' } }
242
170
onClick = { this . props . onClickEdge }
243
- className = "edge-group"
171
+ className = "edge-group cursor "
244
172
onMouseOver = { ( ) => this . props . onMouseOverEdge ( this . props . startNode , this . props . endNode ) }
245
173
>
246
174
< path
0 commit comments