Fix: reset documents sort field if user deletes the custom field (#9127)

This commit is contained in:
shamoon
2025-02-16 07:24:17 -08:00
committed by GitHub
parent 17bb3ebbf5
commit 4718df271f
4 changed files with 18 additions and 6 deletions

View File

@@ -195,11 +195,7 @@ describe('DocumentListViewService', () => {
{ custom_field_999: ['Custom field not found'] },
{ status: 400, statusText: 'Unexpected error' }
)
expect(documentListViewService.error).toEqual(
'custom_field_999: Custom field not found'
)
// reset the list
documentListViewService.sortField = 'created'
// resets itself
req = httpTestingController.expectOne(
`${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true`
)

View File

@@ -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.
activeListViewState.currentPage = 1
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 {
this.selectionData = null
let errorMessage

View File

@@ -62,6 +62,10 @@ export class DocumentService extends AbstractPaperlessService<Document> {
private customFieldService: CustomFieldsService
) {
super(http, 'documents')
this.reload()
}
public reload() {
if (
this.permissionsService.currentUserCan(
PermissionAction.View,