mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix: use static object for activedisplayfields to prevent changes (#8120)
This commit is contained in:
parent
11cfa0871e
commit
56d296f04b
@ -599,14 +599,17 @@ describe('DocumentListViewService', () => {
|
||||
it('should not filter out custom fields if settings not initialized', () => {
|
||||
const customFields = ['custom_field_1', 'custom_field_2']
|
||||
documentListViewService.displayFields = customFields as any
|
||||
settingsService.displayFieldsInitialized = false
|
||||
expect(documentListViewService.displayFields).toEqual(customFields)
|
||||
jest.spyOn(settingsService, 'allDisplayFields', 'get').mockReturnValue([
|
||||
{ id: DisplayField.ADDED, name: 'Added' },
|
||||
{ id: DisplayField.TITLE, name: 'Title' },
|
||||
{ id: 'custom_field_1', name: 'Custom Field 1' },
|
||||
] as any)
|
||||
settingsService.displayFieldsInitialized = true
|
||||
settingsService.displayFieldsInit.emit(true)
|
||||
expect(documentListViewService.displayFields).toEqual(['custom_field_1'])
|
||||
|
||||
// will now filter on set
|
||||
documentListViewService.displayFields = customFields as any
|
||||
expect(documentListViewService.displayFields).toEqual(['custom_field_1'])
|
||||
})
|
||||
})
|
||||
|
@ -20,6 +20,10 @@ import { paramsFromViewState, paramsToViewState } from '../utils/query-params'
|
||||
import { DocumentService, SelectionData } from './rest/document.service'
|
||||
import { SettingsService } from './settings.service'
|
||||
|
||||
const LIST_DEFAULT_DISPLAY_FIELDS: DisplayField[] = DEFAULT_DISPLAY_FIELDS.map(
|
||||
(f) => f.id
|
||||
).filter((f) => f !== DisplayField.ADDED)
|
||||
|
||||
/**
|
||||
* Captures the current state of the list view.
|
||||
*/
|
||||
@ -102,6 +106,8 @@ export class DocumentListViewService {
|
||||
|
||||
private _activeSavedViewId: number = null
|
||||
|
||||
private displayFieldsInitialized: boolean = false
|
||||
|
||||
get activeSavedViewId() {
|
||||
return this._activeSavedViewId
|
||||
}
|
||||
@ -134,6 +140,19 @@ export class DocumentListViewService {
|
||||
localStorage.removeItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG)
|
||||
}
|
||||
}
|
||||
|
||||
this.settings.displayFieldsInit.subscribe(() => {
|
||||
this.displayFieldsInitialized = true
|
||||
if (this.activeListViewState.displayFields) {
|
||||
this.activeListViewState.displayFields =
|
||||
this.activeListViewState.displayFields.filter(
|
||||
(field) =>
|
||||
this.settings.allDisplayFields.find((f) => f.id === field) !==
|
||||
undefined
|
||||
)
|
||||
this.saveDocumentListView()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private defaultListViewState(): ListViewState {
|
||||
@ -415,23 +434,17 @@ export class DocumentListViewService {
|
||||
}
|
||||
|
||||
get displayFields(): DisplayField[] {
|
||||
let fields =
|
||||
this.activeListViewState.displayFields ??
|
||||
DEFAULT_DISPLAY_FIELDS.map((f) => f.id)
|
||||
if (!this.activeListViewState.displayFields) {
|
||||
fields = fields.filter((f) => f !== DisplayField.ADDED)
|
||||
}
|
||||
return this.settings.displayFieldsInitialized
|
||||
? fields.filter(
|
||||
return this.activeListViewState.displayFields ?? LIST_DEFAULT_DISPLAY_FIELDS
|
||||
}
|
||||
|
||||
set displayFields(fields: DisplayField[]) {
|
||||
this.activeListViewState.displayFields = this.displayFieldsInitialized
|
||||
? fields?.filter(
|
||||
(field) =>
|
||||
this.settings.allDisplayFields.find((f) => f.id === field) !==
|
||||
undefined
|
||||
)
|
||||
: fields
|
||||
}
|
||||
|
||||
set displayFields(fields: DisplayField[]) {
|
||||
this.activeListViewState.displayFields = fields
|
||||
this.saveDocumentListView()
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ export class SettingsService {
|
||||
public get allDisplayFields(): Array<{ id: DisplayField; name: string }> {
|
||||
return this._allDisplayFields
|
||||
}
|
||||
public displayFieldsInitialized: boolean = false
|
||||
public displayFieldsInit: EventEmitter<boolean> = new EventEmitter()
|
||||
|
||||
constructor(
|
||||
rendererFactory: RendererFactory2,
|
||||
@ -382,10 +382,10 @@ export class SettingsService {
|
||||
}
|
||||
})
|
||||
)
|
||||
this.displayFieldsInitialized = true
|
||||
this.displayFieldsInit.emit(true)
|
||||
})
|
||||
} else {
|
||||
this.displayFieldsInitialized = true
|
||||
this.displayFieldsInit.emit(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user