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
cd2cefc4
Commit
cd2cefc4
authored
Oct 20, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[docs] implement cache off with pagination correctly
parent
414815aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
19 deletions
+89
-19
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+53
-19
Table.purs
src/Gargantext/Components/Table.purs
+4
-0
QueryString.purs
src/Gargantext/Utils/QueryString.purs
+32
-0
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
cd2cefc4
...
...
@@ -11,7 +11,7 @@ import Data.Lens.At (at)
import Data.Lens.Record (prop)
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe, isJust)
import Data.Maybe (Maybe(..), fromMaybe, isJust
, maybe
)
import Data.Ord.Down (Down(..))
import Data.Sequence as Seq
import Data.Set (Set)
...
...
@@ -40,6 +40,7 @@ import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, delete, put)
import Gargantext.Types (NodeType(..), OrderBy(..), TableResult, TabSubType(..), TabType, showTabType')
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.QueryString
import Gargantext.Utils.Reactix as R2
thisModule :: String
...
...
@@ -324,7 +325,7 @@ pageLayoutCpt = R.hooksComponentWithModule thisModule "pageLayout" cpt where
--Tuple 0 (take limit $ drop offset sampleData)
Tuple 0 sampleData
else
Tuple
(A.length docs)
docs
Tuple
res.count
docs
case cacheState of
(NT.CacheOn /\ _) -> do
let paint (Tuple count docs) = page params (props { totalRecords = count }) docs
...
...
@@ -340,13 +341,16 @@ pageLayoutCpt = R.hooksComponentWithModule thisModule "pageLayout" cpt where
, renderer: paint
}
(NT.CacheOff /\ _) -> do
localCategories <- R.useState' (mempty :: LocalCategories)
paramsS <- R.useState' params
let loader p@{ listId, nodeId, tabType } = do
res <- get session $ tableRouteWithPage { listId, nodeId, params: fst paramsS, tabType }
res <- get session $ tableRouteWithPage { listId, nodeId, params: fst paramsS,
query,
tabType }
pure $ handleResponse res
render (Tuple count documents) = pagePaint { documents
, layout: props { totalRecords = count }
, params: paramsS }
render (Tuple count documents) = pagePaintRaw { documents
, layout: props { params = fst paramsS
, totalRecords = count }
, localCategories
, params: paramsS }
useLoader (path { params = fst paramsS }) loader render
type PageProps = (
...
...
@@ -375,8 +379,38 @@ pagePaint props = R.createElement pagePaintCpt props []
pagePaintCpt :: R.Component PagePaintProps
pagePaintCpt = R.hooksComponentWithModule thisModule "pagePaintCpt" cpt where
cpt {
layout: { corpusId, frontends, listId, nodeId, session, totalRecords }, documents
, params } _ = do
cpt {
documents, layout
, params } _ = do
localCategories <- R.useState' (mempty :: LocalCategories)
pure $ pagePaintRaw { documents: A.fromFoldable filteredRows, layout, localCategories, params }
where
orderWith =
case convOrderBy (fst params).orderBy of
Just DateAsc -> Seq.sortWith \(DocumentsView { date }) -> date
Just DateDesc -> Seq.sortWith \(DocumentsView { date }) -> Down date
Just SourceAsc -> Seq.sortWith \(DocumentsView { source }) -> Str.toLower source
Just SourceDesc -> Seq.sortWith \(DocumentsView { source }) -> Down $ Str.toLower source
Just TitleAsc -> Seq.sortWith \(DocumentsView { title }) -> Str.toLower title
Just TitleDesc -> Seq.sortWith \(DocumentsView { title }) -> Down $ Str.toLower title
_ -> identity -- the server ordering is enough here
filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents
type PagePaintRawProps = (
documents :: Array DocumentsView
, layout :: Record PageLayoutProps
, localCategories :: R.State LocalCategories
, params :: R.State T.Params
)
pagePaintRaw :: Record PagePaintRawProps -> R.Element
pagePaintRaw props = R.createElement pagePaintRawCpt props []
pagePaintRawCpt :: R.Component PagePaintRawProps
pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt where
cpt { documents
, layout: { corpusId, frontends, listId, nodeId, session, totalRecords }
, localCategories
, params } _ = do
pure $ T.table
{ colNames
, container: T.defaultContainer { title: "Documents" }
...
...
@@ -397,17 +431,7 @@ pagePaintCpt = R.hooksComponentWithModule thisModule "pagePaintCpt" cpt where
colNames = T.ColumnName <$> [ "Tag", "Date", "Title", "Source"]
wrapColElts = const identity
getCategory (localCategories /\ _) {_id, category} = fromMaybe category (localCategories ^. at _id)
orderWith =
case convOrderBy (fst params).orderBy of
Just DateAsc -> Seq.sortWith \(DocumentsView { date }) -> date
Just DateDesc -> Seq.sortWith \(DocumentsView { date }) -> Down date
Just SourceAsc -> Seq.sortWith \(DocumentsView { source }) -> Str.toLower source
Just SourceDesc -> Seq.sortWith \(DocumentsView { source }) -> Down $ Str.toLower source
Just TitleAsc -> Seq.sortWith \(DocumentsView { title }) -> Str.toLower title
Just TitleDesc -> Seq.sortWith \(DocumentsView { title }) -> Down $ Str.toLower title
_ -> identity -- the server ordering is enough here
filteredRows = T.filterRows { params: fst params } $ orderWith $ A.toUnfoldable documents
rows localCategories = row <$> filteredRows
rows localCategories = row <$> A.toUnfoldable documents
where
row (DocumentsView r) =
{ row:
...
...
@@ -476,8 +500,18 @@ tableHashRoute nodeId tabType = NodeAPI Node (Just nodeId) $ "table/hash" <> "?t
tableRouteWithPage :: { listId :: Int
, nodeId :: Int
, params :: T.Params
, query :: Query
, tabType :: TabType } -> SessionRoute
tableRouteWithPage { listId, nodeId, params: { limit, offset, orderBy, searchType }, tabType } = NodeAPI Node (Just nodeId) $ "table" <> "?tabType=" <> (showTabType' tabType) <> "&list=" <> (show listId) <> "&limit=" <> (show limit) <> "&offset=" <> (show offset) <> "&orderBy=" <> (show orderBy) <> "&searchType=" <> (show searchType)
tableRouteWithPage { listId, nodeId, params: { limit, offset, orderBy, searchType }, query, tabType } =
NodeAPI Node (Just nodeId) $ "table" <> joinQueryStrings [tt, lst, lmt, odb, ofs, st, q]
where
lmt = queryParam "limit" limit
lst = queryParam "list" listId
ofs = queryParam "offset" offset
odb = maybe "" (\o -> "orderBy=" <> (T.orderByToForm o)) orderBy
st = queryParam "searchType" searchType
tt = queryParamS "tabType" (showTabType' tabType)
q = queryParamS "query" query
deleteAllDocuments :: Session -> Int -> Aff (Array Int)
deleteAllDocuments session = delete session <<< documentsRoute
...
...
src/Gargantext/Components/Table.purs
View file @
cd2cefc4
...
...
@@ -61,6 +61,10 @@ instance showOrderByDirection :: Show a => Show (OrderByDirection a) where
derive instance eqOrderByDirection :: Eq a => Eq (OrderByDirection a)
orderByToForm :: OrderByDirection ColumnName -> String
orderByToForm (ASC (ColumnName x)) = x <> "Asc"
orderByToForm (DESC (ColumnName x)) = x <> "Desc"
type Props =
( colNames :: Array ColumnName
, container :: Record TableContainerProps -> R.Element
...
...
src/Gargantext/Utils/QueryString.purs
0 → 100644
View file @
cd2cefc4
module Gargantext.Utils.QueryString where
import Data.Array
import Data.Maybe
import Data.String.Common (joinWith)
import Gargantext.Prelude
queryParam :: forall a. Show a => String -> a -> String
queryParam key value = key <> "=" <> show value
queryParamS :: String -> String -> String
queryParamS key value = key <> "=" <> value
mQueryParam :: forall a. Show a => String -> Maybe a -> String
mQueryParam _ Nothing = ""
mQueryParam key (Just v) = queryParam key v
mQueryParamS :: String -> (String -> String) -> Maybe String -> String
mQueryParamS _ _ Nothing = ""
mQueryParamS key mFunc (Just v) = queryParamS key $ mFunc v
joinQueryStrings :: Array String -> String
joinQueryStrings qs =
case uncons qs of
Nothing -> ""
Just { head, tail } -> "?" <> head <> (joinQS tail)
where
joinQS ys =
case uncons ys of
Nothing -> ""
Just { tail: ys } -> "&" <> (joinWith "&" ys)
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