Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/OutputPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ const handleEditorHeightChange = (newHeight) => {
outputPanel.value.style.height = `${height + diff}px`;
};

const handleNodeExpanded = ({ newNodes, newRels }) => {
nodes.value.push(...newNodes);
relationships.value.push(...newRels);
};

onMounted(() => {
run(props.query, props.queryTypeInput);
if (!props.disableResizer) {
Expand Down Expand Up @@ -184,7 +189,7 @@ onMounted(() => {
v-if="nodes.length"
class="output-tab-panel"
>
<GraphOutput :nodes="nodes" :relationships="relationships" />
<GraphOutput :nodes="nodes" :relationships="relationships" @nodeExpanded="handleNodeExpanded"/>
</q-tab-panel>
<q-tab-panel
name="table"
Expand Down
41 changes: 35 additions & 6 deletions src/components/output/GraphOutput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ref, onMounted, onUnmounted, watch } from "vue";
import { ref, onMounted, onUnmounted, watch, inject } from "vue";
import { NVL } from "@neo4j-nvl/base";
import {
ZoomInteraction,
Expand All @@ -9,6 +9,8 @@ import {
ClickInteraction,
} from "@neo4j-nvl/interaction-handlers";

const Neo4jApi = inject("Neo4jApi");
const emit = defineEmits(['nodeExpanded']);
const props = defineProps(["nodes", "relationships"]);

const graph = ref();
Expand Down Expand Up @@ -62,9 +64,36 @@ const reset = () => {
nvl.resetZoom();
};

const nodeExpansion = () => {
console.log("Expand:", nodeRightClickMenu.value.node);
};
const fetchConnectedNodes = async (nodeId) => {
const cypher = `
MATCH (n)
WHERE elementId(n) = "${nodeId}"
MATCH (n)-[r]->(m)
WITH type(r) AS relType, r, m
WITH relType, collect({r: r, m: m}) AS connections
UNWIND connections[..1] AS conn
RETURN conn.r AS rel, conn.m AS target
`
const res = await Neo4jApi.run(cypher);
return {
nodes: res.graph?.nodes || [],
relationships: res.graph?.relationships || []
}
}

const nodeExpansion = async (nodeId) => {
const { nodes: newNodes, relationships: newRels, rows: newRows, columns: newCols } = await fetchConnectedNodes(nodeId);
if(newNodes.length){
nvl.addAndUpdateElementsInGraph([...newNodes], [...newRels]);
emit('nodeExpanded', {
newNodes,
newRels
});
}
else{
console.log("node is not expandable");
}
}

const updateNvlElementselectedElement = (element) => {
if (!element && selectedElement.value.clicked) {
Expand Down Expand Up @@ -218,9 +247,9 @@ onUnmounted(() => {
<template>
<div class="graph">
<div ref="graph">
<q-menu :target="nodeRightClickMenu.clicked" context-menu>
<q-menu v-model="nodeRightClickMenu.clicked" context-menu>
<q-list dense>
<q-item clickable v-close-popup @click="nodeExpansion">
<q-item clickable v-close-popup @click="() => nodeExpansion(nodeRightClickMenu.node?.id)">
<q-item-section>Expand</q-item-section>
</q-item>
</q-list>
Expand Down