From 497bd2297eb20cecc028515766125fb1697e3e0f Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Mon, 26 Oct 2020 13:46:36 +0100 Subject: [PATCH] Add color to relationships in sidebar --- src/browser/modules/DBMSInfo/DBMSInfo.jsx | 1 + src/browser/modules/DBMSInfo/MetaItems.jsx | 69 ++++++++++++++++------ 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/browser/modules/DBMSInfo/DBMSInfo.jsx b/src/browser/modules/DBMSInfo/DBMSInfo.jsx index 7b7ff38531a..9ef9597c3c7 100644 --- a/src/browser/modules/DBMSInfo/DBMSInfo.jsx +++ b/src/browser/modules/DBMSInfo/DBMSInfo.jsx @@ -87,6 +87,7 @@ export function DBMSInfo(props) { totalNumItems={relationshipTypes.length} onMoreClick={onMoreClick('relationships', relationshipsMax)} moreStep={moreStep} + graphStyleData={props.graphStyleData} /> l.val)} diff --git a/src/browser/modules/DBMSInfo/MetaItems.jsx b/src/browser/modules/DBMSInfo/MetaItems.jsx index 245f874f78d..55689e0a041 100644 --- a/src/browser/modules/DBMSInfo/MetaItems.jsx +++ b/src/browser/modules/DBMSInfo/MetaItems.jsx @@ -56,6 +56,49 @@ const ShowMore = ({ total, shown, moreStep, onMore }) => { ) } +function createStyleGetter(graphStyleData, kind) { + const graphStyle = neoGraphStyle() + if (graphStyleData) { + graphStyle.loadRules(deepmerge(graphStyle.toSheet(), graphStyleData || {})) + } + + if (kind === 'node') { + return function(text) { + if (graphStyleData) { + const styleForItem = graphStyle.forNode({ + labels: [text] + }) + return { + backgroundColor: styleForItem.get('color'), + color: styleForItem.get('text-color-internal') + } + } + return {} + } + } + if (kind === 'relationship') { + return function(text) { + if (graphStyleData) { + const styleForItem = graphStyle.forRelationship({ + type: text + }) + return { + backgroundColor: styleForItem.get('color'), + color: styleForItem.get('text-color-internal') + } + } + return {} + } + } + throw new Error(`Unsupported argument: ${kind}`) +} +function createNodeStyleGetter(graphStyleData) { + return createStyleGetter(graphStyleData, 'node') +} +function createRelationStyleGetter(graphStyleData) { + return createStyleGetter(graphStyleData, 'relationship') +} + const createItems = ( originalList, onItemClick, @@ -63,7 +106,7 @@ const createItems = ( editorCommandTemplate, showStar = true, count, - graphStyleData + styleGetter = () => ({}) ) => { const items = [...originalList] if (showStar) { @@ -73,29 +116,15 @@ const createItems = ( } items.unshift(str) } - const graphStyle = neoGraphStyle() - if (graphStyleData) { - graphStyle.loadRules(deepmerge(graphStyle.toSheet(), graphStyleData || {})) - } return items.map((text, index) => { - let style = {} - if (graphStyleData) { - const styleForItem = graphStyle.forNode({ - labels: [text] - }) - style = { - backgroundColor: styleForItem.get('color'), - color: styleForItem.get('text-color-internal') - } - } const getNodesCypher = editorCommandTemplate(text, index) return ( onItemClick(getNodesCypher)} - style={style} + style={styleGetter(text)} > {text} @@ -127,7 +156,7 @@ const LabelItems = ({ editorCommandTemplate, true, count, - graphStyleData + createNodeStyleGetter(graphStyleData) ) } return ( @@ -151,7 +180,8 @@ const RelationshipItems = ({ onItemClick, moreStep, onMoreClick, - count + count, + graphStyleData }) => { let relationshipItems =

No relationships in database

if (relationshipTypes.length > 0) { @@ -169,7 +199,8 @@ const RelationshipItems = ({ { component: StyledRelationship }, editorCommandTemplate, true, - count + count, + createRelationStyleGetter(graphStyleData) ) } return (