-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcanvas-svg.component.tsx
More file actions
79 lines (76 loc) · 2.41 KB
/
canvas-svg.component.tsx
File metadata and controls
79 lines (76 loc) · 2.41 KB
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
import { GUID, Size } from '@/core/model';
import classes from './canvas.pod.module.css';
import {
DatabaseSchemaVm,
TableVm,
UpdatePositionFn,
} from '@/core/providers/canvas-schema';
import { DatabaseTable } from './components/table/database-table.component';
import { DatabaseRelationCollectionComponent } from './components/relation';
import { SelectedTableFilterHighlightComponent } from './components/table/components/selected-table-filter-highlight.component';
import { CANVAS_MAX_HEIGHT, CANVAS_MAX_WIDTH } from '@/core/providers';
interface Props {
viewBoxSize: Size;
canvasSize: Size;
zoomFactor: number;
canvasSchema: DatabaseSchemaVm;
onUpdateTablePosition: UpdatePositionFn;
onToggleCollapse: (tableId: GUID, fieldId: GUID) => void;
onEditTable: (tableInfo: TableVm) => void;
onManageIndex: (tableInfo: TableVm) => void;
onEditRelation: (relationId: GUID) => void;
onSelectElement: (relationId: GUID | null) => void;
isTabletOrMobileDevice: boolean;
}
export const CanvasSvgComponent: React.FC<Props> = props => {
const {
viewBoxSize,
canvasSize,
zoomFactor,
canvasSchema,
onUpdateTablePosition,
onToggleCollapse,
onEditTable,
onManageIndex,
onEditRelation,
onSelectElement,
isTabletOrMobileDevice,
} = props;
const clearSelection = () => {
onSelectElement(null);
};
return (
<svg
xmlns="http://www.w3.org/2000/svg"
className={classes.containerSvg}
viewBox={`0 0 ${viewBoxSize.width} ${viewBoxSize.height}`}
width={CANVAS_MAX_WIDTH}
height={CANVAS_MAX_HEIGHT}
onClick={clearSelection}
aria-hidden={true}
>
<DatabaseRelationCollectionComponent
schema={canvasSchema}
onEditRelation={onEditRelation}
onSelectRelation={onSelectElement}
/>
<SelectedTableFilterHighlightComponent />
{canvasSchema.tables.map(table => (
<DatabaseTable
key={table.id}
tableInfo={table}
updatePosition={onUpdateTablePosition}
onToggleCollapse={onToggleCollapse}
onEditTable={onEditTable}
onManageIndex={onManageIndex}
canvasSize={canvasSize}
isSelected={canvasSchema.selectedElementId === table.id}
selectTable={onSelectElement}
isTabletOrMobileDevice={isTabletOrMobileDevice}
viewBoxSize={viewBoxSize}
zoomFactor={zoomFactor}
/>
))}
</svg>
);
};