Filter out parent document ID & already-selected documents
This commit is contained in:
parent
6f4ee8c332
commit
2c8eb1c395
@ -20,6 +20,10 @@ const documents = [
|
||||
id: 12,
|
||||
title: 'Document 12 bar',
|
||||
},
|
||||
{
|
||||
id: 16,
|
||||
title: 'Document 16 bar',
|
||||
},
|
||||
{
|
||||
id: 23,
|
||||
title: 'Document 23 bar',
|
||||
@ -101,7 +105,7 @@ describe('DocumentLinkComponent', () => {
|
||||
})
|
||||
component.writeValue([12, 23])
|
||||
expect(component.value).toEqual([12, 23])
|
||||
expect(component.selectedDocuments).toEqual([documents[1], documents[2]])
|
||||
expect(component.selectedDocuments).toEqual([documents[1], documents[3]])
|
||||
component.writeValue(null)
|
||||
expect(component.value).toEqual([])
|
||||
expect(component.selectedDocuments).toEqual([])
|
||||
@ -131,4 +135,26 @@ describe('DocumentLinkComponent', () => {
|
||||
expect(component.compareDocuments(documents[0], { id: 2 })).toBeFalsy()
|
||||
expect(component.trackByFn(documents[1])).toEqual(12)
|
||||
})
|
||||
|
||||
it('should not include the current document or already selected documents in results', () => {
|
||||
let foundDocs
|
||||
component.foundDocuments$.subscribe((found) => (foundDocs = found))
|
||||
component.parentDocumentID = 23
|
||||
component.selectedDocuments = [documents[2]]
|
||||
const listSpy = jest.spyOn(documentService, 'listFiltered')
|
||||
listSpy.mockImplementation(
|
||||
(page, pageSize, sortField, sortReverse, filterRules, extraParams) => {
|
||||
const docs = documents.filter((d) =>
|
||||
d.title.includes(filterRules[0].value)
|
||||
)
|
||||
return of({
|
||||
count: docs.length,
|
||||
results: docs,
|
||||
all: docs.map((d) => d.id),
|
||||
})
|
||||
}
|
||||
)
|
||||
component.documentsInput$.next('bar')
|
||||
expect(foundDocs).toEqual([documents[1]])
|
||||
})
|
||||
})
|
||||
|
@ -43,6 +43,9 @@ export class DocumentLinkComponent
|
||||
@Input()
|
||||
notFoundText: string = $localize`No documents found`
|
||||
|
||||
@Input()
|
||||
parentDocumentID: number
|
||||
|
||||
constructor(private documentsService: DocumentService) {
|
||||
super()
|
||||
}
|
||||
@ -86,7 +89,13 @@ export class DocumentLinkComponent
|
||||
{ truncate_content: true }
|
||||
)
|
||||
.pipe(
|
||||
map((results) => results.results),
|
||||
map((results) =>
|
||||
results.results.filter(
|
||||
(d) =>
|
||||
d.id !== this.parentDocumentID &&
|
||||
!this.selectedDocuments.find((sd) => sd.id === d.id)
|
||||
)
|
||||
),
|
||||
catchError(() => of([])), // empty on error
|
||||
tap(() => (this.loading = false))
|
||||
)
|
||||
|
@ -124,7 +124,7 @@
|
||||
<pngx-input-number *ngSwitchCase="PaperlessCustomFieldDataType.Monetary" formControlName="value" [title]="getCustomFieldFromInstance(fieldInstance)?.name" [removable]="true" (removed)="removeField(fieldInstance)" [horizontal]="true" [showAdd]="false" [step]=".01" [error]="getCustomFieldError(i)"></pngx-input-number>
|
||||
<pngx-input-check *ngSwitchCase="PaperlessCustomFieldDataType.Boolean" formControlName="value" [title]="getCustomFieldFromInstance(fieldInstance)?.name" [removable]="true" (removed)="removeField(fieldInstance)" [horizontal]="true"></pngx-input-check>
|
||||
<pngx-input-url *ngSwitchCase="PaperlessCustomFieldDataType.Url" formControlName="value" [title]="getCustomFieldFromInstance(fieldInstance)?.name" [removable]="true" (removed)="removeField(fieldInstance)" [horizontal]="true" [error]="getCustomFieldError(i)"></pngx-input-url>
|
||||
<pngx-input-document-link *ngSwitchCase="PaperlessCustomFieldDataType.DocumentLink" formControlName="value" [title]="getCustomFieldFromInstance(fieldInstance)?.name" [removable]="true" (removed)="removeField(fieldInstance)" [horizontal]="true" [error]="getCustomFieldError(i)"></pngx-input-document-link>
|
||||
<pngx-input-document-link *ngSwitchCase="PaperlessCustomFieldDataType.DocumentLink" formControlName="value" [title]="getCustomFieldFromInstance(fieldInstance)?.name" [parentDocumentID]="documentId" [removable]="true" (removed)="removeField(fieldInstance)" [horizontal]="true" [error]="getCustomFieldError(i)"></pngx-input-document-link>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user