Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
bced885a
Commit
bced885a
authored
Jun 14, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT] forms
parent
b6b19010
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
40 deletions
+57
-40
Add.purs
src/Gargantext/Components/Forest/Tree/Node/Action/Add.purs
+5
-29
Tools.purs
src/Gargantext/Components/Forest/Tree/Node/Tools.purs
+52
-11
No files found.
src/Gargantext/Components/Forest/Tree/Node/Action/Add.purs
View file @
bced885a
module Gargantext.Components.Forest.Tree.Node.Action.Add where
module Gargantext.Components.Forest.Tree.Node.Action.Add where
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>))
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>))
import Data.Array (
length,
head)
import Data.Array (head)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Effect.Aff (Aff)
import Effect.Uncurried (mkEffectFn1)
import Gargantext.Components.Forest.Tree.Node (SettingsBox(..), settingsBox)
import Gargantext.Components.Forest.Tree.Node (SettingsBox(..), settingsBox)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, formEdit)
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, formEdit
, formChoiceSafe
)
import Gargantext.Prelude (Unit, bind,
const, map, pure, show, ($), (<>), (>), (<<<), read
)
import Gargantext.Prelude (Unit, bind,
pure, show, ($), (<>)
)
import Gargantext.Routes as GR
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, post)
import Gargantext.Sessions (Session, post)
import Gargantext.Types as GT
import Gargantext.Types as GT
import Gargantext.Types (NodeType(..))
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
...
@@ -80,36 +78,14 @@ addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
...
@@ -80,36 +78,14 @@ addNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
]
]
]
]
where
where
maybeChoose = [ formChoiceSafe nodeTypes Error setNodeType ]
SettingsBox {edit} = settingsBox nt
SettingsBox {edit} = settingsBox nt
maybeEdit = [ if edit
maybeEdit = [ if edit
then formEdit "Node Name" setNodeName
then formEdit "Node Name" setNodeName
else H.div {} []
else H.div {} []
]
]
maybeChoose = [ if length nodeTypes > 1 then
R.fragment [
H.div {className: "form-group"} $ [
R2.select { className: "form-control"
, onChange : mkEffectFn1
$ setNodeType
<<< const
<<< fromMaybe Error
<<< read
<<< R2.unsafeEventValue
}
(map (\opt -> H.option {} [ H.text $ show opt ]) nodeTypes)
]
-- , showConfig nt
]
else
H.button { className : "btn btn-primary center"
, type : "button"
, onClick : mkEffectFn1 $ \_ -> setNodeType ( const
$ fromMaybe nt
$ head nodeTypes
)
} []
]
-- END Create Node
-- END Create Node
...
...
src/Gargantext/Components/Forest/Tree/Node/Tools.purs
View file @
bced885a
module Gargantext.Components.Forest.Tree.Node.Tools where
module Gargantext.Components.Forest.Tree.Node.Tools where
import Data.Maybe (fromMaybe)
import Data.String as S
import Data.String as S
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect (Effect)
...
@@ -8,7 +9,7 @@ import Effect.Uncurried (mkEffectFn1)
...
@@ -8,7 +9,7 @@ import Effect.Uncurried (mkEffectFn1)
import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Types (ID)
import Gargantext.Types (ID)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Prelude (Unit, bind, const, discard, pure, show, ($), (<<<), (<>))
import Gargantext.Prelude (Unit, bind, const, discard, pure, show, ($), (<<<), (<>)
, read, map, class Read, class Show
)
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
...
@@ -89,12 +90,7 @@ fragmentPT :: String -> R.Element
...
@@ -89,12 +90,7 @@ fragmentPT :: String -> R.Element
fragmentPT text = H.div {style: {margin: "10px"}} [H.text text]
fragmentPT text = H.div {style: {margin: "10px"}} [H.text text]
-- | Edit input
-- | Form Edit input
-- form ::
-- formEdit :: forall a. String -> R.State a -> R.Element
type DefaultText = String
type DefaultText = String
formEdit :: forall previous next
formEdit :: forall previous next
...
@@ -115,9 +111,54 @@ formEdit defaultValue setter =
...
@@ -115,9 +111,54 @@ formEdit defaultValue setter =
}
}
]
]
-- | Form
-- | Form Choice input
formChoiceSafe :: forall a b c
. Read a
=> Show a
=> Array a
-> a
-> ((b -> a) -> Effect c)
-> R.Element
formChoiceSafe [] _ _ = H.div {} []
formChoiceSafe [n] _defaultNodeType setNodeType =
formButton n setNodeType
formChoiceSafe nodeTypes defaultNodeType setNodeType =
formChoice nodeTypes defaultNodeType setNodeType
formChoice :: forall a b c d
. Read b
=> Show d
=> Array d
-> b
-> ((c -> b) -> Effect a)
-> R.Element
formChoice nodeTypes defaultNodeType setNodeType =
H.div { className: "form-group"}
[ R2.select { className: "form-control"
, onChange : mkEffectFn1
$ setNodeType
<<< const
<<< fromMaybe defaultNodeType
<<< read
<<< R2.unsafeEventValue
}
(map (\opt -> H.option {} [ H.text $ show opt ]) nodeTypes)
]
formButton :: forall a b c
. a
-> ((b -> a) -> Effect c)
-> R.Element
formButton nodeType setNodeType =
H.button { className : "btn btn-primary center"
, type : "button"
, onClick : mkEffectFn1
$ \_ -> setNodeType ( const nodeType)
} []
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment