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';
77import debounce from 'lodash/debounce' ;
88import { RUN_QUERY_DELAY_MS } from '../../../config/ReportConfig' ;
99import NeoParameterSelectionChart from '../../../chart/parameter/ParameterSelectionChart' ;
10+ import { checkParametersNameInGlobalParameter , extractAllParameterNames } from '../../../utils/parameterUtils' ;
1011
1112enum FormStatus {
1213 DATA_ENTRY = 0 , // The user is filling in the form.
@@ -42,6 +43,14 @@ const NeoForm = (props: ChartProps) => {
4243 } ) ;
4344 }
4445
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+
4554 useEffect ( ( ) => {
4655 // If the parameters change after the form is completed, reset it, as there might be another submission.
4756 if ( status == FormStatus . SUBMITTED ) {
@@ -77,7 +86,7 @@ const NeoForm = (props: ChartProps) => {
7786 < Button
7887 style = { { marginLeft : 15 } }
7988 id = 'form-submit'
80- disabled = { ! submitButtonActive }
89+ disabled = { ! submitButtonActive || isParametersDefined ( props . query ) }
8190 onClick = { ( ) => {
8291 if ( ! props . query || ! props . query . trim ( ) ) {
8392 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