]> BookStack Code Mirror - bookstack/commitdiff
Searching: Fixed some form search issues
authorDan Brown <redacted>
Sat, 5 Oct 2024 13:47:00 +0000 (14:47 +0100)
committerDan Brown <redacted>
Sat, 5 Oct 2024 13:49:30 +0000 (14:49 +0100)
- Form was not retaining certain filters
- Form request handling of entity type set wrong filter name
Added test to cover.

app/Search/SearchOptions.php
tests/Entity/EntitySearchTest.php
tests/Entity/SearchOptionsTest.php

index 7f9db2a64302b7dbea4f860a2919ec5b0dbd3de3..a6f82029920ee7dd0a0ce1de8416a3498764f11b 100644 (file)
@@ -73,7 +73,7 @@ class SearchOptions
         }
 
         if (isset($inputs['types']) && count($inputs['types']) < 4) {
-            $cleanedFilters[] = new FilterSearchOption(implode('|', $inputs['types']), 'types');
+            $cleanedFilters[] = new FilterSearchOption(implode('|', $inputs['types']), 'type');
         }
 
         $instance->filters = new SearchOptionSet($cleanedFilters);
@@ -235,11 +235,14 @@ class SearchOptions
     {
         $options = [];
 
-        // Non-[created/updated]-by-me options
+        // Handle filters without UI support
         $userFilters = ['updated_by', 'created_by', 'owned_by'];
+        $unsupportedFilters = ['is_template', 'sort_by'];
         foreach ($this->filters->all() as $filter) {
             if (in_array($filter->getKey(), $userFilters, true) && $filter->value !== null && $filter->value !== 'me') {
                 $options[] = $filter;
+            } else if (in_array($filter->getKey(), $unsupportedFilters, true)) {
+                $options[] = $filter;
             }
         }
 
index 3a1a0a6620001d87121014c2c6ac1ace327eddcd..57b7c3f6b88c1b7ca8ee4cb237395701cd7a0c92 100644 (file)
@@ -573,8 +573,8 @@ class EntitySearchTest extends TestCase
 
     public function test_searches_with_terms_without_controls_includes_them_in_extras()
     {
-        $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog"'));
-        $this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} -"dog" -[a=b] -{viewed_by_me}');
+        $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog" {is_template} {sort_by:last_commented}'));
+        $this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} {is_template} {sort_by:last_commented} -"dog" -[a=b] -{viewed_by_me}');
     }
 
     public function test_negated_searches_dont_show_in_inputs()
index ae0f1e56a9ecd6b7e513480b169743fca11c1d5c..0c2ad271c58892df4bfc7b186f948a76bf5b20b5 100644 (file)
@@ -113,6 +113,19 @@ class SearchOptionsTest extends TestCase
         $this->assertEquals(['"cheese"', '""', '"baked',  'beans"'], $options->exacts->toValueArray());
     }
 
+    public function test_from_request_properly_parses_provided_types()
+    {
+        $request = new Request([
+            'search' => '',
+            'types' => ['page', 'book'],
+        ]);
+
+        $options = SearchOptions::fromRequest($request);
+        $filters = $options->filters->toValueMap();
+        $this->assertCount(1, $filters);
+        $this->assertEquals('page|book', $filters['type'] ?? 'notfound');
+    }
+
     public function test_from_request_properly_parses_out_extras_as_string()
     {
         $request = new Request([