Commit cdae18ff authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams] fixes to ngrams PUT JSON response

parent 5e12ef58
...@@ -45,9 +45,10 @@ instance Eq RESTError where ...@@ -45,9 +45,10 @@ instance Eq RESTError where
eq _ _ = false eq _ _ = false
logRESTError :: R2.Here -> String -> RESTError -> Effect Unit logRESTError :: R2.Here -> String -> RESTError -> Effect Unit
logRESTError here prefix (SendResponseError e) = here.warn2 (prefix <> " SendResponseError ") e -- TODO: No show logRESTError here prefix e = here.warn2 (prefix <> " " <> show e) e
logRESTError here prefix (ReadJSONError e) = here.warn2 (prefix <> " ReadJSONError ") $ show e -- logRESTError here prefix (SendResponseError e) = here.warn2 (prefix <> " SendResponseError ") e -- TODO: No show
logRESTError here prefix (CustomError e) = here.warn2 (prefix <> " CustomError ") $ e -- logRESTError here prefix (ReadJSONError e) = here.warn2 (prefix <> " ReadJSONError ") $ show e
-- logRESTError here prefix (CustomError e) = here.warn2 (prefix <> " CustomError ") $ e
type AffRESTError a = Aff (Either RESTError a) type AffRESTError a = Aff (Either RESTError a)
......
...@@ -35,7 +35,7 @@ import Effect.Class (liftEffect) ...@@ -35,7 +35,7 @@ import Effect.Class (liftEffect)
import Gargantext.AsyncTasks as GAT import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T import Gargantext.Components.Table.Types as T
import Gargantext.Config.REST (AffRESTError, RESTError) import Gargantext.Config.REST (AffRESTError, RESTError, logRESTError)
import Gargantext.Config.Utils (handleRESTError) import Gargantext.Config.Utils (handleRESTError)
import Gargantext.Core.NgramsTable.Types import Gargantext.Core.NgramsTable.Types
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
...@@ -375,7 +375,7 @@ syncPatches props state callback = do ...@@ -375,7 +375,7 @@ syncPatches props state callback = do
launchAff_ $ do launchAff_ $ do
ePatches <- putNgramsPatches props pt ePatches <- putNgramsPatches props pt
case ePatches of case ePatches of
Left err -> liftEffect $ here.warn2 "[syncPatches] RESTError" err Left err -> liftEffect $ logRESTError here "[syncPatches]" err
Right (Versioned { data: newPatch, version: newVersion }) -> do Right (Versioned { data: newPatch, version: newVersion }) -> do
callback unit callback unit
liftEffect $ do liftEffect $ do
......
...@@ -13,9 +13,10 @@ import Data.Lens.Index (class Index, ix) ...@@ -13,9 +13,10 @@ import Data.Lens.Index (class Index, ix)
import Data.Lens.Iso.Newtype (_Newtype) import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.List (List) import Data.List (List)
import Data.List.Types (NonEmptyList(..))
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), isJust) import Data.Maybe (Maybe(..), fromJust, isJust)
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Ord.Generic (genericCompare) import Data.Ord.Generic (genericCompare)
import Data.Show.Generic (genericShow) import Data.Show.Generic (genericShow)
...@@ -32,6 +33,7 @@ import Gargantext.Components.Table.Types as T ...@@ -32,6 +33,7 @@ import Gargantext.Components.Table.Types as T
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.SimpleJSON as USJ
import Simple.JSON as JSON import Simple.JSON as JSON
import Reactix as R import Reactix as R
import Type.Proxy (Proxy(..)) import Type.Proxy (Proxy(..))
...@@ -207,14 +209,17 @@ instance JSON.ReadForeign NgramsPatch where ...@@ -207,14 +209,17 @@ instance JSON.ReadForeign NgramsPatch where
readImpl f = do readImpl f = do
inst :: { patch_old :: Maybe NgramsRepoElement inst :: { patch_old :: Maybe NgramsRepoElement
, patch_new :: Maybe NgramsRepoElement , patch_new :: Maybe NgramsRepoElement
, patch_children :: PatchSet NgramsTerm , patch_children :: Maybe (PatchSet NgramsTerm)
, patch_list :: Replace GT.TermList } <- JSON.readImpl f , patch_list :: Maybe (Replace GT.TermList) } <- JSON.readImpl f
-- TODO handle empty fields -- TODO handle empty fields
-- TODO handle patch_new -- TODO handle patch_new
if isJust inst.patch_new || isJust inst.patch_old then if isJust inst.patch_new || isJust inst.patch_old then
pure $ NgramsReplace { patch_old: inst.patch_old, patch_new: inst.patch_new } pure $ NgramsReplace { patch_old: inst.patch_old
else do , patch_new: inst.patch_new }
pure $ NgramsPatch { patch_list: inst.patch_list, patch_children: inst.patch_children } else case (Tuple inst.patch_children inst.patch_list) of
Tuple (Just patch_children) (Just patch_list) ->
pure $ NgramsPatch { patch_list, patch_children }
_ -> USJ.throwJSONError $ F.ForeignError "[readForeign NgramsPatch] patch_children or patch_list undefined"
----------------------------------------------------- -----------------------------------------------------
newtype NgramsTerm = NormNgramsTerm String newtype NgramsTerm = NormNgramsTerm String
......
...@@ -3,9 +3,12 @@ module Gargantext.Utils.SimpleJSON where ...@@ -3,9 +3,12 @@ module Gargantext.Utils.SimpleJSON where
import Prelude import Prelude
import Control.Alt ((<|>)) import Control.Alt ((<|>))
import Control.Monad.Except (withExcept) import Control.Monad.Except (throwError, withExcept)
import Data.Generic.Rep as GR import Data.Generic.Rep as GR
import Data.List as L
import Data.List.Types (NonEmptyList(..))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.NonEmpty (NonEmpty(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Foreign (Foreign, ForeignError(..), fail) import Foreign (Foreign, ForeignError(..), fail)
import Foreign as Foreign import Foreign as Foreign
...@@ -86,3 +89,8 @@ instance untaggedSumRepArgument :: ...@@ -86,3 +89,8 @@ instance untaggedSumRepArgument ::
( JSON.ReadForeign a ( JSON.ReadForeign a
) => UntaggedSumRep (GR.Argument a) where ) => UntaggedSumRep (GR.Argument a) where
untaggedSumRep f = GR.Argument <$> JSON.readImpl f untaggedSumRep f = GR.Argument <$> JSON.readImpl f
throwJSONError :: forall a. Foreign.ForeignError -> Foreign.F a
throwJSONError err =
throwError $ NonEmptyList $ NonEmpty err L.Nil
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