Export and import enums in diagrams

This commit is contained in:
1ilit 2024-07-03 13:25:24 +03:00
parent 61d97e8143
commit 1430db881c
3 changed files with 39 additions and 7 deletions

View File

@ -65,6 +65,7 @@ import Sidesheet from "./SideSheet/Sidesheet";
import Modal from "./Modal/Modal";
import { useTranslation } from "react-i18next";
import { exportSQL } from "../../utils/exportSQL";
import { databases } from "../../data/databases";
export default function ControlPanel({
diagramId,
@ -100,7 +101,7 @@ export default function ControlPanel({
deleteRelationship,
database,
} = useTables();
const { enums } = useEnums();
const { enums, setEnums } = useEnums();
const { types, addType, deleteType, updateType, setTypes } = useTypes();
const { notes, setNotes, updateNote, addNote, deleteNote } = useNotes();
const { areas, setAreas, updateArea, addArea, deleteArea } = useAreas();
@ -116,7 +117,7 @@ export default function ControlPanel({
const undo = () => {
if (undoStack.length === 0) return;
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.element === ObjectType.TABLE) {
deleteTable(tables[tables.length - 1].id, false);
@ -732,6 +733,7 @@ export default function ControlPanel({
setAreas([]);
setNotes([]);
setTypes([]);
setEnums([]);
setUndoStack([]);
setRedoStack([]);
})
@ -919,7 +921,8 @@ export default function ControlPanel({
relationships: relationships,
notes: notes,
subjectAreas: areas,
types: types,
...(databases[database].hasTypes && { types: types }),
...(databases[database].hasEnums && { enums: enums }),
title: title,
},
null,
@ -978,8 +981,8 @@ export default function ControlPanel({
relationships: relationships,
notes: notes,
subjectAreas: areas,
types: types,
},
...(databases[database].hasTypes && { types: types }),
...(databases[database].hasEnums && { enums: enums }), },
null,
2,
);

View File

@ -4,13 +4,21 @@ import {
} from "../../../utils/validateSchema";
import { Upload, Banner } from "@douyinfe/semi-ui";
import { STATUS } from "../../../data/constants";
import { useAreas, useNotes, useTables } from "../../../hooks";
import {
useAreas,
useEnums,
useNotes,
useTables,
useTypes,
} from "../../../hooks";
import { useTranslation } from "react-i18next";
export default function ImportDiagram({ setImportData, error, setError }) {
const { areas } = useAreas();
const { notes } = useNotes();
const { tables, relationships } = useTables();
const { types } = useTypes();
const { enums } = useEnums();
const { t } = useTranslation();
const diagramIsEmpty = () => {
@ -18,7 +26,9 @@ export default function ImportDiagram({ setImportData, error, setError }) {
tables.length === 0 &&
relationships.length === 0 &&
notes.length === 0 &&
areas.length === 0
areas.length === 0 &&
types.length === 0 &&
enums.length === 0
);
};

View File

@ -108,6 +108,17 @@ export const typeSchema = {
required: ["name", "fields", "comment"],
};
export const enumSchema = {
type: "object",
properties: {
name: { type: "string" },
values: {
type: "array",
items: { type: "string" },
},
},
};
export const jsonSchema = {
type: "object",
properties: {
@ -151,6 +162,14 @@ export const jsonSchema = {
type: "array",
items: { ...areaSchema },
},
types: {
type: "array",
items: { ...typeSchema },
},
enums: {
type: "array",
items: { ...enumSchema },
},
title: { type: "string" },
},
required: ["tables", "relationships", "notes", "subjectAreas"],