refactor: improve graph property update mechanism

- Move graph data and UI state update logic into store
- Ensure all property updates trigger PropertiesView refresh
- Add graphDataVersion dependency to PropertiesView
- Follow React best practices by avoiding direct UI state modification in utility functions
- Fix issue where non-entity_id property changes weren't reflected in UI
This commit is contained in:
yangdx
2025-04-15 12:29:52 +08:00
parent f58fb43f67
commit 28d26c3a4a
3 changed files with 162 additions and 124 deletions

View File

@@ -16,10 +16,12 @@ const PropertiesView = () => {
const focusedNode = useGraphStore.use.focusedNode()
const selectedEdge = useGraphStore.use.selectedEdge()
const focusedEdge = useGraphStore.use.focusedEdge()
const graphDataVersion = useGraphStore.use.graphDataVersion()
const [currentElement, setCurrentElement] = useState<NodeType | EdgeType | null>(null)
const [currentType, setCurrentType] = useState<'node' | 'edge' | null>(null)
// This effect will run when selection changes or when graph data is updated
useEffect(() => {
let type: 'node' | 'edge' | null = null
let element: RawNodeType | RawEdgeType | null = null
@@ -53,6 +55,7 @@ const PropertiesView = () => {
selectedNode,
focusedEdge,
selectedEdge,
graphDataVersion, // Add dependency on graphDataVersion to refresh when data changes
setCurrentElement,
setCurrentType,
getNode,