mirror of
https://github.com/drawdb-io/drawdb.git
synced 2026-01-13 07:02:37 +08:00
Show/hide tables (#673)
This commit is contained in:
@@ -19,7 +19,8 @@ export default function Relationship({ data }) {
|
|||||||
const startTable = tables.find((t) => t.id === data.startTableId);
|
const startTable = tables.find((t) => t.id === data.startTableId);
|
||||||
const endTable = tables.find((t) => t.id === data.endTableId);
|
const endTable = tables.find((t) => t.id === data.endTableId);
|
||||||
|
|
||||||
if (!startTable || !endTable) return null;
|
if (!startTable || !endTable || startTable.hidden || endTable.hidden)
|
||||||
|
return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
startFieldIndex: startTable.fields.findIndex(
|
startFieldIndex: startTable.fields.findIndex(
|
||||||
@@ -110,6 +111,8 @@ export default function Relationship({ data }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!pathValues) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<g className="select-none group" onDoubleClick={edit}>
|
<g className="select-none group" onDoubleClick={edit}>
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ export default function Table({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (tableData.hidden) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<foreignObject
|
<foreignObject
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { Collapse, Button } from "@douyinfe/semi-ui";
|
import { Collapse, Button } from "@douyinfe/semi-ui";
|
||||||
|
import { IconEyeOpened, IconEyeClosed } from "@douyinfe/semi-icons";
|
||||||
import { IconPlus } from "@douyinfe/semi-icons";
|
import { IconPlus } from "@douyinfe/semi-icons";
|
||||||
import { useSelect, useDiagram, useSaveState, useLayout } from "../../../hooks";
|
import {
|
||||||
import { ObjectType, State } from "../../../data/constants";
|
useSelect,
|
||||||
|
useDiagram,
|
||||||
|
useSaveState,
|
||||||
|
useLayout,
|
||||||
|
useUndoRedo,
|
||||||
|
} from "../../../hooks";
|
||||||
|
import { Action, ObjectType, State } from "../../../data/constants";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { DragHandle } from "../../SortableList/DragHandle";
|
import { DragHandle } from "../../SortableList/DragHandle";
|
||||||
import { SortableList } from "../../SortableList/SortableList";
|
import { SortableList } from "../../SortableList/SortableList";
|
||||||
@@ -67,24 +74,56 @@ export default function TablesTab() {
|
|||||||
|
|
||||||
function TableListItem({ table }) {
|
function TableListItem({ table }) {
|
||||||
const { layout } = useLayout();
|
const { layout } = useLayout();
|
||||||
|
const { updateTable } = useDiagram();
|
||||||
|
const { setUndoStack, setRedoStack } = useUndoRedo();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const toggleTableVisibility = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
setUndoStack((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
action: Action.EDIT,
|
||||||
|
element: ObjectType.TABLE,
|
||||||
|
component: "self",
|
||||||
|
tid: table.id,
|
||||||
|
undo: { hidden: table.hidden },
|
||||||
|
redo: { hidden: !table.hidden },
|
||||||
|
message: t("edit_table", {
|
||||||
|
tableName: table.name,
|
||||||
|
extra: "[hidden]",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
setRedoStack([]);
|
||||||
|
updateTable(table.id, { hidden: !table.hidden });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id={`scroll_table_${table.id}`}>
|
<div id={`scroll_table_${table.id}`}>
|
||||||
<Collapse.Panel
|
<Collapse.Panel
|
||||||
className="relative"
|
className="relative"
|
||||||
header={
|
header={
|
||||||
<>
|
<div className="flex items-center justify-between w-full">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2 flex-1">
|
||||||
<DragHandle readOnly={layout.readOnly} id={table.id} />
|
<DragHandle readOnly={layout.readOnly} id={table.id} />
|
||||||
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
|
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
|
||||||
{table.name}
|
{table.name}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
theme="borderless"
|
||||||
|
type="tertiary"
|
||||||
|
onClick={toggleTableVisibility}
|
||||||
|
icon={table.hidden ? <IconEyeClosed /> : <IconEyeOpened />}
|
||||||
|
className="me-2"
|
||||||
|
/>
|
||||||
<div
|
<div
|
||||||
className="w-1 h-full absolute top-0 left-0 bottom-0"
|
className="w-1 h-full absolute top-0 left-0 bottom-0"
|
||||||
style={{ backgroundColor: table.color }}
|
style={{ backgroundColor: table.color }}
|
||||||
/>
|
/>
|
||||||
</>
|
</div>
|
||||||
}
|
}
|
||||||
itemKey={`${table.id}`}
|
itemKey={`${table.id}`}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export function DragHandle({ id, readOnly }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`opacity-50 mt-0.5 ${readOnly ? "cursor-not-allowed" : "cursor-move"}`}
|
className={`opacity-50 mt-1.5 ${readOnly ? "cursor-not-allowed" : "cursor-move"}`}
|
||||||
{...(!readOnly && listeners)}
|
{...(!readOnly && listeners)}
|
||||||
>
|
>
|
||||||
<IconHandle />
|
<IconHandle />
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const tableSchema = {
|
|||||||
},
|
},
|
||||||
comment: { type: "string" },
|
comment: { type: "string" },
|
||||||
locked: { type: "boolean" },
|
locked: { type: "boolean" },
|
||||||
|
hidden: { type: "boolean" },
|
||||||
indices: {
|
indices: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: {
|
||||||
|
|||||||
Reference in New Issue
Block a user