Commit b96ba4b5 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graphql] node csv upload with graphql

parent 01136431
...@@ -11,9 +11,11 @@ import Data.Maybe (Maybe(..)) ...@@ -11,9 +11,11 @@ import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Nullable (Nullable, null, toMaybe) import Data.Nullable (Nullable, null, toMaybe)
import Data.Show.Generic (genericShow) import Data.Show.Generic (genericShow)
import Data.Tuple (Tuple(..))
import Effect.Aff (Aff, launchAff_) import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.FolderView as FV import Gargantext.Components.FolderView as FV
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..))
import Gargantext.Components.GraphQL.Endpoints (getNodeParent) import Gargantext.Components.GraphQL.Endpoints (getNodeParent)
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Config.REST (RESTError, logRESTError) import Gargantext.Config.REST (RESTError, logRESTError)
...@@ -146,18 +148,22 @@ importIntoListButtonCpt = here.component "importIntoListButton" cpt where ...@@ -146,18 +148,22 @@ importIntoListButtonCpt = here.component "importIntoListButton" cpt where
--task = GT.AsyncTaskWithType { task, typ: GT.ListCSVUpload } --task = GT.AsyncTaskWithType { task, typ: GT.ListCSVUpload }
launchAff_ $ do launchAff_ $ do
-- Get corpus_id -- Get corpus_id
eCorpusNodes <- getNodeParent session nodeId Corpus corpusNodes <- getNodeParent session nodeId Corpus
case eCorpusNodes of case A.uncons corpusNodes of
Left err -> liftEffect $ here.log2 "[importIntoListButton] error parsing corpus" err Nothing -> liftEffect $ here.log2 "[importIntoListButton] corpusNodes empty" corpusNodes
Right corpusNodes -> do Just { head: corpusNode } -> do
case A.uncons corpusNodes of -- Use that corpus id
Nothing -> liftEffect $ here.log2 "[importIntoListButton] corpusNodes empty" corpusNodes eCsv <- EC.downloadCSV base frame_id
Just { head: corpusNode } -> do case eCsv of
-- Use that corpus id Left err -> liftEffect $ here.log2 "[importIntoListButton] error with csv" err
csv <- EC.downloadCSV base frame_id Right csv -> do
liftEffect $ here.log2 "[importIntoListButton] CSV: " csv
let uploadPath = GR.NodeAPI NodeList (Just corpusNode.id) $ GT.asyncTaskTypePath GT.ListCSVUpload let uploadPath = GR.NodeAPI NodeList (Just corpusNode.id) $ GT.asyncTaskTypePath GT.ListCSVUpload
eTask <- postWwwUrlencoded session uploadPath csv eTask :: Either RESTError GT.AsyncTaskWithType <- postWwwUrlencoded
session
uploadPath
[ Tuple "_wf_data" (Just csv.body)
, Tuple "_wf_filetype" (Just $ show CSV)
, Tuple "_wf_name" (Just frame_id) ]
pure unit pure unit
type NodeFrameVisioProps = type NodeFrameVisioProps =
......
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