Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy draw dropdowns to improve performance #2925

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/src/admin/components/PermissionDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class PermissionDropdown extends Dropdown {

attrs.className = 'PermissionDropdown';
attrs.buttonClassName = 'Button Button--text';
attrs.lazyDraw = true;
}

view(vnode) {
Expand Down
2 changes: 2 additions & 0 deletions js/src/admin/components/PermissionGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default class PermissionGrid extends Component {
{ value: '1', label: app.translator.trans('core.admin.permissions_controls.signup_open_button') },
{ value: '0', label: app.translator.trans('core.admin.permissions_controls.signup_closed_button') },
],
lazyDraw: true,
}),
},
90
Expand Down Expand Up @@ -190,6 +191,7 @@ export default class PermissionGrid extends Component {
{ value: '10', label: app.translator.trans('core.admin.permissions_controls.allow_ten_minutes_button') },
{ value: 'reply', label: app.translator.trans('core.admin.permissions_controls.allow_until_reply_button') },
],
lazyDraw: true,
});
},
},
Expand Down
21 changes: 17 additions & 4 deletions js/src/common/components/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ export default class Dropdown extends Component {

view(vnode) {
const items = vnode.children ? listItems(vnode.children) : [];
const renderItems = this.attrs.lazyDraw ? this.showing : true;

return (
<div className={'ButtonGroup Dropdown dropdown ' + this.attrs.className + ' itemCount' + items.length + (this.showing ? ' open' : '')}>
{this.getButton(vnode.children)}
{this.getMenu(items)}
{renderItems && this.getMenu(items)}
</div>
);
}
Expand All @@ -53,13 +54,25 @@ export default class Dropdown extends Component {
// bottom of the viewport. If it does, we will apply class to make it show
// above the toggle button instead of below it.
this.$().on('shown.bs.dropdown', () => {
const { lazyDraw, onshow } = this.attrs;

this.showing = true;

if (this.attrs.onshow) {
this.attrs.onshow();
// If using lazy drawing, redraw before calling `onshow` function
// to make sure the menu DOM exists in case the callback tries to use it.
if (lazyDraw) {
m.redraw.sync();
davwheat marked this conversation as resolved.
Show resolved Hide resolved
}

m.redraw();
if (typeof onshow === 'function') {
onshow();
}

// If not using lazy drawing, keep previous functionality
// of redrawing after calling onshow()
if (!lazyDraw) {
m.redraw();
}

const $menu = this.$('.Dropdown-menu');
const isRight = $menu.hasClass('Dropdown-menu--right');
Expand Down