Skip to content

Commit b8d764f

Browse files
Merge branch 'main' into main
2 parents e4b6bf0 + 2b85226 commit b8d764f

File tree

29 files changed

+1002
-139
lines changed

29 files changed

+1002
-139
lines changed

src/components/EditorCanvas/Canvas.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { useEventListener } from "usehooks-ts";
3131
import { areFieldsCompatible, getTableHeight } from "../../utils/utils";
3232
import { getRectFromEndpoints, isInsideRect } from "../../utils/rect";
3333
import { State, noteWidth } from "../../data/constants";
34+
import { nanoid } from "nanoid";
3435

3536
export default function Canvas() {
3637
const { t } = useTranslation();
@@ -622,7 +623,7 @@ export default function Canvas() {
622623
updateConstraint: Constraint.NONE,
623624
deleteConstraint: Constraint.NONE,
624625
name: `fk_${startTableName}_${startField.name}_${endTableName}`,
625-
id: relationships.length,
626+
id: nanoid(),
626627
};
627628
delete newRelationship.startX;
628629
delete newRelationship.startY;

src/components/EditorHeader/ControlPanel.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default function ControlPanel({
163163
} else if (a.element === ObjectType.NOTE) {
164164
deleteNote(notes[notes.length - 1].id, false);
165165
} else if (a.element === ObjectType.RELATIONSHIP) {
166-
deleteRelationship(a.data.id, false);
166+
deleteRelationship(a.data.relationship.id, false);
167167
} else if (a.element === ObjectType.TYPE) {
168168
deleteType(types.length - 1, false);
169169
} else if (a.element === ObjectType.ENUM) {
@@ -361,7 +361,7 @@ export default function ControlPanel({
361361
if (a.element === ObjectType.TABLE) {
362362
deleteTable(a.data.table.id, false);
363363
} else if (a.element === ObjectType.RELATIONSHIP) {
364-
deleteRelationship(a.data.id, false);
364+
deleteRelationship(a.data.relationship.id, false);
365365
} else if (a.element === ObjectType.NOTE) {
366366
deleteNote(a.data.id, false);
367367
} else if (a.element === ObjectType.AREA) {

src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { Collapse } from "@douyinfe/semi-ui";
2-
import { useSelect, useDiagram } from "../../../hooks";
2+
import { useSelect, useDiagram, useSaveState, useLayout } from "../../../hooks";
33
import Empty from "../Empty";
44
import SearchBar from "./SearchBar";
55
import RelationshipInfo from "./RelationshipInfo";
6-
import { ObjectType } from "../../../data/constants";
6+
import { ObjectType, State } from "../../../data/constants";
77
import { useTranslation } from "react-i18next";
8+
import { SortableList } from "../../SortableList/SortableList";
9+
import { DragHandle } from "../../SortableList/DragHandle";
810

911
export default function RelationshipsTab() {
10-
const { relationships } = useDiagram();
12+
const { relationships, setRelationships } = useDiagram();
1113
const { selectedElement, setSelectedElement } = useSelect();
14+
const { setSaveState } = useSaveState();
15+
const { layout } = useLayout();
1216
const { t } = useTranslation();
1317

1418
return (
@@ -29,30 +33,40 @@ export default function RelationshipsTab() {
2933
}
3034
keepDOM={false}
3135
lazyRender
32-
onChange={(k) =>
36+
onChange={(k) => {
3337
setSelectedElement((prev) => ({
3438
...prev,
3539
open: true,
36-
id: parseInt(k),
40+
id: k[0],
3741
element: ObjectType.RELATIONSHIP,
38-
}))
39-
}
42+
}));
43+
}}
4044
accordion
4145
>
42-
{relationships.map((r) => (
43-
<div id={`scroll_ref_${r.id}`} key={"relationship_" + r.id}>
44-
<Collapse.Panel
45-
header={
46-
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
47-
{r.name}
48-
</div>
49-
}
50-
itemKey={`${r.id}`}
51-
>
52-
<RelationshipInfo data={r} />
53-
</Collapse.Panel>
54-
</div>
55-
))}
46+
<SortableList
47+
keyPrefix="relationships-tab"
48+
items={relationships}
49+
onChange={(newRelationships) => setRelationships(newRelationships)}
50+
afterChange={() => setSaveState(State.SAVING)}
51+
renderItem={(item) => (
52+
<div id={`scroll_ref_${item.id}`} key={"relationship_" + item.id}>
53+
<Collapse.Panel
54+
className="relative"
55+
header={
56+
<div className="w-full flex items-center gap-2">
57+
<DragHandle readOnly={layout.readOnly} id={item.id} />
58+
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
59+
{item.name}
60+
</div>
61+
</div>
62+
}
63+
itemKey={`${item.id}`}
64+
>
65+
<RelationshipInfo data={item} />
66+
</Collapse.Panel>
67+
</div>
68+
)}
69+
/>
5670
</Collapse>
5771
)}
5872
</>

src/components/EditorSidePanel/TypesTab/TypeField.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default function TypeField({ data, tid, fid }) {
7878
})),
7979
...types
8080
.filter(
81-
(type) => type.name.toLowerCase() !== data.name.toLowerCase(),
81+
(type) => type.name.toLowerCase() !== types[tid].name.toLowerCase(),
8282
)
8383
.map((type) => ({
8484
label: type.name.toUpperCase(),

src/context/DiagramContext.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function DiagramContextProvider({ children }) {
2929
...prev,
3030
{
3131
id,
32-
name: `table_${prev.length}`,
32+
name: `table_${id}`,
3333
x: transform.pan.x,
3434
y: transform.pan.y,
3535
locked: false,
@@ -183,7 +183,10 @@ export default function DiagramContextProvider({ children }) {
183183
{
184184
action: Action.ADD,
185185
element: ObjectType.RELATIONSHIP,
186-
data: data,
186+
data: {
187+
relationship: data,
188+
index: prevUndo.length
189+
},
187190
message: t("add_relationship"),
188191
},
189192
]);
@@ -193,30 +196,32 @@ export default function DiagramContextProvider({ children }) {
193196
} else {
194197
setRelationships((prev) => {
195198
const temp = prev.slice();
196-
temp.splice(data.id, 0, data);
197-
return temp.map((t, i) => ({ ...t, id: i }));
199+
temp.splice(data.index, 0, data.relationship || data);
200+
return temp;
198201
});
199202
}
200203
};
201204

202205
const deleteRelationship = (id, addToHistory = true) => {
203206
if (addToHistory) {
207+
const relationshipIndex = relationships.findIndex((r) => r.id === id);
204208
setUndoStack((prev) => [
205209
...prev,
206210
{
207211
action: Action.DELETE,
208212
element: ObjectType.RELATIONSHIP,
209-
data: relationships[id],
213+
data: {
214+
relationship: relationships[relationshipIndex],
215+
index: relationshipIndex,
216+
},
210217
message: t("delete_relationship", {
211-
refName: relationships[id].name,
218+
refName: relationships[relationshipIndex].name,
212219
}),
213220
},
214221
]);
215222
setRedoStack([]);
216223
}
217-
setRelationships((prev) =>
218-
prev.filter((e) => e.id !== id).map((e, i) => ({ ...e, id: i })),
219-
);
224+
setRelationships((prev) => prev.filter((e) => e.id !== id));
220225
};
221226

222227
const updateRelationship = (id, updatedValues) => {

src/data/schemas.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const tableSchema = {
1313
id: { type: ["integer", "string"] },
1414
name: { type: "string" },
1515
type: { type: "string" },
16-
default: { type: "string" },
16+
default: { type: ["string", "number", "boolean"] },
1717
check: { type: "string" },
1818
primary: { type: "boolean" },
1919
unique: { type: "boolean" },
@@ -55,10 +55,10 @@ export const tableSchema = {
5555
},
5656
},
5757
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
58-
},
59-
inherits: {
60-
type: "array",
61-
items: { type: ["string"] },
58+
inherits: {
59+
type: "array",
60+
items: { type: ["string"] },
61+
},
6262
},
6363
required: ["id", "name", "x", "y", "fields", "comment", "indices", "color"],
6464
};
@@ -148,7 +148,7 @@ export const jsonSchema = {
148148
cardinality: { type: "string" },
149149
updateConstraint: { type: "string" },
150150
deleteConstraint: { type: "string" },
151-
id: { type: "integer" },
151+
id: { type: ["integer", "string"] },
152152
},
153153
required: [
154154
"startTableId",

src/i18n/i18n.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ import { ne, nepali } from "./locales/ne";
4040
import { ug, uyghur } from "./locales/ug";
4141
import { pa_pk, punjabipk } from "./locales/pa-pk";
4242
import { cz, czech } from "./locales/cz";
43-
import { th, thai } from "./locales/th";
43+
import { ml, malayalam } from "./locales/ml";
44+
import { nl, dutch } from './locales/nl';
45+
import { sd, sindhi } from './locales/sd';
46+
import { th, thai } from './locales/th';
4447

4548
export const languages = [
4649
english,
@@ -82,6 +85,9 @@ export const languages = [
8285
uyghur,
8386
punjabipk,
8487
czech,
88+
malayalam,
89+
dutch,
90+
sindhi,
8591
].sort((a, b) => a.name.localeCompare(b.name));
8692

8793
i18n
@@ -133,6 +139,9 @@ i18n
133139
ug,
134140
"pa-PK": pa_pk,
135141
cz,
142+
ml,
143+
nl,
144+
sd,
136145
th,
137146
},
138147
});

0 commit comments

Comments
 (0)