From 6ae205a64dcef080dc8ba8bc0dbf538502823bd8 Mon Sep 17 00:00:00 2001
From: 1ilit <1ilit@proton.me>
Date: Fri, 31 Jan 2025 16:17:37 +0400
Subject: [PATCH] Add compiler errors in issues
---
.../EditorSidePanel/DBMLEditor/DBMLEditor.jsx | 6 +--
src/components/EditorSidePanel/Issues.jsx | 39 +++++++++++++------
src/components/EditorSidePanel/SidePanel.jsx | 7 ++--
src/data/constants.js | 5 +++
src/utils/dbml/fromDBML.js | 28 -------------
5 files changed, 39 insertions(+), 46 deletions(-)
diff --git a/src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx b/src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx
index 0f7f986..400d771 100644
--- a/src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx
+++ b/src/components/EditorSidePanel/DBMLEditor/DBMLEditor.jsx
@@ -7,7 +7,7 @@ import { useDebounceValue } from "usehooks-ts";
import "./styles.css";
import { fromDBML } from "../../../utils/dbml/fromDBML";
-export default function DBMLEditor() {
+export default function DBMLEditor({ setIssues }) {
const { settings } = useSettings();
const { setTables } = useDiagram();
const [value, setValue] = useState("");
@@ -20,10 +20,10 @@ export default function DBMLEditor() {
console.log(tables);
setTables(tables);
} catch (e) {
- console.log("error: ", e);
+ setIssues((prev) => ({ ...prev, dbml: e.diags.map((x) => x.message) }));
}
}
- }, [debouncedValue, setTables]);
+ }, [debouncedValue, setTables, setIssues]);
return (
diff --git a/src/components/EditorSidePanel/Issues.jsx b/src/components/EditorSidePanel/Issues.jsx
index f3de9a3..a0b28cf 100644
--- a/src/components/EditorSidePanel/Issues.jsx
+++ b/src/components/EditorSidePanel/Issues.jsx
@@ -1,17 +1,16 @@
-import { useState, useEffect } from "react";
+import { useEffect } from "react";
import { Collapse, Badge } from "@douyinfe/semi-ui";
import { arrayIsEqual } from "../../utils/utils";
import { getIssues } from "../../utils/issues";
import { useEnums, useSettings, useDiagram, useTypes } from "../../hooks";
import { useTranslation } from "react-i18next";
-export default function Issues() {
+export default function Issues({ issues, setIssues }) {
const { types } = useTypes();
const { t } = useTranslation();
const { settings } = useSettings();
const { enums } = useEnums();
const { tables, relationships, database } = useDiagram();
- const [issues, setIssues] = useState([]);
useEffect(() => {
const findIssues = async () => {
@@ -23,21 +22,29 @@ export default function Issues() {
enums: enums,
});
- if (!arrayIsEqual(newIssues, issues)) {
- setIssues(newIssues);
+ if (!arrayIsEqual(newIssues, issues.diagram)) {
+ setIssues((prev) => ({ ...prev, diagram: newIssues }));
}
};
findIssues();
- }, [tables, relationships, issues, types, database, enums]);
+ }, [tables, relationships, issues, types, database, enums, setIssues]);
return (
0 ? "danger" : "primary"}
- count={settings.strictMode ? null : issues.length}
+ type={
+ issues.dbml.length > 0 || issues.diagram.length > 0
+ ? "danger"
+ : "primary"
+ }
+ count={
+ settings.strictMode
+ ? null
+ : issues.dbml.length + issues.diagram.length
+ }
overflowCount={99}
className="mt-1"
>
@@ -52,11 +59,19 @@ export default function Issues() {
{settings.strictMode ? (
{t("strict_mode_is_on_no_issues")}
- ) : issues.length > 0 ? (
+ ) : issues.dbml.length > 0 || issues.diagram.length > 0 ? (
<>
- {issues.map((e, i) => (
-
- {e}
+ {!settings.dbmlEditor &&
+ issues.dbml.map((e, i) => (
+
+ ))}
+ {issues.diagram.map((e, i) => (
+
))}
>
diff --git a/src/components/EditorSidePanel/SidePanel.jsx b/src/components/EditorSidePanel/SidePanel.jsx
index 65d5c52..b2fc295 100644
--- a/src/components/EditorSidePanel/SidePanel.jsx
+++ b/src/components/EditorSidePanel/SidePanel.jsx
@@ -16,7 +16,7 @@ import AreasTab from "./AreasTab/AreasTab";
import NotesTab from "./NotesTab/NotesTab";
import TablesTab from "./TablesTab/TablesTab";
import { useTranslation } from "react-i18next";
-import { useMemo } from "react";
+import { useMemo, useState } from "react";
import { databases } from "../../data/databases";
import EnumsTab from "./EnumsTab/EnumsTab";
import { isRtl } from "../../i18n/utils/rtl";
@@ -32,6 +32,7 @@ export default function SidePanel({ width, resize, setResize }) {
const { typesCount } = useTypes();
const { enumsCount } = useEnums();
const { t } = useTranslation();
+ const [issues, setIssues] = useState({ diagram: [], dbml: [] });
const tabList = useMemo(() => {
const tabs = [
@@ -116,12 +117,12 @@ export default function SidePanel({ width, resize, setResize }) {
))}
) : (
-
+
)}
{layout.issues && (
-
+
)}
diff --git a/src/data/constants.js b/src/data/constants.js
index 3dd8eee..0f7498b 100644
--- a/src/data/constants.js
+++ b/src/data/constants.js
@@ -115,3 +115,8 @@ export const DB = {
MARIADB: "mariadb",
GENERIC: "generic",
};
+
+export const ErrorType = {
+ DIAGRAM: "diagram",
+ DBML: "dbml",
+};
diff --git a/src/utils/dbml/fromDBML.js b/src/utils/dbml/fromDBML.js
index 714696b..f656d34 100644
--- a/src/utils/dbml/fromDBML.js
+++ b/src/utils/dbml/fromDBML.js
@@ -3,34 +3,6 @@ import { arrangeTables } from "../arrangeTables";
const parser = new Parser();
-/**
-
-{
- "id": 0,
- "name": "some_table",
- "x": 812.9083754222163,
- "y": 400.3451698134321,
- "fields": [
- {
- "name": "id",
- "type": "INT",
- "default": "",
- "check": "",
- "primary": true,
- "unique": true,
- "notNull": true,
- "increment": true,
- "comment": "",
- "id": 0
- }
- ],
- "comment": "",
- "indices": [],
- "color": "#175e7a",
- "key": 1737222753837
- }
- */
-
export function fromDBML(src) {
const ast = parser.parse(src, "dbml");