-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathGraphPropertiesPanel.tsx
91 lines (85 loc) · 3.39 KB
/
GraphPropertiesPanel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { useMemo } from 'react';
import { ResizePanelDetails } from './ResizePanel';
import { BasicNode, BasicRelationship, GraphPropertiesPanelProps } from '../../types';
import { LegendsChip } from './LegendsChip';
import GraphPropertiesTable from './GraphPropertiesTable';
const sortAlphabetically = (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase());
const isNode = (item: BasicNode | BasicRelationship): item is BasicNode => {
return 'labels' in item && !('from' in item) && !('to' in item);
};
const GraphPropertiesPanel = ({ inspectedItem, newScheme }: GraphPropertiesPanelProps) => {
const inspectedItemType = isNode(inspectedItem) ? 'node' : 'relationship';
const properties = inspectedItemType === 'node'
? [
{
key: '<id>',
value: `${(inspectedItem as BasicNode).id}`,
type: 'String',
},
...Object.keys((inspectedItem as BasicNode).properties).map((key) => {
const value = (inspectedItem as BasicNode).properties[key];
return { key: key, value: value ?? '' };
}),
]
: [
{
key: '<element_id>',
value: `${(inspectedItem as BasicRelationship).id}`,
type: 'String',
},
{
key: '<from>',
value: `${(inspectedItem as BasicRelationship).from}`,
type: 'String',
},
{
key: '<to>',
value: `${(inspectedItem as BasicRelationship).to}`,
type: 'String',
},
{
key: '<caption>',
value: `${(inspectedItem as BasicRelationship).caption ?? ''}`,
type: 'String',
},
];
const labelsSorted = useMemo(() => {
if (isNode(inspectedItem)) {
return [...inspectedItem.labels].sort(sortAlphabetically);
}
return [];
}, [inspectedItem]);
return (
<>
<ResizePanelDetails.Title>
<h6 className="mr-auto">
{inspectedItemType === 'node' ? 'Node details' : 'Relationship details'}
</h6>
</ResizePanelDetails.Title>
<ResizePanelDetails.Content>
<div className="mx-4 flex flex-row flex-wrap gap-2">
{isNode(inspectedItem) ? (
labelsSorted.map((label) => (
<LegendsChip
type="node"
key={`node ${label}`}
label={label}
scheme={newScheme}
/>
))
) : (
<LegendsChip
type="relationship"
label={(inspectedItem as BasicRelationship).caption ?? ''}
key={`relationship ${(inspectedItem as BasicRelationship).id}`}
scheme={{}}
/>
)}
</div>
<div className="bg-palette-neutral-border-weak my-3 h-px w-full" />
<GraphPropertiesTable propertiesWithTypes={properties} />
</ResizePanelDetails.Content>
</>
);
}
export default GraphPropertiesPanel;