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

3 4 5
import Gargantext.Prelude

import Data.Either (Either)
6
import Data.Maybe (Maybe(..))
7
import Data.Set as Set
8
import Effect.Aff (Aff)
9 10
import Reactix as R
import Reactix.DOM.HTML as H
11
import Toestand as T
12

13
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
14
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel, checkbox, checkboxesListGroup)
15
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
16
import Gargantext.Config.REST (RESTError)
17 18
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
19
import Gargantext.Types as GT
20 21
import Gargantext.Utils.Reactix as R2

22
here :: R2.Here
23
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Merge"
24

25
mergeNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Either RESTError (Array GT.ID))
26 27 28
mergeNodeReq session fromId toId =
  put_ session $ NodeAPI GT.Node (Just fromId) ("merge/" <> show toId)

29 30 31
mergeNode :: R2.Component SubTreeParamsIn
mergeNode = R.createElement mergeNodeCpt
mergeNodeCpt :: R.Component SubTreeParamsIn
32
mergeNodeCpt = here.component "mergeNode" cpt
33
  where
34
    cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
35 36
      action <- T.useBox (MergeNode { params: Nothing })
      action' <- T.useLive T.unequal action
Alexandre Delanoë's avatar
Alexandre Delanoë committed
37

38 39
      merge   <- T.useBox false
      options <- T.useBox (Set.singleton GT.MapTerm)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
40

41
      let button = case action' of
42 43 44 45
            MergeNode {params} -> case params of
              Just val -> submitButton (MergeNode {params: Just val}) dispatch
              Nothing -> H.div {} []
            _                   -> H.div {} []
46

47 48
      pure $ panel
        [ subTreeView { action
49
                      , boxes
50 51 52 53 54
                      , dispatch
                      , id
                      , nodeType
                      , session
                      , subTreeParams
55
                      } []
56 57 58
                  , H.ul { className:"merge mx-auto list-group"}
                     ([ H.li { className: "list-group-item" }
                       [ H.h5 { className: "mb-1" } [ H.text "Merge which list?" ]
59 60
                       , checkboxesListGroup { groups: [ GT.MapTerm, GT.CandidateTerm, GT.StopTerm ]
                                             , options } []
61
                       ]
62
                     ])
63 64 65 66 67 68
                  , H.ul { className:"merge mx-auto list-group"}
                     [ H.li { className: "list-group-item" }
                       [ H.h5 { className: "mb-1" } [ H.text "Title" ]
                       ]
                     , H.li { className: "list-group-item" }
                       [ H.div { className: " form-check" }
69
                         [ checkbox { value: merge }
70 71 72 73 74 75
                         , H.label { className: "form-check-label" } [ H.text "Merge data?" ]
                         ]
                       ]
                     ]
                  ]
                  button