diff --git a/src/components/EditorSidePanel/SidePanel.jsx b/src/components/EditorSidePanel/SidePanel.jsx index 3f0b9b6..e5f2e02 100644 --- a/src/components/EditorSidePanel/SidePanel.jsx +++ b/src/components/EditorSidePanel/SidePanel.jsx @@ -1,6 +1,6 @@ import { Tabs, TabPane } from "@douyinfe/semi-ui"; -import { Tab } from "../../data/constants"; -import { useLayout, useSelect } from "../../hooks"; +import { DB, Tab } from "../../data/constants"; +import { useLayout, useSelect, useTables } from "../../hooks"; import RelationshipsTab from "./RelationshipsTab/RelationshipsTab"; import TypesTab from "./TypesTab/TypesTab"; import Issues from "./Issues"; @@ -8,23 +8,34 @@ import AreasTab from "./AreasTab/AreasTab"; import NotesTab from "./NotesTab/NotesTab"; import TablesTab from "./TablesTab/TablesTab"; import { useTranslation } from "react-i18next"; +import { useMemo } from "react"; export default function SidePanel({ width, resize, setResize }) { const { layout } = useLayout(); const { selectedElement, setSelectedElement } = useSelect(); + const { database } = useTables(); const { t } = useTranslation(); - const tabList = [ - { tab: t("tables"), itemKey: Tab.TABLES, component: }, - { - tab: t("relationships"), - itemKey: Tab.RELATIONSHIPS, - component: , - }, - { tab: t("subject_areas"), itemKey: Tab.AREAS, component: }, - { tab: t("notes"), itemKey: Tab.NOTES, component: }, - { tab: t("types"), itemKey: Tab.TYPES, component: }, - ]; + const tabList = useMemo(() => { + const tabs = [ + { tab: t("tables"), itemKey: Tab.TABLES, component: }, + { + tab: t("relationships"), + itemKey: Tab.RELATIONSHIPS, + component: , + }, + { tab: t("subject_areas"), itemKey: Tab.AREAS, component: }, + { tab: t("notes"), itemKey: Tab.NOTES, component: }, + ]; + if (database === DB.GENERIC || database === DB.POSTGRES) { + tabs.push({ + tab: t("types"), + itemKey: Tab.TYPES, + component: , + }); + } + return tabs; + }, [t, database]); return (
diff --git a/src/context/TablesContext.jsx b/src/context/TablesContext.jsx index fd3c6bc..d090b8b 100644 --- a/src/context/TablesContext.jsx +++ b/src/context/TablesContext.jsx @@ -1,5 +1,5 @@ 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 useUndoRedo from "../hooks/useUndoRedo"; import useSelect from "../hooks/useSelect"; @@ -35,7 +35,7 @@ export default function TablesContextProvider({ children }) { fields: [ { name: "id", - type: "INTEGER", + type: database === DB.GENERIC ? "INT" : "INTEGER", default: "", check: "", primary: true, diff --git a/src/data/datatypes.js b/src/data/datatypes.js index 59e6780..dc44cc5 100644 --- a/src/data/datatypes.js +++ b/src/data/datatypes.js @@ -6,8 +6,8 @@ const binaryRegex = /^[01]+$/; /* eslint-disable no-unused-vars */ export const defaultTypes = { - INTEGER: { - type: "INTEGER", + INT: { + type: "INT", checkDefault: (field) => { return intRegex.test(field.default); }, diff --git a/src/utils/exportSQL/generic.js b/src/utils/exportSQL/generic.js index f330387..8663140 100644 --- a/src/utils/exportSQL/generic.js +++ b/src/utils/exportSQL/generic.js @@ -151,7 +151,9 @@ export function jsonToMySQL(obj) { }\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${ field.increment ? " AUTO_INCREMENT" : "" }${field.unique ? " UNIQUE" : ""}${ - field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" + field.default !== "" + ? ` DEFAULT ${parseDefault(field, obj.database)}` + : "" }${ field.check === "" || !dbToTypes[obj.database][field.type].hasCheck @@ -250,7 +252,9 @@ export function jsonToPostgreSQL(obj) { }" ${getTypeString(field, obj.database, "postgres")}${ field.notNull ? " NOT NULL" : "" }${ - field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" + field.default !== "" + ? ` DEFAULT ${parseDefault(field, obj.database)}` + : "" }${ field.check === "" || !dbToTypes[obj.database][field.type].hasCheck @@ -397,7 +401,9 @@ export function jsonToMariaDB(obj) { }\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${ field.increment ? " AUTO_INCREMENT" : "" }${field.unique ? " UNIQUE" : ""}${ - field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" + field.default !== "" + ? ` DEFAULT ${parseDefault(field, obj.database)}` + : "" }${ field.check === "" || !dbToTypes[obj.database][field.type].hasCheck @@ -471,7 +477,9 @@ export function jsonToSQLServer(obj) { }${field.increment ? " IDENTITY" : ""}${ field.unique ? " UNIQUE" : "" }${ - field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : "" + field.default !== "" + ? ` DEFAULT ${parseDefault(field, obj.database)}` + : "" }${ field.check === "" || !dbToTypes[obj.database][field.type].hasCheck