mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-06 16:20:30 +00:00
Fix: dont overcount same title or date suggestions
This commit is contained in:
3 files changed
+32
-2
No files matched your search
+13
@@ -154,6 +154,19 @@ describe('SuggestionsDropdownComponent', () => {
|
||||
expect(fixture.nativeElement.textContent).not.toContain('existing value')
|
||||
})
|
||||
|
||||
it('should not count title or date suggestions matching the current values', () => {
|
||||
fixture.componentRef.setInput('suggestions', {
|
||||
title: 'Current title',
|
||||
dates: ['2026-01-04', '2026-02-01'],
|
||||
})
|
||||
expect(component.fieldSuggestions).toBe(3)
|
||||
|
||||
fixture.componentRef.setInput('appliedTitle', 'Current title')
|
||||
fixture.componentRef.setInput('appliedCreated', '2026-01-04')
|
||||
expect(component.fieldSuggestions).toBe(1)
|
||||
expect(component.totalSuggestions).toBe(1)
|
||||
})
|
||||
|
||||
it('should show when a completed request returned no suggestions', () => {
|
||||
fixture.componentRef.setInput('suggestions', {
|
||||
correspondents: [],
|
||||
|
||||
+17
-2
@@ -34,6 +34,8 @@ export class SuggestionsDropdownComponent {
|
||||
readonly appliedCorrespondent = input<number>(null)
|
||||
readonly appliedDocumentType = input<number>(null)
|
||||
readonly appliedStoragePath = input<number>(null)
|
||||
readonly appliedTitle = input<string>(null)
|
||||
readonly appliedCreated = input<string>(null)
|
||||
|
||||
@Output()
|
||||
getSuggestions: EventEmitter<SuggestionSource> = new EventEmitter()
|
||||
@@ -134,11 +136,24 @@ export class SuggestionsDropdownComponent {
|
||||
get fieldSuggestions(): number {
|
||||
return (
|
||||
this.reusableSuggestions +
|
||||
(this.suggestions()?.title ? 1 : 0) +
|
||||
(this.suggestions()?.dates?.length ?? 0)
|
||||
this.unappliedTitleSuggestions +
|
||||
this.unappliedDateSuggestions
|
||||
)
|
||||
}
|
||||
|
||||
// hide a title or date suggestion equal to the current value
|
||||
private get unappliedTitleSuggestions(): number {
|
||||
const title = this.suggestions()?.title
|
||||
return title && title !== this.appliedTitle() ? 1 : 0
|
||||
}
|
||||
|
||||
private get unappliedDateSuggestions(): number {
|
||||
const created = this.appliedCreated()
|
||||
return (this.suggestions()?.dates ?? []).filter(
|
||||
(date) => !created || date !== created
|
||||
).length
|
||||
}
|
||||
|
||||
private countUnapplied(suggested: number[], applied: number[]): number {
|
||||
return (suggested ?? []).filter((id) => !(applied ?? []).includes(id))
|
||||
.length
|
||||
|
||||
@@ -141,6 +141,8 @@
|
||||
[appliedCorrespondent]="documentForm.value.correspondent"
|
||||
[appliedDocumentType]="documentForm.value.document_type"
|
||||
[appliedStoragePath]="documentForm.value.storage_path"
|
||||
[appliedTitle]="documentForm.value.title"
|
||||
[appliedCreated]="documentForm.value.created"
|
||||
(getSuggestions)="getSuggestions($event)"
|
||||
(sourceChange)="suggestionSourceOverride.set($event)"
|
||||
(addTag)="createTag($event)"
|
||||
|
||||
Reference in new issue
Block a user