Commit 4a79d427 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] open sidebar when first node is selected

parent 1f4462b0
...@@ -76,6 +76,12 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -76,6 +76,12 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
showLogin <- snd <$> R.useState' true showLogin <- snd <$> R.useState' true
selectedNodeIds <- R.useState' $ Set.empty selectedNodeIds <- R.useState' $ Set.empty
R.useEffect' $ do
if fst controls.showSidePanel == GET.InitialClosed && (not Set.isEmpty $ fst selectedNodeIds) then
snd controls.showSidePanel $ \_ -> GET.Opened
else
pure unit
pure $ pure $
RH.div RH.div
{ id: "graph-explorer" } { id: "graph-explorer" }
...@@ -125,7 +131,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -125,7 +131,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
mSidebar :: Maybe Graph.Graph mSidebar :: Maybe Graph.Graph
-> Maybe GET.MetaData -> Maybe GET.MetaData
-> { showSidePanel :: Boolean -> { showSidePanel :: GET.SidePanelState
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session } , session :: Session }
-> R.Element -> R.Element
......
...@@ -6,7 +6,6 @@ module Gargantext.Components.GraphExplorer.Controls ...@@ -6,7 +6,6 @@ module Gargantext.Components.GraphExplorer.Controls
, controlsCpt , controlsCpt
, getShowTree, setShowTree , getShowTree, setShowTree
, getShowControls, setShowControls , getShowControls, setShowControls
, getShowSidePanel, setShowSidePanel
, getCursorSize, setCursorSize , getCursorSize, setCursorSize
, getMultiNodeSelect, setMultiNodeSelect , getMultiNodeSelect, setMultiNodeSelect
) where ) where
...@@ -25,17 +24,17 @@ import Gargantext.Components.GraphExplorer.Button (centerButton) ...@@ -25,17 +24,17 @@ import Gargantext.Components.GraphExplorer.Button (centerButton)
import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSizeControl) import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSizeControl)
import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton) import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton)
import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton, pauseForceAtlasButton) import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton, pauseForceAtlasButton)
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax as Sigmax import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Utils.Range as Range import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
type Controls = type Controls =
( cursorSize :: R.State Number ( cursorSize :: R.State Number
, multiNodeSelect :: R.Ref Boolean , multiNodeSelect :: R.Ref Boolean
, showControls :: R.State Boolean , showControls :: R.State Boolean
, showSidePanel :: R.State Boolean , showSidePanel :: R.State GET.SidePanelState
, showTree :: R.State Boolean , showTree :: R.State Boolean
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
) )
...@@ -125,7 +124,7 @@ useGraphControls = do ...@@ -125,7 +124,7 @@ useGraphControls = do
cursorSize <- R.useState' 10.0 cursorSize <- R.useState' 10.0
multiNodeSelect <- R.useRef false multiNodeSelect <- R.useRef false
showControls <- R.useState' false showControls <- R.useState' false
showSidePanel <- R.useState' false showSidePanel <- R.useState' GET.InitialClosed
showTree <- R.useState' false showTree <- R.useState' false
sigma <- Sigmax.initSigma sigma <- Sigmax.initSigma
sigmaRef <- R.useRef sigma sigmaRef <- R.useRef sigma
...@@ -141,9 +140,6 @@ useGraphControls = do ...@@ -141,9 +140,6 @@ useGraphControls = do
getShowControls :: Record Controls -> Boolean getShowControls :: Record Controls -> Boolean
getShowControls { showControls: ( should /\ _ ) } = should getShowControls { showControls: ( should /\ _ ) } = should
getShowSidePanel :: Record Controls -> Boolean
getShowSidePanel { showSidePanel: ( should /\ _ ) } = should
getShowTree :: Record Controls -> Boolean getShowTree :: Record Controls -> Boolean
getShowTree { showTree: ( should /\ _ ) } = should getShowTree { showTree: ( should /\ _ ) } = should
...@@ -156,9 +152,6 @@ getMultiNodeSelect { multiNodeSelect } = R.readRef multiNodeSelect ...@@ -156,9 +152,6 @@ getMultiNodeSelect { multiNodeSelect } = R.readRef multiNodeSelect
setShowControls :: Record Controls -> Boolean -> Effect Unit setShowControls :: Record Controls -> Boolean -> Effect Unit
setShowControls { showControls: ( _ /\ set ) } v = set $ const v setShowControls { showControls: ( _ /\ set ) } v = set $ const v
setShowSidePanel :: Record Controls -> Boolean -> Effect Unit
setShowSidePanel { showSidePanel: ( _ /\ set ) } v = set $ const v
setShowTree :: Record Controls -> Boolean -> Effect Unit setShowTree :: Record Controls -> Boolean -> Effect Unit
setShowTree { showTree: ( _ /\ set ) } v = set $ not <<< const v setShowTree { showTree: ( _ /\ set ) } v = set $ not <<< const v
......
...@@ -23,7 +23,7 @@ type Props = ...@@ -23,7 +23,7 @@ type Props =
, metaData :: GET.MetaData , metaData :: GET.MetaData
, selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds , selectedNodeIds :: R.State SigmaxTypes.SelectedNodeIds
, session :: Session , session :: Session
, showSidePanel :: Boolean , showSidePanel :: GET.SidePanelState
) )
sidebar :: Record Props -> R.Element sidebar :: Record Props -> R.Element
...@@ -32,7 +32,9 @@ sidebar props = R.createElement sidebarCpt props [] ...@@ -32,7 +32,9 @@ sidebar props = R.createElement sidebarCpt props []
sidebarCpt :: R.Component Props sidebarCpt :: R.Component Props
sidebarCpt = R.hooksComponent "Sidebar" cpt sidebarCpt = R.hooksComponent "Sidebar" cpt
where where
cpt {showSidePanel: false} _children = do cpt {showSidePanel: GET.Closed} _children = do
pure $ RH.div {} []
cpt {showSidePanel: GET.InitialClosed} _children = do
pure $ RH.div {} [] pure $ RH.div {} []
cpt props _children = do cpt props _children = do
let nodesMap = SigmaxTypes.nodesMap props.graph let nodesMap = SigmaxTypes.nodesMap props.graph
......
...@@ -16,6 +16,7 @@ import Effect (Effect) ...@@ -16,6 +16,7 @@ import Effect (Effect)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax as Sigmax import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
...@@ -87,11 +88,26 @@ treeToggleButton state = ...@@ -87,11 +88,26 @@ treeToggleButton state =
, onClick: \_ -> snd state not , onClick: \_ -> snd state not
} }
sidebarToggleButton :: R.State Boolean -> R.Element sidebarToggleButton :: R.State GET.SidePanelState -> R.Element
sidebarToggleButton state = sidebarToggleButton (state /\ setState) = R.createElement el {} []
toggleButton { where
state: state el = R.hooksComponent "SidebarToggleButton" cpt
, onMessage: "Hide Sidebar" cpt {} _ = do
, offMessage: "Show Sidebar" pure $
, onClick: \_ -> snd state not H.span {}
} [
H.button
{ className: "btn btn-primary", on: {click: onClick} }
[ H.text (text onMessage offMessage state) ]
]
onMessage = "Hide Sidebar"
offMessage = "Show Sidebar"
text on _off GET.Opened = on
text _on off GET.InitialClosed = off
text _on off GET.Closed = off
onClick = \_ -> do
setState $ \s -> case s of
GET.InitialClosed -> GET.Opened
GET.Closed -> GET.Opened
GET.Opened -> GET.Closed
...@@ -184,3 +184,8 @@ defaultPalette = ["#5fa571","#ab9ba2","#da876d","#bdd3ff","#b399df","#ffdfed","# ...@@ -184,3 +184,8 @@ defaultPalette = ["#5fa571","#ab9ba2","#da876d","#bdd3ff","#b399df","#ffdfed","#
intColor :: Int -> String intColor :: Int -> String
intColor i = unsafePartial $ fromJust $ defaultPalette !! (i `mod` length defaultPalette) intColor i = unsafePartial $ fromJust $ defaultPalette !! (i `mod` length defaultPalette)
data SidePanelState = InitialClosed | Opened | Closed
derive instance eqSidePanelState :: Eq SidePanelState
...@@ -157,7 +157,6 @@ setEdges sigma val = do ...@@ -157,7 +157,6 @@ setEdges sigma val = do
markSelectedNodes :: Sigma.Sigma -> SelectedNodeIds -> NodesMap -> Effect Unit markSelectedNodes :: Sigma.Sigma -> SelectedNodeIds -> NodesMap -> Effect Unit
markSelectedNodes sigma selectedNodeIds graphNodes = do markSelectedNodes sigma selectedNodeIds graphNodes = do
log2 "[markSelectedNodes] selectedNodeIds" selectedNodeIds
Sigma.forEachNode sigma \n -> do Sigma.forEachNode sigma \n -> do
case Map.lookup n.id graphNodes of case Map.lookup n.id graphNodes of
Nothing -> error $ "Node id " <> n.id <> " not found in graphNodes map" Nothing -> error $ "Node id " <> n.id <> " not found in graphNodes map"
...@@ -176,7 +175,6 @@ bindSelectedNodesClick :: R.Ref Sigma -> R.State SelectedNodeIds -> Effect Unit ...@@ -176,7 +175,6 @@ bindSelectedNodesClick :: R.Ref Sigma -> R.State SelectedNodeIds -> Effect Unit
bindSelectedNodesClick sigmaRef (_ /\ setSelectedNodeIds) = bindSelectedNodesClick sigmaRef (_ /\ setSelectedNodeIds) =
dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma -> dependOnSigma (R.readRef sigmaRef) "[graphCpt] no sigma" $ \sigma ->
Sigma.bindClickNode sigma $ \node -> do Sigma.bindClickNode sigma $ \node -> do
log2 "[graphCpt] clickNode" node
setSelectedNodeIds \nids -> setSelectedNodeIds \nids ->
if Set.member node.id nids then if Set.member node.id nids then
Set.delete node.id nids Set.delete node.id nids
......
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