Commit 606de8e2 authored by James Laver's avatar James Laver

[DEBUG] fix the effect that was the problem

parent 97d89bae
......@@ -274,17 +274,12 @@ page params layout documents = R.createElement pageCpt {params, layout, document
pageCpt :: R.Memo PageProps
pageCpt = R.memo' $ R.hooksComponent "G.C.DocsTable.pageCpt" cpt where
cpt { layout: {session, nodeId, corpusId, listId, totalRecords}
, documents, params: (_ /\ setParams) } _children = do
cpt { layout: {session, nodeId, corpusId, listId, totalRecords}, documents, params } _ = do
localCategories <- R.useState' (mempty :: LocalCategories)
pure $ T.table
{ rows: rows localCategories
-- , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, query})
, setParams: setParams <<< const
, container: T.defaultContainer { title: "Documents" }
, colNames
, totalRecords
}
, params, colNames, totalRecords }
where
sid = sessionId session
gi Favorite = "glyphicon glyphicon-star"
......
......@@ -278,9 +278,10 @@ pageCpt :: R.Component PageProps
pageCpt = R.staticComponent "G.C.FacetsTable.Page" cpt
where
cpt {totalRecords, container, deletions, documents, session, path: path@({nodeId, listId, query} /\ setPath)} _ = do
T.table { rows, container, colNames, totalRecords, setParams }
T.table { rows, container, colNames, totalRecords, params }
where
setParams params = setPath (_ {params = params})
setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
params = (fst path).params /\ setParams
colNames = T.ColumnName <$> [ "", "Date", "Title", "Source", "Authors", "Delete" ]
-- TODO: how to interprete other scores?
gi Favorite = "glyphicon glyphicon-star-empty"
......
......@@ -19,6 +19,7 @@ import Data.Monoid.Additive (Additive(..))
import Data.Ord.Down (Down(..))
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Reactix as R
import Reactix.DOM.HTML as H
......@@ -243,13 +244,14 @@ ngramsTableSpec session ntype setPath = simpleSpec performAction render
{ ngramsTablePatch, ngramsParent, ngramsChildren }
_reactChildren =
[ autoUpdateElt { duration: 3000, effect: dispatch Refresh }
, R2.scuff $ T.table { rows, setParams, container, colNames, totalRecords}
, R2.scuff $ T.table { rows, params, container, colNames, totalRecords}
]
where
totalRecords = 47361 -- TODO
colNames = T.ColumnName <$> ["Map", "Stop", "Terms", "Score (Occurrences)"] -- see convOrderBy
container = tableContainer {pageParams, setPath, dispatch, ngramsParent, ngramsChildren, ngramsTable}
setParams params = setPath $ const (pageParams {params = params})
setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
params = pageParams.params /\ setParams
ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable
orderWith =
case convOrderBy <$> pageParams.params.orderBy of
......
......@@ -5,6 +5,7 @@ import Data.Array (filter)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Reactix as R
......@@ -50,7 +51,7 @@ derive instance eqOrderByDirection :: Eq a => Eq (OrderByDirection a)
type Props =
( colNames :: Array ColumnName
, totalRecords :: Int
, setParams :: Params -> Effect Unit
, params :: R.State Params
, rows :: Rows
, container :: Record TableContainerProps -> R.Element
)
......@@ -124,14 +125,14 @@ table props = R.createElement tableCpt props []
tableCpt :: R.Component Props
tableCpt = R.hooksComponent "Table" cpt
where
cpt {container, colNames, totalRecords, rows, setParams} _ = do
cpt {container, colNames, totalRecords, rows, params} _ = do
(pageSize /\ setPageSize) <- R.useState' PS10
(page /\ setPage) <- R.useState' 1
(orderBy /\ setOrderBy) <- R.useState' Nothing
let state = {pageSize, orderBy, page}
let ps = pageSizes2Int pageSize
let totalPages = (totalRecords / ps) + min 1 (totalRecords `mod` ps)
-- R.useEffect1' state $ setParams (stateParams state)
R.useEffect1' state $ when (fst params /= stateParams state) $ (snd params) (const $ stateParams state)
pure $ container
{ pageSizeControl: sizeDD pageSize setPageSize
, pageSizeDescription: textDescription page pageSize totalRecords
......@@ -139,16 +140,17 @@ tableCpt = R.hooksComponent "Table" cpt
, tableHead: H.tr {} (colHeader setOrderBy orderBy <$> colNames)
, tableBody: map (H.tr {} <<< map (\c -> H.td {} [c]) <<< _.row) rows
}
colHeader :: (R2.Setter OrderBy) -> OrderBy -> ColumnName -> R.Element
colHeader setOrderBy currentOrderBy c = H.th {scope: "col"} [ H.b {} cs ]
where
lnk mc = effectLink (setOrderBy (const mc))
cs :: Array R.Element
cs =
case currentOrderBy of
Just (ASC d) | c == d -> [lnk (Just (DESC c)) "DESC ", lnk Nothing (columnName c)]
Just (DESC d) | c == d -> [lnk (Just (ASC c)) "ASC ", lnk Nothing (columnName c)]
_ -> [lnk (Just (ASC c)) (columnName c)]
where
colHeader :: (R2.Setter OrderBy) -> OrderBy -> ColumnName -> R.Element
colHeader setOrderBy orderBy c = H.th {scope: "col"} [ H.b {} cs ]
where
lnk mc = effectLink (setOrderBy (const mc))
cs :: Array R.Element
cs =
case orderBy of
Just (ASC d) | c == d -> [lnk (Just (DESC c)) "DESC ", lnk Nothing (columnName c)]
Just (DESC d) | c == d -> [lnk (Just (ASC c)) "ASC ", lnk Nothing (columnName c)]
_ -> [lnk (Just (ASC c)) (columnName c)]
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer {title} props = R.fragment
......
......@@ -5,6 +5,7 @@ import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?))
import Data.Array (head)
import Data.Maybe (Maybe(..), maybe)
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Gargantext.Components.Table as T
import Gargantext.Ends (url)
......@@ -101,13 +102,15 @@ pageCpt = R.staticComponent "LoadedAnnuairePage" cpt
where
cpt { session, annuairePath, pagePath
, table: (AnnuaireTable {annuaireTable}) } _ = do
T.table { rows, setParams, container, colNames, totalRecords }
T.table { rows, params, container, colNames, totalRecords }
where
totalRecords = 4361 -- TODO
rows = (\c -> {row: contactCells session c, delete: false}) <$> annuaireTable
setParams params = snd pagePath $ const {params, nodeId: fst annuairePath}
container = T.defaultContainer { title: "Annuaire" } -- TODO
colNames = T.ColumnName <$> [ "", "Name", "Company", "Service", "Role"]
setParams f = snd pagePath $ \{nodeId, params} ->
{params: f params, nodeId: fst annuairePath}
params = T.initialParams /\ setParams
contactCells :: Session -> Maybe Contact -> Array R.Element
contactCells session = maybe [] render
......
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