Commit b9fb7988 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[simple-json] fix dashboard code saving

parent c237ff21
Pipeline #1581 canceled with stage
......@@ -9,8 +9,6 @@ import Data.Show.Generic (genericShow)
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, null, toMaybe)
import Data.String.Utils (endsWith)
import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import FFI.Simple ((.=))
import Reactix as R
......@@ -24,7 +22,6 @@ import Toestand as T
import Gargantext.Prelude
import Gargantext.Utils.HighlightJS as HLJS
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
here :: R2.Here
here = R2.here "Gargantext.Components.CodeEditor"
......@@ -214,8 +211,8 @@ toolbar p = R.createElement toolbarCpt p []
toolbarCpt :: R.Component ToolbarProps
toolbarCpt = here.component "toolbar" cpt
where
cpt props@{ controls: { codeS, codeType, error, viewType }
, onChange } _ = do
cpt { controls: { codeS, codeType, viewType }
, onChange } _ = do
codeS' <- T.useLive T.unequal codeS
codeType' <- T.useLive T.unequal codeType
......
......@@ -119,14 +119,13 @@ corpusLayoutWithKeyCpt = here.component "corpusLayoutWithKey" cpt where
type ViewProps =
( corpus :: NodePoly Hyperdata
, reload :: T2.ReloadS
, nodeId :: Int
, reload :: T2.ReloadS
, session :: Session
)
corpusLayoutView :: Record ViewProps -> R.Element
corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
corpusLayoutViewCpt :: R.Component ViewProps
corpusLayoutViewCpt = here.component "corpusLayoutView" cpt
where
......@@ -449,8 +448,6 @@ changeCode onc (JSON j) CE.Markdown _ = onc $ Markdown $ defaultMarkdown' { text
text = R2.stringify (JSON.writeImpl j) 2
type LoadProps =
( nodeId :: Int
, session :: Session
......@@ -470,7 +467,7 @@ type SaveProps = (
saveCorpus :: Record SaveProps -> Aff Unit
saveCorpus {hyperdata, nodeId, session} = do
id_ <- (put session (NodeAPI Corpus (Just nodeId) "") hyperdata) :: Aff Int
_id <- (put session (NodeAPI Corpus (Just nodeId) "") hyperdata) :: Aff Int
pure unit
loadCorpus :: Record LoadProps -> Aff CorpusData
......
......@@ -51,7 +51,7 @@ dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
reload' <- T.useLive T.unequal reload
useLoader {nodeId, reload: reload', session} DT.loadDashboardWithReload $
\(DT.DashboardData dashboardData@{hyperdata: DT.Hyperdata h, parentId}) -> do
\(DT.DashboardData { hyperdata: DT.Hyperdata h, parentId }) -> do
let { charts, fields } = h
dashboardLayoutLoaded { charts
, corpusId: parentId
......@@ -86,7 +86,7 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
dashboardLayoutLoadedCpt :: R.Component LoadedProps
dashboardLayoutLoadedCpt = here.component "dashboardLayoutLoaded" cpt
where
cpt props@{ charts, corpusId, defaultListId, fields, nodeId, onChange, session } _ = do
cpt { charts, corpusId, defaultListId, fields, nodeId, onChange, session } _ = do
pure $ H.div {}
[ dashboardCodeEditor { fields
, nodeId
......@@ -130,7 +130,7 @@ dashboardCodeEditor = R.createElement dashboardCodeEditorCpt
dashboardCodeEditorCpt :: R.Component CodeEditorProps
dashboardCodeEditorCpt = here.component "dashboardCodeEditor" cpt
where
cpt props@{ fields: FTFieldList fields, nodeId, onChange, session } _ = do
cpt { fields: FTFieldList fields, nodeId, onChange, session } _ = do
let fieldsWithIndex = FTFieldsWithIndex $ List.mapWithIndex (\idx -> \ftField -> { idx, ftField }) fields
fieldsS <- T.useBox fieldsWithIndex
fields' <- T.useLive T.unequal fieldsS
......@@ -173,12 +173,7 @@ dashboardCodeEditorCpt = here.component "dashboardCodeEditor" cpt
onClickSave :: forall e. FTFieldsWithIndex -> e -> Effect Unit
onClickSave (FTFieldsWithIndex fields') _ = do
here.log "saving (TODO)"
onChange $ FTFieldList $ (_.ftField) <$> fields'
-- launchAff_ do
-- saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS}
-- , nodeId
-- , session }
onClickAddField :: forall e. T.Box FTFieldsWithIndex -> e -> Effect Unit
onClickAddField fieldsS _ = do
......
......@@ -4,16 +4,17 @@ import Gargantext.Prelude
import Data.Eq.Generic (genericEq)
import Data.Generic.Rep (class Generic)
import Data.List as List
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Effect.Aff (Aff)
import Simple.JSON as JSON
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.Types (FTField, FTFieldList(..))
import Gargantext.Components.Nodes.Types (FTFieldList)
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, get, put)
import Gargantext.Types (NodeType(..))
import Simple.JSON as JSON
type Preferences = Maybe String
......@@ -50,7 +51,7 @@ type SaveProps = ( hyperdata :: Hyperdata | LoadProps )
saveDashboard :: Record SaveProps -> Aff Unit
saveDashboard {hyperdata, nodeId, session} = do
id_ <- (put session (NodeAPI Node (Just nodeId) "") hyperdata) :: Aff Int
_id <- (put session (NodeAPI Node (Just nodeId) "") hyperdata) :: Aff Int
pure unit
newtype DashboardData =
......
......@@ -8,7 +8,6 @@ import Data.List as List
import Data.Maybe (Maybe, fromMaybe)
import Data.Newtype (class Newtype)
import Data.Show.Generic (genericShow)
import Data.Tuple (Tuple)
import Foreign as F
import Simple.JSON as JSON
......
......@@ -37,7 +37,7 @@ readList f = do
readAtIdx i f' = withExcept (map (ErrorAtIndex i)) (JSON.readImpl f')
writeList :: forall a. JSON.WriteForeign a => List.List a -> Foreign
writeList xs = unsafeToForeign $ JSON.writeImpl <$> xs
writeList xs = unsafeToForeign $ JSON.writeImpl <$> (List.toUnfoldable xs :: Array a)
readMapInt :: forall v. JSON.ReadForeign v => Foreign -> F (Map.Map Int v)
readMapInt f = do
......
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