From 77bdb77a9ed1f74197416547ef15bb56776b00d3 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Fri, 7 Jun 2024 14:18:05 +0300 Subject: [PATCH 1/9] Enable editing index names --- .../TablesTab/IndexDetails.jsx | 48 +++++++++++++++++-- .../EditorSidePanel/TablesTab/TableField.jsx | 2 +- .../EditorSidePanel/TablesTab/TableInfo.jsx | 4 +- src/i18n/locales/en.js | 1 + src/utils/issues.js | 7 +++ 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/components/EditorSidePanel/TablesTab/IndexDetails.jsx b/src/components/EditorSidePanel/TablesTab/IndexDetails.jsx index c990d63..1af09c2 100644 --- a/src/components/EditorSidePanel/TablesTab/IndexDetails.jsx +++ b/src/components/EditorSidePanel/TablesTab/IndexDetails.jsx @@ -3,11 +3,13 @@ import { Input, Button, Popover, Checkbox, Select } from "@douyinfe/semi-ui"; import { IconMore, IconDeleteStroked } from "@douyinfe/semi-icons"; import { useTables, useUndoRedo } from "../../../hooks"; import { useTranslation } from "react-i18next"; +import { useState } from "react"; export default function IndexDetails({ data, fields, iid, tid }) { const { t } = useTranslation(); const { tables, updateTable } = useTables(); const { setUndoStack, setRedoStack } = useUndoRedo(); + const [editField, setEditField] = useState({}); return (
@@ -29,11 +31,9 @@ export default function IndexDetails({ data, fields, iid, tid }) { iid: iid, undo: { fields: [...data.fields], - name: `${data.fields.join("_")}_index`, }, redo: { fields: [...value], - name: `${value.join("_")}_index`, }, message: t("edit_table", { tableName: tables[tid].name, @@ -48,7 +48,6 @@ export default function IndexDetails({ data, fields, iid, tid }) { ? { ...index, fields: [...value], - name: `${value.join("_")}_index`, } : index, ), @@ -59,7 +58,48 @@ export default function IndexDetails({ data, fields, iid, tid }) { content={
{t("name")}:
- + + setEditField({ + name: data.name, + }) + } + onChange={(value) => + updateTable(tid, { + indices: tables[tid].indices.map((index) => + index.id === iid + ? { + ...index, + name: value, + } + : index, + ), + }) + } + onBlur={(e) => { + if (e.target.value === editField.name) return; + setUndoStack((prev) => [ + ...prev, + { + action: Action.EDIT, + element: ObjectType.TABLE, + component: "index", + tid: tid, + iid: iid, + undo: editField, + redo: { name: e.target.value }, + message: t("edit_table", { + tableName: tables[tid].name, + extra: "[index]", + }), + }, + ]); + setRedoStack([]); + }} + />
{t("unique")}
updateField(tid, index, { name: value })} onFocus={(e) => setEditField({ name: e.target.value })} diff --git a/src/components/EditorSidePanel/TablesTab/TableInfo.jsx b/src/components/EditorSidePanel/TablesTab/TableInfo.jsx index 63bf392..b5bd39c 100644 --- a/src/components/EditorSidePanel/TablesTab/TableInfo.jsx +++ b/src/components/EditorSidePanel/TablesTab/TableInfo.jsx @@ -33,7 +33,7 @@ export default function TableInfo({ data }) {
{t("name")}:
updateTable(data.id, { name: value })} @@ -290,7 +290,7 @@ export default function TableInfo({ data }) { ...data.indices, { id: data.indices.length, - name: `index_${data.indices.length}`, + name: `${data.name}_index_${data.indices.length}`, unique: false, fields: [], }, diff --git a/src/i18n/locales/en.js b/src/i18n/locales/en.js index 32c7ef7..1359a98 100644 --- a/src/i18n/locales/en.js +++ b/src/i18n/locales/en.js @@ -212,6 +212,7 @@ const en = { edit_relationship: "{{extra}} Edit relationship {{refName}}", delete_relationship: "Delete relationship {{refName}}", not_found: "Not found", + empty_index_name: "Declared an index with no name in table '{{tableName}}'", }, }; diff --git a/src/utils/issues.js b/src/utils/issues.js index d7cde0f..986be22 100644 --- a/src/utils/issues.js +++ b/src/utils/issues.js @@ -168,6 +168,13 @@ export function getIssues(diagram) { }); table.indices.forEach((index) => { + if (index.name.trim() === "") { + issues.push( + i18n.t("empty_index_name", { + tableName: table.name, + }), + ); + } if (index.fields.length === 0) { issues.push( i18n.t("empty_index", { From 7716980be47c4b210de153a01e1939935829807d Mon Sep 17 00:00:00 2001 From: lilit <96800776+1ilit@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:27:38 +0300 Subject: [PATCH 2/9] Fix title on json export --- src/utils/modalTitles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/modalTitles.js b/src/utils/modalTitles.js index 6501aa0..2887aae 100644 --- a/src/utils/modalTitles.js +++ b/src/utils/modalTitles.js @@ -7,7 +7,7 @@ export const getModalTitle = (modal) => { case MODAL.IMPORT_SRC: return i18n.t("import_diagram"); case MODAL.CODE: - return i18n.t("export_source"); + return i18n.t("export"); case MODAL.IMG: return i18n.t("export_image"); case MODAL.RENAME: From 43e4744afadd380d6780a6ce0c0661a1e01fdfa9 Mon Sep 17 00:00:00 2001 From: Huy Bui Date: Wed, 5 Jun 2024 12:39:55 +0700 Subject: [PATCH 3/9] fix: todo details value --- src/components/EditorHeader/SideSheet/Todo.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/EditorHeader/SideSheet/Todo.jsx b/src/components/EditorHeader/SideSheet/Todo.jsx index fd53196..6f000dd 100644 --- a/src/components/EditorHeader/SideSheet/Todo.jsx +++ b/src/components/EditorHeader/SideSheet/Todo.jsx @@ -247,7 +247,7 @@ export default function Todo() { From 960d8feec35007053b51a52533f2d273a9fc9cc5 Mon Sep 17 00:00:00 2001 From: Huy Bui Date: Mon, 17 Jun 2024 00:43:43 +0700 Subject: [PATCH 4/9] feat: search nested fields in tables --- .../EditorSidePanel/TablesTab/SearchBar.jsx | 58 +++++++++++++------ .../EditorSidePanel/TablesTab/TableField.jsx | 1 + 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/components/EditorSidePanel/TablesTab/SearchBar.jsx b/src/components/EditorSidePanel/TablesTab/SearchBar.jsx index ab0f35d..bcaec05 100644 --- a/src/components/EditorSidePanel/TablesTab/SearchBar.jsx +++ b/src/components/EditorSidePanel/TablesTab/SearchBar.jsx @@ -1,40 +1,64 @@ -import { useMemo, useState } from "react"; +import { useMemo } from "react"; import { useSelect } from "../../../hooks"; -import { AutoComplete } from "@douyinfe/semi-ui"; +import { TreeSelect } from "@douyinfe/semi-ui"; import { IconSearch } from "@douyinfe/semi-icons"; import { ObjectType } from "../../../data/constants"; import { useTranslation } from "react-i18next"; export default function SearchBar({ tables }) { const { setSelectedElement } = useSelect(); - const [searchText, setSearchText] = useState(""); const { t } = useTranslation(); - const filteredTable = useMemo( - () => tables.map((t) => t.name).filter((i) => i.includes(searchText)), - [tables, searchText], - ); + + const treeData = useMemo(() => { + return tables.map(({ id, name: parentName, fields }, i) => { + const children = fields.map(({ name }, j) => ({ + tableId: id, + id: `${j}`, + label: name, + value: name, + key: `${i}-${j}`, + })); + + return { + tableId: id, + id: `${i}`, + label: parentName, + value: parentName, + key: `${i}`, + children, + }; + }); + }, [tables]); return ( - } - placeholder={t("search")} emptyContent={
{t("not_found")}
} - onChange={(v) => setSearchText(v)} - onSelect={(v) => { - const { id } = tables.find((t) => t.name === v); + filterTreeNode + placeholder={t("search")} + onChange={(node) => { + const { tableId, id, children } = node; + setSelectedElement((prev) => ({ ...prev, - id: id, + id: tableId, open: true, element: ObjectType.TABLE, })); document - .getElementById(`scroll_table_${id}`) + .getElementById(`scroll_table_${tableId}`) .scrollIntoView({ behavior: "smooth" }); + + if (!children) { + document + .getElementById(`scroll_table_${tableId}_input_${id}`) + .focus(); + } }} + onChangeWithObject className="w-full" /> ); diff --git a/src/components/EditorSidePanel/TablesTab/TableField.jsx b/src/components/EditorSidePanel/TablesTab/TableField.jsx index fe0f9f6..824d35b 100644 --- a/src/components/EditorSidePanel/TablesTab/TableField.jsx +++ b/src/components/EditorSidePanel/TablesTab/TableField.jsx @@ -19,6 +19,7 @@ export default function TableField({ data, tid, index }) { Date: Mon, 17 Jun 2024 12:20:49 +0700 Subject: [PATCH 5/9] feat: add color for table info --- .../EditorSidePanel/NotesTab/NoteInfo.jsx | 2 +- .../EditorSidePanel/TablesTab/TablesTab.jsx | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/EditorSidePanel/NotesTab/NoteInfo.jsx b/src/components/EditorSidePanel/NotesTab/NoteInfo.jsx index 8ceee8e..ccf1859 100644 --- a/src/components/EditorSidePanel/NotesTab/NoteInfo.jsx +++ b/src/components/EditorSidePanel/NotesTab/NoteInfo.jsx @@ -98,7 +98,7 @@ export default function NoteInfo({ data, nid }) {
From 0899b2c453f7f3e5905d88c586a1503dd38b78ea Mon Sep 17 00:00:00 2001 From: 1ilit Date: Wed, 19 Jun 2024 19:22:07 +0300 Subject: [PATCH 7/9] Fix extra comma being added after index on export (#141) --- src/utils/toSQL.js | 56 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/utils/toSQL.js b/src/utils/toSQL.js index 2ad4961..0625b93 100644 --- a/src/utils/toSQL.js +++ b/src/utils/toSQL.js @@ -181,7 +181,7 @@ export function jsonToMySQL(obj) { )}", \`${field.name}\`))` : "" : ` CHECK(${field.check})` - }${field.comment ? ` COMMENT '${field.comment}'` : ''}`, + }${field.comment ? ` COMMENT '${field.comment}'` : ""}`, ) .join(",\n")}${ table.fields.filter((f) => f.primary).length > 0 @@ -190,16 +190,16 @@ export function jsonToMySQL(obj) { .map((f) => `\`${f.name}\``) .join(", ")})` : "" - }\n)${table.comment ? ` COMMENT='${table.comment}'` : ''};\n${ + }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${ table.indices.length > 0 - ? `\n${table.indices.map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ - i.name - }\`\nON \`${table.name}\` (${i.fields - .map((f) => `\`${f}\``) - .join(", ")});`, - )}` + ? `\n${table.indices + .map( + (i) => + `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${i.name}\`\nON \`${table.name}\` (${i.fields + .map((f) => `\`${f}\``) + .join(", ")});`, + ) + .join("\n")}` : "" }`, ) @@ -282,14 +282,16 @@ export function jsonToPostgreSQL(obj) { : "" }\n);\n${ table.indices.length > 0 - ? `${table.indices.map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX "${ - i.name - }"\nON "${table.name}" (${i.fields - .map((f) => `"${f}"`) - .join(", ")});`, - )}` + ? `${table.indices + .map( + (i) => + `CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${ + i.name + }"\nON "${table.name}" (${i.fields + .map((f) => `"${f}"`) + .join(", ")});`, + ) + .join("\n")}` : "" }`, ) @@ -433,14 +435,16 @@ export function jsonToMariaDB(obj) { : "" }\n);${ table.indices.length > 0 - ? `\n${table.indices.map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ - i.name - }\`\nON \`${table.name}\` (${i.fields - .map((f) => `\`${f}\``) - .join(", ")});`, - )}` + ? `\n${table.indices + .map( + (i) => + `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ + i.name + }\`\nON \`${table.name}\` (${i.fields + .map((f) => `\`${f}\``) + .join(", ")});`, + ) + .join("\n")}` : "" }`, ) From 55295a67900b7131b5d9436b742ffcda7a523a91 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Tue, 2 Jul 2024 13:18:38 +0300 Subject: [PATCH 8/9] Add FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a17ed84 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +open_collective: drawdb \ No newline at end of file From 219a5a877bf7e8374f7f9874675e5512a9ad66d6 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Wed, 3 Jul 2024 03:27:36 +0300 Subject: [PATCH 9/9] Fix UNIQUE not added in postgres --- src/utils/toSQL.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/toSQL.js b/src/utils/toSQL.js index 0625b93..9f1fa30 100644 --- a/src/utils/toSQL.js +++ b/src/utils/toSQL.js @@ -265,7 +265,7 @@ export function jsonToPostgreSQL(obj) { field.name }" ${getTypeString(field, "postgres")}${ field.notNull ? " NOT NULL" : "" - }${ + }${field.unique ? " UNIQUE" : ""}${ field.default !== "" ? ` DEFAULT ${parseDefault(field)}` : "" }${ field.check === "" || !hasCheck(field.type)