fix PutNgrams

parent 680f2a2e
...@@ -16,6 +16,7 @@ module Gargantext.Components.NgramsTable ...@@ -16,6 +16,7 @@ module Gargantext.Components.NgramsTable
import Control.Monad.State (class MonadState, execState) import Control.Monad.State (class MonadState, execState)
import Control.Monad.Cont.Trans (lift) import Control.Monad.Cont.Trans (lift)
import Data.Array (head)
import Data.Argonaut ( Json, class DecodeJson, decodeJson, class EncodeJson, encodeJson import Data.Argonaut ( Json, class DecodeJson, decodeJson, class EncodeJson, encodeJson
, jsonEmptyObject, fromObject, (:=), (~>), (.?), (.??) ) , jsonEmptyObject, fromObject, (:=), (~>), (.?), (.??) )
import Data.Either (Either(..)) import Data.Either (Either(..))
...@@ -485,10 +486,12 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable ...@@ -485,10 +486,12 @@ tableContainer {searchQuery, dispatch, ngramsParent, ngramsChildren, ngramsTable
] ]
] ]
putTable :: {nodeId :: Int, listId :: Maybe Int, tabType :: TabType} -> Versioned NgramsTablePatch -> Aff (Versioned NgramsTablePatch) putTable :: {nodeId :: Int, listIds :: Array Int, tabType :: TabType} -> Versioned NgramsTablePatch -> Aff (Versioned NgramsTablePatch)
putTable {nodeId, listId, tabType} = put (toUrl Back (PutNgrams tabType listId) $ Just nodeId) putTable {nodeId, listIds, tabType} =
put (toUrl Back (PutNgrams tabType (head listIds)) $ Just nodeId)
commitPatch :: {nodeId :: Int, listId :: Maybe Int, tabType :: TabType} -> Versioned NgramsTablePatch -> StateCoTransformer State Unit commitPatch :: {nodeId :: Int, listIds :: Array Int, tabType :: TabType}
-> Versioned NgramsTablePatch -> StateCoTransformer State Unit
commitPatch props pt@(Versioned {data: tablePatch}) = do commitPatch props pt@(Versioned {data: tablePatch}) = do
Versioned {version: newVersion, data: newPatch} <- lift $ putTable props pt Versioned {version: newVersion, data: newPatch} <- lift $ putTable props pt
modifyState_ $ \s -> modifyState_ $ \s ->
...@@ -515,8 +518,8 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -515,8 +518,8 @@ ngramsTableSpec = simpleSpec performAction render
modifyState_ $ setParentResetChildren p modifyState_ $ setParentResetChildren p
performAction (ToggleChild b c) _ _ = performAction (ToggleChild b c) _ _ =
modifyState_ $ _ngramsChildren <<< at c %~ toggleMap b modifyState_ $ _ngramsChildren <<< at c %~ toggleMap b
performAction (SetTermListItem n pl) {path: {nodeId, tabType}} {ngramsVersion} = performAction (SetTermListItem n pl) {path: {nodeId, listIds, tabType}} {ngramsVersion} =
commitPatch {nodeId, listId, tabType} (Versioned {version: ngramsVersion, data: pt}) commitPatch {nodeId, listIds, tabType} (Versioned {version: ngramsVersion, data: pt})
where where
listId = Just 10 -- List.head listIds listId = Just 10 -- List.head listIds
pe = NgramsPatch { patch_list: pl, patch_children: mempty } pe = NgramsPatch { patch_list: pl, patch_children: mempty }
...@@ -524,13 +527,13 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -524,13 +527,13 @@ ngramsTableSpec = simpleSpec performAction render
performAction AddTermChildren _ {ngramsParent: Nothing} = performAction AddTermChildren _ {ngramsParent: Nothing} =
-- impossible but harmless -- impossible but harmless
pure unit pure unit
performAction AddTermChildren {path: {nodeId, tabType}} performAction AddTermChildren {path: {nodeId, listIds, tabType}}
{ ngramsParent: Just parent { ngramsParent: Just parent
, ngramsChildren , ngramsChildren
, ngramsVersion , ngramsVersion
} = do } = do
modifyState_ $ setParentResetChildren Nothing modifyState_ $ setParentResetChildren Nothing
commitPatch {nodeId, listId, tabType} (Versioned {version: ngramsVersion, data: pt}) commitPatch {nodeId, listIds, tabType} (Versioned {version: ngramsVersion, data: pt})
where where
listId = Just 10 -- List.head listIds listId = Just 10 -- List.head listIds
pc = patchSetFromMap ngramsChildren pc = patchSetFromMap ngramsChildren
......
...@@ -204,7 +204,7 @@ data Path ...@@ -204,7 +204,7 @@ data Path
| Tab TabType Offset Limit (Maybe OrderBy) | Tab TabType Offset Limit (Maybe OrderBy)
| Children NodeType Offset Limit (Maybe OrderBy) | Children NodeType Offset Limit (Maybe OrderBy)
| GetNgrams TabType Offset Limit (Array ListId) (Maybe TermList) | GetNgrams TabType Offset Limit (Array ListId) (Maybe TermList)
| PutNgrams TabType (Maybe TermList) | PutNgrams TabType (Maybe ListId)
| NodeAPI NodeType | NodeAPI NodeType
| Search { {-id :: Int | Search { {-id :: Int
, query :: Array String , query :: Array String
......
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