]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: retain sort field from global search filtering, use `FILTER_HAS_TAGS_ALL` (...
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 15 May 2024 20:10:07 +0000 (13:10 -0700)
committerGitHub <noreply@github.com>
Wed, 15 May 2024 20:10:07 +0000 (13:10 -0700)
src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts
src-ui/src/app/components/app-frame/global-search/global-search.component.ts

index 20e39ee57c2b1203619f619f19e36986ead94552..076fa95d1e43bdcc88ddaf4a6b540ad6c24cf378 100644 (file)
@@ -24,7 +24,7 @@ import {
   FILTER_HAS_CORRESPONDENT_ANY,
   FILTER_HAS_DOCUMENT_TYPE_ANY,
   FILTER_HAS_STORAGE_PATH_ANY,
-  FILTER_HAS_TAGS_ANY,
+  FILTER_HAS_TAGS_ALL,
 } from 'src/app/data/filter-rule-type'
 import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
 import { DocumentService } from 'src/app/services/rest/document.service'
@@ -294,36 +294,67 @@ describe('GlobalSearchComponent', () => {
 
     component.primaryAction(DataType.Correspondent, object)
     expect(routerSpy).toHaveBeenCalledWith(['/documents'], {
-      queryParams: queryParamsFromFilterRules([
+      queryParams: Object.assign(
         {
-          rule_type: FILTER_HAS_CORRESPONDENT_ANY,
-          value: object.id.toString(),
+          page: 1,
+          reverse: 1,
+          sort: 'created',
         },
-      ]),
+        queryParamsFromFilterRules([
+          {
+            rule_type: FILTER_HAS_CORRESPONDENT_ANY,
+            value: object.id.toString(),
+          },
+        ])
+      ),
     })
 
     component.primaryAction(DataType.DocumentType, object)
     expect(routerSpy).toHaveBeenCalledWith(['/documents'], {
-      queryParams: queryParamsFromFilterRules([
+      queryParams: Object.assign(
         {
-          rule_type: FILTER_HAS_DOCUMENT_TYPE_ANY,
-          value: object.id.toString(),
+          page: 1,
+          reverse: 1,
+          sort: 'created',
         },
-      ]),
+        queryParamsFromFilterRules([
+          {
+            rule_type: FILTER_HAS_DOCUMENT_TYPE_ANY,
+            value: object.id.toString(),
+          },
+        ])
+      ),
     })
 
     component.primaryAction(DataType.StoragePath, object)
     expect(routerSpy).toHaveBeenCalledWith(['/documents'], {
-      queryParams: queryParamsFromFilterRules([
-        { rule_type: FILTER_HAS_STORAGE_PATH_ANY, value: object.id.toString() },
-      ]),
+      queryParams: Object.assign(
+        {
+          page: 1,
+          reverse: 1,
+          sort: 'created',
+        },
+        queryParamsFromFilterRules([
+          {
+            rule_type: FILTER_HAS_STORAGE_PATH_ANY,
+            value: object.id.toString(),
+          },
+        ])
+      ),
     })
 
     component.primaryAction(DataType.Tag, object)
     expect(routerSpy).toHaveBeenCalledWith(['/documents'], {
-      queryParams: queryParamsFromFilterRules([
-        { rule_type: FILTER_HAS_TAGS_ANY, value: object.id.toString() },
-      ]),
+      queryParams: Object.assign(
+        {
+          page: 1,
+          reverse: 1,
+          sort: 'created',
+        },
+        queryParamsFromFilterRules([
+          { rule_type: FILTER_HAS_TAGS_ALL, value: object.id.toString() },
+        ])
+      ),
     })
 
     component.primaryAction(DataType.User, object)
index 837a8f39d708dc86762fb875a407a59782f841bc..2742ff59a483c2f58d261fb41e4e88be71ee7496 100644 (file)
@@ -14,7 +14,7 @@ import {
   FILTER_HAS_CORRESPONDENT_ANY,
   FILTER_HAS_DOCUMENT_TYPE_ANY,
   FILTER_HAS_STORAGE_PATH_ANY,
-  FILTER_HAS_TAGS_ANY,
+  FILTER_HAS_TAGS_ALL,
 } from 'src/app/data/filter-rule-type'
 import { DataType } from 'src/app/data/datatype'
 import { ObjectWithId } from 'src/app/data/object-with-id'
@@ -41,7 +41,7 @@ import { TagEditDialogComponent } from '../../common/edit-dialog/tag-edit-dialog
 import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
 import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component'
 import { HotKeyService } from 'src/app/services/hot-key.service'
-import { queryParamsFromFilterRules } from 'src/app/utils/query-params'
+import { paramsFromViewState } from 'src/app/utils/query-params'
 
 @Component({
   selector: 'pngx-global-search',
@@ -132,7 +132,7 @@ export class GlobalSearchComponent implements OnInit {
         filterRuleType = FILTER_HAS_STORAGE_PATH_ANY
         break
       case DataType.Tag:
-        filterRuleType = FILTER_HAS_TAGS_ANY
+        filterRuleType = FILTER_HAS_TAGS_ALL
         break
       case DataType.User:
         editDialogComponent = UserEditDialogComponent
@@ -160,9 +160,14 @@ export class GlobalSearchComponent implements OnInit {
     }
 
     if (filterRuleType) {
-      let params = queryParamsFromFilterRules([
-        { rule_type: filterRuleType, value: object.id.toString() },
-      ])
+      let params = paramsFromViewState({
+        filterRules: [
+          { rule_type: filterRuleType, value: object.id.toString() },
+        ],
+        currentPage: 1,
+        sortField: this.documentListViewService.sortField ?? 'created',
+        sortReverse: this.documentListViewService.sortReverse,
+      })
       this.navigateOrOpenInNewWindow(['/documents'], newWindow, {
         queryParams: params,
       })