Export and import enums in diagrams
This commit is contained in:
parent
61d97e8143
commit
1430db881c
@ -65,6 +65,7 @@ import Sidesheet from "./SideSheet/Sidesheet";
|
|||||||
import Modal from "./Modal/Modal";
|
import Modal from "./Modal/Modal";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { exportSQL } from "../../utils/exportSQL";
|
import { exportSQL } from "../../utils/exportSQL";
|
||||||
|
import { databases } from "../../data/databases";
|
||||||
|
|
||||||
export default function ControlPanel({
|
export default function ControlPanel({
|
||||||
diagramId,
|
diagramId,
|
||||||
@ -100,7 +101,7 @@ export default function ControlPanel({
|
|||||||
deleteRelationship,
|
deleteRelationship,
|
||||||
database,
|
database,
|
||||||
} = useTables();
|
} = useTables();
|
||||||
const { enums } = useEnums();
|
const { enums, setEnums } = useEnums();
|
||||||
const { types, addType, deleteType, updateType, setTypes } = useTypes();
|
const { types, addType, deleteType, updateType, setTypes } = useTypes();
|
||||||
const { notes, setNotes, updateNote, addNote, deleteNote } = useNotes();
|
const { notes, setNotes, updateNote, addNote, deleteNote } = useNotes();
|
||||||
const { areas, setAreas, updateArea, addArea, deleteArea } = useAreas();
|
const { areas, setAreas, updateArea, addArea, deleteArea } = useAreas();
|
||||||
@ -116,7 +117,7 @@ export default function ControlPanel({
|
|||||||
const undo = () => {
|
const undo = () => {
|
||||||
if (undoStack.length === 0) return;
|
if (undoStack.length === 0) return;
|
||||||
const a = undoStack[undoStack.length - 1];
|
const a = undoStack[undoStack.length - 1];
|
||||||
setUndoStack((prev) => prev.filter((e, i) => i !== prev.length - 1));
|
setUndoStack((prev) => prev.filter((_, i) => i !== prev.length - 1));
|
||||||
if (a.action === Action.ADD) {
|
if (a.action === Action.ADD) {
|
||||||
if (a.element === ObjectType.TABLE) {
|
if (a.element === ObjectType.TABLE) {
|
||||||
deleteTable(tables[tables.length - 1].id, false);
|
deleteTable(tables[tables.length - 1].id, false);
|
||||||
@ -732,6 +733,7 @@ export default function ControlPanel({
|
|||||||
setAreas([]);
|
setAreas([]);
|
||||||
setNotes([]);
|
setNotes([]);
|
||||||
setTypes([]);
|
setTypes([]);
|
||||||
|
setEnums([]);
|
||||||
setUndoStack([]);
|
setUndoStack([]);
|
||||||
setRedoStack([]);
|
setRedoStack([]);
|
||||||
})
|
})
|
||||||
@ -919,7 +921,8 @@ export default function ControlPanel({
|
|||||||
relationships: relationships,
|
relationships: relationships,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
subjectAreas: areas,
|
subjectAreas: areas,
|
||||||
types: types,
|
...(databases[database].hasTypes && { types: types }),
|
||||||
|
...(databases[database].hasEnums && { enums: enums }),
|
||||||
title: title,
|
title: title,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
@ -978,8 +981,8 @@ export default function ControlPanel({
|
|||||||
relationships: relationships,
|
relationships: relationships,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
subjectAreas: areas,
|
subjectAreas: areas,
|
||||||
types: types,
|
...(databases[database].hasTypes && { types: types }),
|
||||||
},
|
...(databases[database].hasEnums && { enums: enums }), },
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
|
@ -4,13 +4,21 @@ import {
|
|||||||
} from "../../../utils/validateSchema";
|
} from "../../../utils/validateSchema";
|
||||||
import { Upload, Banner } from "@douyinfe/semi-ui";
|
import { Upload, Banner } from "@douyinfe/semi-ui";
|
||||||
import { STATUS } from "../../../data/constants";
|
import { STATUS } from "../../../data/constants";
|
||||||
import { useAreas, useNotes, useTables } from "../../../hooks";
|
import {
|
||||||
|
useAreas,
|
||||||
|
useEnums,
|
||||||
|
useNotes,
|
||||||
|
useTables,
|
||||||
|
useTypes,
|
||||||
|
} from "../../../hooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export default function ImportDiagram({ setImportData, error, setError }) {
|
export default function ImportDiagram({ setImportData, error, setError }) {
|
||||||
const { areas } = useAreas();
|
const { areas } = useAreas();
|
||||||
const { notes } = useNotes();
|
const { notes } = useNotes();
|
||||||
const { tables, relationships } = useTables();
|
const { tables, relationships } = useTables();
|
||||||
|
const { types } = useTypes();
|
||||||
|
const { enums } = useEnums();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const diagramIsEmpty = () => {
|
const diagramIsEmpty = () => {
|
||||||
@ -18,7 +26,9 @@ export default function ImportDiagram({ setImportData, error, setError }) {
|
|||||||
tables.length === 0 &&
|
tables.length === 0 &&
|
||||||
relationships.length === 0 &&
|
relationships.length === 0 &&
|
||||||
notes.length === 0 &&
|
notes.length === 0 &&
|
||||||
areas.length === 0
|
areas.length === 0 &&
|
||||||
|
types.length === 0 &&
|
||||||
|
enums.length === 0
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,6 +108,17 @@ export const typeSchema = {
|
|||||||
required: ["name", "fields", "comment"],
|
required: ["name", "fields", "comment"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const enumSchema = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
name: { type: "string" },
|
||||||
|
values: {
|
||||||
|
type: "array",
|
||||||
|
items: { type: "string" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const jsonSchema = {
|
export const jsonSchema = {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
@ -151,6 +162,14 @@ export const jsonSchema = {
|
|||||||
type: "array",
|
type: "array",
|
||||||
items: { ...areaSchema },
|
items: { ...areaSchema },
|
||||||
},
|
},
|
||||||
|
types: {
|
||||||
|
type: "array",
|
||||||
|
items: { ...typeSchema },
|
||||||
|
},
|
||||||
|
enums: {
|
||||||
|
type: "array",
|
||||||
|
items: { ...enumSchema },
|
||||||
|
},
|
||||||
title: { type: "string" },
|
title: { type: "string" },
|
||||||
},
|
},
|
||||||
required: ["tables", "relationships", "notes", "subjectAreas"],
|
required: ["tables", "relationships", "notes", "subjectAreas"],
|
||||||
|
Loading…
Reference in New Issue
Block a user