mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-11-21 04:36:53 -06:00
Fix: sort editing filterable dropdowns sooner (#11404)
This commit is contained in:
@@ -631,6 +631,47 @@ describe('FilterableDropdownComponent & FilterableDropdownSelectionModel', () =>
|
||||
])
|
||||
})
|
||||
|
||||
it('resorts items immediately when document count sorting enabled', () => {
|
||||
const apple: Tag = { id: 55, name: 'Apple' }
|
||||
const zebra: Tag = { id: 56, name: 'Zebra' }
|
||||
|
||||
selectionModel.documentCountSortingEnabled = true
|
||||
selectionModel.items = [apple, zebra]
|
||||
expect(selectionModel.items.map((item) => item?.id ?? null)).toEqual([
|
||||
null,
|
||||
apple.id,
|
||||
zebra.id,
|
||||
])
|
||||
|
||||
selectionModel.documentCounts = [
|
||||
{ id: zebra.id, document_count: 5 },
|
||||
{ id: apple.id, document_count: 0 },
|
||||
]
|
||||
|
||||
expect(selectionModel.items.map((item) => item?.id ?? null)).toEqual([
|
||||
null,
|
||||
zebra.id,
|
||||
apple.id,
|
||||
])
|
||||
})
|
||||
|
||||
it('does not resort items by default when document counts are set', () => {
|
||||
const first: Tag = { id: 57, name: 'First' }
|
||||
const second: Tag = { id: 58, name: 'Second' }
|
||||
|
||||
selectionModel.items = [first, second]
|
||||
selectionModel.documentCounts = [
|
||||
{ id: second.id, document_count: 10 },
|
||||
{ id: first.id, document_count: 0 },
|
||||
]
|
||||
|
||||
expect(selectionModel.items.map((item) => item?.id ?? null)).toEqual([
|
||||
null,
|
||||
first.id,
|
||||
second.id,
|
||||
])
|
||||
})
|
||||
|
||||
it('uses fallback document counts when selection data is missing', () => {
|
||||
const fallbackRoot: Tag = {
|
||||
id: 50,
|
||||
|
||||
@@ -61,8 +61,13 @@ export class FilterableDropdownSelectionModel {
|
||||
temporaryIntersection: Intersection = this._intersection
|
||||
|
||||
private _documentCounts: SelectionDataItem[] = []
|
||||
public documentCountSortingEnabled = false
|
||||
|
||||
public set documentCounts(counts: SelectionDataItem[]) {
|
||||
this._documentCounts = counts
|
||||
if (this.documentCountSortingEnabled) {
|
||||
this.sortItems()
|
||||
}
|
||||
}
|
||||
|
||||
private _items: MatchingModel[] = []
|
||||
@@ -651,8 +656,9 @@ export class FilterableDropdownComponent
|
||||
this.selectionModel.changed.complete()
|
||||
model.items = this.selectionModel.items
|
||||
model.manyToOne = this.selectionModel.manyToOne
|
||||
model.singleSelect = this.editing && !this.selectionModel.manyToOne
|
||||
model.singleSelect = this._editing && !model.manyToOne
|
||||
}
|
||||
model.documentCountSortingEnabled = this._editing
|
||||
model.changed.subscribe((updatedModel) => {
|
||||
this.selectionModelChange.next(updatedModel)
|
||||
})
|
||||
@@ -682,8 +688,21 @@ export class FilterableDropdownComponent
|
||||
@Input()
|
||||
allowSelectNone: boolean = false
|
||||
|
||||
private _editing = false
|
||||
|
||||
@Input()
|
||||
editing = false
|
||||
set editing(value: boolean) {
|
||||
this._editing = value
|
||||
if (this.selectionModel) {
|
||||
this.selectionModel.singleSelect =
|
||||
this._editing && !this.selectionModel.manyToOne
|
||||
this.selectionModel.documentCountSortingEnabled = this._editing
|
||||
}
|
||||
}
|
||||
|
||||
get editing() {
|
||||
return this._editing
|
||||
}
|
||||
|
||||
@Input()
|
||||
applyOnClose = false
|
||||
|
||||
Reference in New Issue
Block a user