Skip to content

Commit

Permalink
feat(layout): remove unuse deps
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jan 5, 2023
1 parent ce58d7e commit 9cac437
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 84 deletions.
2 changes: 1 addition & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/layout/src/components/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ const BaseMenu: React.FC<BaseMenuProps & PrivateSiderMenuProps> = (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('-')],
Expand Down
1 change: 1 addition & 0 deletions packages/layout/src/demos/AlwaysDefaultOpenAllMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default () => (
collapsed: true,
menuName: '域买家维度交易',
name: '域买家维度交易',
path: '/xx',
routes: [
{
id: 2,
Expand Down
1 change: 1 addition & 0 deletions packages/layout/src/demos/complexMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default [
collapsed: true,
menuName: '域买家维度交易',
name: '域买家维度交易',
path: '/xx',
routes: [
{
id: 2,
Expand Down
1 change: 1 addition & 0 deletions packages/layout/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions packages/layout/src/utils/getMenuData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const getMenuData = (
formatMessage,
true,
);

if (!menuDataRender) {
return {
breadcrumb: fromEntries(breadcrumb),
Expand Down
6 changes: 4 additions & 2 deletions packages/layout/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tests/layout/PageHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ describe('PageContainer', () => {
it('change container width', async () => {
const { container } = render(<PageHeader title="Page Title" extra="extra" />);
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();
Expand Down
32 changes: 16 additions & 16 deletions tests/layout/__snapshots__/demo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3893,11 +3893,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/AlwaysDefaultOpen
role="none"
>
<div
aria-controls="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4-popup"
aria-controls="rc-menu-uuid-test-/xx-popup"
aria-expanded="true"
aria-haspopup="true"
class="ant-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4"
data-menu-id="rc-menu-uuid-test-/xx"
role="menuitem"
style="padding-left: 32px;"
tabindex="-1"
Expand All @@ -3923,7 +3923,7 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/AlwaysDefaultOpen
<ul
class="ant-menu ant-menu-sub ant-menu-inline"
data-menu-list="true"
id="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4-popup"
id="rc-menu-uuid-test-/xx-popup"
>
<li
class="ant-menu-item ant-menu-item-only-child ant-pro-base-menu-menu-item"
Expand Down Expand Up @@ -3976,11 +3976,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/AlwaysDefaultOpen
role="none"
>
<div
aria-controls="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2-popup"
aria-controls="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe-popup"
aria-expanded="true"
aria-haspopup="true"
class="ant-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2"
data-menu-id="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe"
role="menuitem"
style="padding-left: 32px;"
tabindex="-1"
Expand All @@ -4006,7 +4006,7 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/AlwaysDefaultOpen
<ul
class="ant-menu ant-menu-sub ant-menu-inline"
data-menu-list="true"
id="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2-popup"
id="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe-popup"
>
<li
class="ant-menu-item ant-menu-item-only-child ant-pro-base-menu-menu-item"
Expand Down Expand Up @@ -4784,11 +4784,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/DefaultOpenAllMen
role="none"
>
<div
aria-controls="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4-popup"
aria-controls="rc-menu-uuid-test-/xx-popup"
aria-expanded="true"
aria-haspopup="true"
class="ant-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4"
data-menu-id="rc-menu-uuid-test-/xx"
role="menuitem"
style="padding-left: 32px;"
tabindex="-1"
Expand All @@ -4814,7 +4814,7 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/DefaultOpenAllMen
<ul
class="ant-menu ant-menu-sub ant-menu-inline"
data-menu-list="true"
id="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4-popup"
id="rc-menu-uuid-test-/xx-popup"
>
<li
class="ant-menu-item ant-menu-item-only-child ant-pro-base-menu-menu-item"
Expand Down Expand Up @@ -4867,11 +4867,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/DefaultOpenAllMen
role="none"
>
<div
aria-controls="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2-popup"
aria-controls="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe-popup"
aria-expanded="true"
aria-haspopup="true"
class="ant-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2"
data-menu-id="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe"
role="menuitem"
style="padding-left: 32px;"
tabindex="-1"
Expand All @@ -4897,7 +4897,7 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/DefaultOpenAllMen
<ul
class="ant-menu ant-menu-sub ant-menu-inline"
data-menu-list="true"
id="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2-popup"
id="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe-popup"
>
<li
class="ant-menu-item ant-menu-item-only-child ant-pro-base-menu-menu-item"
Expand Down Expand Up @@ -5766,11 +5766,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/MenuGroup.tsx cor
role="none"
>
<div
aria-controls="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4-popup"
aria-controls="rc-menu-uuid-test-/xx-popup"
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-/cc19e384db0c314c8f5bae7bd08375a1eb8280bc00fba70f3941602421d509c4"
data-menu-id="rc-menu-uuid-test-/xx"
role="menuitem"
style="padding-left: 16px;"
tabindex="-1"
Expand Down Expand Up @@ -5799,11 +5799,11 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/MenuGroup.tsx cor
role="none"
>
<div
aria-controls="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2-popup"
aria-controls="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe-popup"
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
data-menu-id="rc-menu-uuid-test-/028ada2346da00990af63de1191f18cc87c96fc671323ae24df9dd39fc8c0fd2"
data-menu-id="rc-menu-uuid-test-/9449c99785ac015b1ec5af4ac62f9e00fe23fa6c23f3f0d36303c9e840f54ffe"
role="menuitem"
style="padding-left: 16px;"
tabindex="-1"
Expand Down
19 changes: 10 additions & 9 deletions tests/layout/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ describe('BasicLayout', () => {
},
]}
route={{
routes: [
children: [
[
{
path: '/home',
name: '首页',
locale: 'menu.home',
routes: [
children: [
{
path: '/home/overview',
name: '概述',
Expand Down Expand Up @@ -166,13 +166,13 @@ describe('BasicLayout', () => {
},
]}
route={{
routes: [
children: [
[
{
path: '/home',
name: '首页',
locale: 'menu.home',
routes: [
children: [
{
path: '/home/overview',
name: '概述',
Expand Down Expand Up @@ -382,13 +382,13 @@ describe('BasicLayout', () => {
const wrapper = render(
<ProLayout
route={{
routes: [
children: [
[
{
path: '/home',
name: '首页',
locale: 'menu.home',
routes: [
children: [
{
path: '/home/overview',
name: '概述',
Expand Down Expand Up @@ -1243,7 +1243,7 @@ describe('BasicLayout', () => {
{
path: '/admin',
name: '管理页',
routes: [
children: [
{
path: '/admin/sub-page1',
name: '一级页面',
Expand All @@ -1261,7 +1261,7 @@ describe('BasicLayout', () => {
{
name: '列表页',
path: '/list',
routes: [
children: [
{
path: '/list/sub-page',
name: '一级列表页面',
Expand Down Expand Up @@ -1422,6 +1422,7 @@ describe('BasicLayout', () => {
collapsed: true,
menuName: '域买家维度交易',
name: '域买家维度交易',
path: '/xx',
children: [
{
id: 2,
Expand Down Expand Up @@ -1563,7 +1564,7 @@ describe('BasicLayout', () => {
locale: true,
}}
route={{
routes: [
children: [
{
name: 'home',
locale: 'menu.home',
Expand Down
Loading

0 comments on commit 9cac437

Please sign in to comment.