From 70e0b3e5f2c4bb6f3fb3ee4c354d99b175f1ab3b Mon Sep 17 00:00:00 2001 From: 1ilit <1ilit@proton.me> Date: Mon, 23 Jun 2025 17:09:14 +0400 Subject: [PATCH] clean up table state and styles --- src/components/EditorCanvas/Table.jsx | 292 +++++++++++--------------- src/context/SettingsContext.jsx | 5 + src/hooks/useThemedPage.js | 5 + src/i18n/locales/en.js | 2 + tailwind.config.js | 22 +- 5 files changed, 143 insertions(+), 183 deletions(-) diff --git a/src/components/EditorCanvas/Table.jsx b/src/components/EditorCanvas/Table.jsx index 1a3bf5e..9990bbb 100644 --- a/src/components/EditorCanvas/Table.jsx +++ b/src/components/EditorCanvas/Table.jsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from "react"; +import { useMemo } from "react"; import { Tab, ObjectType, @@ -21,19 +21,18 @@ import TableInfo from "../EditorSidePanel/TablesTab/TableInfo"; import { useTranslation } from "react-i18next"; import { dbToTypes } from "../../data/datatypes"; import { isRtl } from "../../i18n/utils/rtl"; -import i18n from "../../i18n/i18n"; import { getTableHeight } from "../../utils/utils"; +import classNames from "classnames"; +import i18n from "../../i18n/i18n"; -export default function Table(props) { - const [hoveredField, setHoveredField] = useState(null); +export default function Table({ + tableData, + onPointerDown, + setHoveredTable, + handleGripField, + setLinkingLine, +}) { const { database } = useDiagram(); - const { - tableData, - onPointerDown, - setHoveredTable, - handleGripField, - setLinkingLine, - } = props; const { layout } = useLayout(); const { deleteTable, deleteField, updateTable } = useDiagram(); const { settings } = useSettings(); @@ -41,21 +40,17 @@ export default function Table(props) { const { selectedElement, setSelectedElement, bulkSelectedElements } = useSelect(); - const borderColor = useMemo( - () => (settings.mode === "light" ? "border-zinc-300" : "border-zinc-600"), - [settings.mode], - ); - const height = getTableHeight(tableData); const isSelected = useMemo(() => { - return ( - (selectedElement.id == tableData.id && - selectedElement.element === ObjectType.TABLE) || - bulkSelectedElements.some( - (e) => e.type === ObjectType.TABLE && e.id === tableData.id, - ) + const isIndividuallySelected = + selectedElement.id == tableData.id && + selectedElement.element === ObjectType.TABLE; + const isBulkSelected = bulkSelectedElements.some( + (e) => e.type === ObjectType.TABLE && e.id === tableData.id, ); + + return isIndividuallySelected || isBulkSelected; }, [selectedElement, tableData, bulkSelectedElements]); const lockUnlockTable = () => @@ -92,85 +87,71 @@ export default function Table(props) { y={tableData.y} width={settings.tableWidth} height={height} - className="group drop-shadow-lg rounded-md cursor-move" + data-selected={isSelected} onPointerDown={onPointerDown} + className="group drop-shadow-lg rounded-md cursor-move" >
{fieldData.name}
++ {typeDisplay} +
+{e.name}
-- {e.type + - ((dbToTypes[database][e.type].isSized || - dbToTypes[database][e.type].hasPrecision) && - e.size && - e.size !== "" - ? "(" + e.size + ")" - : "")} -
-- {t("default_value")}: - {e.default === "" ? t("not_set") : e.default} -
-- {t("comment")}: - {e.comment === "" ? t("not_set") : e.comment} -
-