Skip to content

Commit

Permalink
limit antd menu performance issue using useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Oct 8, 2024
1 parent cc80b73 commit 03dd67b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
32 changes: 17 additions & 15 deletions src/renderer/component/TableList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react';
import { ReactElement, useMemo } from 'react';
import { Menu, MenuProps } from 'antd';
import { Link, useParams } from 'react-router-dom';
import { useConnectionContext } from '../../contexts/ConnectionContext';
Expand All @@ -18,24 +18,26 @@ export default function TableList({
const { database } = useDatabaseContext();
const { tableName } = useParams();

const items: MenuItem[] = useMemo(
() =>
tableStatusList?.map((rowDataPacket: ShowTableStatus) => ({
key: rowDataPacket.Name,
label: (
<Link
to={`/connections/${currentConnectionSlug}/${database}/tables/${rowDataPacket.Name}`}
>
{rowDataPacket.Name}
</Link>
),
title: rowDataPacket.Name,
})),
[currentConnectionSlug, database, tableStatusList]
);

if (!tableStatusList) {
return null;
}

const items: MenuItem[] = tableStatusList.map(
(rowDataPacket: ShowTableStatus) => ({
key: rowDataPacket.Name,
label: (
<Link
to={`/connections/${currentConnectionSlug}/${database}/tables/${rowDataPacket.Name}`}
>
{rowDataPacket.Name}
</Link>
),
title: rowDataPacket.Name,
})
);

return (
<Menu items={items} selectedKeys={tableName ? [tableName] : undefined} />
);
Expand Down
11 changes: 8 additions & 3 deletions src/renderer/routes/connections.$connectionSlug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import NavigateModalContextProvider, {
const Sider = styled(Layout.Sider)`
border-right: 1px solid ${foreground};
background: ${background} !important;
overflow: auto;
`;

const Content = styled(Layout.Content)`
overflow: auto;
`;

interface RouteParams extends LoaderFunctionArgs {
Expand Down Expand Up @@ -114,16 +119,16 @@ export default function ConnectionDetailPage() {
<AllColumnsContextProvider allColumns={allColumns}>
<NavigateModalContextProvider>
<Layout>
<Sider width={200} style={{ overflow: 'auto' }}>
<Sider width={200}>
<Flex vertical gap="small">
<DatabaseSelector databaseList={databaseList} />
<OpenNavigateModalButton />
<TableList tableStatusList={tableStatusList} />
</Flex>
</Sider>
<Layout.Content style={{ overflow: 'auto' }}>
<Content>
<Outlet />
</Layout.Content>
</Content>
</Layout>
</NavigateModalContextProvider>
</AllColumnsContextProvider>
Expand Down

0 comments on commit 03dd67b

Please sign in to comment.