Commit 872d4941 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[DocsTable] fix tableElt initial state

This was reinitialized after each component refresh. Now state is passed
so that table interaction works (change current page, order by etc).
parent 704f071f
...@@ -261,7 +261,7 @@ loadPage {nodeId, tabType, query, listId, corpusId, params: {limit, offset, orde ...@@ -261,7 +261,7 @@ loadPage {nodeId, tabType, query, listId, corpusId, params: {limit, offset, orde
convOrderBy _ = DateAsc -- TODO convOrderBy _ = DateAsc -- TODO
renderPage :: R.State T.Params -> PageLoaderProps -> Array DocumentsView -> R.Element renderPage :: R.State T.Params -> PageLoaderProps -> Array DocumentsView -> R.Element
renderPage (_ /\ setTableParams) p res = R.createElement el p [] renderPage (tableParams /\ setTableParams) p res = R.createElement el p []
where where
el = R.hooksComponent "RenderPage" cpt el = R.hooksComponent "RenderPage" cpt
...@@ -275,10 +275,11 @@ renderPage (_ /\ setTableParams) p res = R.createElement el p [] ...@@ -275,10 +275,11 @@ renderPage (_ /\ setTableParams) p res = R.createElement el p []
cpt {nodeId, corpusId, listId, totalRecords} _children = do cpt {nodeId, corpusId, listId, totalRecords} _children = do
localCategories <- R.useState' (mempty :: LocalCategories) localCategories <- R.useState' (mempty :: LocalCategories)
pure $ R2.buff $ T.tableElt pure $ R2.buff $ T.tableEltWithInitialState
(T.paramsState tableParams)
{ rows: rows localCategories { rows: rows localCategories
-- , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, query}) -- , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, query})
, setParams: \params -> setTableParams $ const params , setParams: setTableParams <<< const
, container: T.defaultContainer { title: "Documents" } , container: T.defaultContainer { title: "Documents" }
, colNames: , colNames:
T.ColumnName <$> T.ColumnName <$>
......
module Gargantext.Components.Table where module Gargantext.Components.Table where
import Gargantext.Prelude
import Data.Array (filter) import Data.Array (filter)
import Data.Maybe (Maybe(..), maybe)
import Data.Either (Either(..)) import Data.Either (Either(..))
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(..), maybe)
import Effect (Effect) import Effect (Effect)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Utils.Reactix as R2
import React (ReactElement, ReactClass, Children, createElement) import React (ReactElement, ReactClass, Children, createElement)
import React.DOM (a, b, b', p, i, h3, hr, div, option, select, span, table, tbody, td, text, th, thead, tr) import React.DOM (a, b, b', p, i, h3, hr, div, option, select, span, table, tbody, td, text, th, thead, tr)
import React.DOM.Props (className, href, onChange, onClick, scope, selected, value, style) import React.DOM.Props (className, href, onChange, onClick, scope, selected, value, style)
import Thermite (PerformAction, Render, Spec, modifyState_, simpleSpec, StateCoTransformer, createClass) import Thermite (PerformAction, Render, Spec, modifyState_, simpleSpec, StateCoTransformer, createClass)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Prelude
import Gargantext.Utils.Reactix as R2
type TableContainerProps = type TableContainerProps =
{ pageSizeControl :: ReactElement { pageSizeControl :: ReactElement
, pageSizeDescription :: ReactElement , pageSizeDescription :: ReactElement
...@@ -132,7 +132,7 @@ tableSpec = simpleSpec performAction render ...@@ -132,7 +132,7 @@ tableSpec = simpleSpec performAction render
where where
modifyStateAndReload :: (State -> State) -> Props -> State -> StateCoTransformer State Unit modifyStateAndReload :: (State -> State) -> Props -> State -> StateCoTransformer State Unit
modifyStateAndReload f {setParams} state = do modifyStateAndReload f {setParams} state = do
logs "modifyStateAndReload" -- TODO rename --logs "modifyStateAndReload" -- TODO rename
modifyState_ f modifyState_ f
liftEffect $ setParams $ stateParams $ f state liftEffect $ setParams $ stateParams $ f state
...@@ -209,12 +209,23 @@ stateParams {pageSize, currentPage, orderBy} = {offset, limit, orderBy} ...@@ -209,12 +209,23 @@ stateParams {pageSize, currentPage, orderBy} = {offset, limit, orderBy}
limit = pageSizes2Int pageSize limit = pageSizes2Int pageSize
offset = limit * (currentPage - 1) offset = limit * (currentPage - 1)
paramsState :: Params -> State
paramsState {offset, limit, orderBy} = {pageSize, currentPage, orderBy}
where
pageSize = string2PageSize $ show limit
currentPage = (offset / limit) + 1
tableClass :: ReactClass {children :: Children | Props'} tableClass :: ReactClass {children :: Children | Props'}
tableClass = createClass "Table" tableSpec (const initialState) tableClass = createClass "Table" tableSpec (const initialState)
tableElt :: Props -> ReactElement tableElt :: Props -> ReactElement
tableElt props = createElement tableClass props [] tableElt props = createElement tableClass props []
tableEltWithInitialState :: State -> Props -> ReactElement
tableEltWithInitialState state props = createElement tc props []
where
tc = createClass "Table" tableSpec (const state)
sizeDD :: PageSizes -> (Action -> Effect Unit) -> ReactElement sizeDD :: PageSizes -> (Action -> Effect Unit) -> ReactElement
sizeDD ps d sizeDD ps d
= span [] = span []
......
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