Commit afb7c223 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams table] fix for versioned table total rows count

The pagination on ngramstable is still broken – pages > 1 don't render
any results even if network analysis shows data wasn't empty.
parent 82659ac2
...@@ -14,7 +14,7 @@ import Data.Lens.Index (ix) ...@@ -14,7 +14,7 @@ import Data.Lens.Index (ix)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), isNothing, maybe) import Data.Maybe (Maybe(..), fromMaybe, isNothing, maybe)
import Data.Monoid.Additive (Additive(..)) import Data.Monoid.Additive (Additive(..))
import Data.Ord.Down (Down(..)) import Data.Ord.Down (Down(..))
import Data.Sequence (Seq, length) as Seq import Data.Sequence (Seq, length) as Seq
...@@ -290,14 +290,15 @@ type CommonProps = ( ...@@ -290,14 +290,15 @@ type CommonProps = (
) )
type Props = ( type Props = (
path :: R.State PageParams mTotalRows :: Maybe Int
, path :: R.State PageParams
, state :: R.State State , state :: R.State State
, versioned :: VersionedNgramsTable , versioned :: VersionedNgramsTable
| CommonProps | CommonProps
) )
loadedNgramsTable :: Record Props -> R.Element loadedNgramsTable :: R2.Component Props
loadedNgramsTable p = R.createElement loadedNgramsTableCpt p [] loadedNgramsTable = R.createElement loadedNgramsTableCpt
where where
loadedNgramsTableCpt :: R.Component Props loadedNgramsTableCpt :: R.Component Props
loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" cpt loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable" cpt
...@@ -305,6 +306,7 @@ loadedNgramsTable p = R.createElement loadedNgramsTableCpt p [] ...@@ -305,6 +306,7 @@ loadedNgramsTable p = R.createElement loadedNgramsTableCpt p []
cpt { afterSync cpt { afterSync
, appReload , appReload
, asyncTasksRef , asyncTasksRef
, mTotalRows
, path: path@(path'@{ listIds, nodeId, params, searchQuery, scoreType, termListFilter, termSizeFilter } /\ setPath) , path: path@(path'@{ listIds, nodeId, params, searchQuery, scoreType, termListFilter, termSizeFilter } /\ setPath)
, sidePanelTriggers , sidePanelTriggers
, state: (state@{ ngramsChildren , state: (state@{ ngramsChildren
...@@ -399,7 +401,7 @@ loadedNgramsTable p = R.createElement loadedNgramsTableCpt p [] ...@@ -399,7 +401,7 @@ loadedNgramsTable p = R.createElement loadedNgramsTableCpt p []
commitPatch (Versioned {version: ngramsVersion, data: pt}) (state /\ setState) commitPatch (Versioned {version: ngramsVersion, data: pt}) (state /\ setState)
performAction (CoreAction a) = coreDispatch path' (state /\ setState) a performAction (CoreAction a) = coreDispatch path' (state /\ setState) a
totalRecords = Seq.length rows totalRecords = fromMaybe (Seq.length rows) mTotalRows
filteredConvertedRows :: T.Rows filteredConvertedRows :: T.Rows
filteredConvertedRows = convertRow <$> filteredRows filteredConvertedRows = convertRow <$> filteredRows
filteredRows :: PreConversionRows filteredRows :: PreConversionRows
...@@ -520,8 +522,8 @@ type MainNgramsTableProps = ( ...@@ -520,8 +522,8 @@ type MainNgramsTableProps = (
| CommonProps | CommonProps
) )
mainNgramsTable :: Record MainNgramsTableProps -> R.Element mainNgramsTable :: R2.Component MainNgramsTableProps
mainNgramsTable props = R.createElement mainNgramsTableCpt props [] mainNgramsTable = R.createElement mainNgramsTableCpt
where where
mainNgramsTableCpt :: R.Component MainNgramsTableProps mainNgramsTableCpt :: R.Component MainNgramsTableProps
mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt mainNgramsTableCpt = R.hooksComponentWithModule thisModule "mainNgramsTable" cpt
...@@ -552,7 +554,7 @@ mainNgramsTable props = R.createElement mainNgramsTableCpt props [] ...@@ -552,7 +554,7 @@ mainNgramsTable props = R.createElement mainNgramsTableCpt props []
, tabNgramType , tabNgramType
, treeReloadRef , treeReloadRef
, versioned , versioned
, withAutoUpdate } , withAutoUpdate } []
useLoaderWithCacheAPI { useLoaderWithCacheAPI {
cacheEndpoint: versionEndpoint props cacheEndpoint: versionEndpoint props
, handleResponse , handleResponse
...@@ -562,22 +564,23 @@ mainNgramsTable props = R.createElement mainNgramsTableCpt props [] ...@@ -562,22 +564,23 @@ mainNgramsTable props = R.createElement mainNgramsTableCpt props []
} }
(NT.CacheOff /\ _) -> do (NT.CacheOff /\ _) -> do
-- pathS <- R.useState' path -- pathS <- R.useState' path
let render versioned = mainNgramsTablePaintNoCache { afterSync let render versionedWithCount = mainNgramsTablePaintNoCache { afterSync
, appReload , appReload
, asyncTasksRef , asyncTasksRef
, pathS , pathS
, sidePanelTriggers , sidePanelTriggers
, tabNgramType , tabNgramType
, treeReloadRef , treeReloadRef
, versioned , versionedWithCount
, withAutoUpdate } , withAutoUpdate } []
useLoader (fst pathS) loader render useLoader (fst pathS) loader render
-- NOTE With cache on
versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version
versionEndpoint { defaultListId, nodeId, session, tabType } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId) versionEndpoint { defaultListId, nodeId, session, tabType } _ = get session $ R.GetNgramsTableVersion { listId: defaultListId, tabType } (Just nodeId)
-- NOTE With cache off -- NOTE With cache off
loader :: PageParams -> Aff VersionedNgramsTable loader :: PageParams -> Aff VersionedWithCountNgramsTable
loader path@{ listIds loader path@{ listIds
, nodeId , nodeId
, params: { limit, offset, orderBy } , params: { limit, offset, orderBy }
...@@ -623,8 +626,8 @@ type MainNgramsTablePaintProps = ( ...@@ -623,8 +626,8 @@ type MainNgramsTablePaintProps = (
| CommonProps | CommonProps
) )
mainNgramsTablePaint :: Record MainNgramsTablePaintProps -> R.Element mainNgramsTablePaint :: R2.Component MainNgramsTablePaintProps
mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p [] mainNgramsTablePaint = R.createElement mainNgramsTablePaintCpt
where where
mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps mainNgramsTablePaintCpt :: R.Component MainNgramsTablePaintProps
mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaint" cpt mainNgramsTablePaintCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaint" cpt
...@@ -643,6 +646,7 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p [] ...@@ -643,6 +646,7 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p []
pure $ loadedNgramsTable { afterSync pure $ loadedNgramsTable { afterSync
, appReload , appReload
, asyncTasksRef , asyncTasksRef
, mTotalRows: Nothing
, path: pathS , path: pathS
, sidePanelTriggers , sidePanelTriggers
, state , state
...@@ -650,20 +654,20 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p [] ...@@ -650,20 +654,20 @@ mainNgramsTablePaint p = R.createElement mainNgramsTablePaintCpt p []
, treeReloadRef , treeReloadRef
, versioned , versioned
, withAutoUpdate , withAutoUpdate
} } []
type MainNgramsTablePaintNoCacheProps = type MainNgramsTablePaintNoCacheProps =
( pathS :: R.State PageParams ( pathS :: R.State PageParams
, versioned :: VersionedNgramsTable , versionedWithCount :: VersionedWithCountNgramsTable
| CommonProps | CommonProps
) )
mainNgramsTablePaintNoCache :: Record MainNgramsTablePaintNoCacheProps -> R.Element mainNgramsTablePaintNoCache :: R2.Component MainNgramsTablePaintNoCacheProps
mainNgramsTablePaintNoCache p = R.createElement mainNgramsTablePaintNoCacheCpt p [] mainNgramsTablePaintNoCache = R.createElement mainNgramsTablePaintNoCacheCpt
mainNgramsTablePaintNoCacheCpt :: R.Component MainNgramsTablePaintNoCacheProps
mainNgramsTablePaintNoCacheCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaintNoCache" cpt
where where
mainNgramsTablePaintNoCacheCpt :: R.Component MainNgramsTablePaintNoCacheProps
mainNgramsTablePaintNoCacheCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaintNoCache" cpt
cpt props@{ afterSync cpt props@{ afterSync
, appReload , appReload
, asyncTasksRef , asyncTasksRef
...@@ -671,14 +675,17 @@ mainNgramsTablePaintNoCacheCpt = R.hooksComponentWithModule thisModule "mainNgra ...@@ -671,14 +675,17 @@ mainNgramsTablePaintNoCacheCpt = R.hooksComponentWithModule thisModule "mainNgra
, sidePanelTriggers , sidePanelTriggers
, tabNgramType , tabNgramType
, treeReloadRef , treeReloadRef
, versioned , versionedWithCount
, withAutoUpdate } _ = do , withAutoUpdate } _ = do
let count /\ versioned = toVersioned versionedWithCount
state <- R.useState' $ initialState versioned state <- R.useState' $ initialState versioned
pure $ loadedNgramsTable { pure $ loadedNgramsTable {
afterSync afterSync
, appReload , appReload
, asyncTasksRef , asyncTasksRef
, mTotalRows: Just count
, path: pathS , path: pathS
, sidePanelTriggers , sidePanelTriggers
, state , state
...@@ -686,35 +693,7 @@ mainNgramsTablePaintNoCacheCpt = R.hooksComponentWithModule thisModule "mainNgra ...@@ -686,35 +693,7 @@ mainNgramsTablePaintNoCacheCpt = R.hooksComponentWithModule thisModule "mainNgra
, treeReloadRef , treeReloadRef
, versioned , versioned
, withAutoUpdate , withAutoUpdate
} } []
-- type MainNgramsTablePaintWithStateProps = (
-- afterSync :: Unit -> Aff Unit
-- , asyncTasksRef :: R.Ref (Maybe GAT.Reductor)
-- , path :: R.State PageParams
-- , tabNgramType :: CTabNgramType
-- , versioned :: VersionedNgramsTable
-- , withAutoUpdate :: Boolean
-- )
-- mainNgramsTablePaintWithState :: Record MainNgramsTablePaintWithStateProps -> R.Element
-- mainNgramsTablePaintWithState p = R.createElement mainNgramsTablePaintWithStateCpt p []
-- mainNgramsTablePaintWithStateCpt :: R.Component MainNgramsTablePaintWithStateProps
-- mainNgramsTablePaintWithStateCpt = R.hooksComponentWithModule thisModule "mainNgramsTablePaintWithState" cpt
-- where
-- cpt { afterSync, asyncTasksRef, path, tabNgramType, versioned, withAutoUpdate } _ = do
-- state <- R.useState' $ initialState versioned
-- pure $ loadedNgramsTable {
-- afterSync
-- , asyncTasksRef
-- , path
-- , state
-- , tabNgramType
-- , versioned
-- , withAutoUpdate
-- }
type NgramsOcc = { occurrences :: Additive Int, children :: Set NgramsTerm } type NgramsOcc = { occurrences :: Additive Int, children :: Set NgramsTerm }
......
...@@ -18,9 +18,13 @@ module Gargantext.Components.NgramsTable.Core ...@@ -18,9 +18,13 @@ module Gargantext.Components.NgramsTable.Core
, findNgramTermList , findNgramTermList
, Version , Version
, Versioned(..) , Versioned(..)
, Count
, VersionedWithCount(..)
, toVersioned
, VersionedNgramsPatches , VersionedNgramsPatches
, AsyncNgramsChartsUpdate , AsyncNgramsChartsUpdate
, VersionedNgramsTable , VersionedNgramsTable
, VersionedWithCountNgramsTable
, NgramsTablePatch , NgramsTablePatch
, NgramsPatch(..) , NgramsPatch(..)
, CoreState , CoreState
...@@ -164,6 +168,32 @@ instance decodeJsonVersioned :: DecodeJson a => DecodeJson (Versioned a) where ...@@ -164,6 +168,32 @@ instance decodeJsonVersioned :: DecodeJson a => DecodeJson (Versioned a) where
version <- obj .: "version" version <- obj .: "version"
data_ <- obj .: "data" data_ <- obj .: "data"
pure $ Versioned {version, data: data_} pure $ Versioned {version, data: data_}
------------------------------------------------------------------------
type Count = Int
newtype VersionedWithCount a = VersionedWithCount
{ version :: Version
, count :: Count
, data :: a
}
instance encodeJsonVersionedWithCount :: EncodeJson a => EncodeJson (VersionedWithCount a) where
encodeJson (VersionedWithCount {count, version, data: data_})
= "version" := version
~> "count" := count
~> "data" := data_
~> jsonEmptyObject
instance decodeJsonVersionedWithCount :: DecodeJson a => DecodeJson (VersionedWithCount a) where
decodeJson json = do
obj <- decodeJson json
count <- obj .: "count"
data_ <- obj .: "data"
version <- obj .: "version"
pure $ VersionedWithCount {count, version, data: data_}
toVersioned :: forall a. VersionedWithCount a -> Tuple Count (Versioned a)
toVersioned (VersionedWithCount { count, data: d, version }) = Tuple count $ Versioned { data: d, version }
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO replace by NgramsPatches directly -- TODO replace by NgramsPatches directly
...@@ -535,6 +565,7 @@ highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 = ...@@ -535,6 +565,7 @@ highlightNgrams ntype table@(NgramsTable {ngrams_repo_elements: elts}) input0 =
----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
type VersionedNgramsTable = Versioned NgramsTable type VersionedNgramsTable = Versioned NgramsTable
type VersionedWithCountNgramsTable = VersionedWithCount NgramsTable
----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
data Replace a data Replace a
......
...@@ -21,6 +21,7 @@ import Gargantext.Components.Nodes.Texts.Types as TTypes ...@@ -21,6 +21,7 @@ import Gargantext.Components.Nodes.Texts.Types as TTypes
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType(..), NodeID, PTabNgramType(..), TabType(..), TabSubType(..)) import Gargantext.Types (CTabNgramType(..), NodeID, PTabNgramType(..), TabType(..), TabSubType(..))
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Reload as GUR
thisModule :: String thisModule :: String
...@@ -80,9 +81,9 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt ...@@ -80,9 +81,9 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
where where
tabs' trg = tabs' trg =
[ "Documents" /\ docs trg [ "Documents" /\ docs trg
, "Patents" /\ ngramsView patentsView , "Patents" /\ ngramsView patentsView []
, "Books" /\ ngramsView booksView , "Books" /\ ngramsView booksView []
, "Communication" /\ ngramsView commView , "Communication" /\ ngramsView commView []
, "Trash" /\ docs trg -- TODO pass-in trash mode , "Trash" /\ docs trg -- TODO pass-in trash mode
] ]
where where
...@@ -141,12 +142,12 @@ type NgramsViewTabsProps = ( ...@@ -141,12 +142,12 @@ type NgramsViewTabsProps = (
, treeReloadRef :: GUR.ReloadWithInitializeRef , treeReloadRef :: GUR.ReloadWithInitializeRef
) )
ngramsView :: Record NgramsViewTabsProps -> R.Element ngramsView :: R2.Component NgramsViewTabsProps
ngramsView props = R.createElement ngramsViewCpt props [] ngramsView = R.createElement ngramsViewCpt
ngramsViewCpt :: R.Component NgramsViewTabsProps
ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
where where
ngramsViewCpt :: R.Component NgramsViewTabsProps
ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
cpt { appReload cpt { appReload
, asyncTasksRef , asyncTasksRef
, cacheState , cacheState
...@@ -172,7 +173,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt ...@@ -172,7 +173,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
, tabNgramType , tabNgramType
, treeReloadRef , treeReloadRef
, withAutoUpdate: false , withAutoUpdate: false
} } []
where where
tabNgramType = modeTabType' mode tabNgramType = modeTabType' mode
tabType = TabPairing $ TabNgramType $ modeTabType mode tabType = TabPairing $ TabNgramType $ modeTabType mode
...@@ -130,7 +130,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt ...@@ -130,7 +130,7 @@ ngramsViewCpt = R.hooksComponentWithModule thisModule "ngramsView" cpt
, tabType , tabType
, treeReloadRef , treeReloadRef
, withAutoUpdate: false , withAutoUpdate: false
} } []
] ]
) )
where where
......
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