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

API Refactor SiteTree filtering to work like GridField filters #3052

Open
wants to merge 1 commit into
base: 6.0
Choose a base branch
from

Conversation

GuySartorelli
Copy link
Member

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

@GuySartorelli GuySartorelli marked this pull request as draft January 30, 2025 03:15
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/refactor-sitetree-filter branch 2 times, most recently from 7d991c5 to be997fd Compare February 5, 2025 04:10
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/refactor-sitetree-filter branch 3 times, most recently from 44daef5 to e8297af Compare February 11, 2025 02:11
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/refactor-sitetree-filter branch 6 times, most recently from ce54bb9 to 85c32a0 Compare February 25, 2025 03:47
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/refactor-sitetree-filter branch 2 times, most recently from 7243da7 to cf1ff64 Compare February 25, 2025 03:53
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.
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/refactor-sitetree-filter branch from cf1ff64 to 19870a3 Compare February 27, 2025 21:27
@GuySartorelli GuySartorelli marked this pull request as ready for review February 28, 2025 02:17
@@ -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)
Copy link
Member Author

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 👌

Comment on lines -20 to +19
public function getFilteredPages()
public function getFilteredPages(DataList $list): DataList
Copy link
Member Author

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.

Comment on lines +28 to +33
$baseTable = SiteTree::singleton()->baseTable();
$liveTable = SiteTree::singleton()->stageTable($baseTable, Versioned::LIVE);
return $list->innerJoin(
$liveTable,
"\"{$baseTable}_Versions\".\"RecordID\" = \"$liveTable\".\"ID\""
);
Copy link
Member Author

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();
Copy link
Member Author

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

Comment on lines -533 to -548
// 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);
};
}
}
Copy link
Member Author

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

Comment on lines -30 to +38
# 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
Copy link
Member Author

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.

Comment on lines -17 to +22
# 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"
Copy link
Member Author

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();
Copy link
Member Author

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.

Comment on lines -1720 to -1722
// Set default filter if other params are set
if ($params && empty($params['FilterClass'])) {
$params['FilterClass'] = CMSSiteTreeFilter_Search::class;
Copy link
Member Author

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

Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant