Commit c86fd7e8 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[doc] some decode/encode json types for docs table

parent 3fbee957
...@@ -30,6 +30,7 @@ import Reactix.DOM.HTML as H ...@@ -30,6 +30,7 @@ import Reactix.DOM.HTML as H
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Components.Loader (loader) import Gargantext.Components.Loader (loader)
import Gargantext.Ends (Frontends, url) import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoaderWithCache)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Routes (SessionRoute(NodeAPI)) import Gargantext.Routes (SessionRoute(NodeAPI))
...@@ -372,11 +373,13 @@ pageLayout props = R.createElement pageLayoutCpt props [] ...@@ -372,11 +373,13 @@ pageLayout props = R.createElement pageLayoutCpt props []
pageLayoutCpt :: R.Memo PageLayoutProps pageLayoutCpt :: R.Memo PageLayoutProps
pageLayoutCpt = R.memo' $ R.staticComponent "G.C.DocsTable.pageLayout" cpt where pageLayoutCpt = R.memo' $ R.staticComponent "G.C.DocsTable.pageLayout" cpt where
cpt props@{frontends, session, nodeId, listId, corpusId, tabType, query, params} _ = cpt props@{frontends, session, nodeId, listId, corpusId, tabType, query, params} _ =
loader path (loadPage session) paint --loader path (loadPage session) paint
useLoader path keyFunc (loadPage session) paint
where where
path = {nodeId, listId, corpusId, tabType, query, params: fst params} path = {nodeId, listId, corpusId, tabType, query, params: fst params}
paint (Tuple count docs) = page params (newProps count) docs paint (Tuple count docs) = page params (newProps count) docs
newProps count = props { totalRecords = count } newProps count = props { totalRecords = count }
keyFunc { corpusId, listId, nodeId, tabType } = "docs-table-" <> (show corpusId) <> "-" <> (show listId) <> "-" <> (show nodeId) <> "-" <> (show tabType)
type PageProps = type PageProps =
( params :: R.State T.Params ( params :: R.State T.Params
......
...@@ -6,6 +6,7 @@ import Data.Tuple.Nested ((/\)) ...@@ -6,6 +6,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Reactix as R import Reactix as R
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Components.LoadingSpinner (loadingSpinner) import Gargantext.Components.LoadingSpinner (loadingSpinner)
......
...@@ -33,6 +33,7 @@ import Gargantext.Components.LoadingSpinner (loadingSpinner) ...@@ -33,6 +33,7 @@ import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Components.NgramsTable.Components as NTC import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core (Action(..), CoreState, Dispatch, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTerm, PageParams, PatchMap(..), Versioned(..), VersionedNgramsTable, _NgramsElement, _NgramsTable, _children, _list, _ngrams, _occurrences, _root, addNewNgram, applyNgramsPatches, applyPatchSet, commitPatchR, convOrderBy, filterTermSize, fromNgramsPatches, initialPageParams, loadNgramsTableAll, ngramsTermText, normNgram, patchSetFromMap, replace, rootsOf, singletonNgramsTablePatch, syncPatchesR) import Gargantext.Components.NgramsTable.Core (Action(..), CoreState, Dispatch, NgramsElement(..), NgramsPatch(..), NgramsTable, NgramsTerm, PageParams, PatchMap(..), Versioned(..), VersionedNgramsTable, _NgramsElement, _NgramsTable, _children, _list, _ngrams, _occurrences, _root, addNewNgram, applyNgramsPatches, applyPatchSet, commitPatchR, convOrderBy, filterTermSize, fromNgramsPatches, initialPageParams, loadNgramsTableAll, ngramsTermText, normNgram, patchSetFromMap, replace, rootsOf, singletonNgramsTablePatch, syncPatchesR)
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Hooks.Loader (useLoaderWithCache)
import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, pure, show, unit, (#), ($), (&&), (/=), (<$>), (<<<), (<>), (=<<), (==), (||), read) import Gargantext.Prelude (class Show, Unit, bind, const, discard, identity, map, mempty, not, pure, show, unit, (#), ($), (&&), (/=), (<$>), (<<<), (<>), (=<<), (==), (||), read)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes) import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
...@@ -500,6 +501,8 @@ mainNgramsTableCpt = R.hooksComponent "G.C.NT.mainNgramsTable" cpt ...@@ -500,6 +501,8 @@ mainNgramsTableCpt = R.hooksComponent "G.C.NT.mainNgramsTable" cpt
mainNgramsTablePaint {path, tabNgramType, versioned, withAutoUpdate} mainNgramsTablePaint {path, tabNgramType, versioned, withAutoUpdate}
Nothing -> loadingSpinner {} Nothing -> loadingSpinner {}
keyFunc { listIds, nodeId, tabType } = "ngrams-table-" <> (show tabType) <> "-" <> (show nodeId) <> "-" <> (show listIds)
type MainNgramsTablePaintProps = type MainNgramsTablePaintProps =
( (
path :: PageParams path :: PageParams
......
...@@ -287,9 +287,10 @@ type ListId = Int ...@@ -287,9 +287,10 @@ type ListId = Int
data ScoreType = Occurrences data ScoreType = Occurrences
derive instance genericScoreType :: Generic ScoreType _ derive instance genericScoreType :: Generic ScoreType _
instance showScoreType :: Show ScoreType where instance showScoreType :: Show ScoreType where
show = genericShow show = genericShow
instance eqScoreType :: Eq ScoreType where
eq = genericEq
type SearchQuery = String type SearchQuery = String
...@@ -425,6 +426,39 @@ data TabSubType a = TabDocs | TabNgramType a | TabTrash | TabMoreLikeFav | TabMo ...@@ -425,6 +426,39 @@ data TabSubType a = TabDocs | TabNgramType a | TabTrash | TabMoreLikeFav | TabMo
derive instance eqTabSubType :: Eq a => Eq (TabSubType a) derive instance eqTabSubType :: Eq a => Eq (TabSubType a)
derive instance ordTabSubType :: Ord a => Ord (TabSubType a) derive instance ordTabSubType :: Ord a => Ord (TabSubType a)
{- instance encodeTabSubType a :: EncodeJson a => EncodeJson (TabSubType a) where
encodeJson TabDocs =
"type" := "TabDocs"
~> "data" := Nothing
~> jsonEmptyObject
encodeJson (TabNgramType a) =
"type" := "TabNgramType"
~> "data" := encodeJson a
~> jsonEmptyObject
encodeJson TabTrash =
"type" := "TabTrash"
~> "data" := Nothing
~> jsonEmptyObject
encodeJson TabMoreLikeFav =
"type" := "TabMoreLikeFav"
~> "data" := Nothing
~> jsonEmptyObject
encodeJson TabMoreLikeTrash =
"type" := "TabMoreLikeTrash"
~> "data" := Nothing
~> jsonEmptyObject
instance decodeTabSubType a :: DecodeJson a => DecodeJson (TabSubType a) where
decodeJson j = do
obj <- decodeJson j
typ <- obj .: "type"
dat <- obj .: "data"
case typ of
"TabDocs" -> TabDocs
"TabNgramType" -> TabNgramType dat
"TabTrash" -> TabTrash
"TabMoreLikeFav" -> TabMoreLikeFav
"TabMoreLikeTrash" -> TabMoreLikeTrash
_ -> Left ("Unknown type '" <> typ <> "'") -}
instance showTabSubType :: Show a => Show (TabSubType a) where instance showTabSubType :: Show a => Show (TabSubType a) where
show TabDocs = "Docs" show TabDocs = "Docs"
...@@ -438,13 +472,34 @@ data TabType ...@@ -438,13 +472,34 @@ data TabType
| TabPairing (TabSubType PTabNgramType) | TabPairing (TabSubType PTabNgramType)
| TabDocument (TabSubType CTabNgramType) | TabDocument (TabSubType CTabNgramType)
derive instance genericTabType :: Generic TabType _
derive instance eqTabType :: Eq TabType derive instance eqTabType :: Eq TabType
derive instance ordTabType :: Ord TabType derive instance ordTabType :: Ord TabType
derive instance genericTabType :: Generic TabType _
instance showTabType :: Show TabType where instance showTabType :: Show TabType where
show = genericShow show = genericShow
{- instance encodeTabType :: EncodeJson TabType where
encodeJson (TabCorpus d) =
"type" := "TabCorpus"
~> "data" := encodeJson d
~> jsonEmptyObject
encodeJson (TabDocument d) =
"type" := "TabDocument"
~> "data" := encodeJson d
~> jsonEmptyObject
encodeJson (TabPairing d) =
"type" := "TabPairing"
~> "data" := encodeJson d
~> jsonEmptyObject
instance decodeTabType :: DecodeJson TabType where
decodeJson j = do
obj <- decodeJson j
typ <- obj .: "type"
dat <- obj .: "data"
case typ of
"TabCorpus" -> TabCorpus dat
"TabDocument" -> TabDocument dat
"TabPairing" -> TabPairing dat
_ -> Left ("Unknown type '" <> typ <> "'") -}
type TableResult a = {count :: Int, docs :: Array a} type TableResult a = {count :: Int, docs :: Array a}
type AffTableResult a = Aff (TableResult a) type AffTableResult a = Aff (TableResult a)
......
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