Commit b134255c authored by Nicolas Pouillard's avatar Nicolas Pouillard Committed by Alexandre Delanoë

[NGRAMS-TABLE] add the Versioned type to follow the API change

parent a913e33d
...@@ -4,6 +4,9 @@ module Gargantext.Components.NgramsTable ...@@ -4,6 +4,9 @@ module Gargantext.Components.NgramsTable
, PatchMap , PatchMap
, NgramsPatch , NgramsPatch
, NgramsTable , NgramsTable
, VersionedNgramsTable
, Version
, Versioned(..)
, Action , Action
, initialPageParams , initialPageParams
, initialState , initialState
...@@ -55,7 +58,7 @@ type PageParams mode = {nodeId :: Int, params :: T.Params, mode :: mode} ...@@ -55,7 +58,7 @@ type PageParams mode = {nodeId :: Int, params :: T.Params, mode :: mode}
initialPageParams :: forall mode. Int -> mode -> PageParams mode initialPageParams :: forall mode. Int -> mode -> PageParams mode
initialPageParams nodeId mode = {nodeId, params: T.initialParams, mode} initialPageParams nodeId mode = {nodeId, params: T.initialParams, mode}
type Props' mode = Loader.InnerProps (PageParams mode) NgramsTable () type Props' mode = Loader.InnerProps (PageParams mode) VersionedNgramsTable ()
type NgramsTerm = String type NgramsTerm = String
...@@ -87,6 +90,20 @@ instance decodeJsonNgramsElement :: DecodeJson NgramsElement where ...@@ -87,6 +90,20 @@ instance decodeJsonNgramsElement :: DecodeJson NgramsElement where
let children = Set.fromFoldable (children' :: Array NgramsTerm) let children = Set.fromFoldable (children' :: Array NgramsTerm)
pure $ NgramsElement {ngrams, list, occurrences, parent, children} pure $ NgramsElement {ngrams, list, occurrences, parent, children}
type Version = Int
newtype Versioned a = Versioned
{ version :: Version
, data :: a
}
instance decodeJsonVersioned :: DecodeJson a => DecodeJson (Versioned a) where
decodeJson json = do
obj <- decodeJson json
version <- obj .? "version"
data_ <- obj .? "data"
pure $ Versioned {version, data: data_}
-- type NgramsTable = Array (NTree NgramsElement) -- type NgramsTable = Array (NTree NgramsElement)
-- type NgramsTable = Array NgramsElement -- type NgramsTable = Array NgramsElement
newtype NgramsTable = NgramsTable (Map NgramsTerm NgramsElement) newtype NgramsTable = NgramsTable (Map NgramsTerm NgramsElement)
...@@ -111,6 +128,8 @@ instance decodeJsonNgramsTable :: DecodeJson NgramsTable where ...@@ -111,6 +128,8 @@ instance decodeJsonNgramsTable :: DecodeJson NgramsTable where
where where
f e@(NgramsElement e') = Tuple e'.ngrams e f e@(NgramsElement e') = Tuple e'.ngrams e
type VersionedNgramsTable = Versioned NgramsTable
data Replace a data Replace a
= Keep = Keep
| Replace { old :: a, new :: a } | Replace { old :: a, new :: a }
...@@ -424,10 +443,12 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -424,10 +443,12 @@ ngramsTableSpec = simpleSpec performAction render
render :: Render State (Props' mode) Action render :: Render State (Props' mode) Action
render dispatch { path: {nodeId, mode} render dispatch { path: {nodeId, mode}
, loaded: initTable , loaded: Versioned { version, data: initTable }
, dispatch: loaderDispatch } , dispatch: loaderDispatch }
{ ngramsTablePatch, ngramsParent, ngramsChildren, searchQuery } { ngramsTablePatch, ngramsParent, ngramsChildren, searchQuery }
_reactChildren = _reactChildren
| version /= 1 = [ p [] [text "Invalid version"] ]
| otherwise =
[ T.tableElt [ T.tableElt
{ rows { rows
, setParams: \params -> loaderDispatch (Loader.SetPath {nodeId, params, mode}) , setParams: \params -> loaderDispatch (Loader.SetPath {nodeId, params, mode})
......
...@@ -31,7 +31,7 @@ type Props = NT.Props Contact Mode ...@@ -31,7 +31,7 @@ type Props = NT.Props Contact Mode
type PageParams = NT.PageParams Mode type PageParams = NT.PageParams Mode
getTable :: PTabNgramType -> Maybe Int -> Offset -> Limit -> Aff NT.NgramsTable getTable :: PTabNgramType -> Maybe Int -> Offset -> Limit -> Aff NT.VersionedNgramsTable
getTable tab nodeId offset limit = getTable tab nodeId offset limit =
get $ toUrl Back (Ngrams (TabPairing (TabNgramType tab)) get $ toUrl Back (Ngrams (TabPairing (TabNgramType tab))
offset limit Nothing) nodeId offset limit Nothing) nodeId
...@@ -41,18 +41,18 @@ modeTabType Patents = PTabPatents ...@@ -41,18 +41,18 @@ modeTabType Patents = PTabPatents
modeTabType Books = PTabBooks modeTabType Books = PTabBooks
modeTabType Communication = PTabCommunication modeTabType Communication = PTabCommunication
loadPage :: PageParams -> Aff NT.NgramsTable loadPage :: PageParams -> Aff NT.VersionedNgramsTable
loadPage {nodeId, mode, params: {offset, limit}} = loadPage {nodeId, mode, params: {offset, limit}} =
getTable (modeTabType mode) (Just nodeId) offset limit getTable (modeTabType mode) (Just nodeId) offset limit
-- TODO this ignores orderBy -- TODO this ignores orderBy
ngramsLoaderClass :: Loader.LoaderClass PageParams NT.NgramsTable ngramsLoaderClass :: Loader.LoaderClass PageParams NT.VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "ContactsNgramsLoader" loadPage ngramsLoaderClass = Loader.createLoaderClass "ContactsNgramsLoader" loadPage
ngramsLoader :: Loader.Props' PageParams NT.NgramsTable -> ReactElement ngramsLoader :: Loader.Props' PageParams NT.VersionedNgramsTable -> ReactElement
ngramsLoader props = React.createElement ngramsLoaderClass props [] ngramsLoader props = React.createElement ngramsLoaderClass props []
ngramsTableClass :: Loader.InnerClass PageParams NT.NgramsTable ngramsTableClass :: Loader.InnerClass PageParams NT.VersionedNgramsTable
ngramsTableClass = createClass "ContactsNgramsTable" NT.ngramsTableSpec NT.initialState ngramsTableClass = createClass "ContactsNgramsTable" NT.ngramsTableSpec NT.initialState
ngramsTableSpec :: Spec {} Props Void ngramsTableSpec :: Spec {} Props Void
......
...@@ -31,7 +31,7 @@ type Props = NT.Props (NodePoly CorpusInfo) Mode ...@@ -31,7 +31,7 @@ type Props = NT.Props (NodePoly CorpusInfo) Mode
type PageParams = NT.PageParams Mode type PageParams = NT.PageParams Mode
getTable :: CTabNgramType -> Maybe Int -> Offset -> Limit -> Aff NT.NgramsTable getTable :: CTabNgramType -> Maybe Int -> Offset -> Limit -> Aff NT.VersionedNgramsTable
getTable tab nodeId offset limit = getTable tab nodeId offset limit =
get $ toUrl Back (Ngrams (TabCorpus (TabNgramType tab)) get $ toUrl Back (Ngrams (TabCorpus (TabNgramType tab))
offset limit Nothing) nodeId offset limit Nothing) nodeId
...@@ -42,18 +42,18 @@ modeTabType Sources = CTabSources ...@@ -42,18 +42,18 @@ modeTabType Sources = CTabSources
modeTabType Institutes = CTabInstitutes modeTabType Institutes = CTabInstitutes
modeTabType Terms = CTabTerms modeTabType Terms = CTabTerms
loadPage :: PageParams -> Aff NT.NgramsTable loadPage :: PageParams -> Aff NT.VersionedNgramsTable
loadPage {nodeId, mode, params: {offset, limit}} = loadPage {nodeId, mode, params: {offset, limit}} =
getTable (modeTabType mode) (Just nodeId) offset limit getTable (modeTabType mode) (Just nodeId) offset limit
-- TODO this ignores orderBy -- TODO this ignores orderBy
ngramsLoaderClass :: Loader.LoaderClass PageParams NT.NgramsTable ngramsLoaderClass :: Loader.LoaderClass PageParams NT.VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "CorpusNgramsLoader" loadPage ngramsLoaderClass = Loader.createLoaderClass "CorpusNgramsLoader" loadPage
ngramsLoader :: Loader.Props' PageParams NT.NgramsTable -> ReactElement ngramsLoader :: Loader.Props' PageParams NT.VersionedNgramsTable -> ReactElement
ngramsLoader props = React.createElement ngramsLoaderClass props [] ngramsLoader props = React.createElement ngramsLoaderClass props []
ngramsTableClass :: Loader.InnerClass PageParams NT.NgramsTable ngramsTableClass :: Loader.InnerClass PageParams NT.VersionedNgramsTable
ngramsTableClass = createClass "CorpusNgramsTable" NT.ngramsTableSpec NT.initialState ngramsTableClass = createClass "CorpusNgramsTable" NT.ngramsTableSpec NT.initialState
ngramsTableSpec :: Spec {} Props Void ngramsTableSpec :: Spec {} Props Void
......
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