Skip to content

Commit e6d29ed

Browse files
authored
Show/hide tables (#673)
1 parent f3dbfbd commit e6d29ed

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

src/components/EditorCanvas/Relationship.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default function Relationship({ data }) {
1919
const startTable = tables.find((t) => t.id === data.startTableId);
2020
const endTable = tables.find((t) => t.id === data.endTableId);
2121

22-
if (!startTable || !endTable) return null;
22+
if (!startTable || !endTable || startTable.hidden || endTable.hidden)
23+
return null;
2324

2425
return {
2526
startFieldIndex: startTable.fields.findIndex(
@@ -110,6 +111,8 @@ export default function Relationship({ data }) {
110111
}
111112
};
112113

114+
if (!pathValues) return null;
115+
113116
return (
114117
<>
115118
<g className="select-none group" onDoubleClick={edit}>

src/components/EditorCanvas/Table.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export default function Table({
129129
}
130130
};
131131

132+
if (tableData.hidden) return null;
133+
132134
return (
133135
<>
134136
<foreignObject

src/components/EditorSidePanel/TablesTab/TablesTab.jsx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Collapse, Button } from "@douyinfe/semi-ui";
2+
import { IconEyeOpened, IconEyeClosed } from "@douyinfe/semi-icons";
23
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";
512
import { useTranslation } from "react-i18next";
613
import { DragHandle } from "../../SortableList/DragHandle";
714
import { SortableList } from "../../SortableList/SortableList";
@@ -67,24 +74,56 @@ export default function TablesTab() {
6774

6875
function TableListItem({ table }) {
6976
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+
};
70101

71102
return (
72103
<div id={`scroll_table_${table.id}`}>
73104
<Collapse.Panel
74105
className="relative"
75106
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">
78109
<DragHandle readOnly={layout.readOnly} id={table.id} />
79110
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
80111
{table.name}
81112
</div>
82113
</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+
/>
83122
<div
84123
className="w-1 h-full absolute top-0 left-0 bottom-0"
85124
style={{ backgroundColor: table.color }}
86125
/>
87-
</>
126+
</div>
88127
}
89128
itemKey={`${table.id}`}
90129
>

src/components/SortableList/DragHandle.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function DragHandle({ id, readOnly }) {
66

77
return (
88
<div
9-
className={`opacity-50 mt-0.5 ${readOnly ? "cursor-not-allowed" : "cursor-move"}`}
9+
className={`opacity-50 mt-1.5 ${readOnly ? "cursor-not-allowed" : "cursor-move"}`}
1010
{...(!readOnly && listeners)}
1111
>
1212
<IconHandle />

src/data/schemas.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const tableSchema = {
3939
},
4040
comment: { type: "string" },
4141
locked: { type: "boolean" },
42+
hidden: { type: "boolean" },
4243
indices: {
4344
type: "array",
4445
items: {

0 commit comments

Comments
 (0)