1
1
import React , { useEffect } from 'react' ;
2
- import { DataGrid , GridColumnVisibilityModel } from '@mui/x-data-grid' ;
2
+ import { DataGrid , GridColumnVisibilityModel , GridRowId } from '@mui/x-data-grid' ;
3
3
import { ChartProps } from '../Chart' ;
4
4
import {
5
5
evaluateRulesOnDict ,
@@ -17,14 +17,21 @@ import {
17
17
performActionOnElement ,
18
18
} from '../../extensions/advancedcharts/Utils' ;
19
19
import { IconButton } from '@neo4j-ndl/react' ;
20
- import { CloudArrowDownIconOutline , XMarkIconOutline } from '@neo4j-ndl/react/icons' ;
20
+ import { CloudArrowDownIconOutline , ArrowPathIconOutline , XMarkIconOutline } from '@neo4j-ndl/react/icons' ;
21
21
import { ThemeProvider , createTheme } from '@mui/material/styles' ;
22
22
import Button from '@mui/material/Button' ;
23
23
import { extensionEnabled } from '../../utils/ReportUtils' ;
24
24
import { renderCellExpand } from '../../component/misc/DataGridExpandRenderer' ;
25
- import { getCheckboxes , hasCheckboxes , updateCheckBoxes } from './TableActionsHelper' ;
25
+ import {
26
+ convertConditionsToExpression ,
27
+ getCheckboxes ,
28
+ hasCheckboxes ,
29
+ hasPreCondition ,
30
+ updateCheckBoxes ,
31
+ } from './TableActionsHelper' ;
26
32
import ApiService from '../../utils/apiService' ;
27
33
import { AxiosResponse } from 'axios' ;
34
+ import Notification from '../../component/custom/Notification' ;
28
35
29
36
const TABLE_HEADER_HEIGHT = 32 ;
30
37
const TABLE_FOOTER_HEIGHT = 62 ;
@@ -96,6 +103,10 @@ export const NeoTableChart = (props: ChartProps) => {
96
103
extensionEnabled ( props . extensions , 'actions' ) && props . settings && props . settings . actionsRules
97
104
? props . settings . actionsRules
98
105
: [ ] ;
106
+ const preConditions =
107
+ extensionEnabled ( props . extensions , 'actions' ) && props . settings && props . settings . preConditions
108
+ ? props . settings . preConditions
109
+ : [ ] ;
99
110
const compact = props . settings && props . settings . compact !== undefined ? props . settings . compact : false ;
100
111
const styleRules = useStyleRules (
101
112
extensionEnabled ( props . extensions , 'styling' ) ,
@@ -129,6 +140,7 @@ export const NeoTableChart = (props: ChartProps) => {
129
140
}
130
141
131
142
const { records } = props ;
143
+ const isApiSpecEnabled = props . settings ?. apiSpec && props . settings ?. apiSpec . apiEnabled ;
132
144
133
145
const generateSafeColumnKey = ( key ) => {
134
146
return key != 'id' ? key : `${ key } ` ;
@@ -142,6 +154,13 @@ export const NeoTableChart = (props: ChartProps) => {
142
154
setAnchorEl ( null ) ;
143
155
} ;
144
156
157
+ const [ alertOpen , setAlertOpen ] = React . useState ( false ) ;
158
+ const [ notificationMessage , setNotificationMessage ] = React . useState ( '' ) ;
159
+ const [ notificationSeverity , setNotificationSeverity ] = React . useState < 'success' | 'warning' | 'error' > ( 'success' ) ;
160
+
161
+ const handleNotificationClose = ( ) => {
162
+ setAlertOpen ( false ) ;
163
+ } ;
145
164
const lineBreakColumns : string [ ] = props . settings ?. lineBreaksAfterListEntry ;
146
165
147
166
const actionableFields = actionsRules . filter ( ( r ) => r . condition !== 'rowCheck' ) . map ( ( r ) => r . field ) ;
@@ -333,60 +352,92 @@ export const NeoTableChart = (props: ChartProps) => {
333
352
throw new Error ( `Unsupported method: ${ method } ` ) ;
334
353
}
335
354
336
- props . updateReportSetting ( 'apiSpec' , { ...props . settings . apiSpec , response } ) ;
355
+ props . updateReportSetting ( 'apiSpec' , { ...props . settings ?. apiSpec , response } ) ;
356
+ setNotificationMessage ( 'RUPS package created. Please find the link above' ) ;
357
+ setNotificationSeverity ( 'success' ) ;
358
+ setAlertOpen ( true ) ;
337
359
} catch ( error ) {
338
360
// Handle errors here
339
361
console . error ( 'API call error:' , error ) ;
362
+ setNotificationMessage ( 'RUPS package creation is currently not working. Please try again later.' ) ;
363
+ setNotificationSeverity ( 'error' ) ;
364
+ setAlertOpen ( true ) ;
340
365
} finally {
341
366
setApiLoading ( false ) ;
342
367
}
343
368
} ;
344
369
370
+ const handleResetApiResponse = ( ) => {
371
+ props . updateReportSetting ( 'apiSpec' , { ...props . settings ?. apiSpec , response : null } ) ;
372
+ } ;
373
+
374
+ useEffect ( ( ) => {
375
+ if ( isApiSpecEnabled ) {
376
+ handleResetApiResponse ( ) ;
377
+ }
378
+ } , [ records ] ) ;
379
+
345
380
const apiCallButton = ( ) => (
346
381
< Stack direction = 'row' spacing = { 2 } justifyContent = 'flex-end' marginRight = { 2 } >
347
- < ButtonGroup color = 'primary' variant = 'outlined' aria-label = 'button group' >
348
- < Button size = 'small' onClick = { handleApiCall } disabled = { isApiLoading } >
349
- { isApiLoading ? 'Loading...' : props . settings ?. sendRequestButtonName || 'send' }
350
- </ Button >
351
- < Button size = 'small' onClick = { handlePopHoverClick } disabled = { ! props . settings . apiSpec . response } >
382
+ < Button variant = 'outlined' size = 'small' onClick = { handleApiCall } disabled = { isApiLoading } >
383
+ { isApiLoading ? 'Loading...' : props . settings ?. sendRequestButtonName || 'send' }
384
+ </ Button >
385
+ { props . settings ?. apiSpec . response && (
386
+ < Button
387
+ size = 'small'
388
+ variant = 'outlined'
389
+ onClick = { handlePopHoverClick }
390
+ disabled = { ! props . settings ?. apiSpec . response }
391
+ >
352
392
{ isApiLoading ? 'Loading...' : props . settings ?. viewResponseButtonName || 'view response' }
353
393
</ Button >
354
- { props . settings . apiSpec . response ? (
355
- < Popover
356
- id = { id }
357
- open = { open }
358
- anchorEl = { anchorEl }
359
- onClose = { handlePopHoverClose }
360
- anchorOrigin = { {
361
- vertical : 'bottom' ,
362
- horizontal : 'left ' ,
363
- } }
364
- transformOrigin = { {
365
- vertical : 'top' ,
366
- horizontal : 'left ' ,
367
- } }
368
- >
369
- < Typography sx = { { p : 2 } } >
370
- < a href = { props . settings ?. apiSpec . response . data } target = '_blank' >
371
- { props . settings ?. apiSpec . response . data }
372
- </ a >
373
- </ Typography >
374
- </ Popover >
375
- ) : (
376
- < > </ >
377
- ) }
378
- </ ButtonGroup >
394
+ ) }
395
+ { props . settings ?. apiSpec . response ? (
396
+ < Popover
397
+ id = { id }
398
+ open = { open }
399
+ anchorEl = { anchorEl }
400
+ onClose = { handlePopHoverClose }
401
+ anchorOrigin = { {
402
+ vertical : 'bottom ' ,
403
+ horizontal : 'left' ,
404
+ } }
405
+ transformOrigin = { {
406
+ vertical : 'top ' ,
407
+ horizontal : 'left' ,
408
+ } }
409
+ >
410
+ < Typography sx = { { p : 2 } } >
411
+ < a href = { props . settings ?. apiSpec . response . data } target = '_blank' >
412
+ { props . settings ?. apiSpec . response . data }
413
+ </ a >
414
+ </ Typography >
415
+ </ Popover >
416
+ ) : (
417
+ < > </ >
418
+ ) }
379
419
</ Stack >
380
420
) ;
381
421
382
- const isApiSpecEnabled = props . settings ?. apiSpec && props . settings ?. apiSpec . apiEnabled ;
383
-
384
422
const tableStyle : any = isApiSpecEnabled
385
423
? { marginTop : 10 , height : '90%' , width : '100%' , position : 'relative' }
386
424
: { height : '100%' , width : '100%' , position : 'relative' } ;
387
425
426
+ const isRowSelectable = ( params : { id : GridRowId ; row : any } ) => {
427
+ if ( hasPreCondition ( preConditions ) ) {
428
+ return convertConditionsToExpression ( preConditions , params . row ) ;
429
+ }
430
+ return true ;
431
+ } ;
432
+
388
433
return (
389
434
< ThemeProvider theme = { theme } >
435
+ < Notification
436
+ open = { alertOpen }
437
+ message = { notificationMessage }
438
+ severity = { notificationSeverity }
439
+ onClose = { handleNotificationClose }
440
+ />
390
441
{ isApiSpecEnabled ? apiCallButton ( ) : < > </ > }
391
442
< div className = { classes . root } style = { tableStyle } >
392
443
< Snackbar
@@ -455,6 +506,7 @@ export const NeoTableChart = (props: ChartProps) => {
455
506
onSelectionModelChange = { ( selection ) =>
456
507
updateCheckBoxes ( actionsRules , rows , selection , props . setGlobalParameter )
457
508
}
509
+ isRowSelectable = { isRowSelectable }
458
510
autoPageSize
459
511
pagination
460
512
disableSelectionOnClick
0 commit comments