-
Notifications
You must be signed in to change notification settings - Fork 333
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
API Refactor SiteTree filtering to work like GridField filters #3052
base: 6.0
Are you sure you want to change the base?
API Refactor SiteTree filtering to work like GridField filters #3052
Conversation
7d991c5
to
be997fd
Compare
44daef5
to
e8297af
Compare
ce54bb9
to
85c32a0
Compare
7243da7
to
cf1ff64
Compare
CMSMain uses an entirely separate code path for building the filter form and for the actual filter functionality compared with the gridfield filter used literally everywhere else in the CMS. This aims to unify the two as much as possible, so that filtering pages in CMSMain is the same as filtering everywhere else.
cf1ff64
to
19870a3
Compare
@@ -12,13 +12,11 @@ | |||
<%-- Full breadcrumbs (useful for tree view which isn't available when viewing an edit form) --%> | |||
<% include SilverStripe\\Admin\\CMSBreadcrumbs %> | |||
<% end_if %> | |||
<% include SilverStripe\\CMS\\Controllers\\CMSMain_Filter %> | |||
$SearchForm.FilterButton($TreeIsFiltered) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that we can pass variables into function calls from templates now 👌
public function getFilteredPages() | ||
public function getFilteredPages(DataList $list): DataList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These CMSSiteTreeFilter
classes used to do all of the filtering, basically duplicating the work SearchContext
is meant to do.
They've now been updated to only update a list to filter by status instead of creating a new filtered list. See SiteTreeSearchContext
for the usage.
$baseTable = SiteTree::singleton()->baseTable(); | ||
$liveTable = SiteTree::singleton()->stageTable($baseTable, Versioned::LIVE); | ||
return $list->innerJoin( | ||
$liveTable, | ||
"\"{$baseTable}_Versions\".\"RecordID\" = \"$liveTable\".\"ID\"" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated refactoring to not use hardcoded table names
@@ -496,11 +490,10 @@ public function AddForm(): CMSMainAddForm | |||
public function TreeAsUL() | |||
{ | |||
$modelClass = $this->getModelClass(); | |||
$filter = $this->getSearchFilter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search filter can't be used in the tree view anyway, so this wasn't doing anything
// Provide better defaults from filter | ||
$filter = $this->getSearchFilter(); | ||
if ($filter) { | ||
if (!$childrenMethod) { | ||
$childrenMethod = $filter->getChildrenMethod(); | ||
} | ||
if (!$numChildrenMethod) { | ||
$numChildrenMethod = $filter->getNumChildrenMethod(); | ||
} | ||
if (!$filterFunction) { | ||
$filterFunction = function ($node) use ($filter) { | ||
return $filter->isRecordIncluded($node); | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search filter can't be used in the tree view anyway, so this wasn't doing anything
# BUG: https://github.com/silverstripe/silverstripe-admin/issues/631 | ||
# Scenario: I can search for a page by its oldest last edited date | ||
# Given a "page" "Recent Page" | ||
# And a "page" "Old Page" was last edited "7 days ago" | ||
# When I press the "Advanced" button | ||
# And I fill in "From" with "the date of 5 days ago" | ||
# And I press the "Search" button | ||
# Then I should see "Recent Page" in the cms list | ||
# But I should not see "Old Page" in the cms list | ||
Scenario: I can search for a page by its oldest last edited date | ||
Given a "page" "Recent Page" was last edited "08-08-2007" | ||
And a "page" "Old Page" was last edited "03-03-2007" | ||
And I take a screenshot after every step | ||
When I press the "Advanced" button | ||
And I fill in "Search__LastEdited_SearchFrom" with "06-06-2007" | ||
And I press the "Search" button | ||
Then I should see "Recent Page" in the cms list | ||
But I should not see "Old Page" in the cms list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the below are our only behat tests for the ranged filtering (though we do have good unit test coverage) - so I'm reviving these.
# BUG: https://github.com/silverstripe/silverstripe-cms/issues/1897 | ||
# Scenario: I can open view permissions to everyone | ||
# Given I select "Anyone" from "Who can view this page?" input group | ||
# And I press the "Save" button | ||
# When I am not logged in | ||
# And I go to the homepage | ||
# Then I should see "Welcome" | ||
Scenario: I can open view permissions to everyone | ||
Given I select "Anyone" from "Who can view this page?" input group | ||
And I press the "Save" button | ||
When I am not logged in | ||
And I go to the homepage | ||
Then I should see "Welcome" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated - spotted this commented out test, ran it, and it passes so I'm uncommenting it.
* @see {@link ModelData::getStatusFlags()} | ||
* @return SS_List | ||
*/ | ||
abstract public function getFilteredPages(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See bottom of the diff for this class - this one stays.
// Set default filter if other params are set | ||
if ($params && empty($params['FilterClass'])) { | ||
$params['FilterClass'] = CMSSiteTreeFilter_Search::class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let the search context handle this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with reusable markup in framework
CMSMain uses an entirely separate code path for building the filter form and for the actual filter functionality compared with the gridfield filter used literally everywhere else in the CMS.
This aims to unify the two as much as possible, so that filtering pages in CMSMain is the same as filtering everywhere else.
It also generalises it which will help to unlock #2951
Issue
CMSMain
/HierarchyModelAdmin
#2949