Skip to content

Commit 46519e2

Browse files
committed
Merge branch 'fix/54-CE-bis' into fix/54-CE-bis-martin
2 parents 29e879c + 92de0dd commit 46519e2

File tree

3 files changed

+54
-26
lines changed

3 files changed

+54
-26
lines changed

cypress/e2e/custom-query-editor.cy.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ORDER BY ?componentName
6666
it("Check if all possible parameters are filled in with parameterized URL", () => {
6767

6868
// Navigate to the URL of a saved query with completely filled-in form
69-
cy.visit("/#/customQuery?name=Query+Name&description=Query+Description&queryString=Sparql+query+text&comunicaContextCheck=on&source=The+Comunica+Source&comunicaContext=%7B%22Advanced+Comunica+Context%22%3Atrue%7D&sourceIndexCheck=on&indexSourceUrl=Index+Source&indexSourceQuery=Index+Query+&askQueryCheck=on&askQuery=%7B%22trueText%22%3A%22+filled+in%22%2C%22falseText%22%3A%22not+filled+in%22%7D&templatedQueryCheck=on&variables=%7B%22firstvariables%22%3A%5B%22only+one%22%5D%7D")
69+
cy.visit("/#/customQuery?name=Query+Name&description=Query+Description&queryString=Sparql+query+text&comunicaContextCheck=on&source=The+Comunica+Source&comunicaContext=%7B%22Advanced+Comunica+Context%22%3Atrue%7D&sourceIndexCheck=on&indexSourceUrl=Index+Source&indexSourceQuery=Index+Query+&askQueryCheck=on&askQuery=%7B%22trueText%22%3A%22+filled+in%22%2C%22falseText%22%3A%22not+filled+in%22%7D&templatedQueryCheck=on&templateOptions=%7B%22firstvariables%22%3A%5B%22only+one%22%5D%7D")
7070

7171
// Verify that every field is correctly filled-in
7272
cy.get('input[name="name"]').should('have.value', 'Query Name');
@@ -81,7 +81,7 @@ ORDER BY ?componentName
8181

8282
cy.get('textarea[name="askQuery"]').should('have.value', `{"trueText":" filled in","falseText":"not filled in"}`);
8383

84-
cy.get('textarea[name="variables"]').should('have.value', `{"firstvariables":["only one"]}`);
84+
cy.get('textarea[name="templateOptions"]').should('have.value', `{"firstvariables":["only one"]}`);
8585

8686
})
8787

@@ -190,14 +190,14 @@ SELECT * WHERE {
190190
cy.get('input[name="source"]').type("http://localhost:8080/example/favourite-musicians");
191191
cy.get('input[name="templatedQueryCheck"]').click()
192192

193-
cy.get('textarea[name="variables"]').clear()
194-
cy.get('textarea[name="variables"]').type(`{
193+
cy.get('textarea[name="templateOptions"]').clear()
194+
cy.get('textarea[name="templateOptions"]').type(`{"variables" : {
195195
"genre": [
196196
"\\"Romantic\\"",
197197
"\\"Baroque\\"",
198198
"\\"Classical\\""
199199
]
200-
}`)
200+
}}`)
201201
cy.get('button[type="submit"]').click();
202202

203203

src/components/Dashboard/CustomQueryEditor/customEditor.jsx

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import IconProvider from '../../../IconProvider/IconProvider';
1414
//const myEngine = new QueryEngine();
1515

1616
export 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' }}

src/components/InteractionLayout/SelectionMenu/SelectionMenu.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const SelectionMenu = () => {
2828
useEffect(() => {
2929
const handleGroupChange = (newConfig) => {
3030
setConfig(newConfig);
31+
32+
// Open the cstm group when a new custom query is created
33+
if(newConfig.queryGroups.find(group => group.id === 'cstm')){
34+
setOpenGroups(prevOpenGroups => ({
35+
...prevOpenGroups,
36+
['cstm']: true,
37+
}));
38+
}
3139
};
3240

3341
configManager.on('configChanged', handleGroupChange);

0 commit comments

Comments
 (0)