Commit 5807c509 authored by Karen Konou's avatar Karen Konou

[Graph explorer] Allow renaming

parent b678ccdd
......@@ -88,6 +88,15 @@ type CloneGraphParams =
cloneGraph :: Record CloneGraphParams -> AffRESTError Int
cloneGraph { hyperdataGraph, id, session } = post session (GR.GraphAPI id $ "clone") hyperdataGraph
type UpdateLegendParams =
( graphId :: Int
, session :: Session
, legend :: Array GET.Legend
)
updateLegend :: Record UpdateLegendParams -> AffRESTError Int
updateLegend { graphId, session, legend } = post session (GR.GraphAPI graphId $ "legend") legend
-----------------------------------------------
getNodes :: Session -> T2.Reload -> GET.GraphId -> AffRESTError GET.HyperdataGraph
......
......@@ -179,6 +179,7 @@ layoutCpt = here.component "layout" cpt where
{ frontends: defaultFrontends
, metaData
, session
, graphId: graphId'
}
]
]
......
......@@ -55,6 +55,7 @@ type Props =
( metaData :: GET.MetaData
, session :: Session
, frontends :: Frontends
, graphId :: GET.GraphId
)
sidebar :: R2.Leaf Props
......@@ -119,7 +120,7 @@ sideTabLegend :: R2.Leaf Props
sideTabLegend = R2.leaf sideTabLegendCpt
sideTabLegendCpt :: R.Component Props
sideTabLegendCpt = here.component "sideTabLegend" cpt where
cpt { metaData: GET.MetaData { legend } } _ = do
cpt { metaData: GET.MetaData { legend }, session, graphId } _ = do
-- | States
-- |
store <- GraphStore.use
......@@ -164,6 +165,8 @@ sideTabLegendCpt = here.component "sideTabLegend" cpt where
, extractedNodeList
, nodeCountList
, selectedNodeIds: store.selectedNodeIds
, session
, graphId
}
]
......
......@@ -4,15 +4,21 @@ module Gargantext.Components.GraphExplorer.Sidebar.Legend
import Prelude hiding (map)
import Data.Array (fromFoldable)
import Data.Array as A
import Data.Maybe (isJust, maybe)
import Data.Sequence (Seq)
import Data.Sequence (Seq, replace)
import Data.Set as Set
import Data.Traversable (foldMap, intercalate)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.GraphExplorer.API (updateLegend)
import Gargantext.Components.GraphExplorer.GraphTypes as GEGT
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Components.Renameable (renameable)
import Gargantext.Hooks.Sigmax.Types as ST
import Gargantext.Sessions (Session)
import Gargantext.Utils (getter, nbsp, (?))
import Gargantext.Utils.Reactix as R2
import Reactix as R
......@@ -27,6 +33,8 @@ type Props =
, extractedNodeList :: Array GEGT.Node
, nodeCountList :: Array GEGT.ClusterCount
, selectedNodeIds :: T.Box ST.NodeIds
, session :: Session
, graphId :: GET.GraphId
)
legend :: R2.Leaf Props
......@@ -37,6 +45,8 @@ legendCpt = here.component "legend" cpt where
, extractedNodeList
, nodeCountList
, selectedNodeIds
, session
, graphId
} _ = do
-- | Hooks
-- |
......@@ -48,7 +58,7 @@ legendCpt = here.component "legend" cpt where
H.ul
{ className: "graph-legend" }
[
flip foldMap legendSeq \(GET.Legend { id_, label }) ->
flip foldMap legendSeq \(GET.Legend { id_, label, color}) ->
H.li
{ className: "graph-legend__item" }
......@@ -62,9 +72,7 @@ legendCpt = here.component "legend" cpt where
B.wad
[ "flex-grow-1" ]
[
B.div'
{ className: "graph-legend__title" }
label
renameable { text: label, className: "graph-legend__label", onRename: \s -> rename s id_ color }
,
selectedNodes
{ selectedNodeIds
......@@ -75,6 +83,13 @@ legendCpt = here.component "legend" cpt where
]
]
]
where
rename :: String -> Int -> String -> Effect Unit
rename s id c = do
let newLegendSeq = replace (GET.Legend $ { id_: id, label: s, color: c}) (id - 1) legendSeq
launchAff_ do
_ <- updateLegend { legend: (fromFoldable newLegendSeq), graphId, session }
pure unit
filterByCluster :: Int -> Array GEGT.Node -> Array GEGT.Node
filterByCluster id
......
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