2024-05-17 08:45:42 +08:00
|
|
|
import { Collapse, Button } from "@douyinfe/semi-ui";
|
2024-04-06 09:58:42 +08:00
|
|
|
import { IconPlus } from "@douyinfe/semi-icons";
|
|
|
|
import { useSelect, useTables } from "../../../hooks";
|
2024-05-02 21:23:18 +08:00
|
|
|
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";
|
2024-05-16 11:44:39 +08:00
|
|
|
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();
|
2024-05-16 11:44:39 +08:00
|
|
|
const { t } = useTranslation();
|
2024-04-06 09:58:42 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-05-17 08:45:42 +08:00
|
|
|
<div className="flex gap-2">
|
|
|
|
<SearchBar tables={tables} />
|
|
|
|
<div>
|
2024-05-14 11:22:13 +08:00
|
|
|
<Button icon={<IconPlus />} block onClick={() => addTable()}>
|
2024-05-16 11:44:39 +08:00
|
|
|
{t("add_table")}
|
2024-04-06 09:58:42 +08:00
|
|
|
</Button>
|
2024-05-17 08:45:42 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-06 09:58:42 +08:00
|
|
|
{tables.length === 0 ? (
|
2024-05-16 11:44:39 +08:00
|
|
|
<Empty title={t("no_tables")} text={t("no_tables_text")} />
|
2024-04-06 09:58:42 +08:00
|
|
|
) : (
|
|
|
|
<Collapse
|
2024-05-02 21:23:18 +08:00
|
|
|
activeKey={
|
|
|
|
selectedElement.open && selectedElement.element === ObjectType.TABLE
|
|
|
|
? `${selectedElement.id}`
|
|
|
|
: ""
|
|
|
|
}
|
2024-05-13 11:14:51 +08:00
|
|
|
keepDOM
|
|
|
|
lazyRender
|
2024-04-06 09:58:42 +08:00
|
|
|
onChange={(k) =>
|
|
|
|
setSelectedElement((prev) => ({
|
|
|
|
...prev,
|
|
|
|
open: true,
|
2024-05-02 21:23:18 +08:00
|
|
|
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
|
2024-06-17 13:20:49 +08:00
|
|
|
className="relative"
|
2024-04-06 14:51:38 +08:00
|
|
|
header={
|
2024-06-17 13:20:49 +08:00
|
|
|
<>
|
|
|
|
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
|
|
|
|
{t.name}
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className="w-1 h-full absolute top-0 left-0 bottom-0"
|
|
|
|
style={{ backgroundColor: t.color }}
|
|
|
|
/>
|
|
|
|
</>
|
2024-04-06 14:51:38 +08:00
|
|
|
}
|
|
|
|
itemKey={`${t.id}`}
|
|
|
|
>
|
|
|
|
<TableInfo data={t} />
|
|
|
|
</Collapse.Panel>
|
|
|
|
</div>
|
2024-04-06 09:58:42 +08:00
|
|
|
))}
|
|
|
|
</Collapse>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|