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
137
Issues
137
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
af59716b
Commit
af59716b
authored
Jul 24, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DocsTable] refactor thermite -> reactix
parent
a357a2d7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
145 deletions
+119
-145
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+119
-145
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
af59716b
...
@@ -16,30 +16,33 @@ import Data.HTTP.Method (Method(..))
...
@@ -16,30 +16,33 @@ import Data.HTTP.Method (Method(..))
import Data.Lens
import Data.Lens
import Data.Lens.At (at)
import Data.Lens.At (at)
import Data.Lens.Record (prop)
import Data.Lens.Record (prop)
import Data.Map (Map)
import Data.Map (Map
, insert
)
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), maybe)
import Data.Set (Set)
import Data.Set (Set)
import Data.Set as Set
import Data.Set as Set
import Data.Int (fromString)
import Data.Int (fromString)
import Data.Symbol (SProxy(..))
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff (Aff
, launchAff
)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Effect.Uncurried (mkEffectFn1)
import React as React
import React as React
import React (ReactClass, ReactElement, Children)
import React (ReactClass, ReactElement, Children)
import Reactix as R
import Reactix.DOM.HTML as H
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
------------------------------------------------------------------------
------------------------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, TabPostQuery(..), toUrl, toLink)
import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, TabPostQuery(..), toUrl, toLink)
import Gargantext.Config.REST (get, put, post, deleteWithBody, delete)
import Gargantext.Config.REST (get, put, post, deleteWithBody, delete)
import Gargantext.Components.Loader
as Loader
import Gargantext.Components.Loader
2 (useLoader)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Utils.DecodeMaybe ((.|))
import Gargantext.Utils.DecodeMaybe ((.|))
import Gargantext.Router as R
import Gargantext.Utils.Reactix as R2
import React.DOM (a, br', button, div, i, input, p, text)
import Gargantext.Router as Router
import React.DOM.Props (_type, className, href, onClick, onChange, placeholder, style, checked, target)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_, simpleSpec, hideState)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_, simpleSpec, hideState)
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -77,26 +80,25 @@ type Props =
...
@@ -77,26 +80,25 @@ type Props =
-- ngramtable. Let's see how this evolves.
-- ngramtable. Let's see how this evolves.
}
}
type State =
type PageLoaderProps =
{ documentIdsDeleted :: Set Int
{ nodeId :: Int
, localCategories :: Map Int Category
, totalRecords :: Int
, mQuery :: Maybe String
, tabType :: TabType
, listId :: Int
, corpusId :: Maybe Int
, mQuery :: MQuery
}
}
initialState :: State
type DocumentIdsDeleted = Set Int
initialState =
type LocalCategories = Map Int Category
{ documentIdsDeleted: mempty
type MQuery = Maybe String
, localCategories: mempty
, mQuery: Nothing
}
_documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted")
_documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted")
_localCategories = prop (SProxy :: SProxy "localCategories")
_localCategories = prop (SProxy :: SProxy "localCategories")
data Action
data Action
= MarkCategory Int Category
= MarkCategory Int Category
| TrashAll
| ChangeQuery (Maybe String)
newtype DocumentsView
newtype DocumentsView
= DocumentsView
= DocumentsView
...
@@ -155,64 +157,51 @@ instance decodeResponse :: DecodeJson Response where
...
@@ -155,64 +157,51 @@ instance decodeResponse :: DecodeJson Response where
pure $ Response { cid, category: decodeCategory favorite, ngramCount, hyperdata }
pure $ Response { cid, category: decodeCategory favorite, ngramCount, hyperdata }
docViewSpec :: Spec {} Props Void
-- | Filter
docViewSpec = R2.elSpec $ R.hooksComponent "DocView" cpt
filterSpec :: forall state props action. Spec state props action
filterSpec = simpleSpec defaultPerformAction render
where
where
render d p s c = []
cpt p _children = do
documentIdsDeleted <- R.useState' (mempty :: DocumentIdsDeleted)
localCategories <- R.useState' (mempty :: LocalCategories)
mQuery <- R.useState' (Nothing :: MQuery)
tableParams <- R.useState' T.initialParams
docViewSpec :: Spec {} Props Void
pure $ layoutDocview documentIdsDeleted localCategories mQuery tableParams p
docViewSpec = hideState (const initialState) layoutDocview
-- | Main layout of the Documents Tab of a Corpus
-- | Main layout of the Documents Tab of a Corpus
layoutDocview ::
Spec State Props Action
layoutDocview ::
R.State DocumentIdsDeleted -> R.State LocalCategories -> R.State MQuery -> R.State T.Params -> Props -> R.Element
layoutDocview
= simpleSpec performAction render
layoutDocview
documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories (mQuery /\ setMQuery) tableParams@(params /\ _) p = R.createElement el p []
where
where
performAction :: PerformAction State Props Action
el = R.hooksComponent "LayoutDocView" cpt
performAction (MarkCategory nid cat) {nodeId} _ = do
cpt {nodeId, tabType, listId, corpusId, totalRecords, chart} _children = do
modifyState_ $ _localCategories <<< at nid ?~ cat
pure $ H.div {className: "container1"}
void $ lift $ putCategories nodeId $ CategoryQuery {nodeIds: [nid], category: cat}
[ H.div {className: "row"}
performAction TrashAll {nodeId} {documentIdsDeleted} = do
[ R2.buff chart
ids <- lift $ deleteAllDocuments nodeId
, H.div {}
modifyState_ $ _ {documentIdsDeleted = Set.union documentIdsDeleted $ Set.fromFoldable ids}
[ H.input { type: "text"
performAction (ChangeQuery mQuery) _ _ = do
, onChange: onChangeQuery
modifyState_ $ _ {mQuery = mQuery}
, placeholder: maybe "" identity mQuery}
render :: Render State Props Action
render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} state@{mQuery} _ =
[
div [className "container1"]
[ div [className "row"]
[ chart
, div []
[
input [ _type "text"
, onChange $ \e -> dispatch $ ChangeQuery $ if (unsafeEventValue e) == "" then Nothing else Just $ unsafeEventValue e
, placeholder $ maybe "" identity mQuery]
]
, div [className "col-md-12"]
[ pageLoader
{ path: initialPageParams {nodeId, tabType, listId, corpusId, mQuery}
, listId
, corpusId
, totalRecords
, state
, dispatch
}
]
]
, div [className "col-md-1 col-md-offset-11"]
, H.div {className: "col-md-12"}
[ button [ className "btn"
[ pageLoader localCategories tableParams {nodeId, totalRecords, tabType, listId, corpusId, mQuery}
, style {backgroundColor: "peru", color : "white", border : "white"}
, onClick $ (\_ -> dispatch TrashAll)
]
[ i [className "glyphitem glyphicon glyphicon-trash"] []
, text "Trash all"
]
]
, H.div {className: "col-md-1 col-md-offset-11"}
[ H.button { className: "btn"
, style: {backgroundColor: "peru", color : "white", border : "white"}
, onClick: onClickTrashAll nodeId
}
[ H.i {className: "glyphitem glyphicon glyphicon-trash"} []
, H.text "Trash all"
]
]
]
]
]
]
]
]
onChangeQuery = mkEffectFn1 $ \e -> do
setMQuery $ const $ if (unsafeEventValue e) == "" then Nothing else Just $ unsafeEventValue e
onClickTrashAll nodeId = mkEffectFn1 $ \_ -> do
launchAff $ deleteAllDocuments nodeId
-- TODO
-- setDocumentIdsDeleted $ \dids -> Set.union dids (Set.fromFoldable ids)
mock :: Boolean
mock :: Boolean
mock = false
mock = false
...
@@ -224,10 +213,6 @@ type PageParams = { nodeId :: Int
...
@@ -224,10 +213,6 @@ type PageParams = { nodeId :: Int
, mQuery :: Maybe String
, mQuery :: Maybe String
, params :: T.Params}
, params :: T.Params}
initialPageParams :: {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType, mQuery :: Maybe String} -> PageParams
initialPageParams {nodeId, listId, corpusId, tabType, mQuery} =
{nodeId, tabType, mQuery, listId, corpusId, params: T.initialParams}
loadPage :: PageParams -> Aff (Array DocumentsView)
loadPage :: PageParams -> Aff (Array DocumentsView)
loadPage {nodeId, tabType, mQuery, listId, corpusId, params: {limit, offset, orderBy}} = do
loadPage {nodeId, tabType, mQuery, listId, corpusId, params: {limit, offset, orderBy}} = do
logs "loading documents page: loadPage with Offset and limit"
logs "loading documents page: loadPage with Offset and limit"
...
@@ -264,34 +249,24 @@ loadPage {nodeId, tabType, mQuery, listId, corpusId, params: {limit, offset, ord
...
@@ -264,34 +249,24 @@ loadPage {nodeId, tabType, mQuery, listId, corpusId, params: {limit, offset, ord
convOrderBy _ = DateAsc -- TODO
convOrderBy _ = DateAsc -- TODO
type PageLoaderProps row =
renderPage :: R.State LocalCategories -> R.State T.Params -> PageLoaderProps -> Array DocumentsView -> R.Element
{ path :: PageParams
renderPage (localCategories /\ setLocalCategories) (_ /\ setTableParams) p res = R.createElement el p []
, totalRecords :: Int
where
, dispatch :: Action -> Effect Unit
el = R.hooksComponent "RenderPage" cpt
, state :: State
, listId :: Int
, corpusId :: Maybe Int
| row
}
renderPage :: forall props path.
gi Favorite = "glyphicon glyphicon-star"
Render (Loader.State {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType, mQuery :: Maybe String | path} (Array DocumentsView))
gi _ = "glyphicon glyphicon-star-empty"
{ totalRecords :: Int
trashStyle Trash = {textDecoration: "line-through"}
, dispatch :: Action -> Effect Unit
trashStyle _ = {textDecoration: "none"}
, state :: State
getCategory {_id, category} = maybe category identity (localCategories ^. at _id)
, listId :: Int
corpusDocument (Just corpusId) = Router.CorpusDocument corpusId
, corpusId :: Maybe Int
corpusDocument _ = Router.Document
| props
}
cpt {nodeId, corpusId, listId} _children = do
(Loader.Action PageParams)
pure $ R2.buff $ T.tableElt
renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner
renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
, state: {documentIdsDeleted, localCategories}}
{currentPath: {nodeId, tabType, mQuery}, loaded: Just res} _ =
[
T.tableElt
{ rows
{ rows
, setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, mQuery})
-- , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, mQuery})
, setParams: \params -> setTableParams $ const params
, container: T.defaultContainer { title: "Documents" }
, container: T.defaultContainer { title: "Documents" }
, colNames:
, colNames:
T.ColumnName <$>
T.ColumnName <$>
...
@@ -301,47 +276,46 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
...
@@ -301,47 +276,46 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
, "Title"
, "Title"
, "Source"
, "Source"
]
]
, totalRecords
-- , totalRecords
, totalRecords: 1000 -- TODO
}
}
]
where
where
gi Favorite = "glyphicon glyphicon-star"
gi _ = "glyphicon glyphicon-star-empty"
trashStyle Trash = style {textDecoration: "line-through"}
trashStyle _ = style {textDecoration: "none"}
getCategory {_id, category} = maybe category identity (localCategories ^. at _id)
corpusDocument (Just corpusId) = R.CorpusDocument corpusId
corpusDocument _ = R.Document
rows = (\(DocumentsView r) ->
rows = (\(DocumentsView r) ->
let cat = getCategory r
let cat = getCategory r
isDel = Trash == cat in
isDel = Trash == cat in
{ row:
{ row: map R2.scuff $ [
[ div []
H.div {}
[ a [ className $ gi cat
[ H.a { className: gi cat
, trashStyle cat
, style: trashStyle cat
, onClick $ \_-> dispatch $ MarkCategory r._id $ favCategory cat
, onClick: onClick Favorite r._id cat
] []
} []
]
, input [ _type "checkbox"
, checked isDel
, onClick $ \_ -> dispatch $ MarkCategory r._id $ trashCategory cat
]
]
, H.input { type: "checkbox"
, checked: isDel
, onClick: onClick Trash r._id cat
}
-- TODO show date: Year-Month-Day only
-- TODO show date: Year-Month-Day only
, div [ trashStyle cat ][text (show r.date)
]
, H.div { style: trashStyle cat } [ H.text (show r.date)
]
, a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, H.a { href: toLink $ (corpusDocument corpusId) listId r._id
,
trashStyle cat
, style:
trashStyle cat
, target
"_blank"
, target:
"_blank"
] [
text r.title ]
} [ H.
text r.title ]
, div [trashStyle cat] [
text r.source ]
, H.div { style: trashStyle cat} [ H.
text r.source ]
]
]
, delete: true
, delete: true
}) <$> res
}) <$> res
onClick catType nid cat = mkEffectFn1 $ \_-> do
let newCat = if (catType == Favorite) then (favCategory cat) else (trashCategory cat)
setLocalCategories $ insert nid newCat
void $ launchAff $ putCategories nodeId $ CategoryQuery {nodeIds: [nid], category: newCat}
pageLoaderClass :: ReactClass (PageLoaderProps (children :: Children))
pageLoader :: R.State LocalCategories -> R.State T.Params -> PageLoaderProps -> R.Element
pageLoaderClass = Loader.createLoaderClass' "PageLoader" loadPage renderPage
pageLoader localCategories tableParams@(pageParams /\ _) p = R.createElement el p []
where
pageLoader :: PageLoaderProps () -> ReactElement
el = R.hooksComponent "PageLoader" cpt
pageLoader props = React.createElement pageLoaderClass props []
cpt p@{nodeId, listId, corpusId, tabType, mQuery} _children = do
useLoader {nodeId, listId, corpusId, tabType, mQuery, params: pageParams} loadPage $ \{loaded} ->
renderPage localCategories tableParams p loaded
---------------------------------------------------------
---------------------------------------------------------
sampleData' :: DocumentsView
sampleData' :: DocumentsView
...
...
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