@@ -8,7 +8,34 @@ import {
8
8
} from '@neo4j-ndl/react/icons' ;
9
9
import { getPageNumbersAndNamesList } from '../advancedcharts/Utils' ;
10
10
import { IconButton , Button , Dialog , Dropdown , TextInput } from '@neo4j-ndl/react' ;
11
- import { Autocomplete , TextField } from '@mui/material' ;
11
+ import { Autocomplete , TextField , Typography } from '@mui/material' ;
12
+
13
+ // Pre conditions
14
+
15
+ const PRE_CONDITIONS_RULES = [
16
+ {
17
+ value : '=' ,
18
+ label : '=' ,
19
+ } ,
20
+ {
21
+ value : '!=' ,
22
+ label : '!=' ,
23
+ } ,
24
+ {
25
+ value : 'contains' ,
26
+ label : 'contains' ,
27
+ } ,
28
+ {
29
+ value : 'not_contains' ,
30
+ label : 'not_contains' ,
31
+ } ,
32
+ ] ;
33
+
34
+ const defaultPreCondition = {
35
+ condition : '=' ,
36
+ field : '' ,
37
+ value : '' ,
38
+ } ;
12
39
13
40
// The set of conditional checks that are included in the rule specification.
14
41
const RULE_CONDITIONS = {
@@ -166,12 +193,17 @@ export const NeoCustomReportActionsModal = ({
166
193
fields,
167
194
setCustomReportActionsModalOpen,
168
195
onReportSettingUpdate,
196
+ preConditionsSetting,
169
197
} ) => {
170
198
// The rule set defined in this modal is updated whenever the setting value is externally changed.
171
199
const [ rules , setRules ] = React . useState ( [ ] ) ;
200
+ const [ preConditions , setPreConditions ] = React . useState ( [ defaultPreCondition ] ) ;
172
201
useEffect ( ( ) => {
173
202
if ( settingValue ) {
174
203
setRules ( settingValue ) ;
204
+ if ( preConditionsSetting ) {
205
+ setPreConditions ( preConditionsSetting ) ;
206
+ }
175
207
}
176
208
} , [ settingValue ] ) ;
177
209
@@ -183,6 +215,12 @@ export const NeoCustomReportActionsModal = ({
183
215
} else {
184
216
onReportSettingUpdate ( settingName , rules ) ;
185
217
}
218
+
219
+ if ( preConditions . length === 0 ) {
220
+ onReportSettingUpdate ( 'preConditions' , undefined ) ;
221
+ } else {
222
+ onReportSettingUpdate ( 'preConditions' , preConditions ) ;
223
+ }
186
224
setCustomReportActionsModalOpen ( false ) ;
187
225
} ;
188
226
@@ -193,6 +231,10 @@ export const NeoCustomReportActionsModal = ({
193
231
setRules ( newRules ) ;
194
232
} ;
195
233
234
+ const updatePreConditionFieldById = ( j , field , value ) => {
235
+ setPreConditions ( ( prevItems ) => prevItems . map ( ( item , i ) => ( i === j ? { ...item , [ field ] : value } : item ) ) ) ;
236
+ } ;
237
+
196
238
/**
197
239
* Create the list of suggestions used in the autocomplete box of the rule specification window.
198
240
* This will be dynamic based on the type of report we are customizing.
@@ -333,7 +375,7 @@ export const NeoCustomReportActionsModal = ({
333
375
const td2Styling = ( type ) => ( { width : type === 'bar' ? '15%' : '30%' } ) ;
334
376
const td2DropdownClassname = ( type ) => `n-align-middle n-pr-1 ${ type === 'bar' ? 'n-w-full' : 'n-w-2/5' } ` ;
335
377
const td2Autocomplete = ( type , index , rule ) =>
336
- ( type !== 'bar' && rule . condition !== 'rowCheck' ? (
378
+ type !== 'bar' && rule . condition !== 'rowCheck' ? (
337
379
< Autocomplete
338
380
className = 'n-align-middle n-inline-block n-w-/5'
339
381
disableClearable = { true }
@@ -364,7 +406,7 @@ export const NeoCustomReportActionsModal = ({
364
406
/>
365
407
) : (
366
408
< > </ >
367
- ) ) ;
409
+ ) ;
368
410
const td4Styling = ( type ) => ( { width : type === 'bar' ? '45%' : '40%' } ) ;
369
411
const td4DropdownClassname = 'n-align-middle, n-w-1/3' ;
370
412
const td6Styling = ( type ) => ( { width : type === 'bar' ? '30%' : '20%' } ) ;
@@ -535,6 +577,114 @@ export const NeoCustomReportActionsModal = ({
535
577
</ td >
536
578
</ tr >
537
579
</ table >
580
+
581
+ < table >
582
+ < tr >
583
+ < td colSpan = { 7 } >
584
+ < tr >
585
+ < th colSpan = { 7 } className = 'n-text-center n-font-bold n-py-2' >
586
+ Report Pre Conditions
587
+ </ th >
588
+ </ tr >
589
+ </ td >
590
+ </ tr >
591
+ { preConditions . map ( ( con , i ) => {
592
+ return (
593
+ < tr >
594
+ < td width = '2.5%' className = 'n-pr-1' >
595
+ < span className = 'n-pr-1' > { i + 1 } .</ span >
596
+ < span className = 'n-font-bold' > IF</ span >
597
+ </ td >
598
+ < td width = '100%' >
599
+ < div style = { { border : '2px dashed grey' } } className = 'n-p-1' >
600
+ < Autocomplete
601
+ className = 'n-align-middle n-inline-block n-w-5/12 n-pr-1'
602
+ disableClearable = { true }
603
+ id = { `autocomplete-label-type${ i } ` }
604
+ size = 'small'
605
+ noOptionsText = '*Specify an exact field name'
606
+ options = { createFieldVariableSuggestions ( null , null , null ) . filter ( ( e ) =>
607
+ e . toLowerCase ( ) . includes ( con . field . toLowerCase ( ) )
608
+ ) }
609
+ value = { con . field ? con . field : '' }
610
+ inputValue = { con . field ? con . field : '' }
611
+ popupIcon = { < > </ > }
612
+ style = { { minWidth : 125 } }
613
+ onInputChange = { ( event , value ) => {
614
+ updatePreConditionFieldById ( i , 'field' , value ) ;
615
+ } }
616
+ onChange = { ( event , newValue ) => {
617
+ updatePreConditionFieldById ( i , 'field' , newValue ) ;
618
+ } }
619
+ renderInput = { ( params ) => (
620
+ < TextField
621
+ { ...params }
622
+ placeholder = 'Field name...'
623
+ InputLabelProps = { { shrink : true } }
624
+ style = { { padding : '6px 0 7px' } }
625
+ size = { 'small' }
626
+ />
627
+ ) }
628
+ />
629
+ < Dropdown
630
+ type = 'select'
631
+ className = 'n-align-middle n-w-2/12 n-pr-1'
632
+ selectProps = { {
633
+ onChange : ( newValue ) => updatePreConditionFieldById ( i , 'condition' , newValue ?. value ) ,
634
+ options : PRE_CONDITIONS_RULES . map ( ( option ) => ( {
635
+ label : option . label ,
636
+ value : option . value ,
637
+ } ) ) ,
638
+ value : { label : con . condition , value : con . condition } ,
639
+ } }
640
+ style = { { minWidth : 70 , display : 'inline-block' } }
641
+ fluid
642
+ />
643
+ < TextInput
644
+ className = 'n-align-middle n-inline-block n-w-5/12'
645
+ style = { { minWidth : 100 } }
646
+ placeholder = 'Value...'
647
+ value = { con . value }
648
+ onChange = { ( e ) => updatePreConditionFieldById ( i , 'value' , e . target . value ) }
649
+ fluid
650
+ > </ TextInput >
651
+ </ div >
652
+ </ td >
653
+
654
+ < td width = '5%' >
655
+ < IconButton
656
+ aria-label = 'remove rule'
657
+ size = 'medium'
658
+ style = { { marginLeft : 10 } }
659
+ floating
660
+ onClick = { ( ) => {
661
+ setPreConditions ( ( prevItems ) => prevItems . filter ( ( _ , j ) => j !== i ) ) ;
662
+ } }
663
+ >
664
+ < XMarkIconOutline />
665
+ </ IconButton >
666
+ </ td >
667
+ </ tr >
668
+ ) ;
669
+ } ) }
670
+
671
+ < tr >
672
+ < td colSpan = { 7 } >
673
+ < div className = 'n-text-center n-mt-1' >
674
+ < IconButton
675
+ aria-label = 'add'
676
+ size = 'medium'
677
+ floating
678
+ onClick = { ( ) => {
679
+ setPreConditions ( [ ...preConditions , defaultPreCondition ] ) ;
680
+ } }
681
+ >
682
+ < PlusIconOutline />
683
+ </ IconButton >
684
+ </ div >
685
+ </ td >
686
+ </ tr >
687
+ </ table >
538
688
</ div >
539
689
</ Dialog . Content >
540
690
< Dialog . Actions >
0 commit comments