Commit a357a2d7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[DocsTable] change docs url to POST node/{id}/search with custom query params

parent df8f3fa5
...@@ -28,9 +28,10 @@ import Effect.Aff (Aff) ...@@ -28,9 +28,10 @@ import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import React as React import React as React
import React (ReactClass, ReactElement, Children) import React (ReactClass, ReactElement, Children)
import Unsafe.Coerce (unsafeCoerce)
------------------------------------------------------------------------ ------------------------------------------------------------------------
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, toUrl, toLink) import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, TabPostQuery(..), toUrl, toLink)
import Gargantext.Config.REST (get, put, post, deleteWithBody, delete) import Gargantext.Config.REST (get, put, post, deleteWithBody, delete)
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
...@@ -38,7 +39,7 @@ import Gargantext.Components.Table as T ...@@ -38,7 +39,7 @@ import Gargantext.Components.Table as T
import Gargantext.Utils.DecodeMaybe ((.|)) import Gargantext.Utils.DecodeMaybe ((.|))
import Gargantext.Router as R import Gargantext.Router as R
import React.DOM (a, br', button, div, i, input, p, text) import React.DOM (a, br', button, div, i, input, p, text)
import React.DOM.Props (_type, className, href, onClick, placeholder, style, checked, target) import React.DOM.Props (_type, className, href, onClick, onChange, placeholder, style, checked, target)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_, simpleSpec, hideState) import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_, simpleSpec, hideState)
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -79,12 +80,14 @@ type Props = ...@@ -79,12 +80,14 @@ type Props =
type State = type State =
{ documentIdsDeleted :: Set Int { documentIdsDeleted :: Set Int
, localCategories :: Map Int Category , localCategories :: Map Int Category
, mQuery :: Maybe String
} }
initialState :: State initialState :: State
initialState = initialState =
{ documentIdsDeleted: mempty { documentIdsDeleted: mempty
, localCategories: mempty , localCategories: mempty
, mQuery: Nothing
} }
_documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted") _documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted")
...@@ -93,6 +96,7 @@ _localCategories = prop (SProxy :: SProxy "localCategories") ...@@ -93,6 +96,7 @@ _localCategories = prop (SProxy :: SProxy "localCategories")
data Action data Action
= MarkCategory Int Category = MarkCategory Int Category
| TrashAll | TrashAll
| ChangeQuery (Maybe String)
newtype DocumentsView newtype DocumentsView
= DocumentsView = DocumentsView
...@@ -172,20 +176,28 @@ layoutDocview = simpleSpec performAction render ...@@ -172,20 +176,28 @@ layoutDocview = simpleSpec performAction render
performAction TrashAll {nodeId} {documentIdsDeleted} = do performAction TrashAll {nodeId} {documentIdsDeleted} = do
ids <- lift $ deleteAllDocuments nodeId ids <- lift $ deleteAllDocuments nodeId
modifyState_ $ _ {documentIdsDeleted = Set.union documentIdsDeleted $ Set.fromFoldable ids} modifyState_ $ _ {documentIdsDeleted = Set.union documentIdsDeleted $ Set.fromFoldable ids}
performAction (ChangeQuery mQuery) _ _ = do
modifyState_ $ _ {mQuery = mQuery}
render :: Render State Props Action render :: Render State Props Action
render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} deletionState _ = render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} state@{mQuery} _ =
[ [
div [className "container1"] div [className "container1"]
[ div [className "row"] [ div [className "row"]
[ chart [ chart
, div []
[
input [ _type "text"
, onChange $ \e -> dispatch $ ChangeQuery $ if (unsafeEventValue e) == "" then Nothing else Just $ unsafeEventValue e
, placeholder $ maybe "" identity mQuery]
]
, div [className "col-md-12"] , div [className "col-md-12"]
[ pageLoader [ pageLoader
{ path: initialPageParams {nodeId, tabType, listId, corpusId} { path: initialPageParams {nodeId, tabType, listId, corpusId, mQuery}
, listId , listId
, corpusId , corpusId
, totalRecords , totalRecords
, deletionState , state
, dispatch , dispatch
} }
] ]
...@@ -205,16 +217,29 @@ layoutDocview = simpleSpec performAction render ...@@ -205,16 +217,29 @@ layoutDocview = simpleSpec performAction render
mock :: Boolean mock :: Boolean
mock = false mock = false
type PageParams = {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType, params :: T.Params} type PageParams = { nodeId :: Int
, listId :: Int
, corpusId :: Maybe Int
, tabType :: TabType
, mQuery :: Maybe String
, params :: T.Params}
initialPageParams :: {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType} -> PageParams initialPageParams :: {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType, mQuery :: Maybe String} -> PageParams
initialPageParams {nodeId, listId, corpusId, tabType} = initialPageParams {nodeId, listId, corpusId, tabType, mQuery} =
{nodeId, tabType, listId, corpusId, params: T.initialParams} {nodeId, tabType, mQuery, listId, corpusId, params: T.initialParams}
loadPage :: PageParams -> Aff (Array DocumentsView) loadPage :: PageParams -> Aff (Array DocumentsView)
loadPage {nodeId, tabType, listId, corpusId, params: {limit, offset, orderBy}} = do loadPage {nodeId, tabType, mQuery, listId, corpusId, params: {limit, offset, orderBy}} = do
logs "loading documents page: loadPage with Offset and limit" logs "loading documents page: loadPage with Offset and limit"
res <- get $ toUrl Back (Tab tabType offset limit (convOrderBy <$> orderBy)) (Just nodeId) -- res <- get $ toUrl Back (Tab tabType offset limit (convOrderBy <$> orderBy)) (Just nodeId)
let url = (toUrl Back Node (Just nodeId)) <> "/search"
res <- post url $ TabPostQuery {
offset
, limit
, orderBy: convOrderBy <$> orderBy
, tabType
, mQuery
}
let docs = res2corpus <$> res let docs = res2corpus <$> res
pure $ pure $
if mock then take limit $ drop offset sampleData else if mock then take limit $ drop offset sampleData else
...@@ -243,17 +268,17 @@ type PageLoaderProps row = ...@@ -243,17 +268,17 @@ type PageLoaderProps row =
{ path :: PageParams { path :: PageParams
, totalRecords :: Int , totalRecords :: Int
, dispatch :: Action -> Effect Unit , dispatch :: Action -> Effect Unit
, deletionState :: State , state :: State
, listId :: Int , listId :: Int
, corpusId :: Maybe Int , corpusId :: Maybe Int
| row | row
} }
renderPage :: forall props path. renderPage :: forall props path.
Render (Loader.State {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType | path} (Array DocumentsView)) Render (Loader.State {nodeId :: Int, listId :: Int, corpusId :: Maybe Int, tabType :: TabType, mQuery :: Maybe String | path} (Array DocumentsView))
{ totalRecords :: Int { totalRecords :: Int
, dispatch :: Action -> Effect Unit , dispatch :: Action -> Effect Unit
, deletionState :: State , state :: State
, listId :: Int , listId :: Int
, corpusId :: Maybe Int , corpusId :: Maybe Int
| props | props
...@@ -261,11 +286,12 @@ renderPage :: forall props path. ...@@ -261,11 +286,12 @@ renderPage :: forall props path.
(Loader.Action PageParams) (Loader.Action PageParams)
renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner
renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
, deletionState: {documentIdsDeleted, localCategories}} , state: {documentIdsDeleted, localCategories}}
{currentPath: {nodeId, tabType}, loaded: Just res} _ = {currentPath: {nodeId, tabType, mQuery}, loaded: Just res} _ =
[ T.tableElt [
T.tableElt
{ rows { rows
, setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params}) , setParams: \params -> liftEffect $ loaderDispatch (Loader.SetPath {nodeId, tabType, listId, corpusId, params, mQuery})
, container: T.defaultContainer { title: "Documents" } , container: T.defaultContainer { title: "Documents" }
, colNames: , colNames:
T.ColumnName <$> T.ColumnName <$>
...@@ -388,3 +414,6 @@ toggleSet :: forall a. Ord a => a -> Set a -> Set a ...@@ -388,3 +414,6 @@ toggleSet :: forall a. Ord a => a -> Set a -> Set a
toggleSet a s toggleSet a s
| Set.member a s = Set.delete a s | Set.member a s = Set.delete a s
| otherwise = Set.insert a s | otherwise = Set.insert a s
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
...@@ -10,7 +10,7 @@ toUrl Front Corpus 1 == "http://localhost:2015/#/corpus/1" ...@@ -10,7 +10,7 @@ toUrl Front Corpus 1 == "http://localhost:2015/#/corpus/1"
module Gargantext.Config where module Gargantext.Config where
import Prelude import Prelude
import Data.Argonaut (class DecodeJson, decodeJson, class EncodeJson, encodeJson) import Data.Argonaut (class DecodeJson, decodeJson, class EncodeJson, encodeJson, (:=), (~>), jsonEmptyObject)
import Data.Foldable (foldMap) import Data.Foldable (foldMap)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
...@@ -122,11 +122,6 @@ endBaseUrl end c = (endOf end c).baseUrl ...@@ -122,11 +122,6 @@ endBaseUrl end c = (endOf end c).baseUrl
endPathUrl :: End -> EndConfig -> Path -> Maybe Id -> UrlPath endPathUrl :: End -> EndConfig -> Path -> Maybe Id -> UrlPath
endPathUrl end = pathUrl <<< endOf end endPathUrl end = pathUrl <<< endOf end
tabTypeDocs :: TabType -> UrlPath
tabTypeDocs (TabCorpus t) = "table?view=" <> show t
tabTypeDocs (TabDocument t)= "table?view=" <> show t
tabTypeDocs (TabPairing t) = "pairing?view=" <> show t
limitUrl :: Limit -> UrlPath limitUrl :: Limit -> UrlPath
limitUrl l = "&limit=" <> show l limitUrl l = "&limit=" <> show l
...@@ -144,10 +139,26 @@ showTabType' (TabCorpus t) = show t ...@@ -144,10 +139,26 @@ showTabType' (TabCorpus t) = show t
showTabType' (TabDocument t) = show t showTabType' (TabDocument t) = show t
showTabType' (TabPairing t) = show t showTabType' (TabPairing t) = show t
data TabPostQuery = TabPostQuery {
offset :: Int
, limit :: Int
, orderBy :: Maybe OrderBy
, tabType :: TabType
, mQuery :: Maybe String
}
instance encodeJsonTabPostQuery :: EncodeJson TabPostQuery where
encodeJson (TabPostQuery post) =
"view" := showTabType' post.tabType
~> "offset" := post.offset
~> "limit" := post.limit
~> "orderBy" := show post.orderBy
~> "query" := post.mQuery
~> jsonEmptyObject
pathUrl :: Config -> Path -> Maybe Id -> UrlPath pathUrl :: Config -> Path -> Maybe Id -> UrlPath
pathUrl c (Tab t o l s) i = pathUrl c (Tab t) i =
pathUrl c (NodeAPI Node) i <> pathUrl c (NodeAPI Node) i <> "/" <> showTabType' t
"/" <> tabTypeDocs t <> offsetUrl o <> limitUrl l <> orderUrl s
pathUrl c (Children n o l s) i = pathUrl c (Children n o l s) i =
pathUrl c (NodeAPI Node) i <> pathUrl c (NodeAPI Node) i <>
"/" <> "children?type=" <> show n <> offsetUrl o <> limitUrl l <> orderUrl s "/" <> "children?type=" <> show n <> offsetUrl o <> limitUrl l <> orderUrl s
...@@ -342,7 +353,7 @@ type ListId = Int ...@@ -342,7 +353,7 @@ type ListId = Int
data Path data Path
= Auth = Auth
| Tab TabType Offset Limit (Maybe OrderBy) | Tab TabType
| Children NodeType Offset Limit (Maybe OrderBy) | Children NodeType Offset Limit (Maybe OrderBy)
| GetNgrams | GetNgrams
{ tabType :: TabType { tabType :: TabType
......
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