@@ -14,7 +14,7 @@ import IconProvider from '../../../IconProvider/IconProvider';
1414//const myEngine = new QueryEngine();
1515
1616export default function CustomEditor ( props ) {
17-
17+
1818 const location = useLocation ( ) ;
1919 const navigate = useNavigate ( ) ;
2020 const [ formData , setFormData ] = useState ( {
@@ -23,20 +23,33 @@ export default function CustomEditor(props) {
2323 source : '' ,
2424 queryString : '' ,
2525 comunicaContext : '' ,
26-
26+
2727 comunicaContextCheck : false ,
2828 sourceIndexCheck : false ,
2929 askQueryCheck : false ,
3030 templatedQueryCheck : false ,
31-
31+
3232 } ) ;
33-
33+
3434 const [ showError , setShowError ] = useState ( false ) ;
35-
35+
3636 const [ parsingErrorComunica , setParsingErrorComunica ] = useState ( false ) ;
3737 const [ parsingErrorAsk , setParsingErrorAsk ] = useState ( false ) ;
3838 const [ parsingErrorTemplate , setParsingErrorTemplate ] = useState ( false ) ;
3939
40+ const defaultSparqlQuery = `SELECT ?s ?p ?o
41+ WHERE {
42+ ?s ?p ?o
43+ }` ;
44+ const defaultSparqlQueryIndexSources = `PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
45+ SELECT ?object
46+ WHERE {
47+ ?s rdfs:seeAlso ?object
48+ }` ;
49+ const defaultExtraComunicaContext = JSON . stringify ( { "lenient" : true } , null , 2 ) ;
50+ const defaultAskQueryDetails = JSON . stringify ( { "trueText" : "this displays when true." , "falseText" : "this displays when false." } , null , 2 ) ;
51+ const defaultTemplateOptions = JSON . stringify ( { "variables" : { "variableOne" : [ "option1" , "option2" , "option3" ] , "variableTwo" : [ "option1" , "option2" , "option3" ] } } , null , 5 )
52+
4053 useEffect ( ( ) => {
4154 let searchParams
4255 if ( props . newQuery ) {
@@ -135,7 +148,25 @@ export default function CustomEditor(props) {
135148 parsedObject . askQuery = JSON . parse ( dataWithStrings . askQuery ) ;
136149 }
137150 if ( ensureBoolean ( dataWithStrings . templatedQueryCheck ) ) {
138- parsedObject . variables = JSON . parse ( dataWithStrings . variables ) ;
151+ //parsedObject.variables = JSON.parse(dataWithStrings.variables);
152+
153+ // hier de logica voor .variables en .querystring voor latere updates
154+ // form name variables gaan hernoemen naar templateOptions
155+
156+ const options = JSON . parse ( dataWithStrings . templateOptions ) ;
157+
158+ if ( options . variables ) {
159+ console . log ( 'het werkt' )
160+ console . log ( options )
161+ parsedObject . variables = options . variables ;
162+ }
163+
164+ // This will serve for the extention of customizable query variables
165+ if ( options . templatedVarSourceQueryString ) {
166+ parsedObject . templatedVarSourceQueryString = options . templatedVarSourceQueryString ;
167+ }
168+
169+
139170 }
140171 return parsedObject ;
141172 }
@@ -162,17 +193,6 @@ export default function CustomEditor(props) {
162193 navigate ( `/${ customQuery . id } ` )
163194 } ;
164195
165- const defaultSparqlQuery = `SELECT ?s ?p ?o
166- WHERE {
167- ?s ?p ?o
168- }` ;
169- const defaultSparqlQueryIndexSources = `PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
170- SELECT ?source
171- WHERE {
172- ?s rdfs:seeAlso ?source
173- }` ;
174- const defaultExtraComunicaContext = JSON . stringify ( { "lenient" : true } , null , 2 ) ;
175- const defaultAskQueryDetails = JSON . stringify ( { "trueText" : "this displays when true." , "falseText" : "this displays when false." } , null , 2 ) ;
176196
177197 return (
178198 < React . Fragment >
@@ -401,16 +421,16 @@ WHERE {
401421 < TextField
402422 required = { ensureBoolean ( formData . templatedQueryCheck ) }
403423 id = "outlined-multiline-flexible"
404- label = "Variables specification "
405- name = "variables "
424+ label = "Templated query options "
425+ name = "templateOptions "
406426 error = { parsingErrorTemplate }
407427 multiline
408428 fullWidth
409429 minRows = { 5 }
410430 variant = "outlined"
411431 helperText = { `Write the variables specification in JSON-format${ parsingErrorTemplate ? ' (Invalid Syntax)' : '.' } ` }
412- value = { ! ! formData . variables ? typeof formData . variables === 'object' ? JSON . stringify ( formData . variables , null , 2 ) : formData . variables : formData . variables === '' ? '' : `{\n\t"variableOne" : ["option1", "option2", "option3"],\n\t"variableTwo" : ["option1", "option2", "option3"]\n}` }
413- placeholder = { `{\n\tvariableOne : ["option1","option2","option3"],\n\tvariableTwo : ["option1","option2","option3"], \n\t...\n}` }
432+ value = { ! ! formData . templateOptions ? typeof formData . templateOptions === 'object' ? JSON . stringify ( formData . templateOptions , null , 5 ) : formData . templateOptions : formData . templateOptions === '' ? '' : defaultTemplateOptions }
433+ placeholder = { defaultTemplateOptions }
414434 onClick = { ( e ) => handleJSONparsing ( e , setParsingErrorTemplate ) }
415435 onChange = { ( e ) => handleJSONparsing ( e , setParsingErrorTemplate ) }
416436 sx = { { marginBottom : '16px' } }
0 commit comments