File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -205,8 +205,10 @@ describe('NeoDash E2E Tests', () => {
205
205
206
206
cy . get ( 'main .react-grid-item:eq(2) button[aria-label="run"]' ) . scrollIntoView ( ) . should ( 'be.visible' ) . click ( ) ;
207
207
cy . wait ( 500 ) ;
208
+ cy . get ( '#form-submit' ) . should ( 'be.disabled' ) ;
208
209
cy . get ( '#autocomplete' ) . type ( 'The Matrix' ) ;
209
210
cy . get ( '#autocomplete-option-0' ) . click ( ) ;
211
+ cy . get ( '#form-submit' ) . should ( 'not.be.disabled' ) ;
210
212
cy . get ( '#form-submit' ) . click ( ) ;
211
213
cy . wait ( 500 ) ;
212
214
cy . get ( '.form-submitted-message' ) . should ( 'have.text' , 'Form Submitted.Reset Form' ) ;
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
+ /**
2
+ * Extracts all parameter names from a given Cypher query string.
3
+ *
4
+ * @param {string } cypherQuery The Cypher query string to extract parameter names from.
5
+ * @returns {string[] } An array containing all extracted parameter names.
6
+ */
7
+ export const extractAllParameterNames = ( cypherQuery : string ) : string [ ] => {
8
+ // A regular expression pattern to match parameter names following '$'
9
+ const pattern = / \$ ( [ A - Z a - z _ ] \w * ) / g;
10
+
11
+ const parameterNames : string [ ] = [ ] ;
12
+ let match : any ;
13
+
14
+ while ( ( match = pattern . exec ( cypherQuery ) ) !== null ) {
15
+ parameterNames . push ( match [ 1 ] ) ;
16
+ }
17
+
18
+ return parameterNames ;
19
+ }
20
+
21
+ /**
22
+ * Checks if all parameter names are present in the global parameter names.
23
+ *
24
+ * @param {string[] } parameterNames An array of parameter names to be checked.
25
+ * @param {object } globalParameterNames The object containing global parameter names to compare against.
26
+ * @returns {boolean } A boolean indicating whether all parameters are present in the global parameters.
27
+ */
28
+ export const checkParametersNameInGlobalParameter = ( parameterNames : string [ ] , globalParameterNames : any ) : boolean => {
29
+ for ( const key of parameterNames ) {
30
+ if ( ! globalParameterNames [ key ] || ( Array . isArray ( globalParameterNames [ key ] ) && globalParameterNames [ key ] . length === 0 ) || globalParameterNames [ key ] === '' ) {
31
+ return true ;
32
+ }
33
+ }
34
+ return false ;
35
+ }
You can’t perform that action at this time.
0 commit comments