Skip to content
Snippets Groups Projects
Commit 9557fcd0 authored by Leonardo's avatar Leonardo
Browse files

feat: query all schema at once button

parent 291ed9bb
No related branches found
Tags v1.73.0
No related merge requests found
Pipeline #137882 passed
......@@ -165,6 +165,71 @@ export const QueryBuilderInner = (props: QueryBuilderProps) => {
event.dataTransfer.dropEffect = 'move';
};
const onAddSchemaToQueryBuilder = () => {
// TODO: incomplete (not being shown) for now due to lack of "OPTIONAL MATCH" support in the backend
const addedNodes: Record<string, string> = {};
// loop through all nodes in the schema and add them to the graph
schemaGraph.nodes.forEach((node) => {
if (!node.key) return;
const { id } = graphologyGraph.addPill2Graphology(
{
type: QueryElementTypes.Entity,
// x: position.x - mouse_x,
// y: position.y - mouse_y,
x: 0,
y: 0,
name: node.key,
schemaKey: node.key,
attributes: [],
},
schema.getNodeAttribute(node.key, 'attributes'),
schemaInference,
);
if (!id) return;
addedNodes[node.key] = id;
});
// loop all edges in the schema and add them to the graph
schemaGraph.edges.forEach((edge) => {
if (!edge.key || !edge.source || !edge.target) return;
const fromNode = graphologyGraph.getNodeAttributes(addedNodes[edge.source]);
const toNode = graphologyGraph.getNodeAttributes(addedNodes[edge.target]);
if (!fromNode || !toNode) return;
const relation = graphologyGraph.addPill2Graphology(
{
type: QueryElementTypes.Relation,
// x: position.x,
// y: position.y,
x: 0,
y: 0,
depth: { min: queryBuilderSettings.depth.min, max: queryBuilderSettings.depth.max },
name: edge.attributes?.collection,
schemaKey: edge.attributes?.name,
collection: edge.attributes?.collection,
attributes: [],
},
schema.getEdgeAttribute(edge.key, 'attributes'),
);
graphologyGraph.addEdge2Graphology(fromNode, relation, {
type: 'connection',
sourceHandleData: toHandleData(edge.source),
targetHandleData: toHandleData(edge.key),
});
graphologyGraph.addEdge2Graphology(relation, toNode, {
type: 'connection',
sourceHandleData: toHandleData(edge.key),
targetHandleData: toHandleData(edge.target),
});
});
dispatch(setQuerybuilderGraphology(graphologyGraph));
};
/**
* The onDrop is called when the user drops an element from the schema onto the QueryBuilder.
* In the onDrop query elements will be created based on the data stored in the drag event (datastrasfer).
......@@ -611,6 +676,20 @@ export const QueryBuilderInner = (props: QueryBuilderProps) => {
<QueryMLDialog />
</PopoverContent>
</Popover>
{/* <Tooltip>
<TooltipTrigger>
<Button
variantType="secondary"
variant="ghost"
size="xs"
iconComponent="icon-[ic--baseline-drive-file-move]"
onClick={() => onAddSchemaToQueryBuilder()}
/>
</TooltipTrigger>
<TooltipContent>
<p>Query All Data</p>
</TooltipContent>
</Tooltip> */}
</TooltipProvider>
</ControlContainer>
</div>
......
......@@ -46,12 +46,8 @@ export const Schema = (props: Props) => {
const settings = useSchemaSettings();
const searchResults = useSearchResultSchema();
const dispatch = useDispatch();
const [toggleSchemaSettings, setToggleSchemaSettings] = useState(false);
const [nodes, setNodes, onNodesChange] = useNodesState([] as Node[]);
const [edges, setEdges, onEdgesChange] = useEdgesState([] as Edge[]);
const [firstUserConnection, setFirstUserConnection] = useState<boolean>(true);
const [auth, setAuth] = useState(props.auth);
const [expanded, setExpanded] = useState<boolean>(false);
const reactFlowInstanceRef = useRef<ReactFlowInstance | null>(null);
const reactFlowRef = useRef<HTMLDivElement>(null);
......@@ -74,13 +70,13 @@ export const Schema = (props: Props) => {
useEffect(() => {
updateLayout();
sessionStorage.setItem('firstUserConnection', firstUserConnection.toString());
if (sessionStorage.getItem('firstUserConnection') === 'true') {
sessionStorage.setItem('firstUserConnection', 'false');
} else {
sessionStorage.setItem('firstUserConnection', 'true');
}
}, []);
useEffect(() => {
setAuth(props.auth);
}, [props.auth]);
async function layoutGraph() {
if (schemaGraphology === undefined || schemaGraphology.order == 0) {
setNodes([]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment