Commit f4855c29 authored by Erwin Zhang's avatar Erwin Zhang Committed by 陈帅

Fix menu typos

parent f60ee6e7
...@@ -21,13 +21,13 @@ const getIcon = icon => { ...@@ -21,13 +21,13 @@ const getIcon = icon => {
return icon; return icon;
}; };
export const getMeunMatcheys = (flatMenuKeys, path) => { export const getMenuMatches = (flatMenuKeys, path) => {
return flatMenuKeys.filter(item => { return flatMenuKeys.filter(item => {
return pathToRegexp(item).test(path); return pathToRegexp(item).test(path);
}); });
}; };
export default class BaseMeun extends PureComponent { export default class BaseMenu extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.menus = props.menuData; this.menus = props.menuData;
...@@ -68,7 +68,7 @@ export default class BaseMeun extends PureComponent { ...@@ -68,7 +68,7 @@ export default class BaseMeun extends PureComponent {
// Get the currently selected menu // Get the currently selected menu
getSelectedMenuKeys = () => { getSelectedMenuKeys = () => {
const { location: { pathname } } = this.props; const { location: { pathname } } = this.props;
return urlToList(pathname).map(itemPath => getMeunMatcheys(this.flatMenuKeys, itemPath).pop()); return urlToList(pathname).map(itemPath => getMenuMatches(this.flatMenuKeys, itemPath).pop());
}; };
/** /**
* get SubMenu or Item * get SubMenu or Item
......
...@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'; ...@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
import { Layout, Menu, Icon } from 'antd'; import { Layout, Menu, Icon } from 'antd';
import { Link } from 'dva/router'; import { Link } from 'dva/router';
import styles from './index.less'; import styles from './index.less';
import BaseMeun, { getMeunMatcheys } from './BaseMeun'; import BaseMenu, { getMenuMatches } from './BaseMenu';
import { urlToList } from '../_utils/pathTools'; import { urlToList } from '../_utils/pathTools';
const { Sider } = Layout; const { Sider } = Layout;
...@@ -131,7 +131,7 @@ export default class SiderMenu extends PureComponent { ...@@ -131,7 +131,7 @@ export default class SiderMenu extends PureComponent {
const { location: { pathname } } = props || this.props; const { location: { pathname } } = props || this.props;
return urlToList(pathname) return urlToList(pathname)
.map(item => { .map(item => {
return getMeunMatcheys(this.flatMenuKeys, item)[0]; return getMenuMatches(this.flatMenuKeys, item)[0];
}) })
.filter(item => item); .filter(item => item);
} }
...@@ -165,7 +165,7 @@ export default class SiderMenu extends PureComponent { ...@@ -165,7 +165,7 @@ export default class SiderMenu extends PureComponent {
<h1>Ant Design Pro</h1> <h1>Ant Design Pro</h1>
</Link> </Link>
</div> </div>
<BaseMeun <BaseMenu
{...this.props} {...this.props}
key="Menu" key="Menu"
mode="inline" mode="inline"
......
import { getMenuMatches } from './BaseMenu';
const menu = ['/dashboard', '/userinfo', '/dashboard/name', '/userinfo/:id', '/userinfo/:id/info'];
describe('test menu match', () => {
it('simple path', () => {
expect(getMenuMatches(menu, '/dashboard')).toEqual(['/dashboard']);
});
it('error path', () => {
expect(getMenuMatches(menu, '/dashboardname')).toEqual([]);
});
it('Secondary path', () => {
expect(getMenuMatches(menu, '/dashboard/name')).toEqual(['/dashboard/name']);
});
it('Parameter path', () => {
expect(getMenuMatches(menu, '/userinfo/2144')).toEqual(['/userinfo/:id']);
});
it('three parameter path', () => {
expect(getMenuMatches(menu, '/userinfo/2144/info')).toEqual(['/userinfo/:id/info']);
});
});
import { getMeunMatcheys } from './BaseMeun';
const meun = ['/dashboard', '/userinfo', '/dashboard/name', '/userinfo/:id', '/userinfo/:id/info'];
describe('test meun match', () => {
it('simple path', () => {
expect(getMeunMatcheys(meun, '/dashboard')).toEqual(['/dashboard']);
});
it('error path', () => {
expect(getMeunMatcheys(meun, '/dashboardname')).toEqual([]);
});
it('Secondary path', () => {
expect(getMeunMatcheys(meun, '/dashboard/name')).toEqual(['/dashboard/name']);
});
it('Parameter path', () => {
expect(getMeunMatcheys(meun, '/userinfo/2144')).toEqual(['/userinfo/:id']);
});
it('three parameter path', () => {
expect(getMeunMatcheys(meun, '/userinfo/2144/info')).toEqual(['/userinfo/:id/info']);
});
});
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Link } from 'dva/router'; import { Link } from 'dva/router';
import RightContent from '../GlobalHeader/RightContent'; import RightContent from '../GlobalHeader/RightContent';
import BaseMeun from '../SiderMenu/BaseMeun'; import BaseMenu from '../SiderMenu/BaseMenu';
import styles from './index.less'; import styles from './index.less';
export default class TopNavHeader extends PureComponent { export default class TopNavHeader extends PureComponent {
...@@ -24,7 +24,7 @@ export default class TopNavHeader extends PureComponent { ...@@ -24,7 +24,7 @@ export default class TopNavHeader extends PureComponent {
<h1>Ant Design Pro</h1> <h1>Ant Design Pro</h1>
</Link> </Link>
</div> </div>
<BaseMeun <BaseMenu
{...this.props} {...this.props}
style={{ padding: '9px 0', border: 'none' }} style={{ padding: '9px 0', border: 'none' }}
/> />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment