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

3 4
import Gargantext.Prelude

5
import Data.Maybe (Maybe(..))
6
import Data.Set as Set
7
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
8
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
9
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
10
import Gargantext.Config.REST (AffRESTError)
11 12
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
13
import Gargantext.Types as GT
14
import Gargantext.Utils.Reactix as R2
15 16 17
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
18

19
here :: R2.Here
20
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Merge"
21

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

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

35 36
      merge   <- T.useBox false
      options <- T.useBox (Set.singleton GT.MapTerm)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
37

38
      let button = case action' of
39 40 41 42
            MergeNode { params } ->
              R2.fromMaybe params $
                \val -> Tools.submitButton { action: MergeNode {params: Just val }
                                           , dispatch }
43
            _                   -> H.div {} []
44

45
      pure $ Tools.panel { mError: Nothing }
46
        [ subTreeView { action
47 48 49 50 51
                      , dispatch
                      , id
                      , nodeType
                      , session
                      , subTreeParams
52
                      } []
53
        , H.ul { className:"merge mx-auto list-group"}
54 55 56 57 58 59
          [ H.li { className: "list-group-item" }
            [ H.h5 { className: "mb-1" } [ H.text "Merge which list?" ]
            , Tools.checkboxesListGroup { groups: [ GT.MapTerm, GT.CandidateTerm, GT.StopTerm ]
                                        , options } []
            ]
          ]
60 61 62 63 64 65 66 67 68 69 70 71 72 73
        , 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" }
              [ Tools.checkbox { value: merge }
              , H.label { className: "form-check-label" } [ H.text "Merge data?" ]
              ]
            ]
          ]
          
          -- footer
        , button ]