@devtron-labs/devtron-fe-common-lib 0.0.7-beta-41 → 0.0.7-beta-42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DeleteComponentProps } from './types';
|
|
3
|
+
declare function DeleteComponent({ setDeleting, toggleConfirmation, deleteComponent, title, component, payload, confirmationDialogDescription, redirectTo, url, reload, configuration, closeCustomComponent, }: DeleteComponentProps): JSX.Element;
|
|
4
|
+
export default DeleteComponent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface DeleteComponentProps {
|
|
2
|
+
setDeleting: (boolean: any) => void;
|
|
3
|
+
toggleConfirmation: any;
|
|
4
|
+
deleteComponent: (any: any) => Promise<any>;
|
|
5
|
+
title: string;
|
|
6
|
+
component: string;
|
|
7
|
+
payload: any;
|
|
8
|
+
confirmationDialogDescription?: string;
|
|
9
|
+
redirectTo?: boolean;
|
|
10
|
+
url?: string;
|
|
11
|
+
reload?: () => void;
|
|
12
|
+
configuration?: string;
|
|
13
|
+
dataTestid?: string;
|
|
14
|
+
closeCustomComponent?: () => void;
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { toast } from 'react-toastify'
|
|
3
|
+
import { useHistory } from 'react-router'
|
|
4
|
+
import info from '../assets/icons/ic-info-filled.svg'
|
|
5
|
+
import ConfirmationDialog from '../Dialogs/ConfirmationDialog'
|
|
6
|
+
import { DeleteDialog } from '../Dialogs'
|
|
7
|
+
import { ServerErrors } from '../ServerError'
|
|
8
|
+
import { DeleteComponentProps } from './types'
|
|
9
|
+
|
|
10
|
+
function DeleteComponent({
|
|
11
|
+
setDeleting,
|
|
12
|
+
toggleConfirmation,
|
|
13
|
+
deleteComponent,
|
|
14
|
+
title,
|
|
15
|
+
component,
|
|
16
|
+
payload,
|
|
17
|
+
confirmationDialogDescription = '',
|
|
18
|
+
redirectTo = false,
|
|
19
|
+
url = '',
|
|
20
|
+
reload,
|
|
21
|
+
configuration = '',
|
|
22
|
+
closeCustomComponent,
|
|
23
|
+
}: DeleteComponentProps) {
|
|
24
|
+
const [showCannotDeleteDialogModal, setCannotDeleteDialogModal] = useState(false)
|
|
25
|
+
const { push } = useHistory()
|
|
26
|
+
|
|
27
|
+
async function handleDelete() {
|
|
28
|
+
setDeleting(true)
|
|
29
|
+
try {
|
|
30
|
+
await deleteComponent(payload)
|
|
31
|
+
toast.success('Successfully deleted')
|
|
32
|
+
toggleConfirmation(false)
|
|
33
|
+
if (redirectTo) {
|
|
34
|
+
push(url)
|
|
35
|
+
} else {
|
|
36
|
+
reload()
|
|
37
|
+
}
|
|
38
|
+
if (typeof closeCustomComponent === 'function') {
|
|
39
|
+
closeCustomComponent()
|
|
40
|
+
}
|
|
41
|
+
} catch (serverError) {
|
|
42
|
+
if (serverError instanceof ServerErrors && serverError.code === 500) {
|
|
43
|
+
setCannotDeleteDialogModal(true)
|
|
44
|
+
}
|
|
45
|
+
} finally {
|
|
46
|
+
setDeleting(false)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const handleConfirmation = () => {
|
|
51
|
+
setCannotDeleteDialogModal(false)
|
|
52
|
+
toggleConfirmation(false)
|
|
53
|
+
if (typeof closeCustomComponent === 'function') {
|
|
54
|
+
closeCustomComponent()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const renderCannotDeleteDialogModal = () => {
|
|
59
|
+
return (
|
|
60
|
+
<ConfirmationDialog className="confirmation-dialog__body--w-360">
|
|
61
|
+
<ConfirmationDialog.Icon src={info} />
|
|
62
|
+
<ConfirmationDialog.Body title={`Cannot delete ${component} '${title}'`} />
|
|
63
|
+
<p className="fs-13 cn-7 ">{confirmationDialogDescription}</p>
|
|
64
|
+
<ConfirmationDialog.ButtonGroup>
|
|
65
|
+
<button type="button" className="cta" onClick={handleConfirmation}>
|
|
66
|
+
Okay
|
|
67
|
+
</button>
|
|
68
|
+
</ConfirmationDialog.ButtonGroup>
|
|
69
|
+
</ConfirmationDialog>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const renderDeleteDialog = () => {
|
|
74
|
+
return (
|
|
75
|
+
<DeleteDialog
|
|
76
|
+
title={`Delete ${component} '${title}'`}
|
|
77
|
+
delete={handleDelete}
|
|
78
|
+
closeDelete={() => toggleConfirmation(false)}
|
|
79
|
+
dataTestId="delete-dialog"
|
|
80
|
+
>
|
|
81
|
+
<DeleteDialog.Description>
|
|
82
|
+
<p>Are you sure you want to delete this {configuration ? configuration : component}? </p>
|
|
83
|
+
</DeleteDialog.Description>
|
|
84
|
+
</DeleteDialog>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
{!showCannotDeleteDialogModal && renderDeleteDialog()}
|
|
90
|
+
{showCannotDeleteDialogModal && renderCannotDeleteDialogModal()}
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default DeleteComponent
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface DeleteComponentProps {
|
|
2
|
+
setDeleting: (boolean) => void
|
|
3
|
+
toggleConfirmation: any
|
|
4
|
+
deleteComponent: (any) => Promise<any>
|
|
5
|
+
title: string
|
|
6
|
+
component: string
|
|
7
|
+
payload: any
|
|
8
|
+
confirmationDialogDescription?: string
|
|
9
|
+
redirectTo?: boolean
|
|
10
|
+
url?: string
|
|
11
|
+
reload?: () => void
|
|
12
|
+
configuration?: string
|
|
13
|
+
dataTestid?: string
|
|
14
|
+
closeCustomComponent?: () => void
|
|
15
|
+
}
|