2024-05-13 11:14:51 +08:00
|
|
|
import { Tabs, TabPane } from "@douyinfe/semi-ui";
|
2024-06-30 18:19:21 +08:00
|
|
|
import { Tab } from "../../data/constants";
|
2024-07-05 04:18:20 +08:00
|
|
|
import { useLayout, useSelect, useDiagram } from "../../hooks";
|
2024-04-06 09:58:42 +08:00
|
|
|
import RelationshipsTab from "./RelationshipsTab/RelationshipsTab";
|
|
|
|
import TypesTab from "./TypesTab/TypesTab";
|
|
|
|
import Issues from "./Issues";
|
|
|
|
import AreasTab from "./AreasTab/AreasTab";
|
|
|
|
import NotesTab from "./NotesTab/NotesTab";
|
|
|
|
import TablesTab from "./TablesTab/TablesTab";
|
2024-05-16 11:44:39 +08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-06-24 10:10:39 +08:00
|
|
|
import { useMemo } from "react";
|
2024-06-30 18:19:21 +08:00
|
|
|
import { databases } from "../../data/databases";
|
|
|
|
import EnumsTab from "./EnumsTab/EnumsTab";
|
2023-09-19 20:47:01 +08:00
|
|
|
|
2024-03-14 02:39:16 +08:00
|
|
|
export default function SidePanel({ width, resize, setResize }) {
|
2024-03-10 01:42:09 +08:00
|
|
|
const { layout } = useLayout();
|
2024-03-14 02:39:16 +08:00
|
|
|
const { selectedElement, setSelectedElement } = useSelect();
|
2024-07-05 04:18:20 +08:00
|
|
|
const { database } = useDiagram();
|
2024-05-16 11:44:39 +08:00
|
|
|
const { t } = useTranslation();
|
2023-09-19 20:47:01 +08:00
|
|
|
|
2024-06-24 10:10:39 +08:00
|
|
|
const tabList = useMemo(() => {
|
|
|
|
const tabs = [
|
|
|
|
{ tab: t("tables"), itemKey: Tab.TABLES, component: <TablesTab /> },
|
|
|
|
{
|
|
|
|
tab: t("relationships"),
|
|
|
|
itemKey: Tab.RELATIONSHIPS,
|
|
|
|
component: <RelationshipsTab />,
|
|
|
|
},
|
|
|
|
{ tab: t("subject_areas"), itemKey: Tab.AREAS, component: <AreasTab /> },
|
|
|
|
{ tab: t("notes"), itemKey: Tab.NOTES, component: <NotesTab /> },
|
|
|
|
];
|
2024-06-30 18:19:21 +08:00
|
|
|
|
|
|
|
if (databases[database].hasTypes) {
|
2024-06-24 10:10:39 +08:00
|
|
|
tabs.push({
|
|
|
|
tab: t("types"),
|
|
|
|
itemKey: Tab.TYPES,
|
|
|
|
component: <TypesTab />,
|
|
|
|
});
|
|
|
|
}
|
2024-06-30 18:19:21 +08:00
|
|
|
|
|
|
|
if (databases[database].hasEnums) {
|
|
|
|
tabs.push({
|
|
|
|
tab: t("enums"),
|
|
|
|
itemKey: Tab.ENUMS,
|
|
|
|
component: <EnumsTab />,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-24 10:10:39 +08:00
|
|
|
return tabs;
|
|
|
|
}, [t, database]);
|
2023-09-19 20:47:50 +08:00
|
|
|
|
2023-09-19 20:47:01 +08:00
|
|
|
return (
|
2023-09-19 20:48:38 +08:00
|
|
|
<div className="flex h-full">
|
2023-09-19 20:49:14 +08:00
|
|
|
<div
|
2023-09-19 20:51:08 +08:00
|
|
|
className="flex flex-col h-full relative border-r border-color"
|
2024-03-14 02:39:16 +08:00
|
|
|
style={{ width: `${width}px` }}
|
2023-09-19 20:49:14 +08:00
|
|
|
>
|
2023-09-19 20:49:13 +08:00
|
|
|
<div className="h-full flex-1 overflow-y-auto">
|
2023-09-19 20:49:14 +08:00
|
|
|
<Tabs
|
|
|
|
type="card"
|
2024-03-14 02:39:16 +08:00
|
|
|
activeKey={selectedElement.currentTab}
|
2024-05-13 11:14:51 +08:00
|
|
|
lazyRender
|
2024-03-14 02:39:16 +08:00
|
|
|
onChange={(key) =>
|
|
|
|
setSelectedElement((prev) => ({ ...prev, currentTab: key }))
|
|
|
|
}
|
2023-09-19 20:49:14 +08:00
|
|
|
collapsible
|
|
|
|
>
|
2024-05-16 11:44:39 +08:00
|
|
|
{tabList.length &&
|
|
|
|
tabList.map((tab) => (
|
|
|
|
<TabPane tab={tab.tab} itemKey={tab.itemKey} key={tab.itemKey}>
|
|
|
|
<div className="p-2">{tab.component}</div>
|
|
|
|
</TabPane>
|
|
|
|
))}
|
2023-09-19 20:49:14 +08:00
|
|
|
</Tabs>
|
2023-09-19 20:49:13 +08:00
|
|
|
</div>
|
2023-09-19 20:49:14 +08:00
|
|
|
{layout.issues && (
|
2023-09-19 20:51:08 +08:00
|
|
|
<div className="mt-auto border-t-2 border-color shadow-inner">
|
2023-09-19 20:49:14 +08:00
|
|
|
<Issues />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-09-19 20:47:01 +08:00
|
|
|
</div>
|
2023-09-19 20:48:30 +08:00
|
|
|
<div
|
2023-09-19 20:51:08 +08:00
|
|
|
className={`flex justify-center items-center p-1 h-auto hover-2 cursor-col-resize ${
|
2024-03-16 08:23:10 +08:00
|
|
|
resize && "bg-semi-grey-2"
|
2023-09-19 20:48:32 +08:00
|
|
|
}`}
|
2024-03-14 02:39:16 +08:00
|
|
|
onMouseDown={() => setResize(true)}
|
2023-09-19 20:48:30 +08:00
|
|
|
>
|
2023-09-19 20:51:08 +08:00
|
|
|
<div className="w-1 border-x border-color h-1/6" />
|
2023-09-19 20:48:30 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-09-19 20:47:01 +08:00
|
|
|
);
|
2024-03-14 02:39:16 +08:00
|
|
|
}
|