From 2695e5b8a2ebf54ef6fc34ed29ff0c3debe908f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?liao=E6=96=87=E7=A6=A7?= <1219585136@qq.com> Date: Mon, 13 May 2024 11:14:51 +0800 Subject: [PATCH] Optimize the rendering logic for the Collapse and Tabs child components(#101) --- src/components/EditorSidePanel/Issues.jsx | 2 +- .../EditorSidePanel/NotesTab/NotesTab.jsx | 2 ++ .../RelationshipsTab/RelationshipsTab.jsx | 2 ++ src/components/EditorSidePanel/SidePanel.jsx | 32 ++++++++----------- .../EditorSidePanel/TablesTab/TableInfo.jsx | 4 ++- .../EditorSidePanel/TablesTab/TablesTab.jsx | 2 ++ .../EditorSidePanel/TypesTab/TypeInfo.jsx | 2 +- .../EditorSidePanel/TypesTab/TypesTab.jsx | 2 ++ 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/components/EditorSidePanel/Issues.jsx b/src/components/EditorSidePanel/Issues.jsx index 7f02c03..b0e2265 100644 --- a/src/components/EditorSidePanel/Issues.jsx +++ b/src/components/EditorSidePanel/Issues.jsx @@ -27,7 +27,7 @@ export default function Issues() { }, [tables, relationships, issues, types]); return ( - + { setSelectedElement((prev) => ({ ...prev, diff --git a/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx b/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx index ee23bd2..27139a9 100644 --- a/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx +++ b/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx @@ -19,6 +19,8 @@ export default function RelationshipsTab() { ? `${selectedElement.id}` : "" } + keepDOM + lazyRender onChange={(k) => setSelectedElement((prev) => ({ ...prev, diff --git a/src/components/EditorSidePanel/SidePanel.jsx b/src/components/EditorSidePanel/SidePanel.jsx index 2a3aaa9..8ac1d90 100644 --- a/src/components/EditorSidePanel/SidePanel.jsx +++ b/src/components/EditorSidePanel/SidePanel.jsx @@ -1,4 +1,4 @@ -import { Tabs } from "@douyinfe/semi-ui"; +import { Tabs, TabPane } from "@douyinfe/semi-ui"; import { Tab } from "../../data/constants"; import { useLayout, useSelect } from "../../hooks"; import RelationshipsTab from "./RelationshipsTab/RelationshipsTab"; @@ -13,19 +13,11 @@ export default function SidePanel({ width, resize, setResize }) { const { selectedElement, setSelectedElement } = useSelect(); const tabList = [ - { tab: "Tables", itemKey: Tab.TABLES }, - { tab: "Relationships", itemKey: Tab.RELATIONSHIPS }, - { tab: "Subject Areas", itemKey: Tab.AREAS }, - { tab: "Notes", itemKey: Tab.NOTES }, - { tab: "Types", itemKey: Tab.TYPES }, - ]; - - const contentList = [ - , - , - , - , - , + { tab: "Tables", itemKey: Tab.TABLES, component: }, + { tab: "Relationships", itemKey: Tab.RELATIONSHIPS, component: }, + { tab: "Subject Areas", itemKey: Tab.AREAS, component: }, + { tab: "Notes", itemKey: Tab.NOTES, component: }, + { tab: "Types", itemKey: Tab.TYPES, component: }, ]; return ( @@ -38,15 +30,19 @@ export default function SidePanel({ width, resize, setResize }) { setSelectedElement((prev) => ({ ...prev, currentTab: key })) } collapsible > -
- {contentList[parseInt(selectedElement.currentTab) - 1]} -
+ {tabList.length && tabList.map(tab => + +
+ {tab.component} +
+
+ )}
{layout.issues && ( diff --git a/src/components/EditorSidePanel/TablesTab/TableInfo.jsx b/src/components/EditorSidePanel/TablesTab/TableInfo.jsx index 7d8e6b8..1b06af0 100644 --- a/src/components/EditorSidePanel/TablesTab/TableInfo.jsx +++ b/src/components/EditorSidePanel/TablesTab/TableInfo.jsx @@ -144,6 +144,8 @@ export default function TableInfo({ data }) { > setIndexActiveKey(itemKey)} accordion > @@ -169,7 +171,7 @@ export default function TableInfo({ data }) { style={{ marginTop: "12px", marginBottom: "12px" }} headerLine={false} > - +