sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
37 lines • 1.67 kB
JavaScript
/*
Traversing trough the building section and read out all the variables.
Delete all variables (Draggables) in the variables-section which are not present
Can be used when a GrpWrapper got deleted and the variable list needs to be updated
*/
export function updateVarList(actionStore) {
// using a set so we don't have double values in it
let varNames = new Set();
actionStore.sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder((grpWrapper) => {
let startGrp = grpWrapper.criteriaGroup.startClassGroup;
let endGrp = grpWrapper.criteriaGroup.endClassGroup;
if (startGrp.isVarSelected() && startGrp.getVarName())
varNames.add(startGrp.getVarName());
if (endGrp.isVarSelected() && endGrp.getVarName())
varNames.add(endGrp.getVarName());
});
updateDraggables(actionStore, varNames);
}
function updateDraggables(actionStore, varNames) {
let draggables = actionStore.sparnatural.variableSection.variableOrderMenu.draggables;
// filter out the variables which don't exist anymore
draggables = draggables.filter((d) => {
if (varNames.has(d.state.selectedVariable.variable.replace("?", ""))
||
// in case there is an aggregation
d.state.originalVariable && varNames.has(d.state.originalVariable.variable.replace("?", ""))) {
//keep draggable
return d;
}
else {
//delete it
d.html.remove();
}
});
actionStore.sparnatural.variableSection.variableOrderMenu.draggables = draggables;
}
//# sourceMappingURL=UpdateVarList.js.map