mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Fix: saved views do not return to default display fields after setting and then removing (#9168)
This commit is contained in:
@@ -145,7 +145,10 @@ export class SavedViewWidgetComponent
|
||||
})
|
||||
}
|
||||
|
||||
if (this.savedView.display_fields) {
|
||||
if (
|
||||
this.savedView.display_fields &&
|
||||
this.savedView.display_fields.length > 0
|
||||
) {
|
||||
this.displayFields = this.savedView.display_fields
|
||||
}
|
||||
|
||||
|
@@ -114,6 +114,48 @@ describe(`Additional service tests for SavedViewService`, () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('should treat empty display_fields as null', () => {
|
||||
subscription = service
|
||||
.patch({
|
||||
id: 1,
|
||||
name: 'Saved View',
|
||||
show_on_dashboard: true,
|
||||
show_in_sidebar: true,
|
||||
sort_field: 'name',
|
||||
sort_reverse: true,
|
||||
filter_rules: [],
|
||||
display_fields: [],
|
||||
})
|
||||
.subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/1/`
|
||||
)
|
||||
expect(req.request.body.display_fields).toBeNull()
|
||||
})
|
||||
|
||||
it('should support patch without reload', () => {
|
||||
subscription = service
|
||||
.patch(
|
||||
{
|
||||
id: 1,
|
||||
name: 'Saved View',
|
||||
show_on_dashboard: true,
|
||||
show_in_sidebar: true,
|
||||
sort_field: 'name',
|
||||
sort_reverse: true,
|
||||
filter_rules: [],
|
||||
},
|
||||
false
|
||||
)
|
||||
.subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/1/`
|
||||
)
|
||||
expect(req.request.method).toEqual('PATCH')
|
||||
req.flush({})
|
||||
httpTestingController.verify() // no reload
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
// Dont need to setup again
|
||||
|
||||
|
@@ -87,12 +87,21 @@ export class SavedViewService extends AbstractPaperlessService<SavedView> {
|
||||
return super.create(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
update(o: SavedView) {
|
||||
return super.update(o).pipe(tap(() => this.reload()))
|
||||
patch(o: SavedView, reload: boolean = false): Observable<SavedView> {
|
||||
if (o.display_fields?.length === 0) {
|
||||
o.display_fields = null
|
||||
}
|
||||
return super.patch(o).pipe(
|
||||
tap(() => {
|
||||
if (reload) {
|
||||
this.reload()
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
patchMany(objects: SavedView[]): Observable<SavedView[]> {
|
||||
return combineLatest(objects.map((o) => super.patch(o))).pipe(
|
||||
return combineLatest(objects.map((o) => this.patch(o, false))).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user