Rename.purs 1.15 KB
Newer Older
1
module Gargantext.Components.Forest.Tree.Node.Action.Rename where
2

3

4 5
import Gargantext.Prelude

6
import Data.Generic.Rep (class Generic)
7
import Data.Maybe (Maybe(..))
8
import Data.Newtype (class Newtype)
9
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
10
import Gargantext.Config.REST (AffRESTError)
11
import Gargantext.Routes as GR
12
import Gargantext.Sessions (Session, put)
13 14
import Gargantext.Types (ID)
import Gargantext.Types as GT
15
import Simple.JSON as JSON
16

17
------------------------------------------------------------------------
18
rename :: Session -> ID -> RenameValue -> AffRESTError (Array ID)
19
rename session renameNodeId =
20
  put session $ GR.NodeAPI GT.Node (Just renameNodeId) "rename"
21

22 23 24 25
renameAction :: String -> Action
renameAction newName = RenameNode newName

------------------------------------------------------------------------
26
newtype RenameValue = RenameValue
27
  { text :: String }
28 29 30 31
derive instance Generic RenameValue _
derive instance Newtype RenameValue _
instance JSON.WriteForeign RenameValue where
  writeImpl (RenameValue {text}) = JSON.writeImpl { name: text }
32

33
------------------------------------------------------------------------