Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Tweak: place 0 result items at bottom of filterable list (#8924)

shamoon082bf6fb8e5d
diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts
index f402cbdce..6ba15eacd 100644
--- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts
+++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts
@@ -496,6 +496,38 @@ describe('FilterableDropdownComponent & FilterableDropdownSelectionModel', () =>
])
})
+ it('selection model should sort items by state and document counts = 0, if set', () => {
+ const tagA = { id: 4, name: 'Tag A' }
+ component.items = items.concat([tagA])
+ component.selectionModel = selectionModel
+ component.documentCounts = [
+ { id: 1, document_count: 0 }, // Tag1
+ { id: 2, document_count: 1 }, // Tag2
+ { id: 4, document_count: 2 }, // Tag A
+ ]
+ component.selectionModel.apply()
+ expect(selectionModel.items).toEqual([
+ nullItem,
+ tagA,
+ items[1], // Tag2
+ items[0], // Tag1
+ ])
+
+ selectionModel.toggle(items[1].id)
+ component.documentCounts = [
+ { id: 1, document_count: 0 },
+ { id: 2, document_count: 1 },
+ { id: 4, document_count: 0 },
+ ]
+ selectionModel.apply()
+ expect(selectionModel.items).toEqual([
+ nullItem,
+ items[1], // Tag2
+ tagA,
+ items[0], // Tag1
+ ])
+ })
+
it('should set support create, keep open model and call createRef method', fakeAsync(() => {
component.items = items
component.icon = 'tag-fill'
diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts
index 73b7fd27b..4e3d280dc 100644
--- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts
+++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts
@@ -81,6 +81,18 @@ export class FilterableDropdownSelectionModel {
this.getNonTemporary(b.id) == ToggleableItemState.NotSelected
) {
return -1
+ } else if (
+ this._documentCounts.length &&
+ this.getDocumentCount(b.id) === 0 &&
+ this.getDocumentCount(a.id) > this.getDocumentCount(b.id)
+ ) {
+ return -1
+ } else if (
+ this._documentCounts.length &&
+ this.getDocumentCount(a.id) === 0 &&
+ this.getDocumentCount(a.id) < this.getDocumentCount(b.id)
+ ) {
+ return 1
} else {
return a.name.localeCompare(b.name)
}