mirror of
https://github.com/drawdb-io/drawdb.git
synced 2026-02-13 02:12:56 +08:00
Fix invalid sql after swapping fields (#287)
This commit is contained in:
@@ -14,11 +14,12 @@ import ColorPalette from "../../ColorPicker";
|
||||
import TableField from "./TableField";
|
||||
import IndexDetails from "./IndexDetails";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { dbToTypes } from "../../../data/datatypes";
|
||||
|
||||
export default function TableInfo({ data }) {
|
||||
const { t } = useTranslation();
|
||||
const [indexActiveKey, setIndexActiveKey] = useState("");
|
||||
const { deleteTable, updateTable, updateField, setRelationships } =
|
||||
const { deleteTable, updateTable, updateField, setRelationships, database } =
|
||||
useDiagram();
|
||||
const { setUndoStack, setRedoStack } = useUndoRedo();
|
||||
const [editField, setEditField] = useState({});
|
||||
@@ -106,8 +107,20 @@ export default function TableInfo({ data }) {
|
||||
const a = data.fields[index];
|
||||
const b = data.fields[j];
|
||||
|
||||
updateField(data.id, index, { ...b, id: index });
|
||||
updateField(data.id, j, { ...a, id: j });
|
||||
updateField(data.id, index, {
|
||||
...b,
|
||||
...(!dbToTypes[database][b.type].isSized && { size: "" }),
|
||||
...(!dbToTypes[database][b.type].hasCheck && { check: "" }),
|
||||
...(dbToTypes[database][b.type].noDefault && { default: "" }),
|
||||
id: index,
|
||||
});
|
||||
updateField(data.id, j, {
|
||||
...a,
|
||||
...(!dbToTypes[database][a.type].isSized && { size: "" }),
|
||||
...(!dbToTypes[database][a.type].hasCheck && { check: "" }),
|
||||
...(!dbToTypes[database][a.type].noDefault && { default: "" }),
|
||||
id: j,
|
||||
});
|
||||
|
||||
setRelationships((prev) =>
|
||||
prev.map((e) => {
|
||||
|
||||
Reference in New Issue
Block a user