mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-28 03:46:06 -05:00 
			
		
		
		
	Fix: reset documents sort field if user deletes the custom field (#9127)
This commit is contained in:
		| @@ -16,6 +16,7 @@ import { IfPermissionsDirective } from 'src/app/directives/if-permissions.direct | |||||||
| import { DocumentListViewService } from 'src/app/services/document-list-view.service' | import { DocumentListViewService } from 'src/app/services/document-list-view.service' | ||||||
| import { PermissionsService } from 'src/app/services/permissions.service' | import { PermissionsService } from 'src/app/services/permissions.service' | ||||||
| import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service' | import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service' | ||||||
|  | import { DocumentService } from 'src/app/services/rest/document.service' | ||||||
| import { SettingsService } from 'src/app/services/settings.service' | import { SettingsService } from 'src/app/services/settings.service' | ||||||
| import { ToastService } from 'src/app/services/toast.service' | import { ToastService } from 'src/app/services/toast.service' | ||||||
| import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component' | import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component' | ||||||
| @@ -48,7 +49,8 @@ export class CustomFieldsComponent | |||||||
|     private modalService: NgbModal, |     private modalService: NgbModal, | ||||||
|     private toastService: ToastService, |     private toastService: ToastService, | ||||||
|     private documentListViewService: DocumentListViewService, |     private documentListViewService: DocumentListViewService, | ||||||
|     private settingsService: SettingsService |     private settingsService: SettingsService, | ||||||
|  |     private documentService: DocumentService | ||||||
|   ) { |   ) { | ||||||
|     super() |     super() | ||||||
|   } |   } | ||||||
| @@ -85,6 +87,7 @@ export class CustomFieldsComponent | |||||||
|         this.toastService.showInfo($localize`Saved field "${newField.name}".`) |         this.toastService.showInfo($localize`Saved field "${newField.name}".`) | ||||||
|         this.customFieldsService.clearCache() |         this.customFieldsService.clearCache() | ||||||
|         this.settingsService.initializeDisplayFields() |         this.settingsService.initializeDisplayFields() | ||||||
|  |         this.documentService.reload() | ||||||
|         this.reload() |         this.reload() | ||||||
|       }) |       }) | ||||||
|     modal.componentInstance.failed |     modal.componentInstance.failed | ||||||
| @@ -111,6 +114,7 @@ export class CustomFieldsComponent | |||||||
|           this.toastService.showInfo($localize`Deleted field "${field.name}"`) |           this.toastService.showInfo($localize`Deleted field "${field.name}"`) | ||||||
|           this.customFieldsService.clearCache() |           this.customFieldsService.clearCache() | ||||||
|           this.settingsService.initializeDisplayFields() |           this.settingsService.initializeDisplayFields() | ||||||
|  |           this.documentService.reload() | ||||||
|           this.reload() |           this.reload() | ||||||
|         }, |         }, | ||||||
|         error: (e) => { |         error: (e) => { | ||||||
|   | |||||||
| @@ -195,11 +195,7 @@ describe('DocumentListViewService', () => { | |||||||
|       { custom_field_999: ['Custom field not found'] }, |       { custom_field_999: ['Custom field not found'] }, | ||||||
|       { status: 400, statusText: 'Unexpected error' } |       { status: 400, statusText: 'Unexpected error' } | ||||||
|     ) |     ) | ||||||
|     expect(documentListViewService.error).toEqual( |     // resets itself | ||||||
|       'custom_field_999: Custom field not found' |  | ||||||
|     ) |  | ||||||
|     // reset the list |  | ||||||
|     documentListViewService.sortField = 'created' |  | ||||||
|     req = httpTestingController.expectOne( |     req = httpTestingController.expectOne( | ||||||
|       `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true` |       `${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true` | ||||||
|     ) |     ) | ||||||
|   | |||||||
| @@ -306,6 +306,14 @@ export class DocumentListViewService { | |||||||
|             // this happens when applying a filter: the current page might not be available anymore due to the reduced result set. |             // this happens when applying a filter: the current page might not be available anymore due to the reduced result set. | ||||||
|             activeListViewState.currentPage = 1 |             activeListViewState.currentPage = 1 | ||||||
|             this.reload() |             this.reload() | ||||||
|  |           } else if ( | ||||||
|  |             activeListViewState.sortField.indexOf('custom_field') === 0 && | ||||||
|  |             this.settings.allDisplayFields.find( | ||||||
|  |               (f) => f.id === activeListViewState.sortField | ||||||
|  |             ) === undefined | ||||||
|  |           ) { | ||||||
|  |             // e.g. field was deleted | ||||||
|  |             this.sortField = 'created' | ||||||
|           } else { |           } else { | ||||||
|             this.selectionData = null |             this.selectionData = null | ||||||
|             let errorMessage |             let errorMessage | ||||||
|   | |||||||
| @@ -62,6 +62,10 @@ export class DocumentService extends AbstractPaperlessService<Document> { | |||||||
|     private customFieldService: CustomFieldsService |     private customFieldService: CustomFieldsService | ||||||
|   ) { |   ) { | ||||||
|     super(http, 'documents') |     super(http, 'documents') | ||||||
|  |     this.reload() | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public reload() { | ||||||
|     if ( |     if ( | ||||||
|       this.permissionsService.currentUserCan( |       this.permissionsService.currentUserCan( | ||||||
|         PermissionAction.View, |         PermissionAction.View, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon