Merge branch 'drawdb-io:main' into popovers_comments
This commit is contained in:
commit
6580a40017
@ -4,6 +4,7 @@ import {
|
|||||||
ObjectType,
|
ObjectType,
|
||||||
tableFieldHeight,
|
tableFieldHeight,
|
||||||
tableHeaderHeight,
|
tableHeaderHeight,
|
||||||
|
tableColorStripHeight,
|
||||||
} from "../../data/constants";
|
} from "../../data/constants";
|
||||||
import {
|
import {
|
||||||
IconEdit,
|
IconEdit,
|
||||||
@ -53,7 +54,7 @@ export default function Table(props) {
|
|||||||
.getElementById(`scroll_table_${tableData.id}`)
|
.getElementById(`scroll_table_${tableData.id}`)
|
||||||
.scrollIntoView({ behavior: "smooth" });
|
.scrollIntoView({ behavior: "smooth" });
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -269,7 +270,9 @@ export default function Table(props) {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
index === tableData.fields.length - 1 || "border-b border-gray-400"
|
index === tableData.fields.length - 1
|
||||||
|
? ""
|
||||||
|
: "border-b border-gray-400"
|
||||||
} group h-[36px] px-2 py-1 flex justify-between items-center gap-1 w-full overflow-hidden`}
|
} group h-[36px] px-2 py-1 flex justify-between items-center gap-1 w-full overflow-hidden`}
|
||||||
onMouseEnter={() => {
|
onMouseEnter={() => {
|
||||||
setHoveredField(index);
|
setHoveredField(index);
|
||||||
@ -296,9 +299,19 @@ export default function Table(props) {
|
|||||||
startFieldId: index,
|
startFieldId: index,
|
||||||
startTableId: tableData.id,
|
startTableId: tableData.id,
|
||||||
startX: tableData.x + 15,
|
startX: tableData.x + 15,
|
||||||
startY: tableData.y + index * 36 + 50 + 19,
|
startY:
|
||||||
|
tableData.y +
|
||||||
|
index * tableFieldHeight +
|
||||||
|
tableHeaderHeight +
|
||||||
|
tableColorStripHeight +
|
||||||
|
12,
|
||||||
endX: tableData.x + 15,
|
endX: tableData.x + 15,
|
||||||
endY: tableData.y + index * 36 + 50 + 19,
|
endY:
|
||||||
|
tableData.y +
|
||||||
|
index * tableFieldHeight +
|
||||||
|
tableHeaderHeight +
|
||||||
|
tableColorStripHeight +
|
||||||
|
12,
|
||||||
}));
|
}));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
import { useEffect, useState, useRef } from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
import { Cardinality } from "../data/constants";
|
import {
|
||||||
|
Cardinality,
|
||||||
|
tableColorStripHeight,
|
||||||
|
tableFieldHeight,
|
||||||
|
tableHeaderHeight,
|
||||||
|
tableWidth,
|
||||||
|
} from "../data/constants";
|
||||||
import { calcPath } from "../utils/calcPath";
|
import { calcPath } from "../utils/calcPath";
|
||||||
|
|
||||||
function Table({ table, grab }) {
|
function Table({ table, grab }) {
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const [hoveredField, setHoveredField] = useState(-1);
|
const [hoveredField, setHoveredField] = useState(-1);
|
||||||
const height = table.fields.length * 36 + 50 + 7;
|
const height =
|
||||||
|
table.fields.length * tableFieldHeight +
|
||||||
|
tableHeaderHeight +
|
||||||
|
tableColorStripHeight;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<foreignObject
|
<foreignObject
|
||||||
key={table.name}
|
key={table.name}
|
||||||
x={table.x}
|
x={table.x}
|
||||||
y={table.y}
|
y={table.y}
|
||||||
width={200}
|
width={tableWidth}
|
||||||
height={height}
|
height={height}
|
||||||
className="drop-shadow-lg rounded-md cursor-move"
|
className="drop-shadow-lg rounded-md cursor-move"
|
||||||
onMouseDown={grab}
|
onMouseDown={grab}
|
||||||
@ -161,8 +171,8 @@ export default function SimpleCanvas({ diagram, zoom }) {
|
|||||||
const dy = e.clientY - offset.y;
|
const dy = e.clientY - offset.y;
|
||||||
setTables((prev) =>
|
setTables((prev) =>
|
||||||
prev.map((table, i) =>
|
prev.map((table, i) =>
|
||||||
i === dragging ? { ...table, x: dx, y: dy } : table
|
i === dragging ? { ...table, x: dx, y: dy } : table,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -52,6 +52,7 @@ export const defaultNoteTheme = "#fcf7ac";
|
|||||||
export const tableHeaderHeight = 50;
|
export const tableHeaderHeight = 50;
|
||||||
export const tableWidth = 200;
|
export const tableWidth = 200;
|
||||||
export const tableFieldHeight = 36;
|
export const tableFieldHeight = 36;
|
||||||
|
export const tableColorStripHeight = 7;
|
||||||
|
|
||||||
export const Cardinality = {
|
export const Cardinality = {
|
||||||
ONE_TO_ONE: "One to one",
|
ONE_TO_ONE: "One to one",
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
|
import {
|
||||||
|
tableColorStripHeight,
|
||||||
|
tableFieldHeight,
|
||||||
|
tableHeaderHeight,
|
||||||
|
} from "./constants";
|
||||||
|
|
||||||
const xOffset = window.innerWidth * 0.65;
|
const xOffset = window.innerWidth * 0.65;
|
||||||
export const diagram = {
|
export const diagram = {
|
||||||
tables: [
|
tables: [
|
||||||
{
|
{
|
||||||
name: "galactic_users",
|
name: "galactic_users",
|
||||||
x: xOffset + 75,
|
x: xOffset + 75,
|
||||||
y: window.innerHeight * 0.23 - (50 + 4 * 36 + 7) * 0.5,
|
y:
|
||||||
|
window.innerHeight * 0.23 -
|
||||||
|
(tableHeaderHeight + 4 * tableFieldHeight + tableColorStripHeight) *
|
||||||
|
0.5,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
@ -29,7 +38,10 @@ export const diagram = {
|
|||||||
id: 1,
|
id: 1,
|
||||||
name: "celestial_data",
|
name: "celestial_data",
|
||||||
x: xOffset + 27,
|
x: xOffset + 27,
|
||||||
y: window.innerHeight * 0.72 - (50 + 5 * 36 + 7) * 0.5,
|
y:
|
||||||
|
window.innerHeight * 0.72 -
|
||||||
|
(tableHeaderHeight + 5 * tableFieldHeight + tableColorStripHeight) *
|
||||||
|
0.5,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
@ -58,7 +70,10 @@ export const diagram = {
|
|||||||
id: 2,
|
id: 2,
|
||||||
name: "astro_mine",
|
name: "astro_mine",
|
||||||
x: xOffset + 336,
|
x: xOffset + 336,
|
||||||
y: window.innerHeight * 0.72 - (50 + 3 * 36 + 7) * 0.5,
|
y:
|
||||||
|
window.innerHeight * 0.72 -
|
||||||
|
(tableHeaderHeight + 3 * tableFieldHeight + tableColorStripHeight) *
|
||||||
|
0.5,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
@ -79,7 +94,10 @@ export const diagram = {
|
|||||||
id: 3,
|
id: 3,
|
||||||
name: "asteroid",
|
name: "asteroid",
|
||||||
x: xOffset + 310,
|
x: xOffset + 310,
|
||||||
y: window.innerHeight * 0.23 - (50 + 3 * 36 + 7) * 0.5,
|
y:
|
||||||
|
window.innerHeight * 0.23 -
|
||||||
|
(tableHeaderHeight + 3 * tableFieldHeight + tableColorStripHeight) *
|
||||||
|
0.5,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
|
Loading…
Reference in New Issue
Block a user