Skip to content

Commit a9fc015

Browse files
Merge pull request #2653 from devtron-labs/feat/webhook-external-image
feat: TriggerView - Webhook Node - add image button UI
2 parents 96ade6f + aa6b7ac commit a9fc015

File tree

5 files changed

+55
-26
lines changed

5 files changed

+55
-26
lines changed

src/components/app/details/triggerView/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import { createContext } from 'react'
1818
import { DeploymentNodeType } from '@devtron-labs/devtron-fe-common-lib'
1919
import { TriggerViewContextType } from './types'
20+
import { importComponentFromFELibrary } from '@Components/common'
21+
22+
const WebhookAddImageButton = importComponentFromFELibrary('WebhookAddImageButton', null, 'function')
2023

2124
export const TriggerViewContext = createContext<TriggerViewContextType>({
2225
invalidateCache: false,
@@ -100,6 +103,16 @@ export const WorkflowTrigger = {
100103
distanceX: 60,
101104
distanceY: 25,
102105
} as NodeDimension,
106+
...(WebhookAddImageButton
107+
? {
108+
webhookNodeSize: {
109+
nodeHeight: 94,
110+
nodeWidth: 200,
111+
distanceX: 60,
112+
distanceY: 20,
113+
} as NodeDimension,
114+
}
115+
: {}),
103116
workflow: {
104117
distanceY: 16,
105118
distanceX: 0,
@@ -129,6 +142,7 @@ export interface WorkflowDimensions {
129142
externalCINodeSizes?: NodeDimension
130143
linkedCINodeSizes?: NodeDimension
131144
cDNodeSizes: NodeDimension
145+
webhookNodeSize?: NodeDimension
132146
workflow: Offset
133147
}
134148

src/components/app/details/triggerView/workflow.service.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,16 @@ export const getInitialWorkflows = ({
147147
})
148148
}
149149
if (isJobView) {
150-
return Promise.all([getWorkflowList(id, null, false), getCIConfig(id, false)]).then(
151-
([workflow, ciConfig]) => {
152-
return processWorkflow(
153-
workflow.result as WorkflowResult,
154-
ciConfig.result as CiPipelineResult,
155-
null,
156-
null,
157-
dimensions,
158-
workflowOffset,
159-
)
160-
},
161-
)
150+
return Promise.all([getWorkflowList(id, null, false), getCIConfig(id, false)]).then(([workflow, ciConfig]) => {
151+
return processWorkflow(
152+
workflow.result as WorkflowResult,
153+
ciConfig.result as CiPipelineResult,
154+
null,
155+
null,
156+
dimensions,
157+
workflowOffset,
158+
)
159+
})
162160
}
163161
return Promise.all([
164162
getWorkflowList(id, filteredEnvIds, isTemplateView),
@@ -644,8 +642,10 @@ function webhookToNode(webhookDetails: WebhookDetailsType, dimensions: WorkflowD
644642
id: String(webhookDetails.id),
645643
x: 0,
646644
y: 0,
647-
height: dimensions.staticNodeSizes.nodeHeight,
648-
width: dimensions.staticNodeSizes.nodeWidth,
645+
height: dimensions.webhookNodeSize
646+
? dimensions.webhookNodeSize.nodeHeight
647+
: dimensions.staticNodeSizes.nodeHeight,
648+
width: dimensions.webhookNodeSize ? dimensions.webhookNodeSize.nodeWidth : dimensions.staticNodeSizes.nodeWidth,
649649
title: 'Webhook',
650650
status: DEFAULT_STATUS,
651651
type: WorkflowNodeType.WEBHOOK,

src/components/app/details/triggerView/workflow/Workflow.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class Workflow extends Component<WorkflowProps> {
124124
key={`webhook-${node.id}`}
125125
id={node.id}
126126
isTemplateView={false}
127+
showAddImageButton
127128
/>
128129
)
129130
}
@@ -386,11 +387,7 @@ export class Workflow extends Component<WorkflowProps> {
386387
</span>
387388

388389
<div className="dc__separated-flexbox">
389-
{BulkDeployLink && numberOfCDNodes > 1 && (
390-
<BulkDeployLink
391-
workflowId={this.props.id}
392-
/>
393-
)}
390+
{BulkDeployLink && numberOfCDNodes > 1 && <BulkDeployLink workflowId={this.props.id} />}
394391

395392
{ImagePromotionLink && (
396393
<ImagePromotionLink
@@ -402,7 +399,6 @@ export class Workflow extends Component<WorkflowProps> {
402399
/>
403400
)}
404401
</div>
405-
406402
</>
407403
)}
408404
</div>

src/components/workflowEditor/nodes/WebhookNode.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515
*/
1616

1717
import { ReactElement, useState } from 'react'
18-
import { WorkflowNodeType, ConditionalWrap, TARGET_IDS, TippyTheme, TippyCustomized } from '@devtron-labs/devtron-fe-common-lib'
18+
import {
19+
WorkflowNodeType,
20+
ConditionalWrap,
21+
TARGET_IDS,
22+
TippyTheme,
23+
TippyCustomized,
24+
} from '@devtron-labs/devtron-fe-common-lib'
1925
import { Link } from 'react-router-dom'
2026
import ToggleCDSelectButton from '../ToggleCDSelectButton'
2127
import { ReactComponent as Webhook } from '../../../assets/icons/ic-CIWebhook.svg'
2228
import { WebhookNodeProps } from '../types'
2329
import { ReactComponent as ICCIWebhook } from '@Icons/ic-CIWebhook.svg'
2430
import { DOCUMENTATION } from '@Config/constants'
31+
import { importComponentFromFELibrary } from '@Components/common'
32+
33+
const WebhookAddImageButton = importComponentFromFELibrary('WebhookAddImageButton', null, 'function')
2534

2635
export const WebhookNode = ({
2736
x,
@@ -38,12 +47,15 @@ export const WebhookNode = ({
3847
isLastNode,
3948
isReadonlyView = false,
4049
isTemplateView,
50+
showAddImageButton = false,
4151
}: WebhookNodeProps) => {
4252
const [isWebhookTippyOpen, setIsWebhookTippyOpen] = useState(false)
4353

4454
const selectedNodeKey = `${selectedNode?.nodeType}-${selectedNode?.id}`
4555
const currentNodeKey = `${WorkflowNodeType.WEBHOOK}-${id ?? ''}`
4656

57+
const showWebhookAddImageButton = WebhookAddImageButton && showAddImageButton
58+
4759
const addNewCD = (event): void => {
4860
event.preventDefault()
4961
event.stopPropagation()
@@ -63,7 +75,7 @@ export const WebhookNode = ({
6375
}
6476

6577
const toggleIsWebhookTippyOpen = () => {
66-
setIsWebhookTippyOpen(prev => !prev)
78+
setIsWebhookTippyOpen((prev) => !prev)
6779
}
6880

6981
const renderWrapWithLinkOrTippy = (children: ReactElement) =>
@@ -90,7 +102,7 @@ export const WebhookNode = ({
90102
{children}
91103
</Link>
92104
)
93-
105+
94106
const handleCardClick = () => {
95107
if (isTemplateView) {
96108
toggleIsWebhookTippyOpen()
@@ -102,11 +114,16 @@ export const WebhookNode = ({
102114

103115
return (
104116
<ConditionalWrap condition={shouldWrap} wrap={renderWrapWithLinkOrTippy}>
105-
<div className={`workflow-node pl-10 ${shouldWrap ? 'cursor' : ''}`} onClick={handleCardClick}>
117+
<div
118+
className={`workflow-node ${showWebhookAddImageButton ? 'flexbox-col dc__gap-10 p-12' : 'pl-10'} ${shouldWrap ? 'cursor' : ''}`}
119+
onClick={handleCardClick}
120+
>
106121
<div className="workflow-node__title flex workflow-node__title--no-margin h-100">
107-
<div className="workflow-node__full-width-minus-Icon p-12">
122+
<div
123+
className={`workflow-node__full-width-minus-Icon ${!showWebhookAddImageButton ? 'p-12' : ''}`}
124+
>
108125
<span className="workflow-node__text-light">Webhook</span>
109-
<div className="dc__ellipsis-left">External source</div>
126+
<div className="dc__ellipsis-left lh-16">External source</div>
110127
</div>
111128

112129
<Webhook className="icon-dim-20 mr-12" />
@@ -121,6 +138,7 @@ export const WebhookNode = ({
121138
/>
122139
)}
123140
</div>
141+
{showWebhookAddImageButton && <WebhookAddImageButton dataTestId={id} onClick={() => {}} />}
124142
</div>
125143
</ConditionalWrap>
126144
)

src/components/workflowEditor/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export interface WebhookNodeProps extends Required<Pick<AppConfigProps, 'isTempl
202202
* @default false
203203
*/
204204
isReadonlyView?: boolean
205+
showAddImageButton?: boolean
205206
}
206207

207208
export interface WebhookTippyType {

0 commit comments

Comments
 (0)