Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pro-blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
pro-blocks
Commits
1dab3e29
Commit
1dab3e29
authored
Oct 04, 2018
by
陈帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce menu renderings
parent
b588df34
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
12 deletions
+22
-12
src/components/SiderMenu/BaseMenu.js
src/components/SiderMenu/BaseMenu.js
+18
-10
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+3
-1
src/pages/Dashboard/Monitor.js
src/pages/Dashboard/Monitor.js
+1
-1
No files found.
src/components/SiderMenu/BaseMenu.js
View file @
1dab3e29
import
React
,
{
PureComponent
}
from
'
react
'
;
import
React
,
{
PureComponent
}
from
'
react
'
;
import
{
Menu
,
Icon
}
from
'
antd
'
;
import
{
Menu
,
Icon
}
from
'
antd
'
;
import
Link
from
'
umi/link
'
;
import
Link
from
'
umi/link
'
;
import
isEqual
from
'
lodash/isEqual
'
;
import
memoizeOne
from
'
memoize-one
'
;
import
{
formatMessage
}
from
'
umi/locale
'
;
import
{
formatMessage
}
from
'
umi/locale
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
{
urlToList
}
from
'
../_utils/pathTools
'
;
import
{
urlToList
}
from
'
../_utils/pathTools
'
;
...
@@ -22,12 +24,15 @@ const getIcon = icon => {
...
@@ -22,12 +24,15 @@ const getIcon = icon => {
return
icon
;
return
icon
;
};
};
export
const
getMenuMatches
=
(
flatMenuKeys
,
path
)
=>
export
const
getMenuMatches
=
memoizeOne
(
flatMenuKeys
.
filter
(
item
=>
item
&&
pathToRegexp
(
item
).
test
(
path
));
(
flatMenuKeys
,
path
)
=>
flatMenuKeys
.
filter
(
item
=>
item
&&
pathToRegexp
(
item
).
test
(
path
)),
isEqual
);
export
default
class
BaseMenu
extends
PureComponent
{
export
default
class
BaseMenu
extends
PureComponent
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
getSelectedMenuKeys
=
memoizeOne
(
this
.
getSelectedMenuKeys
,
isEqual
);
this
.
flatMenuKeys
=
this
.
getFlatMenuKeys
(
props
.
menuData
);
this
.
flatMenuKeys
=
this
.
getFlatMenuKeys
(
props
.
menuData
);
}
}
...
@@ -66,12 +71,10 @@ export default class BaseMenu extends PureComponent {
...
@@ -66,12 +71,10 @@ export default class BaseMenu extends PureComponent {
};
};
// Get the currently selected menu
// Get the currently selected menu
getSelectedMenuKeys
=
()
=>
{
getSelectedMenuKeys
=
pathname
=>
const
{
urlToList
(
pathname
).
map
(
function
(
itemPath
)
{
location
:
{
pathname
},
return
getMenuMatches
(
this
.
flatMenuKeys
,
itemPath
).
pop
();
}
=
this
.
props
;
});
return
urlToList
(
pathname
).
map
(
itemPath
=>
getMenuMatches
(
this
.
flatMenuKeys
,
itemPath
).
pop
());
};
/**
/**
* get SubMenu or Item
* get SubMenu or Item
...
@@ -158,9 +161,14 @@ export default class BaseMenu extends PureComponent {
...
@@ -158,9 +161,14 @@ export default class BaseMenu extends PureComponent {
};
};
render
()
{
render
()
{
const
{
openKeys
,
theme
,
mode
}
=
this
.
props
;
const
{
openKeys
,
theme
,
mode
,
location
:
{
pathname
},
}
=
this
.
props
;
// if pathname can't match, use the nearest parent's key
// if pathname can't match, use the nearest parent's key
let
selectedKeys
=
this
.
getSelectedMenuKeys
();
let
selectedKeys
=
this
.
getSelectedMenuKeys
(
pathname
);
if
(
!
selectedKeys
.
length
&&
openKeys
)
{
if
(
!
selectedKeys
.
length
&&
openKeys
)
{
selectedKeys
=
[
openKeys
[
openKeys
.
length
-
1
]];
selectedKeys
=
[
openKeys
[
openKeys
.
length
-
1
]];
}
}
...
...
src/layouts/BasicLayout.js
View file @
1dab3e29
...
@@ -46,6 +46,8 @@ function formatter(data, parentPath = '', parentAuthority, parentName) {
...
@@ -46,6 +46,8 @@ function formatter(data, parentPath = '', parentAuthority, parentName) {
});
});
}
}
const
memoizeOneFormatter
=
memoizeOne
(
formatter
,
isEqual
);
const
query
=
{
const
query
=
{
'
screen-xs
'
:
{
'
screen-xs
'
:
{
maxWidth
:
575
,
maxWidth
:
575
,
...
@@ -136,7 +138,7 @@ class BasicLayout extends React.PureComponent {
...
@@ -136,7 +138,7 @@ class BasicLayout extends React.PureComponent {
const
{
const
{
route
:
{
routes
},
route
:
{
routes
},
}
=
this
.
props
;
}
=
this
.
props
;
return
f
ormatter
(
routes
);
return
memoizeOneF
ormatter
(
routes
);
}
}
/**
/**
...
...
src/pages/Dashboard/Monitor.js
View file @
1dab3e29
...
@@ -121,7 +121,7 @@ class Monitor extends PureComponent {
...
@@ -121,7 +121,7 @@ class Monitor extends PureComponent {
<
Card
<
Card
title
=
{
title
=
{
<
FormattedMessage
<
FormattedMessage
id
=
"
app.monitor.
total-
activity-forecast
"
id
=
"
app.monitor.activity-forecast
"
defaultMessage
=
"
Activity forecast
"
defaultMessage
=
"
Activity forecast
"
/>
/>
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment