Fix Neo4j node and edge edit problem

This commit is contained in:
yangdx
2025-04-15 12:27:03 +08:00
parent ddf61d71a1
commit f2c471c7ba
4 changed files with 64 additions and 60 deletions

View File

@@ -13,7 +13,10 @@ interface EditablePropertyRowProps {
name: string // Property name to display and edit
value: any // Initial value of the property
onClick?: () => void // Optional click handler for the property value
nodeId?: string // ID of the node (for node type)
entityId?: string // ID of the entity (for node type)
edgeId?: string // ID of the edge (for edge type)
dynamicId?: string
entityType?: 'node' | 'edge' // Type of graph entity
sourceId?: string // Source node ID (for edge type)
targetId?: string // Target node ID (for edge type)
@@ -30,7 +33,10 @@ const EditablePropertyRow = ({
name,
value: initialValue,
onClick,
nodeId,
edgeId,
entityId,
dynamicId,
entityType,
sourceId,
targetId,
@@ -66,7 +72,7 @@ const EditablePropertyRow = ({
setIsSubmitting(true)
try {
if (entityType === 'node' && entityId) {
if (entityType === 'node' && entityId && nodeId) {
let updatedData = { [name]: value }
if (name === 'entity_id') {
@@ -79,12 +85,12 @@ const EditablePropertyRow = ({
}
await updateEntity(entityId, updatedData, true)
await updateGraphNode(entityId, name, value)
await updateGraphNode(nodeId, entityId, name, value)
toast.success(t('graphPanel.propertiesView.success.entityUpdated'))
} else if (entityType === 'edge' && sourceId && targetId) {
} else if (entityType === 'edge' && sourceId && targetId && edgeId && dynamicId) {
const updatedData = { [name]: value }
await updateRelation(sourceId, targetId, updatedData)
await updateGraphEdge(sourceId, targetId, name, value)
await updateGraphEdge(edgeId, dynamicId, sourceId, targetId, name, value)
toast.success(t('graphPanel.propertiesView.success.relationUpdated'))
}

View File

@@ -93,6 +93,7 @@ const refineNodeProperties = (node: RawNodeType): NodeType => {
if (state.sigmaGraph && state.rawGraph) {
try {
if (!state.sigmaGraph.hasNode(node.id)) {
console.warn('Node not found in sigmaGraph:', node.id)
return {
...node,
relationships: []
@@ -139,7 +140,8 @@ const refineEdgeProperties = (edge: RawEdgeType): EdgeType => {
if (state.sigmaGraph && state.rawGraph) {
try {
if (!state.sigmaGraph.hasEdge(edge.id)) {
if (!state.sigmaGraph.hasEdge(edge.dynamicId)) {
console.warn('Edge not found in sigmaGraph:', edge.id, 'dynamicId:', edge.dynamicId)
return {
...edge,
sourceNode: undefined,
@@ -171,6 +173,9 @@ const PropertyRow = ({
value,
onClick,
tooltip,
nodeId,
edgeId,
dynamicId,
entityId,
entityType,
sourceId,
@@ -181,7 +186,10 @@ const PropertyRow = ({
value: any
onClick?: () => void
tooltip?: string
nodeId?: string
entityId?: string
edgeId?: string
dynamicId?: string
entityType?: 'node' | 'edge'
sourceId?: string
targetId?: string
@@ -202,7 +210,10 @@ const PropertyRow = ({
name={name}
value={value}
onClick={onClick}
nodeId={nodeId}
entityId={entityId}
edgeId={edgeId}
dynamicId={dynamicId}
entityType={entityType}
sourceId={sourceId}
targetId={targetId}
@@ -265,7 +276,7 @@ const NodePropertiesView = ({ node }: { node: NodeType }) => {
</div>
</div>
<div className="bg-primary/5 max-h-96 overflow-auto rounded p-1">
<PropertyRow name={t('graphPanel.propertiesView.node.id')} value={node.id} />
<PropertyRow name={t('graphPanel.propertiesView.node.id')} value={String(node.id)} />
<PropertyRow
name={t('graphPanel.propertiesView.node.labels')}
value={node.labels.join(', ')}
@@ -285,7 +296,8 @@ const NodePropertiesView = ({ node }: { node: NodeType }) => {
key={name}
name={name}
value={node.properties[name]}
entityId={node.properties['entity_id'] || node.id}
nodeId={String(node.id)}
entityId={node.properties['entity_id']}
entityType="node"
isEditable={name === 'description' || name === 'entity_id'}
/>
@@ -350,10 +362,11 @@ const EdgePropertiesView = ({ edge }: { edge: EdgeType }) => {
key={name}
name={name}
value={edge.properties[name]}
entityId={edge.id}
edgeId={String(edge.id)}
dynamicId={String(edge.dynamicId)}
entityType="edge"
sourceId={edge.source}
targetId={edge.target}
sourceId={edge.sourceNode?.properties['entity_id'] || edge.source}
targetId={edge.targetNode?.properties['entity_id'] || edge.target}
isEditable={name === 'description' || name === 'keywords'}
/>
)