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 SearchBar from "./SearchBar";
|
|
|
|
import Empty from "../Empty";
|
|
|
|
import TableInfo from "./TableInfo";
|
|
|
|
|
|
|
|
export default function TablesTab() {
|
|
|
|
const { tables, addTable } = useTables();
|
|
|
|
const { selectedElement, setSelectedElement } = useSelect();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Row gutter={6}>
|
|
|
|
<Col span={16}>
|
|
|
|
<SearchBar />
|
|
|
|
</Col>
|
|
|
|
<Col span={8}>
|
|
|
|
<Button icon={<IconPlus />} block onClick={() => addTable(true)}>
|
|
|
|
Add table
|
|
|
|
</Button>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
{tables.length === 0 ? (
|
|
|
|
<Empty title="No tables" text="Start building your diagram!" />
|
|
|
|
) : (
|
|
|
|
<Collapse
|
|
|
|
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
|
|
|
|
onChange={(k) =>
|
|
|
|
setSelectedElement((prev) => ({
|
|
|
|
...prev,
|
|
|
|
id: parseInt(k),
|
|
|
|
open: true,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|