Commit 9a759b06 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[tree] some more props cleanup

parent f5589c05
......@@ -104,13 +104,17 @@ toHtml { frontends
pure $ H.ul {}
[ H.li {}
( [ nodeMainSpan pAction { id
, asyncTasks
, mCurrentRoute
, name
, nodeType
, onAsyncTaskFinish
} folderOpen session frontends ]
( [ nodeMainSpan { id
, asyncTasks
, dispatch: pAction
, folderOpen
, frontends
, mCurrentRoute
, name
, nodeType
, onAsyncTaskFinish
, session
} ]
<> childNodes {children: ary, folderOpen, frontends, mCurrentRoute, openNodes, reload, session }
)
]
......
......@@ -16,19 +16,21 @@ import Reactix.DOM.HTML as H
-- START Create Node
type Dispatch = Action -> Aff Unit
data NodePopup = CreatePopup | NodePopup
type CreateNodeProps =
( id :: ID
, dispatch :: Dispatch
, name :: Name
, nodeType :: NodeType
, nodeTypes :: Array NodeType
)
createNodeView :: (Action -> Aff Unit)
-> Record CreateNodeProps
-> Array NodeType
createNodeView :: Record CreateNodeProps
-> R.Element
createNodeView d p@{nodeType} nodeTypes = R.createElement el p []
createNodeView p@{ dispatch, nodeType, nodeTypes } = R.createElement el p []
where
el = R.hooksComponent "CreateNodeView" cpt
cpt {id, name} _ = do
......@@ -95,7 +97,7 @@ createNodeView d p@{nodeType} nodeTypes = R.createElement el p []
, onClick: mkEffectFn1 $ \_ -> do
-- TODO
--setPopupOpen $ const Nothing
launchAff $ d $ CreateSubmit name' nt
launchAff $ dispatch $ CreateSubmit name' nt
} [H.text "Add"]
]
......
......@@ -12,14 +12,19 @@ import Gargantext.Types (NodeType)
import Gargantext.Utils.Reactix as R2
type Dispatch = Action -> Aff Unit
-- | START Rename Box
type RenameBoxProps =
( id :: ID
, dispatch :: Dispatch
, name :: Name
, nodeType :: NodeType)
, nodeType :: NodeType
, renameBoxOpen :: R.State Boolean
)
renameBox :: (Action -> Aff Unit) -> Record RenameBoxProps -> R.State Boolean -> R.Element
renameBox d p (true /\ setRenameBoxOpen) = R.createElement el p []
renameBox :: Record RenameBoxProps -> R.Element
renameBox p@{ dispatch, renameBoxOpen: (true /\ setRenameBoxOpen) } = R.createElement el p []
where
el = R.hooksComponent "RenameBox" cpt
cpt {id, name, nodeType} _ = do
......@@ -44,7 +49,7 @@ renameBox d p (true /\ setRenameBoxOpen) = R.createElement el p []
, type: "button"
, onClick: mkEffectFn1 $ \_ -> do
setRenameBoxOpen $ const false
launchAff $ d $ Submit newName
launchAff $ dispatch $ Submit newName
, title: "Rename"
} []
cancelBtn =
......@@ -53,7 +58,7 @@ renameBox d p (true /\ setRenameBoxOpen) = R.createElement el p []
, onClick: mkEffectFn1 $ \_ -> setRenameBoxOpen $ const false
, title: "Cancel"
} []
renameBox _ p (false /\ _) = R.createElement el p []
renameBox p@{ renameBoxOpen: (false /\ _) } = R.createElement el p []
where
el = R.hooksComponent "RenameBox" cpt
cpt {name} _ = pure $ H.div {} []
......
......@@ -3,7 +3,7 @@ module Gargantext.Components.Forest.Tree.Node.Action.Upload where
import Data.Array as A
import Data.Maybe (Maybe(..), fromJust)
import Data.Newtype (class Newtype)
import Data.Tuple (Tuple(..), fst, snd)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff)
......@@ -14,13 +14,12 @@ import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as QP
import Web.File.File as WF
import Web.File.FileReader.Aff (readAsText)
import Gargantext.Prelude
import Gargantext.Prelude (class Show, Unit, bind, const, discard, map, pure, show, unit, void, ($), (&&), (/=), (<>))
import Gargantext.Components.Data.Lang (readLang, Lang(..))
import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), DroppedFile(..), FTree, FileType(..), ID, LNode(..), NTree(..), UploadFile, UploadFileContents(..), readFileType)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session(..), postWwwUrlencoded, get)
......@@ -28,8 +27,10 @@ import Gargantext.Types as GT
import Gargantext.Utils (id)
import Gargantext.Utils.Reactix as R2
type Dispatch = Action -> Aff Unit
type Props =
( dispatch :: Action -> Aff Unit
( dispatch :: Dispatch
, id :: Int
, nodeType :: GT.NodeType
, session :: Session
......@@ -42,7 +43,7 @@ uploadFileView props = R.createElement uploadFileViewCpt props []
uploadFileViewCpt :: R.Component Props
uploadFileViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
where
cpt {dispatch: d, id, nodeType} _ = do
cpt {dispatch, id, nodeType} _ = do
mFile :: R.State (Maybe UploadFile) <- R.useState' Nothing
fileType :: R.State FileType <- R.useState' CSV
lang :: R.State (Maybe Lang) <- R.useState' (Just EN)
......@@ -71,7 +72,7 @@ uploadFileViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
} (map renderOptionLang [EN, FR])
]
, H.div {} [ uploadButton {action: d, fileType, lang, id, mFile, nodeType } ]
, H.div {} [ uploadButton {dispatch, fileType, lang, id, mFile, nodeType } ]
]
renderOptionFT :: FileType -> R.Element
......@@ -110,7 +111,7 @@ uploadFileViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
type UploadButtonProps =
(
action :: Action -> Aff Unit
dispatch :: Dispatch
, fileType :: R.State FileType
, id :: Int
, lang :: R.State (Maybe Lang)
......@@ -124,7 +125,7 @@ uploadButton props = R.createElement uploadButtonCpt props []
uploadButtonCpt :: R.Component UploadButtonProps
uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt
where
cpt {action, fileType: (fileType /\ setFileType), id, lang: (lang /\ setLang), mFile: (mFile /\ setMFile), nodeType} _ = do
cpt {dispatch, fileType: (fileType /\ setFileType), id, lang: (lang /\ setLang), mFile: (mFile /\ setMFile), nodeType} _ = do
pure $ H.button {className: "btn btn-primary", disabled, on: {click: onClick}} [ H.text "Upload" ]
where
disabled = case mFile of
......@@ -134,7 +135,7 @@ uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt
onClick e = do
let {name, contents} = unsafePartial $ fromJust mFile
void $ launchAff do
_ <- action $ UploadFile nodeType fileType (Just name) contents
_ <- dispatch $ UploadFile nodeType fileType (Just name) contents
liftEffect $ do
setMFile $ const $ Nothing
setFileType $ const $ CSV
......@@ -142,7 +143,7 @@ uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt
-- START File Type View
type FileTypeProps =
( action :: Action -> Aff Unit
( dispatch :: Dispatch
, droppedFile :: R.State (Maybe DroppedFile)
, id :: ID
, isDragOver :: R.State Boolean
......@@ -155,7 +156,7 @@ fileTypeView p = R.createElement fileTypeViewCpt p []
fileTypeViewCpt :: R.Component FileTypeProps
fileTypeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.fileTypeView" cpt
where
cpt {action, droppedFile: (Just (DroppedFile {contents, fileType}) /\ setDroppedFile), isDragOver: (_ /\ setIsDragOver), nodeType} _ = do
cpt {dispatch, droppedFile: (Just (DroppedFile {contents, fileType}) /\ setDroppedFile), isDragOver: (_ /\ setIsDragOver), nodeType} _ = do
pure $ H.div tooltipProps $
[ H.div {className: "panel panel-default"}
[ panelHeading
......@@ -207,7 +208,7 @@ fileTypeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.fileTypeView" cpt
, type: "button"
, on: {click: \_ -> do
setDroppedFile $ const Nothing
launchAff $ action $ UploadFile nodeType ft Nothing contents
launchAff $ dispatch $ UploadFile nodeType ft Nothing contents
}
} [H.text "Upload"]
Nothing ->
......@@ -285,7 +286,7 @@ uploadTermListViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadTermListView" cpt
type UploadTermButtonProps =
(
dispatch :: Action -> Aff Unit
dispatch :: Dispatch
, id :: Int
, mFile :: R.State (Maybe UploadFile)
, nodeType :: GT.NodeType
......
......@@ -40,24 +40,29 @@ import Gargantext.Utils.Reactix as R2
type Dispatch = Action -> Aff Unit
type CommonProps =
(
dispatch :: Dispatch
, session :: Session
)
-- Main Node
type NodeMainSpanProps =
( id :: ID
, asyncTasks :: Array GT.AsyncTaskWithType
, folderOpen :: R.State Boolean
, frontends :: Frontends
, mCurrentRoute :: Maybe AppRoute
, name :: Name
, nodeType :: GT.NodeType
, onAsyncTaskFinish :: GT.AsyncTaskWithType -> Effect Unit
| CommonProps
)
nodeMainSpan :: Dispatch
-> Record NodeMainSpanProps
-> R.State Boolean
-> Session
-> Frontends
nodeMainSpan :: Record NodeMainSpanProps
-> R.Element
nodeMainSpan d p folderOpen session frontends = R.createElement el p []
nodeMainSpan p@{ dispatch, folderOpen, frontends, session } = R.createElement el p []
where
el = R.hooksComponent "G.C.F.T.N.B.NodeMainSpan" cpt
cpt props@{id, asyncTasks, mCurrentRoute, name, nodeType, onAsyncTaskFinish} _ = do
......@@ -81,7 +86,7 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
popOverIcon true
, mNodePopupView props showBox
]
, fileTypeView {action: d, droppedFile, id, isDragOver, nodeType}
, fileTypeView {dispatch, droppedFile, id, isDragOver, nodeType}
, H.div {} (map (\t -> asyncProgressBar { asyncTask: t
, corpusId: id
, onFinish: \_ -> onAsyncTaskFinish t
......@@ -105,7 +110,7 @@ nodeMainSpan d p folderOpen session frontends = R.createElement el p []
mNodePopupView _ false = H.div {} []
mNodePopupView props@{asyncTasks, id, nodeType} true =
nodePopupView { id
, dispatch: d
, dispatch
, name: name' props
, nodeType
, session
......@@ -180,10 +185,9 @@ mCorpusId _ = Nothing
-- | START Popup View
type NodePopupProps =
( id :: ID
, dispatch :: Dispatch
, name :: Name
, nodeType :: GT.NodeType
, session :: Session
| CommonProps
)
type NodePopupS =
......@@ -242,11 +246,11 @@ nodePopupCpt = R.hooksComponent "G.C.F.T.N.B.nodePopupView" cpt
--, style: { top: y - 65.0, left: x + 10.0 }
}
panelHeading renameBoxOpen@(open /\ _) {dispatch: d, id, name, nodeType} =
panelHeading renameBoxOpen@(open /\ _) {dispatch, id, name, nodeType} =
H.div {className: "panel-heading"}
[ R2.row
[ H.div {className: "col-md-8"}
[ renameBox d {id, name, nodeType} renameBoxOpen ]
[ renameBox { dispatch, id, name, nodeType, renameBoxOpen } ]
, H.div {className: "flex-end"}
[ if edit then editIcon renameBoxOpen else H.div {} []
......@@ -431,13 +435,13 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
pure $ R.fragment [
H.div {style: {margin: "10px"}} [H.text "Yes, we are RGPD compliant! But you can not delete User Node yet (we are still on development). Thanks for your comprehensin."]
]
cpt {action: Delete, dispatch: d} _ = do
cpt {action: Delete, dispatch} _ = do
pure $ R.fragment [
H.div {style: {margin: "10px"}} (map (\t -> H.p {} [H.text t]) ["Are your sure you want to delete it ?", "If yes, click again below."])
, reallyDelete d
, reallyDelete dispatch
]
cpt {action: Add xs, dispatch: d, id, name, nodePopup: p, nodeType} _ = do
pure $ createNodeView d {id, name, nodeType} xs
cpt {action: Add xs, dispatch, id, name, nodePopup: p, nodeType} _ = do
pure $ createNodeView {dispatch, id, name, nodeType, nodeTypes: xs}
cpt {action: CopyFromCorpus, dispatch, id, nodeType, session} _ = do
pure $ copyFromCorpusView {dispatch, id, nodeType, session}
cpt _ _ = do
......@@ -446,8 +450,8 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
fragmentPT text = H.div {style: {margin: "10px"}} [H.text text]
onSearch :: Record PanelActionProps -> GT.AsyncTaskWithType -> Effect Unit
onSearch {dispatch: d, nodePopup: p} task = do
_ <- launchAff $ d (SearchQuery task)
onSearch {dispatch, nodePopup: p} task = do
_ <- launchAff $ dispatch (SearchQuery task)
-- close popup
-- TODO
--snd p $ const Nothing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment