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

Only lazy load categories dropdown if there is a large number of categories #637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion src/Model/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ public function getCMSFields()
);
}

$shouldLazyLoadCategories = true;
if($this->Categories()->count() < 15) {
$shouldLazyLoadCategories = false;
}
Comment on lines +315 to +318
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be changed to be a bit more readable (IMO) and also a bit better to phrase it in the positive sense "lazy load if more than 15" rather than currently "don't lazy load if less than 15".

Suggested change
$shouldLazyLoadCategories = true;
if($this->Categories()->count() < 15) {
$shouldLazyLoadCategories = false;
}
$shouldLazyLoadCategories = $this->Categories()->count() > 15;


// Get categories and tags
// @todo: Reimplement the sidebar
// $options = BlogAdminSidebar::create(
Expand All @@ -326,7 +331,7 @@ public function getCMSFields()
$this->Categories()
)
->setCanCreate($this->canCreateCategories())
->setShouldLazyLoad(true),
->setShouldLazyLoad($shouldLazyLoadCategories),
TagField::create(
'Tags',
_t(__CLASS__ . '.Tags', 'Tags'),
Expand Down