drawDB/src/components/EditorSidePanel/TablesTab/TablesTab.jsx

67 lines
1.9 KiB
React
Raw Normal View History

2024-04-06 09:58:42 +08:00
import { Collapse, Row, Col, Button } from "@douyinfe/semi-ui";
import { IconPlus } from "@douyinfe/semi-icons";
import { useSelect, useTables } from "../../../hooks";
import { ObjectType } from "../../../data/constants";
2024-04-06 09:58:42 +08:00
import SearchBar from "./SearchBar";
import Empty from "../Empty";
import TableInfo from "./TableInfo";
import { useTranslation } from "react-i18next";
2024-04-06 09:58:42 +08:00
export default function TablesTab() {
const { tables, addTable } = useTables();
const { selectedElement, setSelectedElement } = useSelect();
const { t } = useTranslation();
2024-04-06 09:58:42 +08:00
return (
<>
<Row gutter={6}>
<Col span={16}>
2024-04-16 14:52:21 +08:00
<SearchBar tables={tables} />
2024-04-06 09:58:42 +08:00
</Col>
<Col span={8}>
<Button icon={<IconPlus />} block onClick={() => addTable()}>
{t("add_table")}
2024-04-06 09:58:42 +08:00
</Button>
</Col>
</Row>
{tables.length === 0 ? (
<Empty title={t("no_tables")} text={t("no_tables_text")} />
2024-04-06 09:58:42 +08:00
) : (
<Collapse
activeKey={
selectedElement.open && selectedElement.element === ObjectType.TABLE
? `${selectedElement.id}`
: ""
}
keepDOM
lazyRender
2024-04-06 09:58:42 +08:00
onChange={(k) =>
setSelectedElement((prev) => ({
...prev,
open: true,
id: parseInt(k),
element: ObjectType.TABLE,
2024-04-06 09:58:42 +08:00
}))
}
accordion
>
{tables.map((t) => (
2024-04-06 14:51:38 +08:00
<div id={`scroll_table_${t.id}`} key={t.id}>
<Collapse.Panel
header={
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
{t.name}
</div>
}
itemKey={`${t.id}`}
>
<TableInfo data={t} />
</Collapse.Panel>
</div>
2024-04-06 09:58:42 +08:00
))}
</Collapse>
)}
</>
);
}