From 9cac43772b9bea76d167a101626a3fdc247e238f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9F=E8=B4=A4?= Date: Thu, 5 Jan 2023 18:29:51 +0800 Subject: [PATCH] feat(layout): remove unuse deps --- packages/layout/package.json | 2 +- .../src/components/SiderMenu/BaseMenu.tsx | 4 +- .../src/demos/AlwaysDefaultOpenAllMenu.tsx | 1 + packages/layout/src/demos/complexMenu.ts | 1 + packages/layout/src/index.tsx | 1 + packages/layout/src/utils/getMenuData.ts | 1 + packages/layout/src/utils/utils.ts | 6 +- tests/layout/PageHeader.test.tsx | 3 +- tests/layout/__snapshots__/demo.test.ts.snap | 32 ++--- tests/layout/index.test.tsx | 19 +-- yarn.lock | 136 +++++++++++------- 11 files changed, 122 insertions(+), 84 deletions(-) diff --git a/packages/layout/package.json b/packages/layout/package.json index 2bf76e3316c6..3731b9959c70 100644 --- a/packages/layout/package.json +++ b/packages/layout/package.json @@ -35,7 +35,7 @@ "@ant-design/pro-provider": "2.3.1", "@ant-design/pro-utils": "2.5.2", "@babel/runtime": "^7.18.0", - "@umijs/route-utils": "^2.1.0", + "@umijs/route-utils": "^4.0.0", "@umijs/use-params": "^1.0.9", "classnames": "^2.2.6", "lodash.merge": "^4.6.2", diff --git a/packages/layout/src/components/SiderMenu/BaseMenu.tsx b/packages/layout/src/components/SiderMenu/BaseMenu.tsx index c7ed64dd59a4..e126a40dd90c 100644 --- a/packages/layout/src/components/SiderMenu/BaseMenu.tsx +++ b/packages/layout/src/components/SiderMenu/BaseMenu.tsx @@ -474,7 +474,9 @@ const BaseMenu: React.FC = (props) => { } else if (menu?.ignoreFlatMenu && defaultOpenAll) { // 忽略用户手动折叠过的菜单状态,折叠按钮切换之后也可实现默认展开所有菜单 setOpenKeys(getOpenKeysFromMenuData(menuData)); - } else setDefaultOpenAll(false); + } else { + setDefaultOpenAll(false); + } }, // eslint-disable-next-line react-hooks/exhaustive-deps [matchMenuKeys.join('-')], diff --git a/packages/layout/src/demos/AlwaysDefaultOpenAllMenu.tsx b/packages/layout/src/demos/AlwaysDefaultOpenAllMenu.tsx index dd584f85f3d6..b341d1860b14 100644 --- a/packages/layout/src/demos/AlwaysDefaultOpenAllMenu.tsx +++ b/packages/layout/src/demos/AlwaysDefaultOpenAllMenu.tsx @@ -42,6 +42,7 @@ export default () => ( collapsed: true, menuName: '域买家维度交易', name: '域买家维度交易', + path: '/xx', routes: [ { id: 2, diff --git a/packages/layout/src/demos/complexMenu.ts b/packages/layout/src/demos/complexMenu.ts index 856879e5bd3d..fe972590c997 100644 --- a/packages/layout/src/demos/complexMenu.ts +++ b/packages/layout/src/demos/complexMenu.ts @@ -27,6 +27,7 @@ export default [ collapsed: true, menuName: '域买家维度交易', name: '域买家维度交易', + path: '/xx', routes: [ { id: 2, diff --git a/packages/layout/src/index.tsx b/packages/layout/src/index.tsx index a21b47f0a7a7..f30d9361c9ee 100644 --- a/packages/layout/src/index.tsx +++ b/packages/layout/src/index.tsx @@ -15,6 +15,7 @@ import 'antd/es/spin/style'; import 'antd/es/switch/style'; import 'antd/es/tabs/style'; import 'antd/es/tooltip/style'; +import 'antd/es/breadcrumb/style'; //---------------------- import { FooterToolbar } from './components/FooterToolbar'; diff --git a/packages/layout/src/utils/getMenuData.ts b/packages/layout/src/utils/getMenuData.ts index 8675e7e939f0..4a6f17c29706 100644 --- a/packages/layout/src/utils/getMenuData.ts +++ b/packages/layout/src/utils/getMenuData.ts @@ -25,6 +25,7 @@ const getMenuData = ( formatMessage, true, ); + if (!menuDataRender) { return { breadcrumb: fromEntries(breadcrumb), diff --git a/packages/layout/src/utils/utils.ts b/packages/layout/src/utils/utils.ts index c6a19f75d859..8551cc38f6fd 100644 --- a/packages/layout/src/utils/utils.ts +++ b/packages/layout/src/utils/utils.ts @@ -5,8 +5,10 @@ export const getOpenKeysFromMenuData = (menuData?: MenuDataItem[]) => { if (item.key) { pre.push(item.key); } - if (item.routes) { - const newArray: string[] = pre.concat(getOpenKeysFromMenuData(item.routes) || []); + if (item.children || item.routes) { + const newArray: string[] = pre.concat( + getOpenKeysFromMenuData(item.children || item.routes) || [], + ); return newArray; } return pre; diff --git a/tests/layout/PageHeader.test.tsx b/tests/layout/PageHeader.test.tsx index 3cc6b5de67cb..e4bef1d6e5fb 100644 --- a/tests/layout/PageHeader.test.tsx +++ b/tests/layout/PageHeader.test.tsx @@ -120,8 +120,7 @@ describe('PageContainer', () => { it('change container width', async () => { const { container } = render(); triggerResize(container.firstChild as HTMLDivElement); - await waitTime(100); - + await waitTime(1000); expect( container.querySelector('div.ant-page-header')?.className.includes('ant-page-header-compact'), ).toBeTruthy(); diff --git a/tests/layout/__snapshots__/demo.test.ts.snap b/tests/layout/__snapshots__/demo.test.ts.snap index cdd9364966c6..339937544e9b 100644 --- a/tests/layout/__snapshots__/demo.test.ts.snap +++ b/tests/layout/__snapshots__/demo.test.ts.snap @@ -3893,11 +3893,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/AlwaysDefaultOpen role="none" >