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

[tree] some more props cleanup

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