Commit e898585b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Table] implement TableResult (with count) in multiple places

DocsTable
Annuaire
Corpus
parent 44ab0a2d
...@@ -48,7 +48,7 @@ annotatedFieldComponent :: R.Component Props ...@@ -48,7 +48,7 @@ annotatedFieldComponent :: R.Component Props
annotatedFieldComponent = R.hooksComponent "AnnotatedField" cpt annotatedFieldComponent = R.hooksComponent "AnnotatedField" cpt
where where
cpt {ngrams,setTermList,text} _ = do cpt {ngrams,setTermList,text} _ = do
menu /\ setMenu <- R.useState $ const Nothing mMenu@(_ /\ setMenu) <- R.useState $ const Nothing
let wrapperProps = let wrapperProps =
{ className: "annotated-field-wrapper" } { className: "annotated-field-wrapper" }
...@@ -70,7 +70,7 @@ annotatedFieldComponent = R.hooksComponent "AnnotatedField" cpt ...@@ -70,7 +70,7 @@ annotatedFieldComponent = R.hooksComponent "AnnotatedField" cpt
runs = runs =
HTML.div { className: "annotated-field-runs" } $ map annotateRun compiled HTML.div { className: "annotated-field-runs" } $ map annotateRun compiled
pure $ HTML.div wrapperProps [maybeAddMenu setMenu runs menu] pure $ HTML.div wrapperProps [maybeAddMenu mMenu runs]
-- forall e. IsMouseEvent e => R2.Setter (Maybe AnnotationMenu) -> R2.Setter ? -> ? -> e -> Effect Unit -- forall e. IsMouseEvent e => R2.Setter (Maybe AnnotationMenu) -> R2.Setter ? -> ? -> e -> Effect Unit
...@@ -89,16 +89,17 @@ maybeShowMenu setMenu setTermList ngrams event = do ...@@ -89,16 +89,17 @@ maybeShowMenu setMenu setTermList ngrams event = do
setTermList n list t setTermList n list t
setMenu (const Nothing) setMenu (const Nothing)
E.preventDefault event E.preventDefault event
range <- Sel.getRange sel 0
log2 "[maybeShowMenu] selection range" $ Sel.rangeToTuple range
setMenu (const $ Just { x, y, list, menuType: NewNgram, setList }) setMenu (const $ Just { x, y, list, menuType: NewNgram, setList })
Nothing -> pure unit Nothing -> pure unit
maybeAddMenu maybeAddMenu
:: R2.Setter (Maybe AnnotationMenu) :: R.State (Maybe AnnotationMenu)
-> R.Element -> R.Element
-> Maybe AnnotationMenu
-> R.Element -> R.Element
maybeAddMenu setMenu e (Just props) = annotationMenu setMenu props <> e maybeAddMenu (Just props /\ setMenu) e = annotationMenu setMenu props <> e
maybeAddMenu _ e _ = e maybeAddMenu _ e = e
compile :: NgramsTable -> Maybe String -> Array (Tuple String (Maybe TermList)) compile :: NgramsTable -> Maybe String -> Array (Tuple String (Maybe TermList))
compile ngrams = maybe [] (highlightNgrams CTabTerms ngrams) compile ngrams = maybe [] (highlightNgrams CTabTerms ngrams)
......
...@@ -34,7 +34,7 @@ import Gargantext.Utils.Reactix as R2 ...@@ -34,7 +34,7 @@ import Gargantext.Utils.Reactix as R2
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Routes (AppRoute, SessionRoute(NodeAPI)) import Gargantext.Routes (AppRoute, SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, post, delete, put) import Gargantext.Sessions (Session, sessionId, post, delete, put)
import Gargantext.Types (NodeType(..), OrderBy(..), TabType, TabPostQuery(..)) import Gargantext.Types (NodeType(..), OrderBy(..), TabType, TabPostQuery(..), AffTableResult)
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Category = Trash | UnRead | Checked | Topic | Favorite data Category = Trash | UnRead | Checked | Topic | Favorite
...@@ -339,7 +339,7 @@ loadPage session {nodeId, tabType, query, listId, corpusId, params: {limit, offs ...@@ -339,7 +339,7 @@ loadPage session {nodeId, tabType, query, listId, corpusId, params: {limit, offs
, orderBy: convOrderBy orderBy , orderBy: convOrderBy orderBy
, tabType , tabType
, query , query
}) :: Aff {count :: Int, docs :: Array Response} }) :: AffTableResult Response
let docs = res2corpus <$> res.docs let docs = res2corpus <$> res.docs
pure $ pure $
if mock then if mock then
......
...@@ -15,7 +15,7 @@ import Gargantext.Ends (url, Frontends) ...@@ -15,7 +15,7 @@ import Gargantext.Ends (url, Frontends)
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, sessionId, get) import Gargantext.Sessions (Session, sessionId, get)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..), AffTableResult, TableResult)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
newtype IndividuView = newtype IndividuView =
...@@ -25,8 +25,8 @@ newtype IndividuView = ...@@ -25,8 +25,8 @@ newtype IndividuView =
, role :: String , role :: String
, company :: String } , company :: String }
toRows :: AnnuaireTable -> Array (Maybe Contact) --toRows :: AnnuaireTable -> Array (Maybe Contact)
toRows (AnnuaireTable a) = a.annuaireTable --toRows (AnnuaireTable a) = a.annuaireTable
-- | Top level layout component. Loads an annuaire by id and renders -- | Top level layout component. Loads an annuaire by id and renders
-- | the annuaire using the result -- | the annuaire using the result
...@@ -100,7 +100,7 @@ type PageProps = ...@@ -100,7 +100,7 @@ type PageProps =
, frontends :: Frontends , frontends :: Frontends
, pagePath :: R.State PagePath , pagePath :: R.State PagePath
-- , info :: AnnuaireInfo -- , info :: AnnuaireInfo
, table :: AnnuaireTable , table :: TableResult Contact
) )
page :: Record PageProps -> R.Element page :: Record PageProps -> R.Element
...@@ -110,12 +110,11 @@ pageCpt :: R.Component PageProps ...@@ -110,12 +110,11 @@ pageCpt :: R.Component PageProps
pageCpt = R.hooksComponent "LoadedAnnuairePage" cpt pageCpt = R.hooksComponent "LoadedAnnuairePage" cpt
where where
cpt { session, pagePath, frontends cpt { session, pagePath, frontends
, table: (AnnuaireTable {annuaireTable})} _ = do , table: ({count: totalRecords, docs})} _ = do
pure $ T.table { rows, params, container, colNames, totalRecords, wrapColElts } pure $ T.table { rows, params, container, colNames, totalRecords, wrapColElts }
where where
totalRecords = 4361 -- TODO
path = fst pagePath path = fst pagePath
rows = (\c -> {row: contactCells session frontends (fst pagePath).nodeId c, delete: false}) <$> annuaireTable rows = (\c -> {row: contactCells session frontends (fst pagePath).nodeId c, delete: false}) <$> docs
container = T.defaultContainer { title: "Annuaire" } -- TODO container = T.defaultContainer { title: "Annuaire" } -- TODO
colNames = T.ColumnName <$> [ "", "Name", "Company", "Service", "Role"] colNames = T.ColumnName <$> [ "", "Name", "Company", "Service", "Role"]
wrapColElts = const identity wrapColElts = const identity
...@@ -125,8 +124,8 @@ pageCpt = R.hooksComponent "LoadedAnnuairePage" cpt ...@@ -125,8 +124,8 @@ pageCpt = R.hooksComponent "LoadedAnnuairePage" cpt
type AnnuaireId = Int type AnnuaireId = Int
contactCells :: Session -> Frontends -> AnnuaireId -> Maybe Contact -> Array R.Element contactCells :: Session -> Frontends -> AnnuaireId -> Contact -> Array R.Element
contactCells session frontends aId = maybe [] render contactCells session frontends aId = render
where where
render (Contact { id, hyperdata : (HyperdataContact contact@{who: who, ou:ou} ) }) = render (Contact { id, hyperdata : (HyperdataContact contact@{who: who, ou:ou} ) }) =
--let nodepath = NodePath (sessionId session) NodeContact (Just id) --let nodepath = NodePath (sessionId session) NodeContact (Just id)
...@@ -190,16 +189,16 @@ instance decodeAnnuaireInfo :: DecodeJson AnnuaireInfo where ...@@ -190,16 +189,16 @@ instance decodeAnnuaireInfo :: DecodeJson AnnuaireInfo where
} }
newtype AnnuaireTable = AnnuaireTable { annuaireTable :: Array (Maybe Contact)} --newtype AnnuaireTable = AnnuaireTable { annuaireTable :: Array (Maybe Contact)}
instance decodeAnnuaireTable :: DecodeJson AnnuaireTable where --instance decodeAnnuaireTable :: DecodeJson AnnuaireTable where
decodeJson json = do -- decodeJson json = do
rows <- decodeJson json -- rows <- decodeJson json
pure $ AnnuaireTable { annuaireTable : rows} -- pure $ AnnuaireTable { annuaireTable : rows}
------------------------------------------------------------------------ ------------------------------------------------------------------------
loadPage :: Session -> PagePath -> Aff AnnuaireTable loadPage :: Session -> PagePath -> AffTableResult Contact
loadPage session {nodeId, params: { offset, limit, orderBy }} = loadPage session {nodeId, params: { offset, limit, orderBy }} =
get session children get session children
-- TODO orderBy -- TODO orderBy
......
...@@ -10,7 +10,7 @@ import Reactix as R ...@@ -10,7 +10,7 @@ import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..), HyperdataList) import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Types (NodeType(..)) import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Routes (SessionRoute(NodeAPI, Children)) import Gargantext.Routes (SessionRoute(NodeAPI, Children))
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
...@@ -77,8 +77,8 @@ loadCorpus {session, nodeId: listId} = do ...@@ -77,8 +77,8 @@ loadCorpus {session, nodeId: listId} = do
-- fetch corpus via lists parentId -- fetch corpus via lists parentId
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get session nodePolyRoute (NodePoly {parentId: corpusId} :: NodePoly {}) <- get session nodePolyRoute
corpusNode <- get session $ corpusNodeRoute corpusId "" corpusNode <- get session $ corpusNodeRoute corpusId ""
defaultListIds <- get session $ defaultListIdsRoute corpusId defaultListIds <- (get session $ defaultListIdsRoute corpusId) :: forall a. DecodeJson a => AffTableResult (NodePoly a)
case (head defaultListIds :: Maybe (NodePoly HyperdataList)) of case (head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) -> Just (NodePoly { id: defaultListId }) ->
pure {corpusId, corpusNode, defaultListId} pure {corpusId, corpusNode, defaultListId}
Nothing -> Nothing ->
......
...@@ -4,6 +4,7 @@ import Prelude ...@@ -4,6 +4,7 @@ import Prelude
import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJson, (:=), (~>), jsonEmptyObject) import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJson, (:=), (~>), jsonEmptyObject)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Effect.Aff (Aff)
import Prim.Row (class Union) import Prim.Row (class Union)
import URI.Query (Query) import URI.Query (Query)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
...@@ -405,3 +406,6 @@ derive instance genericTabType :: Generic TabType _ ...@@ -405,3 +406,6 @@ derive instance genericTabType :: Generic TabType _
instance showTabType :: Show TabType where instance showTabType :: Show TabType where
show = genericShow show = genericShow
type TableResult a = {count :: Int, docs :: Array a}
type AffTableResult a = Aff (TableResult a)
...@@ -3,6 +3,7 @@ module Gargantext.Utils.Selection where ...@@ -3,6 +3,7 @@ module Gargantext.Utils.Selection where
import Prelude import Prelude
import Data.Maybe (Maybe, maybe) import Data.Maybe (Maybe, maybe)
import Data.Nullable (Nullable, toMaybe) import Data.Nullable (Nullable, toMaybe)
import Data.Tuple (Tuple(..))
import DOM.Simple.Types (Element, DOMRect) import DOM.Simple.Types (Element, DOMRect)
import DOM.Simple.Element as Element import DOM.Simple.Element as Element
import Effect (Effect) import Effect (Effect)
...@@ -43,6 +44,10 @@ selectionToString s = s ... "toString" $ [] ...@@ -43,6 +44,10 @@ selectionToString s = s ... "toString" $ []
rangeToString :: Range -> String rangeToString :: Range -> String
rangeToString s = s ... "toString" $ [] rangeToString s = s ... "toString" $ []
--- | Convert range to an offset tuple
rangeToTuple :: Range -> Tuple Int Int
rangeToTuple r = Tuple (r .. "startOffset") (r .. "endOffset")
-- | Whether the anchor and focus are at the same point -- | Whether the anchor and focus are at the same point
isRangeCollapsed :: Range -> Boolean isRangeCollapsed :: Range -> Boolean
isRangeCollapsed r = r .. "isCollapsed" isRangeCollapsed r = r .. "isCollapsed"
......
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