8
8
showInfoNotification ,
9
9
showSuccessNotification ,
10
10
} from '@greenbone/opensight-ui-components-mantinev7' ;
11
+ import { isDefined } from 'gmp/utils/identity' ;
11
12
import ConfirmationDialog from 'web/components/dialog/ConfirmationDialog' ;
12
13
import { DELETE_ACTION } from 'web/components/dialog/DialogTwoButtonFooter' ;
13
14
import Select from 'web/components/form/Select' ;
@@ -20,16 +21,45 @@ import IconDivider from 'web/components/layout/IconDivider';
20
21
import Layout from 'web/components/layout/Layout' ;
21
22
import TableFooter from 'web/components/table/TableFooter' ;
22
23
import TableRow from 'web/components/table/TableRow' ;
24
+ import { WithEntitiesFooterComponentProps } from 'web/entities/withEntitiesFooter' ;
23
25
import useTranslation from 'web/hooks/useTranslation' ;
24
- import PropTypes from 'web/utils/PropTypes' ;
25
- import SelectionType from 'web/utils/SelectionType' ;
26
+ import SelectionType , { SelectionTypeType } from 'web/utils/SelectionType' ;
26
27
27
28
const DIALOG_TYPES = {
28
29
TRASH : 'trash' ,
29
30
DELETE : 'delete' ,
30
- } ;
31
+ } as const ;
32
+
33
+ type DialogType = ( typeof DIALOG_TYPES ) [ keyof typeof DIALOG_TYPES ] ;
34
+
35
+ interface DialogConfig {
36
+ useCustomDialog : boolean ;
37
+ customDialogElement ?: React . ReactElement | null ;
38
+ dialogProcessing ?: boolean ;
39
+ }
40
+
41
+ interface ConfigDialog {
42
+ dialogText : string ;
43
+ dialogTitle : string ;
44
+ dialogButtonTitle : string ;
45
+ confirmFunction : ( ) => Promise < void > ;
46
+ }
31
47
32
- export const EntitiesFooter = ( {
48
+ export interface EntitiesFooterProps extends WithEntitiesFooterComponentProps {
49
+ actions ?: boolean ;
50
+ children ?: React . ReactNode ;
51
+ delete ?: boolean ;
52
+ dialogConfig ?: DialogConfig ;
53
+ download ?: string ;
54
+ selection ?: boolean ;
55
+ selectionType ?: SelectionTypeType ;
56
+ span ?: number ;
57
+ tags ?: boolean ;
58
+ trash ?: boolean ;
59
+ onSelectionTypeChange ?: ( selectionType : SelectionTypeType ) => void ;
60
+ }
61
+
62
+ const EntitiesFooter = ( {
33
63
actions = true ,
34
64
children,
35
65
download,
@@ -45,16 +75,22 @@ export const EntitiesFooter = ({
45
75
onTrashClick,
46
76
dialogConfig = { useCustomDialog : false } ,
47
77
delete : deleteEntities ,
48
- ...props
49
- } ) => {
78
+ } : EntitiesFooterProps ) => {
50
79
const [ _ ] = useTranslation ( ) ;
51
- const [ configDialog , setConfigDialog ] = useState ( undefined ) ;
80
+ const [ configDialog , setConfigDialog ] = useState < ConfigDialog | undefined > (
81
+ undefined ,
82
+ ) ;
52
83
const [ isDialogVisible , setIsDialogVisible ] = useState ( false ) ;
53
84
const [ isInProgress , setIsInProgress ] = useState ( false ) ;
54
85
55
- const onIconClick = ( type , propOnAction ) => {
86
+ const onIconClick = (
87
+ type : DialogType ,
88
+ propOnAction ?: ( ) => void | Promise < void > ,
89
+ ) => {
56
90
if ( dialogConfig . useCustomDialog ) {
57
- propOnAction ( ) ;
91
+ if ( isDefined ( propOnAction ) ) {
92
+ void propOnAction ( ) ;
93
+ }
58
94
return ;
59
95
}
60
96
@@ -69,7 +105,9 @@ export const EntitiesFooter = ({
69
105
try {
70
106
setIsInProgress ( true ) ;
71
107
showInfoNotification ( '' , _ ( 'Deletion started' ) ) ;
72
- await propOnAction ( ) ;
108
+ if ( isDefined ( propOnAction ) ) {
109
+ await propOnAction ( ) ;
110
+ }
73
111
showSuccessNotification ( '' , _ ( 'Deletion completed' ) ) ;
74
112
} finally {
75
113
setIsInProgress ( false ) ;
@@ -86,14 +124,16 @@ export const EntitiesFooter = ({
86
124
try {
87
125
setIsInProgress ( true ) ;
88
126
showInfoNotification ( '' , _ ( 'Moving to trashcan' ) ) ;
89
- await propOnAction ( ) ;
127
+ if ( isDefined ( propOnAction ) ) {
128
+ await propOnAction ( ) ;
129
+ }
90
130
showSuccessNotification ( '' , _ ( 'Move to trashcan completed' ) ) ;
91
131
} finally {
92
132
setIsInProgress ( false ) ;
93
133
}
94
134
} ,
95
135
} ,
96
- } ;
136
+ } as const ;
97
137
setConfigDialog ( configMap [ type ] ) ;
98
138
setIsDialogVisible ( true ) ;
99
139
} ;
@@ -129,7 +169,12 @@ export const EntitiesFooter = ({
129
169
< Select
130
170
items = { selectItems }
131
171
value = { selectionType }
132
- onChange = { onSelectionTypeChange }
172
+ onChange = {
173
+ onSelectionTypeChange as (
174
+ value : string ,
175
+ name ?: string ,
176
+ ) => void
177
+ }
133
178
/>
134
179
) }
135
180
< IconDivider >
@@ -161,7 +206,12 @@ export const EntitiesFooter = ({
161
206
< ExportIcon
162
207
selectionType = { selectionType }
163
208
value = { download }
164
- onClick = { onDownloadClick }
209
+ onClick = {
210
+ onDownloadClick as (
211
+ value ?: string ,
212
+ name ?: string ,
213
+ ) => void
214
+ }
165
215
/>
166
216
) }
167
217
{ children }
@@ -185,7 +235,7 @@ export const EntitiesFooter = ({
185
235
width = "500px"
186
236
onClose = { closeDialog }
187
237
onResumeClick = { ( ) => {
188
- configDialog . confirmFunction ( ) ;
238
+ void configDialog . confirmFunction ( ) ;
189
239
closeDialog ( ) ;
190
240
} }
191
241
/>
@@ -194,58 +244,4 @@ export const EntitiesFooter = ({
194
244
) ;
195
245
} ;
196
246
197
- EntitiesFooter . propTypes = {
198
- actions : PropTypes . bool ,
199
- delete : PropTypes . bool ,
200
- download : PropTypes . stringOrFalse ,
201
- selection : PropTypes . bool ,
202
- selectionType : PropTypes . string ,
203
- span : PropTypes . number . isRequired ,
204
- tags : PropTypes . bool ,
205
- trash : PropTypes . bool ,
206
- onDeleteClick : PropTypes . func ,
207
- onDownloadClick : PropTypes . func ,
208
- onSelectionTypeChange : PropTypes . func ,
209
- onTagsClick : PropTypes . func ,
210
- onTrashClick : PropTypes . func ,
211
- children : PropTypes . node ,
212
- dialogConfig : PropTypes . shape ( {
213
- useCustomDialog : PropTypes . bool ,
214
- dialog : PropTypes . element ,
215
- } ) ,
216
- } ;
217
-
218
- export const withEntitiesFooter =
219
- ( options = { } ) =>
220
- Component => {
221
- const EntitiesFooterWrapper = ( {
222
- onDownloadBulk,
223
- onDeleteBulk,
224
- onTagsBulk,
225
- ...props
226
- } ) => {
227
- return (
228
- < Component
229
- { ...options }
230
- { ...props }
231
- onDeleteClick = { onDeleteBulk }
232
- onDownloadClick = { onDownloadBulk }
233
- onTagsClick = { onTagsBulk }
234
- onTrashClick = { onDeleteBulk }
235
- />
236
- ) ;
237
- } ;
238
-
239
- EntitiesFooterWrapper . propTypes = {
240
- onDeleteBulk : PropTypes . func ,
241
- onDownloadBulk : PropTypes . func ,
242
- onTagsBulk : PropTypes . func ,
243
- } ;
244
-
245
- return EntitiesFooterWrapper ;
246
- } ;
247
-
248
- export const createEntitiesFooter = options =>
249
- withEntitiesFooter ( options ) ( EntitiesFooter ) ;
250
-
251
247
export default EntitiesFooter ;
0 commit comments