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