File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { REPORT_LOADING_ICON } from '../../../report/Report';
7
7
import debounce from 'lodash/debounce' ;
8
8
import { RUN_QUERY_DELAY_MS } from '../../../config/ReportConfig' ;
9
9
import NeoParameterSelectionChart from '../../../chart/parameter/ParameterSelectionChart' ;
10
+ import { checkParametersNameInGlobalParameter , extractAllParameterNames } from '../../../utils/parameterUtils' ;
10
11
11
12
enum FormStatus {
12
13
DATA_ENTRY = 0 , // The user is filling in the form.
@@ -42,6 +43,14 @@ const NeoForm = (props: ChartProps) => {
42
43
} ) ;
43
44
}
44
45
46
+ const isParametersDefined = ( cypherQuery : string | undefined ) => {
47
+ const parameterNames = extractAllParameterNames ( cypherQuery ) ;
48
+ if ( props . parameters ) {
49
+ return checkParametersNameInGlobalParameter ( parameterNames , props . parameters ) ;
50
+ }
51
+ return false ;
52
+ } ;
53
+
45
54
useEffect ( ( ) => {
46
55
// If the parameters change after the form is completed, reset it, as there might be another submission.
47
56
if ( status == FormStatus . SUBMITTED ) {
@@ -77,7 +86,7 @@ const NeoForm = (props: ChartProps) => {
77
86
< Button
78
87
style = { { marginLeft : 15 } }
79
88
id = 'form-submit'
80
- disabled = { ! submitButtonActive }
89
+ disabled = { ! submitButtonActive || isParametersDefined ( props . query ) }
81
90
onClick = { ( ) => {
82
91
if ( ! props . query || ! props . query . trim ( ) ) {
83
92
props . createNotification (
Original file line number Diff line number Diff line change
1
+ export const extractAllParameterNames = ( cypherQuery ) => {
2
+ // A regular expression pattern to match parameter names following '$'
3
+ const pattern = / \$ ( [ A - Z a - z _ ] \w * ) / g;
4
+
5
+ const parameterNames : string [ ] = [ ] ;
6
+ let match : any ;
7
+
8
+ while ( ( match = pattern . exec ( cypherQuery ) ) !== null ) {
9
+ parameterNames . push ( match [ 1 ] ) ;
10
+ }
11
+
12
+ return parameterNames ;
13
+ }
14
+
15
+ export const checkParametersNameInGlobalParameter = ( parameterNames : string [ ] , globalParameterNames : any ) => {
16
+ for ( const key of parameterNames ) {
17
+ if ( ! globalParameterNames [ key ] || ( Array . isArray ( globalParameterNames [ key ] ) && globalParameterNames [ key ] . length === 0 ) ) {
18
+ return true ;
19
+ }
20
+ }
21
+ return false ;
22
+ }
You can’t perform that action at this time.
0 commit comments