Skip to content

Commit

Permalink
Add color to relationships in sidebar (#1232)
Browse files Browse the repository at this point in the history
* Add color to relationships in sidebar
  • Loading branch information
OskarDamkjaer authored Nov 3, 2020
1 parent 79a02ef commit 71b4019
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/browser/modules/DBMSInfo/DBMSInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function DBMSInfo(props) {
totalNumItems={relationshipTypes.length}
onMoreClick={onMoreClick('relationships', relationshipsMax)}
moreStep={moreStep}
graphStyleData={props.graphStyleData}
/>
<PropertyItems
properties={properties.slice(0, propertiesMax).map(l => l.val)}
Expand Down
69 changes: 50 additions & 19 deletions src/browser/modules/DBMSInfo/MetaItems.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,57 @@ 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 createRelationshipStyleGetter(graphStyleData) {
return createStyleGetter(graphStyleData, 'relationship')
}

const createItems = (
originalList,
onItemClick,
RenderType,
editorCommandTemplate,
showStar = true,
count,
graphStyleData
styleGetter = () => ({})
) => {
const items = [...originalList]
if (showStar) {
Expand All @@ -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 (
<RenderType.component
data-testid="sidebarMetaItem"
key={index}
onClick={() => onItemClick(getNodesCypher)}
style={style}
style={styleGetter(text)}
>
{text}
</RenderType.component>
Expand Down Expand Up @@ -127,7 +156,7 @@ const LabelItems = ({
editorCommandTemplate,
true,
count,
graphStyleData
createNodeStyleGetter(graphStyleData)
)
}
return (
Expand All @@ -151,7 +180,8 @@ const RelationshipItems = ({
onItemClick,
moreStep,
onMoreClick,
count
count,
graphStyleData
}) => {
let relationshipItems = <p>No relationships in database</p>
if (relationshipTypes.length > 0) {
Expand All @@ -169,7 +199,8 @@ const RelationshipItems = ({
{ component: StyledRelationship },
editorCommandTemplate,
true,
count
count,
createRelationshipStyleGetter(graphStyleData)
)
}
return (
Expand Down

0 comments on commit 71b4019

Please sign in to comment.