16
16
17
17
import { useState } from 'react'
18
18
import { ERROR_STATUS_CODE } from '@Common/Constants'
19
- import { Button , ButtonStyleType , ButtonVariantType , DeleteConfirmationModal } from '@Shared/Components'
19
+ import { Button , ButtonStyleType , ButtonVariantType , DeleteConfirmationModal , Icon } from '@Shared/Components'
20
20
import { ComponentSizeType , DeleteComponentsName } from '@Shared/constants'
21
21
import { ToastManager , ToastVariantType } from '@Shared/index'
22
- import { ReactComponent as ICDelete } from '@IconsV2/ic-delete.svg'
23
22
import { deleteWorkflow , savePipeline } from './utils'
24
23
import { DeleteCINodeButtonProps } from './types'
25
24
import { preventDefault , showError , stopPropagation } from '..'
26
25
27
26
export const DeleteCINodeButton = ( {
28
27
testId,
29
- isCIPipeline ,
30
- disabled,
28
+ showIconOnly = true ,
29
+ disabled = false ,
31
30
title,
32
31
isJobView,
33
32
deletePayloadConfig,
@@ -47,29 +46,31 @@ export const DeleteCINodeButton = ({
47
46
}
48
47
49
48
const onDeleteWorkflow = async ( ) => {
50
- await deleteWorkflow ( String ( deletePayloadConfig . appId ) , Number ( deletePayloadConfig . appWorkflowId ) )
51
- . then ( ( response ) => {
52
- if ( response . errors ) {
53
- const { errors } = response
54
- const { userMessage } = errors [ 0 ]
55
- ToastManager . showToast ( {
56
- variant : ToastVariantType . error ,
57
- description : userMessage ,
58
- } )
59
- return
60
- }
49
+ try {
50
+ const response = await deleteWorkflow (
51
+ String ( deletePayloadConfig . appId ) ,
52
+ Number ( deletePayloadConfig . appWorkflowId ) ,
53
+ )
54
+ if ( response . errors ) {
55
+ const { errors } = response
56
+ const { userMessage } = errors [ 0 ]
57
+ ToastManager . showToast ( {
58
+ variant : ToastVariantType . error ,
59
+ description : userMessage ,
60
+ } )
61
+ return
62
+ }
61
63
62
- if ( response . status . toLowerCase ( ) === 'ok' ) {
63
- ToastManager . showToast ( {
64
- variant : ToastVariantType . success ,
65
- description : 'Workflow Deleted' ,
66
- } )
67
- getWorkflows ( )
68
- }
69
- } )
70
- . catch ( ( errors ) => {
71
- showError ( errors )
72
- } )
64
+ if ( response . status . toLowerCase ( ) === 'ok' ) {
65
+ ToastManager . showToast ( {
66
+ variant : ToastVariantType . success ,
67
+ description : 'Workflow Deleted' ,
68
+ } )
69
+ getWorkflows ( )
70
+ }
71
+ } catch ( error ) {
72
+ showError ( error )
73
+ }
73
74
}
74
75
75
76
const onClickDelete = async ( ) => {
@@ -86,20 +87,11 @@ export const DeleteCINodeButton = ({
86
87
if ( typeof onDelete === 'function' ) {
87
88
onDelete ( )
88
89
}
89
-
90
90
await onDeleteWorkflow ( )
91
91
}
92
92
93
93
const renderDeleteButton = ( ) =>
94
- isCIPipeline ? (
95
- < Button
96
- dataTestId = { testId }
97
- disabled = { disabled }
98
- onClick = { onClickDeleteShowModal }
99
- text = "Delete Pipeline"
100
- style = { ButtonStyleType . negative }
101
- />
102
- ) : (
94
+ showIconOnly ? (
103
95
< Button
104
96
ariaLabel = "Delete pipeline"
105
97
variant = { ButtonVariantType . borderLess }
@@ -108,8 +100,21 @@ export const DeleteCINodeButton = ({
108
100
showAriaLabelInTippy
109
101
onClick = { onClickDeleteShowModal }
110
102
style = { ButtonStyleType . negativeGrey }
111
- icon = { < ICDelete /> }
103
+ icon = { < Icon name = "ic-delete" color = { null } strokeWidth = { 1 } size = { 12 } /> }
112
104
disabled = { disabled }
105
+ showTooltip
106
+ tooltipProps = { {
107
+ placement : 'right' ,
108
+ content : 'Delete Pipeline' ,
109
+ } }
110
+ />
111
+ ) : (
112
+ < Button
113
+ dataTestId = { testId }
114
+ disabled = { disabled }
115
+ onClick = { onClickDeleteShowModal }
116
+ text = "Delete Pipeline"
117
+ style = { ButtonStyleType . negative }
113
118
/>
114
119
)
115
120
0 commit comments