-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableNode.tsx
87 lines (78 loc) · 3.02 KB
/
TableNode.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
import { useState, FC, useEffect } from "react";
import { Handle, Position, NodeProps } from "reactflow";
import { KeyIcon } from "../components";
import { markdown } from "../helpers";
import "@reactflow/node-resizer/dist/style.css";
export const TableNode: FC<NodeProps> = ({ data }) => {
const [selectedColumn, setSelectedColumn] = useState("");
const [showDescription, setshowDescription] = useState(false);
const [descriptionOnHoverActive, setDescriptionOnHoverActive] = useState(false);
useEffect(() => {
document.addEventListener("keydown", (e: KeyboardEvent) => {
if(e.code === "MetaLeft") {
setDescriptionOnHoverActive(true)
}
}, false);
document.addEventListener("keyup", (e: KeyboardEvent) => {
if(e.code === "MetaLeft") {
setDescriptionOnHoverActive(false)
}
}, false);
}, []);
return (
<div className="table">
<div
style={{ backgroundColor: data.schemaColor }}
className="table__name"
onMouseEnter={() => {
if(descriptionOnHoverActive) {
setshowDescription(true)
}
}}
onMouseLeave={() => setshowDescription(false)}>
{data.schema ? `${data.schema}.${data.name}` : data.name}
<div
className={showDescription ? "table__description table__description--active" : "table__description"}
dangerouslySetInnerHTML={{__html: markdown(data.description || "No description.") }} />
</div>
<div className="table__columns">
{data.columns.map((column: any, index: any) => (
<div
key={index}
className={selectedColumn === column.name ? "column-name column-name--selected" : "column-name"}
onMouseEnter={() => {
if(descriptionOnHoverActive) {
setSelectedColumn(column.name)
}
}}
onMouseLeave={() => setSelectedColumn("")}>
{column.handleType && <Handle
type={column.handleType}
position={Position.Right}
id={`${column.name}-right`}
className={column.handleType === "source" ? "right-handle source-handle" : "right-handle target-handle"}
/>}
{column.handleType && <Handle
type={column.handleType}
position={Position.Left}
id={`${column.name}-left`}
className={column.handleType === "source" ? "left-handle source-handle" : "left-handle target-handle"}
/>}
<div className="column-name__inner">
<div className="column-name__name">
{column.key && <KeyIcon />}
{column.name}
</div>
<div className="column-name__type">
{column.type}
</div>
<div
className="column-name__description"
dangerouslySetInnerHTML={{__html: markdown(column.description || "No description.") }} />
</div>
</div>
))}
</div>
</div>
);
};