Skip to content

Commit a258747

Browse files
committed
chore: move addCDButton to common
1 parent fac6245 commit a258747

File tree

1 file changed

+18
-90
lines changed

1 file changed

+18
-90
lines changed

src/components/common/edge/rectangularEdge.tsx

Lines changed: 18 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
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'
311
import { nodeColors } from './colors'
412

5-
interface Point {
6-
x: number
7-
y: number
8-
}
9-
1013
interface Line {
1114
startNode: Point
1215
endNode: Point
1316
}
1417

1518
interface EdgeProps {
1619
// 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
1922
onClickEdge: (event: any) => void
2023
deleteEdge: () => void
2124
onMouseOverEdge: (startID: any, endID: any) => void
@@ -44,49 +47,6 @@ interface LineDots {
4447
midPointY: number
4548
}
4649

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-
9050
export default class Edge extends Component<EdgeProps> {
9151
getLineDots(): LineDots {
9252
let lineStartX = this.props.startNode.x + this.props.startNode.width
@@ -192,44 +152,13 @@ export default class Edge extends Component<EdgeProps> {
192152
}
193153
const { handleCDSelect, startNode, endNode, workflowId, ciPipelineId, isWebhookCD } = this.props
194154
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
195160

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)
233162
}
234163

235164
render() {
@@ -238,9 +167,8 @@ export default class Edge extends Component<EdgeProps> {
238167

239168
return (
240169
<g
241-
style={{ cursor: 'pointer' }}
242170
onClick={this.props.onClickEdge}
243-
className="edge-group"
171+
className="edge-group cursor"
244172
onMouseOver={() => this.props.onMouseOverEdge(this.props.startNode, this.props.endNode)}
245173
>
246174
<path

0 commit comments

Comments
 (0)