Skip to content

Commit 795fba5

Browse files
1ilitewqazxc
authored andcommitted
Show/hide tables (drawdb-io#673)
1 parent 597ef16 commit 795fba5

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,9 +1,16 @@
11
import { useState } from "react";
22
import { Collapse, Button } from "@douyinfe/semi-ui";
3+
import { IconEyeOpened, IconEyeClosed } from "@douyinfe/semi-icons";
34
import { IconPlus } from "@douyinfe/semi-icons";
45
import LocateTargetPosition from "../../Tools/LocateTargetPosition";
5-
import { useSelect, useDiagram, useSaveState, useLayout } from "../../../hooks";
6-
import { ObjectType, State } from "../../../data/constants";
6+
import {
7+
useSelect,
8+
useDiagram,
9+
useSaveState,
10+
useLayout,
11+
useUndoRedo,
12+
} from "../../../hooks";
13+
import { Action, ObjectType, State } from "../../../data/constants";
714
import { useTranslation } from "react-i18next";
815
import { DragHandle } from "../../SortableList/DragHandle";
916
import { SortableList } from "../../SortableList/SortableList";
@@ -72,25 +79,57 @@ export default function TablesTab() {
7279

7380
function TableListItem({ table }) {
7481
const { layout } = useLayout();
82+
const { updateTable } = useDiagram();
83+
const { setUndoStack, setRedoStack } = useUndoRedo();
84+
const { t } = useTranslation();
85+
86+
const toggleTableVisibility = (e) => {
87+
e.stopPropagation();
88+
setUndoStack((prev) => [
89+
...prev,
90+
{
91+
action: Action.EDIT,
92+
element: ObjectType.TABLE,
93+
component: "self",
94+
tid: table.id,
95+
undo: { hidden: table.hidden },
96+
redo: { hidden: !table.hidden },
97+
message: t("edit_table", {
98+
tableName: table.name,
99+
extra: "[hidden]",
100+
}),
101+
},
102+
]);
103+
setRedoStack([]);
104+
updateTable(table.id, { hidden: !table.hidden });
105+
};
75106

76107
return (
77108
<div id={`scroll_table_${table.id}`}>
78109
<Collapse.Panel
79110
className="relative"
80111
header={
81-
<>
82-
<div className="flex items-center gap-2">
112+
<div className="flex items-center justify-between w-full">
113+
<div className="flex items-center gap-2 flex-1">
83114
<DragHandle readOnly={layout.readOnly} id={table.id} />
84115
<LocateTargetPosition position={{ x: table.x, y: table.y }} />
85116
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
86117
{table.name}
87118
</div>
88119
</div>
120+
<Button
121+
size="small"
122+
theme="borderless"
123+
type="tertiary"
124+
onClick={toggleTableVisibility}
125+
icon={table.hidden ? <IconEyeClosed /> : <IconEyeOpened />}
126+
className="me-2"
127+
/>
89128
<div
90129
className="w-1 h-full absolute top-0 left-0 bottom-0"
91130
style={{ backgroundColor: table.color }}
92131
/>
93-
</>
132+
</div>
94133
}
95134
itemKey={`${table.id}`}
96135
>

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)