|
1 | 1 | import { Collapse, Button } from "@douyinfe/semi-ui"; |
| 2 | +import { IconEyeOpened, IconEyeClosed } from "@douyinfe/semi-icons"; |
2 | 3 | import { IconPlus } from "@douyinfe/semi-icons"; |
3 | | -import { useSelect, useDiagram, useSaveState, useLayout } from "../../../hooks"; |
4 | | -import { ObjectType, State } from "../../../data/constants"; |
| 4 | +import { |
| 5 | + useSelect, |
| 6 | + useDiagram, |
| 7 | + useSaveState, |
| 8 | + useLayout, |
| 9 | + useUndoRedo, |
| 10 | +} from "../../../hooks"; |
| 11 | +import { Action, ObjectType, State } from "../../../data/constants"; |
5 | 12 | import { useTranslation } from "react-i18next"; |
6 | 13 | import { DragHandle } from "../../SortableList/DragHandle"; |
7 | 14 | import { SortableList } from "../../SortableList/SortableList"; |
@@ -67,24 +74,56 @@ export default function TablesTab() { |
67 | 74 |
|
68 | 75 | function TableListItem({ table }) { |
69 | 76 | const { layout } = useLayout(); |
| 77 | + const { updateTable } = useDiagram(); |
| 78 | + const { setUndoStack, setRedoStack } = useUndoRedo(); |
| 79 | + const { t } = useTranslation(); |
| 80 | + |
| 81 | + const toggleTableVisibility = (e) => { |
| 82 | + e.stopPropagation(); |
| 83 | + setUndoStack((prev) => [ |
| 84 | + ...prev, |
| 85 | + { |
| 86 | + action: Action.EDIT, |
| 87 | + element: ObjectType.TABLE, |
| 88 | + component: "self", |
| 89 | + tid: table.id, |
| 90 | + undo: { hidden: table.hidden }, |
| 91 | + redo: { hidden: !table.hidden }, |
| 92 | + message: t("edit_table", { |
| 93 | + tableName: table.name, |
| 94 | + extra: "[hidden]", |
| 95 | + }), |
| 96 | + }, |
| 97 | + ]); |
| 98 | + setRedoStack([]); |
| 99 | + updateTable(table.id, { hidden: !table.hidden }); |
| 100 | + }; |
70 | 101 |
|
71 | 102 | return ( |
72 | 103 | <div id={`scroll_table_${table.id}`}> |
73 | 104 | <Collapse.Panel |
74 | 105 | className="relative" |
75 | 106 | header={ |
76 | | - <> |
77 | | - <div className="flex items-center gap-2"> |
| 107 | + <div className="flex items-center justify-between w-full"> |
| 108 | + <div className="flex items-center gap-2 flex-1"> |
78 | 109 | <DragHandle readOnly={layout.readOnly} id={table.id} /> |
79 | 110 | <div className="overflow-hidden text-ellipsis whitespace-nowrap"> |
80 | 111 | {table.name} |
81 | 112 | </div> |
82 | 113 | </div> |
| 114 | + <Button |
| 115 | + size="small" |
| 116 | + theme="borderless" |
| 117 | + type="tertiary" |
| 118 | + onClick={toggleTableVisibility} |
| 119 | + icon={table.hidden ? <IconEyeClosed /> : <IconEyeOpened />} |
| 120 | + className="me-2" |
| 121 | + /> |
83 | 122 | <div |
84 | 123 | className="w-1 h-full absolute top-0 left-0 bottom-0" |
85 | 124 | style={{ backgroundColor: table.color }} |
86 | 125 | /> |
87 | | - </> |
| 126 | + </div> |
88 | 127 | } |
89 | 128 | itemKey={`${table.id}`} |
90 | 129 | > |
|
0 commit comments