@@ -56,14 +56,57 @@ const ShowMore = ({ total, shown, moreStep, onMore }) => {
5656 )
5757}
5858
59+ function createStyleGetter ( graphStyleData , kind ) {
60+ const graphStyle = neoGraphStyle ( )
61+ if ( graphStyleData ) {
62+ graphStyle . loadRules ( deepmerge ( graphStyle . toSheet ( ) , graphStyleData || { } ) )
63+ }
64+
65+ if ( kind === 'node' ) {
66+ return function ( text ) {
67+ if ( graphStyleData ) {
68+ const styleForItem = graphStyle . forNode ( {
69+ labels : [ text ]
70+ } )
71+ return {
72+ backgroundColor : styleForItem . get ( 'color' ) ,
73+ color : styleForItem . get ( 'text-color-internal' )
74+ }
75+ }
76+ return { }
77+ }
78+ }
79+ if ( kind === 'relationship' ) {
80+ return function ( text ) {
81+ if ( graphStyleData ) {
82+ const styleForItem = graphStyle . forRelationship ( {
83+ type : text
84+ } )
85+ return {
86+ backgroundColor : styleForItem . get ( 'color' ) ,
87+ color : styleForItem . get ( 'text-color-internal' )
88+ }
89+ }
90+ return { }
91+ }
92+ }
93+ throw new Error ( `Unsupported argument: ${ kind } ` )
94+ }
95+ function createNodeStyleGetter ( graphStyleData ) {
96+ return createStyleGetter ( graphStyleData , 'node' )
97+ }
98+ function createRelationStyleGetter ( graphStyleData ) {
99+ return createStyleGetter ( graphStyleData , 'relationship' )
100+ }
101+
59102const createItems = (
60103 originalList ,
61104 onItemClick ,
62105 RenderType ,
63106 editorCommandTemplate ,
64107 showStar = true ,
65108 count ,
66- graphStyleData
109+ styleGetter = ( ) => ( { } )
67110) => {
68111 const items = [ ...originalList ]
69112 if ( showStar ) {
@@ -73,29 +116,15 @@ const createItems = (
73116 }
74117 items . unshift ( str )
75118 }
76- const graphStyle = neoGraphStyle ( )
77- if ( graphStyleData ) {
78- graphStyle . loadRules ( deepmerge ( graphStyle . toSheet ( ) , graphStyleData || { } ) )
79- }
80119
81120 return items . map ( ( text , index ) => {
82- let style = { }
83- if ( graphStyleData ) {
84- const styleForItem = graphStyle . forNode ( {
85- labels : [ text ]
86- } )
87- style = {
88- backgroundColor : styleForItem . get ( 'color' ) ,
89- color : styleForItem . get ( 'text-color-internal' )
90- }
91- }
92121 const getNodesCypher = editorCommandTemplate ( text , index )
93122 return (
94123 < RenderType . component
95124 data-testid = "sidebarMetaItem"
96125 key = { index }
97126 onClick = { ( ) => onItemClick ( getNodesCypher ) }
98- style = { style }
127+ style = { styleGetter ( text ) }
99128 >
100129 { text }
101130 </ RenderType . component >
@@ -127,7 +156,7 @@ const LabelItems = ({
127156 editorCommandTemplate ,
128157 true ,
129158 count ,
130- graphStyleData
159+ createNodeStyleGetter ( graphStyleData )
131160 )
132161 }
133162 return (
@@ -151,7 +180,8 @@ const RelationshipItems = ({
151180 onItemClick,
152181 moreStep,
153182 onMoreClick,
154- count
183+ count,
184+ graphStyleData
155185} ) => {
156186 let relationshipItems = < p > No relationships in database</ p >
157187 if ( relationshipTypes . length > 0 ) {
@@ -169,7 +199,8 @@ const RelationshipItems = ({
169199 { component : StyledRelationship } ,
170200 editorCommandTemplate ,
171201 true ,
172- count
202+ count ,
203+ createRelationStyleGetter ( graphStyleData )
173204 )
174205 }
175206 return (
0 commit comments