[corpus] create list if it doesn't exist

When user created a corpus with docs, there was an error that list is
missing.
parent b731bf1b
Pipeline #7520 passed with stages
in 23 minutes and 23 seconds
......@@ -15,6 +15,7 @@ import Effect.Exception (error)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), Variant(..))
import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.Forest.Tree.Node.Action.Add (addNode, AddNodeValue(..))
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Node (HyperdataList, NodePoly(..))
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, Hyperdata)
......@@ -23,7 +24,7 @@ import Gargantext.Config.REST (AffRESTError, RESTError(..))
import Gargantext.Data.Array as GDA
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(Children, NodeAPI))
import Gargantext.Sessions (Session, get, put)
import Gargantext.Sessions (Session, get, post, put)
import Gargantext.Types (AffETableResult, NodeType(..), ID)
import Gargantext.Utils ((?))
import Gargantext.Utils.Reactix as R2
......@@ -469,8 +470,17 @@ fetchDefaultList session corpusId = do
case (A.head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) ->
pure $ Right defaultListId
Nothing ->
pure $ Left $ CustomError "Missing default list"
Nothing -> do
let listNode = AddNodeValue { name: "List", nodeType: NodeList }
eListIds <- addNode session corpusId $ listNode
case eListIds of
Left err -> pure $ Left err
Right listIds ->
case (A.head listIds :: Maybe Int) of
Nothing ->
pure $ Left $ CustomError "Missing default list"
Just listId ->
pure $ Right listId
where
defaultListIdsRoute = Children NodeList 0 1 Nothing <<< Just
......
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