Skip to content

Commit 62e4318

Browse files
committed
Fix opening type and table at the same time
1 parent 4424173 commit 62e4318

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/components/EditorSidePanel/TablesTab/SearchBar.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import { useState } from "react";
22
import { useSelect, useTables } from "../../../hooks";
33
import { AutoComplete } from "@douyinfe/semi-ui";
44
import { IconSearch } from "@douyinfe/semi-icons";
5+
import { ObjectType } from "../../../data/constants";
56

67
export default function SearchBar() {
78
const { tables } = useTables();
89
const { setSelectedElement } = useSelect();
910
const [searchText, setSearchText] = useState("");
1011
const [filteredResult, setFilteredResult] = useState(
11-
tables.map((t) => t.name)
12+
tables.map((t) => t.name),
1213
);
1314

1415
const handleStringSearch = (value) => {
1516
setFilteredResult(
16-
tables.map((t) => t.name).filter((i) => i.includes(value))
17+
tables.map((t) => t.name).filter((i) => i.includes(value)),
1718
);
1819
};
1920

@@ -33,6 +34,7 @@ export default function SearchBar() {
3334
...prev,
3435
id: id,
3536
open: true,
37+
element: ObjectType.TABLE,
3638
}));
3739
document
3840
.getElementById(`scroll_table_${id}`)

src/components/EditorSidePanel/TablesTab/TablesTab.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Collapse, Row, Col, Button } from "@douyinfe/semi-ui";
22
import { IconPlus } from "@douyinfe/semi-icons";
33
import { useSelect, useTables } from "../../../hooks";
4+
import { ObjectType } from "../../../data/constants";
45
import SearchBar from "./SearchBar";
56
import Empty from "../Empty";
67
import TableInfo from "./TableInfo";
@@ -25,12 +26,17 @@ export default function TablesTab() {
2526
<Empty title="No tables" text="Start building your diagram!" />
2627
) : (
2728
<Collapse
28-
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
29+
activeKey={
30+
selectedElement.open && selectedElement.element === ObjectType.TABLE
31+
? `${selectedElement.id}`
32+
: ""
33+
}
2934
onChange={(k) =>
3035
setSelectedElement((prev) => ({
3136
...prev,
32-
id: parseInt(k),
3337
open: true,
38+
id: parseInt(k),
39+
element: ObjectType.TABLE,
3440
}))
3541
}
3642
accordion

src/components/EditorSidePanel/TypesTab/SearchBar.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from "react";
22
import { AutoComplete } from "@douyinfe/semi-ui";
33
import { IconSearch } from "@douyinfe/semi-icons";
44
import { useSelect, useTypes } from "../../../hooks";
5+
import { ObjectType } from "../../../data/constants";
56

67
export default function Searchbar() {
78
const { types } = useTypes();
@@ -32,8 +33,9 @@ export default function Searchbar() {
3233
const i = types.findIndex((t) => t.name === v);
3334
setSelectedElement((prev) => ({
3435
...prev,
35-
id: parseInt(i),
36+
id: i,
3637
open: true,
38+
element: ObjectType.TYPE,
3739
}));
3840
document
3941
.getElementById(`scroll_type_${i}`)

src/components/EditorSidePanel/TypesTab/TypesTab.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Collapse, Row, Col, Button, Popover } from "@douyinfe/semi-ui";
22
import { IconPlus, IconInfoCircle } from "@douyinfe/semi-icons";
3+
import { useSelect, useTypes } from "../../../hooks";
4+
import { ObjectType } from "../../../data/constants";
35
import Searchbar from "./SearchBar";
46
import Empty from "../Empty";
5-
import { useSelect, useTypes } from "../../../hooks";
67
import TypeInfo from "./TypeInfo";
78

89
export default function TypesTab() {
@@ -54,12 +55,17 @@ export default function TypesTab() {
5455
<Empty title="No types" text="Make your own custom data types" />
5556
) : (
5657
<Collapse
57-
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
58+
activeKey={
59+
selectedElement.open && selectedElement.element === ObjectType.TYPE
60+
? `${selectedElement.id}`
61+
: ""
62+
}
5863
onChange={(id) =>
5964
setSelectedElement((prev) => ({
6065
...prev,
61-
id: parseInt(id),
6266
open: true,
67+
id: parseInt(id),
68+
element: ObjectType.TYPE,
6369
}))
6470
}
6571
accordion

0 commit comments

Comments
 (0)