Skip to content

issue #333; Feature- button in table to toggle datatype visibility #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 66 additions & 42 deletions src/components/EditorCanvas/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
IconMinus,
IconDeleteStroked,
IconKeyStroked,
IconEyeOpened,
IconEyeClosedSolid
} from "@douyinfe/semi-icons";
import { Popover, Tag, Button, SideSheet } from "@douyinfe/semi-ui";
import { useLayout, useSettings, useDiagram, useSelect } from "../../hooks";
Expand All @@ -22,6 +24,8 @@ import { isRtl } from "../../i18n/utils/rtl";
import i18n from "../../i18n/i18n";

export default function Table(props) {
// show data type state
const [showDataType, setShowDataType] = useState(true);
const [hoveredField, setHoveredField] = useState(-1);
const { database } = useDiagram();
const {
Expand Down Expand Up @@ -76,32 +80,52 @@ export default function Table(props) {
<div
onDoubleClick={openEditor}
className={`border-2 hover:border-dashed hover:border-blue-500
select-none rounded-lg w-full ${
settings.mode === "light"
? "bg-zinc-100 text-zinc-800"
: "bg-zinc-800 text-zinc-200"
} ${
selectedElement.id === tableData.id &&
selectedElement.element === ObjectType.TABLE
? "border-solid border-blue-500"
: "border-zinc-500"
}`}
select-none rounded-lg w-full ${settings.mode === "light"
? "bg-zinc-100 text-zinc-800"
: "bg-zinc-800 text-zinc-200"
} ${selectedElement.id === tableData.id &&
selectedElement.element === ObjectType.TABLE
? "border-solid border-blue-500"
: "border-zinc-500"
}`}
style={{ direction: "ltr" }}
>
<div
className="h-[10px] w-full rounded-t-md"
style={{ backgroundColor: tableData.color }}
/>
<div
className={`overflow-hidden font-bold h-[40px] flex justify-between items-center border-b border-gray-400 ${
settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900"
}`}
className={`overflow-hidden font-bold h-[40px] flex justify-between items-center border-b border-gray-400 ${settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900"
}`}
>
<div className=" px-3 overflow-hidden text-ellipsis whitespace-nowrap">
{tableData.name}
</div>
<div className="hidden group-hover:block">
<div className="flex justify-end items-center mx-2">
<Popover
content={
<div className=" popover-theme flex justify-between items-center pb-2" style={{ direction: "ltr" }}>
<p className="me-4 font-bold">{t("Click to toggle datatype visibility")}</p>
</div>
}
trigger="hover"
position="top"
showArrow
>
<Button

type="tertiary"
size="small"
icon={showDataType ? <IconEyeOpened /> : <IconEyeClosedSolid />}
style={{
backgroundColor: "#2f68adb3",
color: "white",
marginRight: "6px",
}}
onClick={() => setShowDataType(!showDataType)}
/>
</Popover>
<Button
icon={<IconEdit />}
size="small"
Expand All @@ -126,9 +150,8 @@ export default function Table(props) {
</div>
<div>
<strong
className={`${
tableData.indices.length === 0 ? "" : "block"
}`}
className={`${tableData.indices.length === 0 ? "" : "block"
}`}
>
{t("indices")}:
</strong>{" "}
Expand All @@ -139,11 +162,10 @@ export default function Table(props) {
{tableData.indices.map((index, k) => (
<div
key={k}
className={`flex items-center my-1 px-2 py-1 rounded ${
settings.mode === "light"
? "bg-gray-100"
: "bg-zinc-800"
}`}
className={`flex items-center my-1 px-2 py-1 rounded ${settings.mode === "light"
? "bg-gray-100"
: "bg-zinc-800"
}`}
>
<i className="fa-solid fa-thumbtack me-2 mt-1 text-slate-500"></i>
<div>
Expand Down Expand Up @@ -202,8 +224,8 @@ export default function Table(props) {
{e.type +
((dbToTypes[database][e.type].isSized ||
dbToTypes[database][e.type].hasPrecision) &&
e.size &&
e.size !== ""
e.size &&
e.size !== ""
? "(" + e.size + ")"
: "")}
</p>
Expand Down Expand Up @@ -282,11 +304,10 @@ export default function Table(props) {
function field(fieldData, index) {
return (
<div
className={`${
index === tableData.fields.length - 1
? ""
: "border-b border-gray-400"
} group h-[36px] px-2 py-1 flex justify-between items-center gap-1 w-full overflow-hidden`}
className={`${index === tableData.fields.length - 1
? ""
: "border-b border-gray-400"
} group h-[36px] px-2 py-1 flex justify-between items-center gap-1 w-full overflow-hidden`}
onPointerEnter={(e) => {
if (!e.isPrimary) return;

Expand All @@ -308,9 +329,8 @@ export default function Table(props) {
}}
>
<div
className={`${
hoveredField === index ? "text-zinc-400" : ""
} flex items-center gap-2 overflow-hidden`}
className={`${hoveredField === index ? "text-zinc-400" : ""
} flex items-center gap-2 overflow-hidden`}
>
<button
className="flex-shrink-0 w-[10px] h-[10px] bg-[#2f68adcc] rounded-full"
Expand Down Expand Up @@ -356,17 +376,21 @@ export default function Table(props) {
/>
) : (
<div className="flex gap-1 items-center">
{fieldData.primary && <IconKeyStroked />}
{!fieldData.notNull && <span>?</span>}
<span>
{fieldData.type +
((dbToTypes[database][fieldData.type].isSized ||
dbToTypes[database][fieldData.type].hasPrecision) &&
fieldData.size &&
fieldData.size !== ""
? "(" + fieldData.size + ")"
: "")}
</span>
{showDataType && (
<>
{fieldData.primary && <IconKeyStroked />}
{!fieldData.notNull && <span>?</span>}
<span>
{fieldData.type +
((dbToTypes[database][fieldData.type].isSized ||
dbToTypes[database][fieldData.type].hasPrecision) &&
fieldData.size &&
fieldData.size !== ""
? "(" + fieldData.size + ")"
: "")}
</span>
</>
)}
</div>
)}
</div>
Expand Down