11import React from 'react' ;
22import { DataGrid } from '@mui/x-data-grid' ;
3- import { Chip } from '@material-ui/core' ;
4- import { withStyles } from '@material-ui/core/styles' ;
5- import Tooltip from '@material-ui/core/Tooltip' ;
63import { ChartProps } from './Chart' ;
7- import { valueIsNode , valueIsRelationship , getRecordType } from '../report/RecordProcessing' ;
8-
9- function addDirection ( relationship , start ) {
10- relationship . direction = ( relationship . start . low == start . identity . low ) ;
11- return relationship ;
12- }
13-
14- const rightRelationship = "polygon(10px 0%, calc(100% - 10px) 0%, 100% 50%, 100% calc(100% - 50%), calc(100% - 10px) 100%, 0px 100%, 0% calc(100% - 0px), 0% 0px)"
15- const leftRelationship = "polygon(10px 0%, calc(100% - 0%) 0%, 100% 10px, 100% calc(100% - 10px), calc(100% - 0%) 100%, 10px 100%, 0% calc(100% - 50%), 0% 50%)"
16-
17- const HtmlTooltip = withStyles ( ( theme ) => ( {
18- tooltip : {
19- color : 'white' ,
20- fontSize : theme . typography . pxToRem ( 12 ) ,
21- border : '1px solid #fcfffa' ,
22- } ,
23- } ) ) ( Tooltip ) ;
24-
25- function RenderNode ( value , key = 0 ) {
26- return < HtmlTooltip key = { key + "-" + value . identity } arrow title = { < div > < b > { value . labels . length > 0 ? value . labels . join ( ", " ) : "Node" } </ b > < table > < tbody > { Object . keys ( value . properties ) . length == 0 ? < tr > < td > (No properties)</ td > </ tr > : Object . keys ( value . properties ) . map ( ( k , i ) => < tr key = { i } > < td key = { 0 } > { k . toString ( ) } :</ td > < td key = { 1 } > { value . properties [ k ] . toString ( ) } </ td > </ tr > ) } </ tbody > </ table > </ div > } >
27- < Chip label = { value . labels . length > 0 ? value . labels . join ( ", " ) : "Node" } />
28- </ HtmlTooltip >
29- }
30-
31- function RenderRelationship ( value , key = 0 ) {
32- return < HtmlTooltip key = { key + "-" + value . identity } arrow title = { < div > < b > { value . type } </ b > < table > < tbody > { Object . keys ( value . properties ) . length == 0 ? < tr > < td > (No properties)</ td > </ tr > : Object . keys ( value . properties ) . map ( ( k , i ) => < tr key = { i } > < td key = { 0 } > { k . toString ( ) } :</ td > < td key = { 1 } > { value . properties [ k ] . toString ( ) } </ td > </ tr > ) } </ tbody > </ table > </ div > } >
33- < Chip style = { { borderRadius : 0 , clipPath : ( value . direction == undefined ) ? "none" : ( ( value . direction ) ? rightRelationship : leftRelationship ) } } label = { value . type } />
34- </ HtmlTooltip >
35- }
36-
37- function RenderPath ( value ) {
38- return value . segments . map ( ( segment , i ) => {
39- return RenderSubValue ( ( i < value . segments . length - 1 ) ?
40- [ segment . start , addDirection ( segment . relationship , segment . start ) ] :
41- [ segment . start , addDirection ( segment . relationship , segment . start ) , segment . end ] , i )
42- } ) ;
43- }
44-
45- function RenderArray ( value ) {
46- const mapped = value . map ( ( v , i ) => {
47- return < div >
48- { RenderSubValue ( v ) }
49- { i < value . length - 1 && ! valueIsNode ( v ) && ! valueIsRelationship ( v ) ? < span > , </ span > : < > </ > }
50- </ div >
51- } ) ;
52- return mapped ;
53- }
54-
55- function RenderString ( value ) {
56- const str = value ? value . toString ( ) : "" ;
57- if ( str . startsWith ( "http" ) || str . startsWith ( "https" ) ) {
58- return < a target = "_blank" href = { str } > { str } </ a > ;
59- }
60- return str ;
61- }
62-
63- const customColumnProperties : any = {
64- "node" : {
65- type : 'string' ,
66- renderCell : ( c ) => RenderNode ( c . value ) ,
67- } ,
68- "relationship" : {
69- type : 'string' ,
70- renderCell : ( c ) => RenderRelationship ( c . value ) ,
71- } ,
72- "path" : {
73- type : 'string' ,
74- renderCell : ( c ) => RenderPath ( c . value ) ,
75- } ,
76- "object" : {
77- type : 'string' ,
78- // valueGetter enables sorting and filtering on string values inside the object
79- valueGetter : ( c ) => { return JSON . stringify ( c . value ) } ,
80- } ,
81- "array" : {
82- type : 'string' ,
83- renderCell : ( c ) => RenderArray ( c . value ) ,
84- } ,
85- "string" : {
86- type : 'string' ,
87- renderCell : ( c ) => RenderString ( c . value ) ,
88- } ,
89- "null" : {
90- type : 'string'
91- } ,
92- "undefined" : {
93- type : 'string'
94- }
95- } ;
4+ import { getRecordType , getRendererForValue } from '../report/RecordProcessing' ;
965
976function ApplyColumnType ( column , value ) {
98- column . type = getRecordType ( value ) ;
99- const columnProperties = customColumnProperties [ column . type ] ;
7+ const renderer = getRendererForValue ( value ) ;
8+ const columnProperties = { type : renderer . type , renderCell : renderer . renderValue } ;
1009
10110 if ( columnProperties ) {
10211 column = { ...column , ...columnProperties }
@@ -105,24 +14,6 @@ function ApplyColumnType(column, value) {
10514 return column ;
10615}
10716
108- function RenderSubValue ( value , key = 0 ) {
109- if ( value == undefined ) {
110- return "" ;
111- }
112- const type = getRecordType ( value ) ;
113- const columnProperties = customColumnProperties [ type ] ;
114-
115- if ( columnProperties ) {
116- if ( columnProperties . renderCell ) {
117- return columnProperties . renderCell ( { value : value } ) ;
118- } else if ( columnProperties . valueGetter ) {
119- return columnProperties . valueGetter ( { value : value } ) ;
120- }
121- }
122-
123- return RenderString ( value ) ;
124- }
125-
12617const NeoTableChart = ( props : ChartProps ) => {
12718 const fullscreen = props . fullscreen ? props . fullscreen : false ;
12819 const transposed = props . settings && props . settings . transposed ? props . settings . transposed : false ;
0 commit comments