Commit 2bb24278 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] turns out createElement is not needed

It is enough to create a portal with that dummy ref-ed container.

This simplifies code and makes parentRef obsolete.
parent 3a1dc8f0
...@@ -38,7 +38,6 @@ type Props sigma forceatlas2 = ...@@ -38,7 +38,6 @@ type Props sigma forceatlas2 =
( elRef :: R.Ref (Nullable Element) ( elRef :: R.Ref (Nullable Element)
, forceAtlas2Settings :: forceatlas2 , forceAtlas2Settings :: forceatlas2
, graph :: Graph , graph :: Graph
, parentRef :: R.Ref (Nullable Element)
, sigmaSettings :: sigma , sigmaSettings :: sigma
, sigmaRef :: R.Ref Sigma , sigmaRef :: R.Ref Sigma
) )
...@@ -50,21 +49,21 @@ graphCpt :: forall s fa2. R.Component (Props s fa2) ...@@ -50,21 +49,21 @@ graphCpt :: forall s fa2. R.Component (Props s fa2)
graphCpt = R.hooksComponent "Graph" cpt graphCpt = R.hooksComponent "Graph" cpt
where where
cpt props _ = do cpt props _ = do
R.useEffectOnce' $ do -- R.useEffectOnce' $ do
el <- case R.readNullableRef props.elRef of -- el <- case R.readNullableRef props.elRef of
Just el -> do -- Just el -> do
pure el -- pure el
Nothing -> do -- Nothing -> do
let el = createElement "div" -- let el = createElement "div"
setAttr el "style" "height: 95%" -- setAttr el "style" "height: 95%"
setAttr el "id" "graph-cpt-root" -- setAttr el "id" "graph-cpt-root"
R.setRef props.elRef $ notNull $ el -- R.setRef props.elRef $ notNull $ el
pure el -- pure el
case R.readNullableRef props.parentRef of -- case R.readNullableRef props.parentRef of
Nothing -> pure unit -- Nothing -> pure unit
Just parentEl -> R2.appendChild parentEl el -- Just parentEl -> R2.appendChild parentEl el
pure unit -- pure unit
R.useEffectOnce $ do R.useEffectOnce $ do
--log "[graphCpt] calling startSigmaEff" --log "[graphCpt] calling startSigmaEff"
......
...@@ -41,8 +41,7 @@ type LayoutProps = ...@@ -41,8 +41,7 @@ type LayoutProps =
) )
type Props = ( type Props = (
graphParentRef :: R.Ref (Nullable Element) graph :: Maybe Graph.Graph | LayoutProps
, graph :: Maybe Graph.Graph | LayoutProps
) )
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -53,11 +52,10 @@ explorerLayoutCpt :: R.Component LayoutProps ...@@ -53,11 +52,10 @@ explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt
where where
cpt {graphId, mCurrentRoute, treeId, session, sessions, frontends} _ = do cpt {graphId, mCurrentRoute, treeId, session, sessions, frontends} _ = do
graphParentRef <- R.useRef null useLoader graphId (getNodes session) handler
useLoader graphId (getNodes session) (handler graphParentRef)
where where
handler graphParentRef loaded = handler loaded =
explorer {graphParentRef, graphId, mCurrentRoute, treeId, session, sessions, graph, frontends} explorer {graphId, mCurrentRoute, treeId, session, sessions, graph, frontends}
where graph = Just (convert loaded) where graph = Just (convert loaded)
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -67,7 +65,8 @@ explorer props = R.createElement explorerCpt props [] ...@@ -67,7 +65,8 @@ explorer props = R.createElement explorerCpt props []
explorerCpt :: R.Component Props explorerCpt :: R.Component Props
explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
where where
cpt {graphParentRef, sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do cpt {sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do
graphRef <- R.useRef null
controls <- Controls.useGraphControls controls <- Controls.useGraphControls
state <- useExplorerState state <- useExplorerState
x /\ setX <- R.useState' 0 x /\ setX <- R.useState' 0
...@@ -87,8 +86,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -87,8 +86,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, RH.div {on: {click: \e -> setX $ \x_ -> x_ + 1}} [ RH.text ("Counter: " <> (show x)) ] , RH.div {on: {click: \e -> setX $ \x_ -> x_ + 1}} [ RH.text ("Counter: " <> (show x)) ]
] ]
, row [ tree {mCurrentRoute, treeId} controls showLogin , row [ tree {mCurrentRoute, treeId} controls showLogin
, RH.div { ref: graphParentRef, id: "graph-view", className: "col-md-12" } [] -- graph parent , RH.div { ref: graphRef, id: "graph-view", className: "col-md-12", style: {height: "95%"} } [] -- graph container
, mGraph graphParentRef controls.sigmaRef {graphId, graph} , mGraph graphRef controls.sigmaRef {graphId, graph}
, Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ] , Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ]
, row [ , row [
] ]
...@@ -113,7 +112,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -113,7 +112,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
mGraph :: R.Ref (Nullable Element) -> R.Ref Sigma -> {graphId :: GraphId, graph :: Maybe Graph.Graph} -> R.Element mGraph :: R.Ref (Nullable Element) -> R.Ref Sigma -> {graphId :: GraphId, graph :: Maybe Graph.Graph} -> R.Element
mGraph _ _ {graph: Nothing} = RH.div {} [] mGraph _ _ {graph: Nothing} = RH.div {} []
mGraph graphParentRef sigmaRef {graphId, graph: Just graph} = graphView graphParentRef sigmaRef {graphId, graph} mGraph graphRef sigmaRef {graphId, graph: Just graph} = graphView graphRef sigmaRef {graphId, graph}
useExplorerState :: R.Hooks (Record GET.State) useExplorerState :: R.Hooks (Record GET.State)
useExplorerState = do pure {} useExplorerState = do pure {}
...@@ -140,18 +139,15 @@ type GraphProps = ( ...@@ -140,18 +139,15 @@ type GraphProps = (
graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element
--graphView sigmaRef props = R.createElement (R.memo el memoCmp) props [] --graphView sigmaRef props = R.createElement (R.memo el memoCmp) props []
graphView parentRef sigmaRef props = R.createElement el props [] graphView elRef sigmaRef props = R.createElement el props []
where where
--memoCmp props1 props2 = props1.graphId == props2.graphId --memoCmp props1 props2 = props1.graphId == props2.graphId
el = R.hooksComponent "GraphView" cpt el = R.hooksComponent "GraphView" cpt
cpt {graphId, graph} _children = do cpt {graphId, graph} _children = do
elRef <- R.useRef null
pure $ Graph.graph { pure $ Graph.graph {
elRef elRef
, forceAtlas2Settings: Graph.forceAtlas2Settings , forceAtlas2Settings: Graph.forceAtlas2Settings
, graph , graph
, parentRef
, sigmaSettings: Graph.sigmaSettings , sigmaSettings: Graph.sigmaSettings
, sigmaRef: sigmaRef , sigmaRef: sigmaRef
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment