@@ -8,8 +8,10 @@ import { debounce, MenuItem, TextField } from '@material-ui/core';
8
8
import { Autocomplete } from '@material-ui/lab' ;
9
9
import NeoField from '../../../component/field/Field' ;
10
10
import { getReportTypes } from '../../../extensions/ExtensionUtils' ;
11
+ import NeoCodeEditorComponent from '../../../component/editor/CodeEditorComponent' ;
11
12
12
13
const NeoCardSettingsContentPropertySelect = ( {
14
+ query,
13
15
type,
14
16
database,
15
17
settings,
@@ -24,6 +26,8 @@ const NeoCardSettingsContentPropertySelect = ({
24
26
) ;
25
27
}
26
28
29
+ const [ queryText , setQueryText ] = React . useState ( query ) ;
30
+ const debouncedQueryUpdate = useCallback ( debounce ( onQueryUpdate , 250 ) , [ ] ) ;
27
31
const debouncedRunCypherQuery = useCallback ( debounce ( runCypherQuery , RUN_QUERY_DELAY_MS ) , [ ] ) ;
28
32
29
33
const { manualPropertyNameSpecification } = settings ;
@@ -45,11 +49,15 @@ const NeoCardSettingsContentPropertySelect = ({
45
49
) ;
46
50
} , [ settings . suggestionLimit , settings . deduplicateSuggestions , settings . searchType , settings . caseSensitive ] ) ;
47
51
52
+ useEffect ( ( ) => {
53
+ setLabelRecords ( [ ] ) ;
54
+ setPropertyRecords ( [ ] ) ;
55
+ } , [ database ] ) ;
56
+
48
57
const cleanParameter = ( parameter : string ) => parameter . replaceAll ( ' ' , '_' ) . replaceAll ( '-' , '_' ) . toLowerCase ( ) ;
49
58
const formatParameterId = ( id : string | undefined | null ) => {
50
59
const cleanedId = id || '' ;
51
- const formattedId = cleanedId == '' || cleanedId . startsWith ( '_' ) ? cleanedId : `_${ cleanedId } ` ;
52
- return formattedId ;
60
+ return cleanedId == '' || cleanedId . startsWith ( '_' ) ? cleanedId : `_${ cleanedId } ` ;
53
61
} ;
54
62
55
63
if ( settings . type == undefined ) {
@@ -64,20 +72,23 @@ const NeoCardSettingsContentPropertySelect = ({
64
72
onReportSettingUpdate ( 'parameterName' , parameterName ) ;
65
73
}
66
74
// Define query callback to allow reports to get extra data on interactions.
67
- const queryCallback = useCallback ( ( query , parameters , setRecords ) => {
68
- debouncedRunCypherQuery (
69
- driver ,
70
- database ,
71
- query ,
72
- parameters ,
73
- 10 ,
74
- ( status ) => {
75
- status == QueryStatus . NO_DATA ? setRecords ( [ ] ) : null ;
76
- } ,
77
- ( result ) => setRecords ( result ) ,
78
- ( ) => { }
79
- ) ;
80
- } , [ ] ) ;
75
+ const queryCallback = useCallback (
76
+ ( query , parameters , setRecords ) => {
77
+ debouncedRunCypherQuery (
78
+ driver ,
79
+ database ,
80
+ query ,
81
+ parameters ,
82
+ 10 ,
83
+ ( status ) => {
84
+ status == QueryStatus . NO_DATA ? setRecords ( [ ] ) : null ;
85
+ } ,
86
+ ( result ) => setRecords ( result ) ,
87
+ ( ) => { }
88
+ ) ;
89
+ } ,
90
+ [ database ]
91
+ ) ;
81
92
82
93
function handleParameterTypeUpdate ( newValue ) {
83
94
onReportSettingUpdate ( 'entityType' , undefined ) ;
@@ -178,13 +189,13 @@ const NeoCardSettingsContentPropertySelect = ({
178
189
`ORDER BY size(toString(value)) ASC LIMIT ${ limit } ` ;
179
190
onQueryUpdate ( newQuery ) ;
180
191
} else {
181
- const newQuery = 'RETURN true' ;
192
+ const newQuery = query ;
182
193
onQueryUpdate ( newQuery ) ;
183
194
}
184
195
}
185
196
186
197
// TODO: since this component is only rendered for parameter select, this is technically not needed
187
- const parameterSelectTypes = [ 'Node Property' , 'Relationship Property' , 'Free Text' , 'Date Picker' ] ;
198
+ const parameterSelectTypes = [ 'Node Property' , 'Relationship Property' , 'Free Text' , 'Custom Query' , ' Date Picker'] ;
188
199
const reportTypes = getReportTypes ( extensions ) ;
189
200
const overridePropertyDisplayName =
190
201
settings . overridePropertyDisplayName !== undefined ? settings . overridePropertyDisplayName : false ;
@@ -219,7 +230,7 @@ const NeoCardSettingsContentPropertySelect = ({
219
230
</ MenuItem >
220
231
) ) }
221
232
</ TextField >
222
-
233
+ < br />
223
234
{ settings . type == 'Free Text' || settings . type == 'Date Picker' ? (
224
235
< NeoField
225
236
label = { 'Name' }
@@ -234,6 +245,53 @@ const NeoCardSettingsContentPropertySelect = ({
234
245
handleFreeTextNameSelectionUpdate ( value ) ;
235
246
} }
236
247
/>
248
+ ) : settings . type == 'Custom Query' ? (
249
+ < >
250
+ < div >
251
+ < NeoField
252
+ label = { 'Name' }
253
+ key = { 'query' }
254
+ value = { settings ?. entityType || '' }
255
+ defaultValue = { '' }
256
+ placeholder = { 'Enter a parameter name here...' }
257
+ style = { { width : 350 , marginLeft : '5px' , marginTop : '0px' } }
258
+ onChange = { ( value ) => {
259
+ setLabelInputText ( value ) ;
260
+ handleNodeLabelSelectionUpdate ( value ) ;
261
+ handleFreeTextNameSelectionUpdate ( value ) ;
262
+ } }
263
+ />
264
+ < br />
265
+ < br />
266
+ < div style = { { display : labelInputText ? 'inherit' : 'none' } } >
267
+ < NeoCodeEditorComponent
268
+ value = { queryText }
269
+ editable = { true }
270
+ language = { reportTypes [ type ] && reportTypes [ type ] . inputMode ? reportTypes [ type ] . inputMode : 'cypher' }
271
+ onChange = { ( value ) => {
272
+ debouncedQueryUpdate ( value ) ;
273
+ setQueryText ( value ) ;
274
+ } }
275
+ placeholder = { 'Enter Cypher here...' }
276
+ />
277
+ < p
278
+ style = { {
279
+ color : 'grey' ,
280
+ fontSize : 12 ,
281
+ paddingLeft : '5px' ,
282
+ borderBottom : '1px solid lightgrey' ,
283
+ borderLeft : '1px solid lightgrey' ,
284
+ borderRight : '1px solid lightgrey' ,
285
+ marginTop : '0px' ,
286
+ } }
287
+ >
288
+ {
289
+ 'Specify a query that takes a parameter $input (the user typed text) and return a number of rows with a field called `value` (the suggestions).'
290
+ }
291
+ </ p >
292
+ </ div >
293
+ </ div >
294
+ </ >
237
295
) : (
238
296
< >
239
297
< Autocomplete
0 commit comments