Swap INTEGER for INT in generic diagrams to maintain backward compatibility

This commit is contained in:
1ilit 2024-06-24 05:10:39 +03:00
parent d8128f5010
commit 9e2684e7a9
4 changed files with 40 additions and 21 deletions

View File

@ -1,6 +1,6 @@
import { Tabs, TabPane } from "@douyinfe/semi-ui"; import { Tabs, TabPane } from "@douyinfe/semi-ui";
import { Tab } from "../../data/constants"; import { DB, Tab } from "../../data/constants";
import { useLayout, useSelect } from "../../hooks"; import { useLayout, useSelect, useTables } from "../../hooks";
import RelationshipsTab from "./RelationshipsTab/RelationshipsTab"; import RelationshipsTab from "./RelationshipsTab/RelationshipsTab";
import TypesTab from "./TypesTab/TypesTab"; import TypesTab from "./TypesTab/TypesTab";
import Issues from "./Issues"; import Issues from "./Issues";
@ -8,13 +8,16 @@ import AreasTab from "./AreasTab/AreasTab";
import NotesTab from "./NotesTab/NotesTab"; import NotesTab from "./NotesTab/NotesTab";
import TablesTab from "./TablesTab/TablesTab"; import TablesTab from "./TablesTab/TablesTab";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useMemo } from "react";
export default function SidePanel({ width, resize, setResize }) { export default function SidePanel({ width, resize, setResize }) {
const { layout } = useLayout(); const { layout } = useLayout();
const { selectedElement, setSelectedElement } = useSelect(); const { selectedElement, setSelectedElement } = useSelect();
const { database } = useTables();
const { t } = useTranslation(); const { t } = useTranslation();
const tabList = [ const tabList = useMemo(() => {
const tabs = [
{ tab: t("tables"), itemKey: Tab.TABLES, component: <TablesTab /> }, { tab: t("tables"), itemKey: Tab.TABLES, component: <TablesTab /> },
{ {
tab: t("relationships"), tab: t("relationships"),
@ -23,8 +26,16 @@ export default function SidePanel({ width, resize, setResize }) {
}, },
{ tab: t("subject_areas"), itemKey: Tab.AREAS, component: <AreasTab /> }, { tab: t("subject_areas"), itemKey: Tab.AREAS, component: <AreasTab /> },
{ tab: t("notes"), itemKey: Tab.NOTES, component: <NotesTab /> }, { tab: t("notes"), itemKey: Tab.NOTES, component: <NotesTab /> },
{ tab: t("types"), itemKey: Tab.TYPES, component: <TypesTab /> },
]; ];
if (database === DB.GENERIC || database === DB.POSTGRES) {
tabs.push({
tab: t("types"),
itemKey: Tab.TYPES,
component: <TypesTab />,
});
}
return tabs;
}, [t, database]);
return ( return (
<div className="flex h-full"> <div className="flex h-full">

View File

@ -1,5 +1,5 @@
import { createContext, useState } from "react"; import { createContext, useState } from "react";
import { Action, ObjectType, defaultBlue } from "../data/constants"; import { Action, DB, ObjectType, defaultBlue } from "../data/constants";
import useTransform from "../hooks/useTransform"; import useTransform from "../hooks/useTransform";
import useUndoRedo from "../hooks/useUndoRedo"; import useUndoRedo from "../hooks/useUndoRedo";
import useSelect from "../hooks/useSelect"; import useSelect from "../hooks/useSelect";
@ -35,7 +35,7 @@ export default function TablesContextProvider({ children }) {
fields: [ fields: [
{ {
name: "id", name: "id",
type: "INTEGER", type: database === DB.GENERIC ? "INT" : "INTEGER",
default: "", default: "",
check: "", check: "",
primary: true, primary: true,

View File

@ -6,8 +6,8 @@ const binaryRegex = /^[01]+$/;
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
export const defaultTypes = { export const defaultTypes = {
INTEGER: { INT: {
type: "INTEGER", type: "INT",
checkDefault: (field) => { checkDefault: (field) => {
return intRegex.test(field.default); return intRegex.test(field.default);
}, },

View File

@ -151,7 +151,9 @@ export function jsonToMySQL(obj) {
}\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${ }\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${
field.increment ? " AUTO_INCREMENT" : "" field.increment ? " AUTO_INCREMENT" : ""
}${field.unique ? " UNIQUE" : ""}${ }${field.unique ? " UNIQUE" : ""}${
field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" field.default !== ""
? ` DEFAULT ${parseDefault(field, obj.database)}`
: ""
}${ }${
field.check === "" || field.check === "" ||
!dbToTypes[obj.database][field.type].hasCheck !dbToTypes[obj.database][field.type].hasCheck
@ -250,7 +252,9 @@ export function jsonToPostgreSQL(obj) {
}" ${getTypeString(field, obj.database, "postgres")}${ }" ${getTypeString(field, obj.database, "postgres")}${
field.notNull ? " NOT NULL" : "" field.notNull ? " NOT NULL" : ""
}${ }${
field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" field.default !== ""
? ` DEFAULT ${parseDefault(field, obj.database)}`
: ""
}${ }${
field.check === "" || field.check === "" ||
!dbToTypes[obj.database][field.type].hasCheck !dbToTypes[obj.database][field.type].hasCheck
@ -397,7 +401,9 @@ export function jsonToMariaDB(obj) {
}\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${ }\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${
field.increment ? " AUTO_INCREMENT" : "" field.increment ? " AUTO_INCREMENT" : ""
}${field.unique ? " UNIQUE" : ""}${ }${field.unique ? " UNIQUE" : ""}${
field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" field.default !== ""
? ` DEFAULT ${parseDefault(field, obj.database)}`
: ""
}${ }${
field.check === "" || field.check === "" ||
!dbToTypes[obj.database][field.type].hasCheck !dbToTypes[obj.database][field.type].hasCheck
@ -471,7 +477,9 @@ export function jsonToSQLServer(obj) {
}${field.increment ? " IDENTITY" : ""}${ }${field.increment ? " IDENTITY" : ""}${
field.unique ? " UNIQUE" : "" field.unique ? " UNIQUE" : ""
}${ }${
field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" field.default !== ""
? ` DEFAULT ${parseDefault(field, obj.database)}`
: ""
}${ }${
field.check === "" || field.check === "" ||
!dbToTypes[obj.database][field.type].hasCheck !dbToTypes[obj.database][field.type].hasCheck