From 9f0a0a6a5d9c27c2e0972119e68ed05a473a3a8b Mon Sep 17 00:00:00 2001 From: Przemek Kaminski <pk@intrepidus.pl> Date: Sat, 5 Sep 2020 06:48:38 +0200 Subject: [PATCH] [graph] reload tree after graph cloning --- src/Gargantext/Components/App.purs | 3 ++- src/Gargantext/Components/GraphExplorer.purs | 16 +++++++++---- .../Components/GraphExplorer/Button.purs | 9 ++++++-- .../Components/GraphExplorer/Controls.purs | 23 +++++++++++++------ src/Gargantext/Version.purs | 7 +++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/Gargantext/Components/App.purs b/src/Gargantext/Components/App.purs index 19b837e2..790f93be 100644 --- a/src/Gargantext/Components/App.purs +++ b/src/Gargantext/Components/App.purs @@ -104,7 +104,8 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where , session , sessions: (fst sessions) , showLogin - , treeReload } + --, treeReload + } type ForestLayoutProps = ( child :: R.Element diff --git a/src/Gargantext/Components/GraphExplorer.purs b/src/Gargantext/Components/GraphExplorer.purs index 2382bc95..e6f88f0b 100644 --- a/src/Gargantext/Components/GraphExplorer.purs +++ b/src/Gargantext/Components/GraphExplorer.purs @@ -45,7 +45,7 @@ type LayoutProps = , session :: Session , sessions :: Sessions , showLogin :: R.State Boolean - , treeReload :: R.State Int + --, treeReload :: R.State Int ) type Props = ( @@ -99,7 +99,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt , session , sessions , showLogin - , treeReload } _ = do + --, treeReload + } _ = do let startForceAtlas = maybe true (\(GET.MetaData { startForceAtlas }) -> startForceAtlas) mMetaData let forceAtlasS = if startForceAtlas then SigmaxT.InitialRunning else SigmaxT.InitialStopped @@ -107,7 +108,14 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt dataRef <- R.useRef graph graphRef <- R.useRef null graphVersionRef <- R.useRef (fst graphVersion) - controls <- Controls.useGraphControls graph graphId hyperdataGraph session forceAtlasS + treeReload <- R.useState' 0 + controls <- Controls.useGraphControls { forceAtlasS + , graph + , graphId + , hyperdataGraph + , session + , treeReload: \_ -> (snd treeReload) $ (+) 1 + } multiSelectEnabledRef <- R.useRef $ fst controls.multiSelectEnabled R.useEffect' $ do @@ -144,7 +152,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt tree { frontends , handed , mCurrentRoute - , reload: props.treeReload + , reload: treeReload , sessions , show: fst controls.showTree , showLogin: snd showLogin } diff --git a/src/Gargantext/Components/GraphExplorer/Button.purs b/src/Gargantext/Components/GraphExplorer/Button.purs index 2ee30185..a6346e43 100644 --- a/src/Gargantext/Components/GraphExplorer/Button.purs +++ b/src/Gargantext/Components/GraphExplorer/Button.purs @@ -15,6 +15,7 @@ import Data.String as DS import DOM.Simple.Console (log2) import Effect (Effect) import Effect.Aff (launchAff_) +import Effect.Class (liftEffect) import Effect.Now as EN import Reactix as R import Reactix.DOM.HTML as H @@ -62,6 +63,7 @@ type CameraButtonProps = ( , hyperdataGraph :: GET.HyperdataGraph , session :: Session , sigmaRef :: R.Ref Sigmax.Sigma + , treeReload :: Unit -> Effect Unit ) @@ -69,7 +71,8 @@ cameraButton :: Record CameraButtonProps -> R.Element cameraButton { id , hyperdataGraph: GET.HyperdataGraph { graph: GET.GraphData hyperdataGraph } , session - , sigmaRef } = simpleButton { + , sigmaRef + , treeReload } = simpleButton { onClick: \_ -> do let sigma = R.readRef sigmaRef Sigmax.dependOnSigma sigma "[cameraButton] sigma: Nothing" $ \s -> do @@ -100,6 +103,8 @@ cameraButton { id , mCamera: Just camera } launchAff_ $ do clonedGraphId <- cloneGraph { id, hyperdataGraph, session } - uploadArbitraryDataURL session clonedGraphId (Just $ nowStr <> "-" <> "screenshot.png") screen + ret <- uploadArbitraryDataURL session clonedGraphId (Just $ nowStr <> "-" <> "screenshot.png") screen + liftEffect $ treeReload unit + pure ret , text: "Screenshot" } diff --git a/src/Gargantext/Components/GraphExplorer/Controls.purs b/src/Gargantext/Components/GraphExplorer/Controls.purs index c591f980..78c60327 100644 --- a/src/Gargantext/Components/GraphExplorer/Controls.purs +++ b/src/Gargantext/Components/GraphExplorer/Controls.purs @@ -52,6 +52,7 @@ type Controls = , showSidePanel :: R.State GET.SidePanelState , showTree :: R.State Boolean , sigmaRef :: R.Ref Sigmax.Sigma + , treeReload :: Unit -> Effect Unit ) type LocalControls = @@ -165,18 +166,25 @@ controlsCpt = R.hooksComponent "GraphControls" cpt , RH.li {} [ cameraButton { id: props.graphId , hyperdataGraph: props.hyperdataGraph , session: props.session - , sigmaRef: props.sigmaRef } ] + , sigmaRef: props.sigmaRef + , treeReload: props.treeReload } ] ] ] ] -useGraphControls :: SigmaxT.SGraph - -> GET.GraphId - -> GET.HyperdataGraph - -> Session - -> SigmaxT.ForceAtlasState +useGraphControls :: { forceAtlasS :: SigmaxT.ForceAtlasState + , graph :: SigmaxT.SGraph + , graphId :: GET.GraphId + , hyperdataGraph :: GET.HyperdataGraph + , session :: Session + , treeReload :: Unit -> Effect Unit } -> R.Hooks (Record Controls) -useGraphControls graph graphId hyperdataGraph session forceAtlasS = do +useGraphControls { forceAtlasS + , graph + , graphId + , hyperdataGraph + , session + , treeReload } = do edgeConfluence <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 } edgeWeight <- R.useState' $ Range.Closed { min: 0.0 @@ -214,6 +222,7 @@ useGraphControls graph graphId hyperdataGraph session forceAtlasS = do , showSidePanel , showTree , sigmaRef + , treeReload } getShowControls :: Record Controls -> Boolean diff --git a/src/Gargantext/Version.purs b/src/Gargantext/Version.purs index 82a7a542..8208e771 100644 --- a/src/Gargantext/Version.purs +++ b/src/Gargantext/Version.purs @@ -4,13 +4,14 @@ import Data.Maybe (Maybe(..)) import Data.Tuple.Nested ((/\)) import Effect.Aff (Aff, launchAff_) import Effect.Class (liftEffect) +import Prelude +import Reactix as R +import Reactix.DOM.HTML as H + import Gargantext.Config.REST as REST import Gargantext.Ends (toUrl) import Gargantext.Sessions (Session(..)) import Gargantext.Sessions as Sessions -import Prelude -import Reactix as R -import Reactix.DOM.HTML as H type Version = String -- 2.21.0