2024-01-09 - Frontend GraphNav requesting relNodes

From Izara Wiki
Jump to navigation Jump to search

Frontend SitePage Element - GraphNavigation

graphNavigation useRef

  • graphNavigation has Ref focusedNodes that stores array of focused nodes for each graphNav
  • graphNavigation has Ref nodesRequested for all nodes sent relNode request to backend (so not double up requests)

initialNodes processing

  • initialNodes sets focusedNodes for each graphNav as all initialNodes shown in that graphNav (objTypes)
  • initialNodes setGraphNode(s)
  • setGraphNode triggers a useEffect that newNodeAdded

newNodeAdded useEffect

  • check nodesRequested if already sent request to backend?

for each GraphNav start

  • check this node shown in that graphNav (objTypes)
  • find shortest # hops to newNode from all focusedNodes
  • if shortest hops is < graphNav hopLimit, need to request backend

for each GraphNav end

if any graphNav need to request backend

  • check nodesRequested if already sent request to backend again, in case updated during processing (?)
  • add to nodesRequested
  • send request

after get backend result

for each relNode

  • setGraphRelationship
  • setGraphNode (must do after setGraphRelationship)
  • setGraphNode triggers a useEffect that newNodeAdded

for each GraphNav start

  • check this node shown in graphNav (objTypes)
  • check this relationship Type shown in graphNav
  • find shortest # hops to newNode from all focusedNodes
  • if shortest hops is < graphNav hopLimit, setGraphRelationshipsPerGraphNav and setGraphNodesPerGraphNav

for each GraphNav end for each relNode end

graphNav change focus

  • when a graphNav changes focus we need to remove from graphRelationshipsPerGraphNav and graphNodesPerGraphNav any that are > hopLimit
  • add new relNodes that are < hopLimit
  • request new relNodes that have not been requested yet

Process

  • graphNav updates graphNavigation focusedNodes reference
  • triggers useEffect that recalculates graphRelationshipsPerGraphNav and graphNodesPerGraphNav for that graphNav
  • if need to request new relNodes trigger useEffect newNodeAdded for leaf node
  • (a little inefficient because will run all tests on that leaf node, even though we already know it needs to be requested, perhaps create another useEffect that is a forced request/skips tests, share code for requesting from backend and result)

old notes

requesting relNodes from backend

  • have standard recursive function that receives graphNodeId, name: getRelNodes(graphNode, hops)
  • in top level GraphNavigation compenent
  • graphNodeId object has a property storing how many hops this node is from currently focused node
  • probably not reference any state in getRelNodes because state might not be updated or could be stale, send all required values as params
  • if reached limit of hops stop
  • if graphNodeId already exists in nodesRequested can stop processing
  • set graphNodeId in nodesRequested
  • send request to backend
  • after get response do most processing inside setGraphNodes and setGraphRelationships so working with latest State
  • use cancelToken on backend request, maybe need code to check if cancelled so not adjust state on cancelled/unmounted request

setGraphNodes

  • check in graphNodes if hops for node still matches, if not use updated hops from State
  • add new nodes to graphNodes
  • if not yet reached hops limit, invoke getRelNodes for new nodes

setGraphRelationships

  • add new relationship to graphRelationships if not already exist

Change focused node

  • handled in GraphNav compenent so all elements do nto re-render when traversing graph
  • if detect more must request more nodes using getRelNodes, have a state prop passed down from GraphNavigation compenent that triggers getRelNodes function

idea 1

  • reset all nodes to 0 hops from focused node
  • traverse graph from focused node using graphRelationships
  • update hops property
  • if reach node that has not yet requested relationships (set to null) and not reached hop limit, invoke getRelNodes in parent GraphNavigation component
  • (later) can remove nodes too distant from focused node here if want to cleanup ram (but must consider all child GraphNav elements)

idea 2

  • create a list of nodes and relationships only up to number of hops shown in this GraphNav component
  • when change focus (or parent graphNodes/graphRelationships updates) empty this list and rebuild from currently focused node