Commit 79910d34 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] subtree out params

parent a918d9b1
...@@ -10,6 +10,7 @@ import Effect.Aff (Aff) ...@@ -10,6 +10,7 @@ import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Forest.Tree.Node (nodeMainSpan) import Gargantext.Components.Forest.Tree.Node (nodeMainSpan)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeOut(..))
import Gargantext.Components.Forest.Tree.Node.Action (Action(..)) import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode) import Gargantext.Components.Forest.Tree.Node.Action.Add (AddNodeValue(..), addNode)
import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode) import Gargantext.Components.Forest.Tree.Node.Action.Delete (deleteNode)
...@@ -104,8 +105,6 @@ getNodeTree :: Session -> GT.ID -> Aff FTree ...@@ -104,8 +105,6 @@ getNodeTree :: Session -> GT.ID -> Aff FTree
getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) "" getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) ""
-------------- --------------
type TreeViewProps = ( asyncTasks :: R.State GAT.Storage type TreeViewProps = ( asyncTasks :: R.State GAT.Storage
, tree :: FTree , tree :: FTree
, tasks :: Record Tasks , tasks :: Record Tasks
...@@ -306,17 +305,26 @@ performAction (UploadFile nodeType fileType mName contents) { session ...@@ -306,17 +305,26 @@ performAction (UploadFile nodeType fileType mName contents) { session
performAction DownloadNode _ = do performAction DownloadNode _ = do
liftEffect $ log "[performAction] DownloadNode" liftEffect $ log "[performAction] DownloadNode"
------- -------
performAction (MoveNode n1 n2) p@{session} = do performAction (MoveNode {params}) p@{session} =
void $ moveNodeReq session n1 n2 case params of
performAction RefreshTree p Nothing -> performAction NoAction p
Just (SubTreeOut {in:in',out}) -> do
void $ moveNodeReq session in' out
performAction RefreshTree p
performAction (MergeNode n1 n2) p@{session} = do performAction (MergeNode {params}) p@{session} =
void $ mergeNodeReq session n1 n2 case params of
performAction RefreshTree p Nothing -> performAction NoAction p
Just (SubTreeOut {in:in',out}) -> do
void $ mergeNodeReq session in' out
performAction RefreshTree p
performAction (LinkNode n1 n2) p@{session} = do performAction (LinkNode {params}) p@{session} =
void $ linkNodeReq session n1 n2 case params of
performAction RefreshTree p Nothing -> performAction NoAction p
Just (SubTreeOut {in:in',out}) -> do
void $ linkNodeReq session in' out
performAction RefreshTree p
------- -------
performAction RefreshTree { reload: (_ /\ setReload) } = do performAction RefreshTree { reload: (_ /\ setReload) } = do
......
module Gargantext.Components.Forest.Tree.Node.Action where module Gargantext.Components.Forest.Tree.Node.Action where
import Data.Maybe (Maybe) import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Prelude (class Show, Unit) import Gargantext.Prelude (class Show, Unit)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
...@@ -29,16 +29,24 @@ data Action = AddNode String GT.NodeType ...@@ -29,16 +29,24 @@ data Action = AddNode String GT.NodeType
| DownloadNode | DownloadNode
| RefreshTree | RefreshTree
| MoveNode GT.ID GT.ID | MoveNode {params :: Maybe SubTreeOut}
| MergeNode GT.ID GT.ID | MergeNode {params :: Maybe SubTreeOut}
| LinkNode GT.ID GT.ID | LinkNode {params :: Maybe SubTreeOut}
-- | MoveNode (Maybe SubTreeOut)
-- | MergeNode (Maybe SubTreeOut)
-- | LinkNode (Maybe SubTreeOut)
| NoAction | NoAction
subTreeOut :: Action -> Maybe SubTreeOut
subTreeOut (MoveNode {params}) = params
subTreeOut (MergeNode {params}) = params
subTreeOut (LinkNode {params}) = params
subTreeOut _ = Nothing
setTreeOut :: Action -> Maybe SubTreeOut -> Action
setTreeOut (MoveNode {params:_}) p = MoveNode {params: p}
setTreeOut a _ = a
instance showShow :: Show Action where instance showShow :: Show Action where
show (AddNode _ _ )= "AddNode" show (AddNode _ _ )= "AddNode"
show DeleteNode = "DeleteNode" show DeleteNode = "DeleteNode"
...@@ -49,9 +57,9 @@ instance showShow :: Show Action where ...@@ -49,9 +57,9 @@ instance showShow :: Show Action where
show (UploadFile _ _ _ _)= "UploadFile" show (UploadFile _ _ _ _)= "UploadFile"
show RefreshTree = "RefreshTree" show RefreshTree = "RefreshTree"
show DownloadNode = "Download" show DownloadNode = "Download"
show (MoveNode _ _) = "MoveNode" show (MoveNode _ ) = "MoveNode"
show (MergeNode _ _) = "MergeNode" show (MergeNode _ ) = "MergeNode"
show (LinkNode _ _) = "LinkNode" show (LinkNode _ ) = "LinkNode"
show NoAction = "NoAction" show NoAction = "NoAction"
----------------------------------------------------------------------- -----------------------------------------------------------------------
...@@ -65,9 +73,9 @@ icon (DoSearch _) = glyphiconNodeAction SearchBox ...@@ -65,9 +73,9 @@ icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh icon RefreshTree = glyphiconNodeAction Refresh
icon DownloadNode = glyphiconNodeAction Download icon DownloadNode = glyphiconNodeAction Download
icon (MoveNode _ _) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (MoveNode _ ) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (MergeNode _ _) = glyphiconNodeAction (Merge { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (MergeNode _ ) = glyphiconNodeAction (Merge { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (LinkNode _ _) = glyphiconNodeAction (Link { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (LinkNode _ ) = glyphiconNodeAction (Link { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon NoAction = "hand-o-right" icon NoAction = "hand-o-right"
...@@ -83,8 +91,8 @@ text (DoSearch _ )= "Launch search !" ...@@ -83,8 +91,8 @@ text (DoSearch _ )= "Launch search !"
text (UploadFile _ _ _ _)= "Upload File !" text (UploadFile _ _ _ _)= "Upload File !"
text RefreshTree = "Refresh Tree !" text RefreshTree = "Refresh Tree !"
text DownloadNode = "Download !" text DownloadNode = "Download !"
text (MoveNode _ _ ) = "Move !" text (MoveNode _ ) = "Move !"
text (MergeNode _ _ ) = "Merge !" text (MergeNode _ ) = "Merge !"
text (LinkNode _ _ ) = "Link !" text (LinkNode _ ) = "Link !"
text NoAction = "No Action" text NoAction = "No Action"
----------------------------------------------------------------------- -----------------------------------------------------------------------
...@@ -21,19 +21,21 @@ linkNodeReq session fromId toId = ...@@ -21,19 +21,21 @@ linkNodeReq session fromId toId =
linkNode :: Record SubTreeParamsIn -> R.Hooks R.Element linkNode :: Record SubTreeParamsIn -> R.Hooks R.Element
linkNode p@{dispatch, subTreeParams, id, nodeType, session} = do linkNode p@{dispatch, subTreeParams, id, nodeType, session} = do
subTreeOut@(subTreeOutParams /\ setSubTreeOut) :: R.State (Maybe SubTreeOut)
<- R.useState' Nothing action@(valAction /\ setAction) :: R.State Action <- R.useState' (MoveNode {params:Nothing})
let button = case subTreeOutParams of
Nothing -> H.div {} [] let button = case valAction of
Just sbto -> submitButton (LinkNode inId outId) dispatch MoveNode {params} -> case params of
where Just val -> submitButton (MoveNode {params: Just val}) dispatch
(SubTreeOut { in:inId, out:outId}) = sbto Nothing -> H.div {} []
pure $ panel [ subTreeView { subTreeOut _ -> H.div {} []
pure $ panel [ subTreeView { action
, dispatch , dispatch
, subTreeParams
, id , id
, nodeType , nodeType
, session , session
, subTreeParams
} }
] button ] button
...@@ -22,24 +22,23 @@ mergeNodeReq session fromId toId = ...@@ -22,24 +22,23 @@ mergeNodeReq session fromId toId =
mergeNode :: Record SubTreeParamsIn -> R.Hooks R.Element mergeNode :: Record SubTreeParamsIn -> R.Hooks R.Element
mergeNode p@{dispatch, subTreeParams, id, nodeType, session} = do mergeNode p@{dispatch, subTreeParams, id, nodeType, session} = do
subTreeOut@(subTreeOutParams /\ setSubTreeOut) :: R.State (Maybe SubTreeOut) action@(valAction /\ setAction) :: R.State Action <- R.useState' (MoveNode {params:Nothing})
<- R.useState' Nothing
merge <- R.useState' false merge <- R.useState' false
options <- R.useState' (Set.singleton GT.MapTerm) options <- R.useState' (Set.singleton GT.MapTerm)
let button = case subTreeOutParams of let button = case valAction of
Nothing -> H.div {} [] MoveNode {params} -> case params of
Just sbto -> submitButton (MergeNode inId outId) dispatch Just val -> submitButton (MoveNode {params: Just val}) dispatch
where Nothing -> H.div {} []
(SubTreeOut { in:inId, out:outId}) = sbto _ -> H.div {} []
pure $ panel [ subTreeView { subTreeOut pure $ panel [ subTreeView { action
, dispatch , dispatch
, subTreeParams
, id , id
, nodeType , nodeType
, session , session
, subTreeParams
} }
, H.div {} [ H.text "Merge which list?" , H.div {} [ H.text "Merge which list?"
, checkboxes [GT.MapTerm, GT.CandidateTerm, GT.StopTerm] options , checkboxes [GT.MapTerm, GT.CandidateTerm, GT.StopTerm] options
......
...@@ -21,21 +21,20 @@ moveNodeReq session fromId toId = ...@@ -21,21 +21,20 @@ moveNodeReq session fromId toId =
moveNode :: Record SubTreeParamsIn -> R.Hooks R.Element moveNode :: Record SubTreeParamsIn -> R.Hooks R.Element
moveNode p@{dispatch, subTreeParams, id, nodeType, session} = do moveNode p@{dispatch, subTreeParams, id, nodeType, session} = do
subTreeOut@(subTreeOutParams /\ setSubTreeOut) :: R.State (Maybe SubTreeOut) action@(valAction /\ setAction) :: R.State Action <- R.useState' (MoveNode {params:Nothing})
<- R.useState' Nothing
let button = case subTreeOutParams of let button = case valAction of
Nothing -> H.div {} [] MoveNode {params} -> case params of
Just sbto -> submitButton (MoveNode inId outId) dispatch Just val -> submitButton (MoveNode {params: Just val}) dispatch
where Nothing -> H.div {} []
(SubTreeOut { in:inId, out:outId}) = sbto _ -> H.div {} []
pure $ panel [ subTreeView { subTreeOut pure $ panel [ subTreeView { action
, dispatch , dispatch
, subTreeParams
, id , id
, nodeType , nodeType
, session , session
, subTreeParams
} }
] button ] button
...@@ -5,7 +5,7 @@ import Data.Maybe (Maybe(..)) ...@@ -5,7 +5,7 @@ import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Components.Forest.Tree.Node.Action (Props) import Gargantext.Components.Forest.Tree.Node.Action (Props, Action(..), subTreeOut, setTreeOut)
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeParams(..), SubTreeOut(..)) import Gargantext.Components.Forest.Tree.Node.Tools.SubTree.Types (SubTreeParams(..), SubTreeOut(..))
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..)) import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Components.Forest.Tree.Node.Tools (nodeText) import Gargantext.Components.Forest.Tree.Node.Tools (nodeText)
...@@ -24,7 +24,7 @@ type SubTreeParamsIn = ...@@ -24,7 +24,7 @@ type SubTreeParamsIn =
------------------------------------------------------------------------ ------------------------------------------------------------------------
type SubTreeParamsProps = type SubTreeParamsProps =
( subTreeOut :: R.State (Maybe SubTreeOut) ( action :: R.State Action
| SubTreeParamsIn | SubTreeParamsIn
) )
...@@ -39,7 +39,7 @@ subTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeView" cpt ...@@ -39,7 +39,7 @@ subTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeView" cpt
, nodeType , nodeType
, session , session
, subTreeParams , subTreeParams
, subTreeOut , action
} _ = } _ =
do do
let SubTreeParams {showtypes} = subTreeParams let SubTreeParams {showtypes} = subTreeParams
...@@ -52,7 +52,7 @@ subTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeView" cpt ...@@ -52,7 +52,7 @@ subTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeView" cpt
, session , session
, tree , tree
, subTreeParams , subTreeParams
, subTreeOut , action
} }
loadSubTree :: Array GT.NodeType -> Session -> Aff FTree loadSubTree :: Array GT.NodeType -> Session -> Aff FTree
...@@ -97,12 +97,12 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt ...@@ -97,12 +97,12 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt
) ary ) ary
, subTreeParams , subTreeParams
, dispatch , dispatch
, subTreeOut , action
} _ = do } _ = do
pure $ H.div {} [ H.div { className: "node " <> GT.fldr nodeType true} pure $ H.div {} [ H.div { className: "node " <> GT.fldr nodeType true}
( [ H.span { className: "name " <> clickable ( [ H.span { className: "name " <> clickable
, on: { click: onClick } , on: { click: onClick }
} [ nodeText { isSelected: isSelected targetId subTreeOutParams } [ nodeText { isSelected: isSelected targetId valAction
, name: " " <> name , name: " " <> name
} }
] ]
...@@ -122,15 +122,16 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt ...@@ -122,15 +122,16 @@ subTreeTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.subTreeTreeViewCpt" cpt
clickable = if validNodeType then "clickable" else "" clickable = if validNodeType then "clickable" else ""
sbto@( subTreeOutParams /\ setSubTreeOut) = subTreeOut ( valAction /\ setAction) = action
isSelected n sbtop = case sbtop of isSelected n action = case (subTreeOut action) of
Nothing -> false Nothing -> false
(Just (SubTreeOut {out})) -> n == out (Just (SubTreeOut {out})) -> n == out
onClick _ = mkEffectFn1 $ \_ -> case validNodeType of onClick _ = mkEffectFn1 $ \_ -> case validNodeType of
false -> setSubTreeOut (const Nothing) false -> setAction (const $ setTreeOut valAction Nothing)
true -> setSubTreeOut (const $ Just $ SubTreeOut { in: id, out:targetId}) true -> setAction (const $ setTreeOut valAction (Just $ SubTreeOut { in: id, out:targetId}))
-------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------
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