mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix: including ordering param for id__in retrievals from frontend (#6875)
This commit is contained in:
parent
085447e7c4
commit
d2883b83c5
@ -18,7 +18,7 @@ const document: Document = {
|
||||
custom_fields: [
|
||||
{ field: 1, document: 1, created: null, value: 'Text value' },
|
||||
{ field: 2, document: 1, created: null, value: 'USD100' },
|
||||
{ field: 3, document: 1, created: null, value: '1,2,3' },
|
||||
{ field: 3, document: 1, created: null, value: [1, 2, 3] },
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,9 @@ export class CustomFieldDisplayComponent implements OnInit, OnDestroy {
|
||||
.getFew(this.value, { fields: 'id,title' })
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe((result: Results<Document>) => {
|
||||
this.docLinkDocuments = result.results
|
||||
this.docLinkDocuments = this.value.map((id) =>
|
||||
result.results.find((d) => d.id === id)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,20 @@ describe('DocumentLinkComponent', () => {
|
||||
expect(getSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shoud maintain ordering of selected documents', () => {
|
||||
const getSpy = jest.spyOn(documentService, 'getFew')
|
||||
getSpy.mockImplementation((ids) => {
|
||||
const docs = documents.filter((d) => ids.includes(d.id))
|
||||
return of({
|
||||
count: docs.length,
|
||||
all: docs.map((d) => d.id),
|
||||
results: docs,
|
||||
})
|
||||
})
|
||||
component.writeValue([12, 1])
|
||||
expect(component.selectedDocuments).toEqual([documents[1], documents[0]])
|
||||
})
|
||||
|
||||
it('should search API on select text input', () => {
|
||||
const listSpy = jest.spyOn(documentService, 'listFiltered')
|
||||
listSpy.mockImplementation(
|
||||
|
@ -65,7 +65,9 @@ export class DocumentLinkComponent
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe((documentResults) => {
|
||||
this.loading = false
|
||||
this.selectedDocuments = documentResults.results
|
||||
this.selectedDocuments = documentIDs.map((id) =>
|
||||
documentResults.results.find((d) => d.id === id)
|
||||
)
|
||||
super.writeValue(documentIDs)
|
||||
})
|
||||
}
|
||||
|
@ -100,13 +100,13 @@ export const commonAbstractPaperlessServiceTests = (endpoint, ServiceClass) => {
|
||||
test('should call appropriate api endpoint for get a few objects', () => {
|
||||
subscription = service.getFew([1, 2, 3]).subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/?id__in=1,2,3`
|
||||
`${environment.apiBaseUrl}${endpoint}/?id__in=1,2,3&ordering=-id`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
req.flush([])
|
||||
subscription = service.getFew([4, 5, 6], { foo: 'bar' }).subscribe()
|
||||
const req2 = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/?id__in=4,5,6&foo=bar`
|
||||
`${environment.apiBaseUrl}${endpoint}/?id__in=4,5,6&ordering=-id&foo=bar`
|
||||
)
|
||||
expect(req2.request.method).toEqual('GET')
|
||||
req2.flush([])
|
||||
|
@ -94,6 +94,7 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
getFew(ids: number[], extraParams?): Observable<Results<T>> {
|
||||
let httpParams = new HttpParams()
|
||||
httpParams = httpParams.set('id__in', ids.join(','))
|
||||
httpParams = httpParams.set('ordering', '-id')
|
||||
for (let extraParamKey in extraParams) {
|
||||
if (extraParams[extraParamKey] != null) {
|
||||
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
|
||||
|
Loading…
x
Reference in New Issue
Block a user