[NGRAMS-TABLE] filters should be stored in the loader since they impact the loaded URL

parent cacef583
...@@ -66,10 +66,21 @@ type PageParams = ...@@ -66,10 +66,21 @@ type PageParams =
, listIds :: Array Int , listIds :: Array Int
, params :: T.Params , params :: T.Params
, tabType :: TabType , tabType :: TabType
, searchQuery :: String
, termListFilter :: Maybe TermList -- Nothing means all
, termTypeFilter :: Maybe TermType -- Nothing means all
} }
initialPageParams :: Int -> Array Int -> TabType -> PageParams initialPageParams :: Int -> Array Int -> TabType -> PageParams
initialPageParams nodeId listIds tabType = {nodeId, listIds, params: T.initialParams, tabType} initialPageParams nodeId listIds tabType =
{ nodeId
, listIds
, params: T.initialParams
, tabType
, termTypeFilter: Nothing
, termListFilter: Nothing
, searchQuery: ""
}
type Props' = Loader.InnerProps PageParams VersionedNgramsTable () type Props' = Loader.InnerProps PageParams VersionedNgramsTable ()
...@@ -366,9 +377,6 @@ type State = ...@@ -366,9 +377,6 @@ type State =
-- This updates the children of `ngramsParent`, -- This updates the children of `ngramsParent`,
-- ngrams set to `true` are to be added, and `false` to -- ngrams set to `true` are to be added, and `false` to
-- be removed. -- be removed.
, searchQuery :: String
, termListFilter :: Maybe TermList -- Nothing means all
, termTypeFilter :: Maybe TermType -- Nothing means all
} }
_ngramsChildren = prop (SProxy :: SProxy "ngramsChildren") _ngramsChildren = prop (SProxy :: SProxy "ngramsChildren")
...@@ -380,9 +388,6 @@ initialState {loaded: Versioned {version}} = ...@@ -380,9 +388,6 @@ initialState {loaded: Versioned {version}} =
, ngramsVersion: version , ngramsVersion: version
, ngramsParent: Nothing , ngramsParent: Nothing
, ngramsChildren: mempty , ngramsChildren: mempty
, searchQuery: ""
, termListFilter: Nothing
, termTypeFilter: Nothing
} }
data Action data Action
...@@ -397,21 +402,29 @@ data Action ...@@ -397,21 +402,29 @@ data Action
-- ^ The NgramsTable argument is here as a cache of `ngramsTablePatch` -- ^ The NgramsTable argument is here as a cache of `ngramsTablePatch`
-- applied to `initTable`. -- applied to `initTable`.
-- TODO more docs -- TODO more docs
| SetTermListFilter (Maybe TermList)
| SetTermTypeFilter (Maybe TermType)
| SetSearchQuery String
| Refresh | Refresh
type Dispatch = Action -> Effect Unit type Dispatch = Action -> Effect Unit
tableContainer :: { searchQuery :: String type LoaderAction = Loader.Action PageParams
type LoaderDispatch = LoaderAction -> Effect Unit
tableContainer :: { pageParams :: PageParams
, dispatch :: Dispatch , dispatch :: Dispatch
, loaderDispatch :: LoaderDispatch
, ngramsParent :: Maybe NgramsTerm , ngramsParent :: Maybe NgramsTerm
, ngramsChildren :: Map NgramsTerm Boolean , ngramsChildren :: Map NgramsTerm Boolean
, ngramsTable :: NgramsTable , ngramsTable :: NgramsTable
} }
-> T.TableContainerProps -> Array ReactElement -> T.TableContainerProps -> Array ReactElement
tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable: ngramsTableCache} props = tableContainer { pageParams
, dispatch
, loaderDispatch
, ngramsParent
, ngramsChildren
, ngramsTable: ngramsTableCache
} props =
[ div [className "container-fluid"] [ div [className "container-fluid"]
[ div [className "jumbotron1"] [ div [className "jumbotron1"]
[ div [className "row"] [ div [className "row"]
...@@ -427,28 +440,29 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable ...@@ -427,28 +440,29 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable
[ button [_id "ImportListOrSaveAll", className "btn btn-warning", style {fontSize : "120%"}] [ button [_id "ImportListOrSaveAll", className "btn btn-warning", style {fontSize : "120%"}]
[ text "Import a Termlist" ] [ text "Import a Termlist" ]
] ]
, div [className "col-md-4", style {marginTop : "37px"}] ,-}
div [className "col-md-4", style {marginTop : "37px"}]
[ input [ className "form-control " [ input [ className "form-control "
, _id "id_password"
, name "search", placeholder "Search" , name "search", placeholder "Search"
, _type "value" , _type "value"
, value searchQuery , value pageParams.searchQuery
, onInput \e -> dispatch (SetSearchQuery (unsafeEventValue e)) , onInput \e -> setSearchQuery (unsafeEventValue e)
] ]
] ]
,-} , div [_id "filter_terms", className "col-md-6", style{ marginTop : "2.1em",paddingLeft :"1em"}]
div [_id "filter_terms", className "col-md-6", style{ marginTop : "2.1em",paddingLeft :"1em"}]
[ div [className "col-md-10 list-group", style {marginTop : "6px"}] [ div [className "col-md-10 list-group", style {marginTop : "6px"}]
[ li [className " list-group-item"] [ li [className " list-group-item"]
[ select [ _id "picklistmenu" [ select [ _id "picklistmenu"
, className "form-control custom-select" , className "form-control custom-select"
, onChange (\e -> dispatch (SetTermListFilter $ readTermList $ unsafeEventValue e)) -- , value ?
, onChange (\e -> setTermListFilter $ readTermList $ unsafeEventValue e)
] $ map optps1 termLists ] $ map optps1 termLists
] ]
, li [className "list-group-item"] , li [className "list-group-item"]
[ select [ _id "picktermtype" [ select [ _id "picktermtype"
, className "form-control custom-select" , className "form-control custom-select"
, onChange (\e -> dispatch (SetTermTypeFilter $ readTermType $ unsafeEventValue e)) -- , value ?
, onChange (\e -> setTermTypeFilter $ readTermType $ unsafeEventValue e)
] $ map optps1 termTypes ] $ map optps1 termTypes
] ]
, li [className " list-group-item"] [ props.pageSizeControl ] , li [className " list-group-item"] [ props.pageSizeControl ]
...@@ -488,6 +502,11 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable ...@@ -488,6 +502,11 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable
] ]
] ]
] ]
where
setPageParams f = loaderDispatch $ Loader.SetPath $ f pageParams
setSearchQuery x = setPageParams $ _ { searchQuery = x }
setTermListFilter x = setPageParams $ _ { termListFilter = x }
setTermTypeFilter x = setPageParams $ _ { termTypeFilter = x }
putTable :: {nodeId :: Int, listIds :: Array Int, tabType :: TabType} -> Versioned NgramsTablePatch -> Aff (Versioned NgramsTablePatch) putTable :: {nodeId :: Int, listIds :: Array Int, tabType :: TabType} -> Versioned NgramsTablePatch -> Aff (Versioned NgramsTablePatch)
putTable {nodeId, listIds, tabType} = putTable {nodeId, listIds, tabType} =
...@@ -514,9 +533,6 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -514,9 +533,6 @@ ngramsTableSpec = simpleSpec performAction render
setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty } setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty }
performAction :: PerformAction State Props' Action performAction :: PerformAction State Props' Action
performAction (SetTermListFilter c) _ _ = modifyState_ $ _ { termListFilter = c }
performAction (SetTermTypeFilter c) _ _ = modifyState_ $ _ { termTypeFilter = c }
performAction (SetSearchQuery s) _ _ = modifyState_ $ _ { searchQuery = s }
performAction (SetParentResetChildren p) _ _ = performAction (SetParentResetChildren p) _ _ =
modifyState_ $ setParentResetChildren p modifyState_ $ setParentResetChildren p
performAction (ToggleChild b c) _ _ = performAction (ToggleChild b c) _ _ =
...@@ -548,18 +564,18 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -548,18 +564,18 @@ ngramsTableSpec = simpleSpec performAction render
-- patch the root of the child to be equal to the root of the parent. -- patch the root of the child to be equal to the root of the parent.
render :: Render State Props' Action render :: Render State Props' Action
render dispatch { path: {nodeId, listIds, tabType} render dispatch { path: pageParams
, loaded: Versioned { data: initTable } , loaded: Versioned { data: initTable }
, dispatch: loaderDispatch } , dispatch: loaderDispatch }
{ ngramsTablePatch, ngramsParent, ngramsChildren, searchQuery } { ngramsTablePatch, ngramsParent, ngramsChildren }
_reactChildren = _reactChildren =
[ autoUpdateElt { duration: 3000 [ autoUpdateElt { duration: 3000
, effect: dispatch Refresh , effect: dispatch Refresh
} }
, T.tableElt , T.tableElt
{ rows { rows
, setParams: \params -> loaderDispatch (Loader.SetPath {nodeId, listIds, params, tabType}) , setParams
, container: tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable} , container: tableContainer {pageParams, loaderDispatch, dispatch, ngramsParent, ngramsChildren, ngramsTable}
, colNames: , colNames:
T.ColumnName <$> T.ColumnName <$>
[ "Graph" [ "Graph"
...@@ -571,6 +587,8 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -571,6 +587,8 @@ ngramsTableSpec = simpleSpec performAction render
} }
] ]
where where
setParams params =
loaderDispatch $ Loader.SetPath $ pageParams {params = params}
ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable
rows = convertRow <$> Map.toUnfoldable (Map.filter displayRow (ngramsTable ^. _NgramsTable)) rows = convertRow <$> Map.toUnfoldable (Map.filter displayRow (ngramsTable ^. _NgramsTable))
isRoot (NgramsElement e) = e.parent == Nothing isRoot (NgramsElement e) = e.parent == Nothing
......
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