From 9e8bb43a0ba1f8224b2d4f2c6169ed2ba3f9d19c Mon Sep 17 00:00:00 2001 From: Nicolas Pouillard <nicolas.pouillard@gmail.com> Date: Tue, 12 Feb 2019 17:40:55 +0100 Subject: [PATCH] fix PutNgrams --- src/Gargantext/Components/NgramsTable.purs | 17 ++++++++++------- src/Gargantext/Config.purs | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Gargantext/Components/NgramsTable.purs b/src/Gargantext/Components/NgramsTable.purs index 80d446d3..076783b0 100644 --- a/src/Gargantext/Components/NgramsTable.purs +++ b/src/Gargantext/Components/NgramsTable.purs @@ -16,6 +16,7 @@ module Gargantext.Components.NgramsTable import Control.Monad.State (class MonadState, execState) import Control.Monad.Cont.Trans (lift) +import Data.Array (head) import Data.Argonaut ( Json, class DecodeJson, decodeJson, class EncodeJson, encodeJson , jsonEmptyObject, fromObject, (:=), (~>), (.?), (.??) ) import Data.Either (Either(..)) @@ -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, listId, tabType} = put (toUrl Back (PutNgrams tabType listId) $ Just nodeId) +putTable :: {nodeId :: Int, listIds :: Array Int, tabType :: TabType} -> Versioned NgramsTablePatch -> Aff (Versioned NgramsTablePatch) +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 Versioned {version: newVersion, data: newPatch} <- lift $ putTable props pt modifyState_ $ \s -> @@ -515,8 +518,8 @@ ngramsTableSpec = simpleSpec performAction render modifyState_ $ setParentResetChildren p performAction (ToggleChild b c) _ _ = modifyState_ $ _ngramsChildren <<< at c %~ toggleMap b - performAction (SetTermListItem n pl) {path: {nodeId, tabType}} {ngramsVersion} = - commitPatch {nodeId, listId, tabType} (Versioned {version: ngramsVersion, data: pt}) + performAction (SetTermListItem n pl) {path: {nodeId, listIds, tabType}} {ngramsVersion} = + commitPatch {nodeId, listIds, tabType} (Versioned {version: ngramsVersion, data: pt}) where listId = Just 10 -- List.head listIds pe = NgramsPatch { patch_list: pl, patch_children: mempty } @@ -524,13 +527,13 @@ ngramsTableSpec = simpleSpec performAction render performAction AddTermChildren _ {ngramsParent: Nothing} = -- impossible but harmless pure unit - performAction AddTermChildren {path: {nodeId, tabType}} + performAction AddTermChildren {path: {nodeId, listIds, tabType}} { ngramsParent: Just parent , ngramsChildren , ngramsVersion } = do modifyState_ $ setParentResetChildren Nothing - commitPatch {nodeId, listId, tabType} (Versioned {version: ngramsVersion, data: pt}) + commitPatch {nodeId, listIds, tabType} (Versioned {version: ngramsVersion, data: pt}) where listId = Just 10 -- List.head listIds pc = patchSetFromMap ngramsChildren diff --git a/src/Gargantext/Config.purs b/src/Gargantext/Config.purs index b9691033..02d0749e 100644 --- a/src/Gargantext/Config.purs +++ b/src/Gargantext/Config.purs @@ -204,7 +204,7 @@ data Path | Tab TabType Offset Limit (Maybe OrderBy) | Children NodeType Offset Limit (Maybe OrderBy) | GetNgrams TabType Offset Limit (Array ListId) (Maybe TermList) - | PutNgrams TabType (Maybe TermList) + | PutNgrams TabType (Maybe ListId) | NodeAPI NodeType | Search { {-id :: Int , query :: Array String -- 2.21.0