Merge.purs 2.36 KB
Newer Older
1
module Gargantext.Components.Forest.Tree.Node.Action.Merge where
2

3
import Data.Maybe (Maybe(..))
4
import Data.Set as Set
5 6
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
7 8 9
import Reactix as R
import Reactix.DOM.HTML as H

10
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
11
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel, checkbox, checkboxes)
12
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
13 14 15 16
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
import Gargantext.Types  as GT
17 18 19
import Gargantext.Utils.Reactix as R2

thisModule = "Gargantext.Components.Forest.Tree.Node.Action.Merge"
20

21 22 23 24
mergeNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
mergeNodeReq session fromId toId =
  put_ session $ NodeAPI GT.Node (Just fromId) ("merge/" <> show toId)

25 26
mergeNode :: Record SubTreeParamsIn -> R.Element
mergeNode p = R.createElement mergeNodeCpt p []
Alexandre Delanoë's avatar
Alexandre Delanoë committed
27

28
mergeNodeCpt :: R.Component SubTreeParamsIn
29
mergeNodeCpt = R.hooksComponentWithModule thisModule "mergeNode" cpt
30
  where
31
    cpt p@{dispatch, subTreeParams, id, nodeType, session, handed} _ = do
32
      action@(valAction /\ setAction) :: R.State Action <- R.useState' (MergeNode {params:Nothing})
Alexandre Delanoë's avatar
Alexandre Delanoë committed
33

34 35
      merge   <- R.useState' false
      options <- R.useState' (Set.singleton GT.MapTerm)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
36

37 38 39 40 41
      let button = case valAction of
            MergeNode {params} -> case params of
              Just val -> submitButton (MergeNode {params: Just val}) dispatch
              Nothing -> H.div {} []
            _                   -> H.div {} []
42

43
      pure $ panel [ subTreeView { action
44 45 46 47 48
                      , dispatch
                      , id
                      , nodeType
                      , session
                      , subTreeParams
49
                      , handed
50
                      }
51 52 53 54 55 56 57 58 59 60
                  , H.div { className:"panel panel-primary"}
                          [ H.text "Merge which list?"
                          , checkboxes [GT.MapTerm, GT.CandidateTerm, GT.StopTerm] options
                          ]
                  , H.div { className:"panel panel-primary"}
                          [ H.text "Title"
                          , H.div {className: "checkbox"}
                                  [checkbox merge, H.text "Merge data?"]
                          ]
                  ] button