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