@@ -14,6 +14,7 @@ import {
14
14
CModalBody ,
15
15
CModalTitle ,
16
16
CCallout ,
17
+ CFormSelect ,
17
18
} from '@coreui/react'
18
19
import DataTable , { createTheme } from 'react-data-table-component'
19
20
import PropTypes from 'prop-types'
@@ -24,6 +25,7 @@ import { cellGenericFormatter } from './CellGenericFormat'
24
25
import { ModalService } from '../utilities'
25
26
import { useLazyGenericGetRequestQuery , useLazyGenericPostRequestQuery } from 'src/store/api/app'
26
27
import { ConfirmModal } from '../utilities/SharedModal'
28
+ import { useState } from 'react'
27
29
28
30
const FilterComponent = ( {
29
31
filterText,
@@ -156,6 +158,40 @@ export default function CippTable({
156
158
const [ selectedRows , setSelectedRows ] = React . useState ( false )
157
159
const [ genericGetRequest , getResults ] = useLazyGenericGetRequestQuery ( )
158
160
const [ genericPostRequest , postResults ] = useLazyGenericPostRequestQuery ( )
161
+ const [ getDrowndownInfo , dropDownInfo ] = useLazyGenericGetRequestQuery ( )
162
+ const [ modalContent , setModalContent ] = useState ( null )
163
+ useEffect ( ( ) => {
164
+ if ( dropDownInfo . isFetching ) {
165
+ handleModal (
166
+ < CSpinner /> ,
167
+ modalContent . item . modalUrl ,
168
+ modalContent . item . modalType ,
169
+ modalContent . item . modalBody ,
170
+ modalContent . item . modalInput ,
171
+ modalContent . item . modalDropdown ,
172
+ )
173
+ }
174
+ if ( dropDownInfo . isSuccess ) {
175
+ console . log ( modalContent )
176
+ handleModal (
177
+ modalContent . item . modalMessage ,
178
+ modalContent . item . modalUrl ,
179
+ modalContent . item . modalType ,
180
+ modalContent . item . modalBody ,
181
+ modalContent . item . modalInput ,
182
+ modalContent . item . modalDropdown ,
183
+ )
184
+ } else if ( dropDownInfo . isError ) {
185
+ handleModal (
186
+ 'Error connecting to the API.' ,
187
+ modalContent . item . modalUrl ,
188
+ modalContent . item . modalType ,
189
+ modalContent . item . modalBody ,
190
+ modalContent . item . modalInput ,
191
+ modalContent . item . modalDropdown ,
192
+ )
193
+ }
194
+ } , [ dropDownInfo ] )
159
195
const handleSelectedChange = ( { selectedRows } ) => {
160
196
setSelectedRows ( selectedRows )
161
197
if ( selectedRows . length < 1 ) {
@@ -229,84 +265,118 @@ export default function CippTable({
229
265
} ,
230
266
} ,
231
267
}
232
- const subHeaderComponentMemo = React . useMemo ( ( ) => {
233
- const handleClear = ( ) => {
234
- if ( filterText ) {
235
- setResetPaginationToggle ( ! resetPaginationToggle )
236
- setFilterText ( '' )
237
- }
238
- }
239
- const handleModal = ( modalMessage , modalUrl , modalType = 'GET' , modalBody , modalInput ) => {
240
- if ( modalType === 'GET' ) {
241
- ModalService . confirm ( {
242
- body : (
243
- < div style = { { overflow : 'visible' } } >
244
- < div > { modalMessage } </ div >
245
- </ div >
246
- ) ,
247
- title : 'Confirm' ,
248
- onConfirm : async ( ) => {
249
- const resultsarr = [ ]
250
- for ( const row of selectedRows ) {
251
- setLoopRunning ( true )
252
- const urlParams = new URLSearchParams ( modalUrl . split ( '?' ) [ 1 ] )
253
- for ( let [ paramName , paramValue ] of urlParams . entries ( ) ) {
254
- if ( paramValue . startsWith ( '!' ) ) {
255
- urlParams . set ( paramName , row [ paramValue . replace ( '!' , '' ) ] )
256
- }
268
+ const handleModal = (
269
+ modalMessage ,
270
+ modalUrl ,
271
+ modalType = 'GET' ,
272
+ modalBody ,
273
+ modalInput ,
274
+ modalDropdown ,
275
+ ) => {
276
+ if ( modalType === 'GET' ) {
277
+ ModalService . confirm ( {
278
+ body : (
279
+ < div style = { { overflow : 'visible' } } >
280
+ < div > { modalMessage } </ div >
281
+ </ div >
282
+ ) ,
283
+ title : 'Confirm' ,
284
+ onConfirm : async ( ) => {
285
+ const resultsarr = [ ]
286
+ for ( const row of selectedRows ) {
287
+ setLoopRunning ( true )
288
+ const urlParams = new URLSearchParams ( modalUrl . split ( '?' ) [ 1 ] )
289
+ for ( let [ paramName , paramValue ] of urlParams . entries ( ) ) {
290
+ if ( paramValue . startsWith ( '!' ) ) {
291
+ urlParams . set ( paramName , row [ paramValue . replace ( '!' , '' ) ] )
257
292
}
258
- const NewModalUrl = `${ modalUrl . split ( '?' ) [ 0 ] } ?${ urlParams . toString ( ) } `
259
- const results = await genericGetRequest ( { path : NewModalUrl , refreshParam : row . id } )
260
- resultsarr . push ( results )
261
- setMassResults ( resultsarr )
262
293
}
263
- setLoopRunning ( false )
264
- } ,
265
- } )
266
- } else {
267
- ModalService . confirm ( {
268
- body : (
269
- < div style = { { overflow : 'visible' } } >
270
- { modalInput && (
271
- < div >
272
- < CFormInput ref = { inputRef } type = "text" />
273
- </ div >
274
- ) }
275
- < div > { modalMessage } </ div >
276
- </ div >
277
- ) ,
278
- title : 'Confirm' ,
279
- onConfirm : async ( ) => {
280
- const resultsarr = [ ]
281
- for ( const row of selectedRows ) {
282
- setLoopRunning ( true )
283
- const urlParams = new URLSearchParams ( modalUrl . split ( '?' ) [ 1 ] )
284
- for ( let [ paramName , paramValue ] of urlParams . entries ( ) ) {
285
- if ( paramValue . toString ( ) . startsWith ( '!' ) ) {
286
- urlParams . set ( paramName , row [ paramValue . replace ( '!' , '' ) ] )
287
- }
294
+ const NewModalUrl = `${ modalUrl . split ( '?' ) [ 0 ] } ?${ urlParams . toString ( ) } `
295
+ const results = await genericGetRequest ( { path : NewModalUrl , refreshParam : row . id } )
296
+ resultsarr . push ( results )
297
+ setMassResults ( resultsarr )
298
+ }
299
+ setLoopRunning ( false )
300
+ } ,
301
+ } )
302
+ } else {
303
+ ModalService . confirm ( {
304
+ body : (
305
+ < div style = { { overflow : 'visible' } } >
306
+ { modalInput && (
307
+ < div >
308
+ < CFormInput ref = { inputRef } type = "text" />
309
+ </ div >
310
+ ) }
311
+ { modalDropdown && (
312
+ < div >
313
+ { dropDownInfo . isSuccess && (
314
+ < CFormSelect
315
+ ref = { inputRef }
316
+ options = { dropDownInfo . data . map ( ( data ) => ( {
317
+ value : data [ modalDropdown . valueField ] ,
318
+ label : data [ modalDropdown . labelField ] ,
319
+ } ) ) }
320
+ />
321
+ ) }
322
+ </ div >
323
+ ) }
324
+ < div > { modalMessage } </ div >
325
+ </ div >
326
+ ) ,
327
+ title : 'Confirm' ,
328
+ onConfirm : async ( ) => {
329
+ const resultsarr = [ ]
330
+ for ( const row of selectedRows ) {
331
+ setLoopRunning ( true )
332
+ const urlParams = new URLSearchParams ( modalUrl . split ( '?' ) [ 1 ] )
333
+ for ( let [ paramName , paramValue ] of urlParams . entries ( ) ) {
334
+ if ( paramValue . toString ( ) . startsWith ( '!' ) ) {
335
+ urlParams . set ( paramName , row [ paramValue . replace ( '!' , '' ) ] )
288
336
}
289
- const newModalBody = { }
290
- for ( let [ objName , objValue ] of Object . entries ( modalBody ) ) {
291
- if ( objValue . toString ( ) . startsWith ( '!' ) ) {
292
- newModalBody [ objName ] = row [ objValue . replace ( '!' , '' ) ]
293
- }
337
+ }
338
+ const newModalBody = { }
339
+ for ( let [ objName , objValue ] of Object . entries ( modalBody ) ) {
340
+ if ( objValue . toString ( ) . startsWith ( '!' ) ) {
341
+ newModalBody [ objName ] = row [ objValue . replace ( '!' , '' ) ]
294
342
}
295
- const NewModalUrl = `${ modalUrl . split ( '?' ) [ 0 ] } ?${ urlParams . toString ( ) } `
296
- const results = await genericPostRequest ( {
297
- path : NewModalUrl ,
298
- values : { ...modalBody , ...newModalBody , ...{ input : inputRef . current . value } } ,
299
- } )
300
- resultsarr . push ( results )
301
- setMassResults ( resultsarr )
302
343
}
303
- setLoopRunning ( false )
304
- } ,
305
- } )
344
+ const NewModalUrl = `${ modalUrl . split ( '?' ) [ 0 ] } ?${ urlParams . toString ( ) } `
345
+ const results = await genericPostRequest ( {
346
+ path : NewModalUrl ,
347
+ values : { ...modalBody , ...newModalBody , ...{ input : inputRef . current . value } } ,
348
+ } )
349
+ resultsarr . push ( results )
350
+ setMassResults ( resultsarr )
351
+ }
352
+ setLoopRunning ( false )
353
+ } ,
354
+ } )
355
+ }
356
+ }
357
+ const subHeaderComponentMemo = React . useMemo ( ( ) => {
358
+ const handleClear = ( ) => {
359
+ if ( filterText ) {
360
+ setResetPaginationToggle ( ! resetPaginationToggle )
361
+ setFilterText ( '' )
306
362
}
307
363
}
364
+
308
365
const executeselectedAction = ( item ) => {
309
- handleModal ( item . modalMessage , item . modalUrl , item . modalType , item . modalBody , item . modalInput )
366
+ setModalContent ( {
367
+ item,
368
+ } )
369
+ if ( item . modalDropdown ) {
370
+ getDrowndownInfo ( { path : item . modalDropdown . url } )
371
+ }
372
+ handleModal (
373
+ item . modalMessage ,
374
+ item . modalUrl ,
375
+ item . modalType ,
376
+ item . modalBody ,
377
+ item . modalInput ,
378
+ item . modalDropdown ,
379
+ )
310
380
}
311
381
const defaultActions = [ ]
312
382
const dataKeys = ( ) => {
0 commit comments