ACS-8572: Support for reloading document list from outside (#10065)

* support for external document list reload

* update docs [ci:force]

* reset selection api and docs [ci:force]
This commit is contained in:
Denys Vuika
2024-08-09 07:33:56 -04:00
committed by GitHub
parent 80a70cf789
commit 9966cf4405
5 changed files with 122 additions and 25 deletions

View File

@@ -126,6 +126,44 @@ describe('DocumentList', () => {
fixture.destroy();
});
it('should reset selection and reload on documentListService reload$', () => {
spyOn(documentList, 'resetSelection').and.callThrough();
spyOn(documentList, 'reload').and.callThrough();
documentListService.reload();
expect(documentList.resetSelection).toHaveBeenCalled();
expect(documentList.reload).toHaveBeenCalled();
});
it('should not reset selection or reload after component is destroyed', () => {
spyOn(documentList, 'resetSelection').and.callThrough();
spyOn(documentList, 'reload').and.callThrough();
documentList.ngOnDestroy();
documentListService.reload();
expect(documentList.resetSelection).not.toHaveBeenCalled();
expect(documentList.reload).not.toHaveBeenCalled();
});
it('should reset selection when resetSelection$ is emitted', () => {
spyOn(documentList, 'resetSelection').and.callThrough();
documentListService.resetSelection();
expect(documentList.resetSelection).toHaveBeenCalled();
});
it('should not reset selection after component is destroyed', () => {
spyOn(documentList, 'resetSelection').and.callThrough();
documentList.ngOnDestroy();
documentListService.resetSelection();
expect(documentList.resetSelection).not.toHaveBeenCalled();
});
describe('presets', () => {
const validatePreset = (keys: string[]) => {
const columns = documentList.data.getColumns();

View File

@@ -517,6 +517,15 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
if (this.columnsPresetKey) {
this.setPresetKey(this.columnsPresetKey);
}
this.documentListService.reload$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.resetSelection();
this.reload();
});
this.documentListService.resetSelection$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.resetSelection();
});
}
ngAfterContentInit() {

View File

@@ -74,6 +74,20 @@ describe('DocumentListService', () => {
jasmine.Ajax.install();
});
it('should emit resetSelection$ when resetSelection is called', (done) => {
service.resetSelection$.subscribe(() => {
done();
});
service.resetSelection();
});
it('should emit reload$ when reload is called', (done) => {
service.reload$.subscribe(() => {
done();
});
service.reload();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});

View File

@@ -17,10 +17,10 @@
import { AlfrescoApiService, PaginationModel } from '@alfresco/adf-core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { Node, NodeEntry, NodePaging, NodesApi } from '@alfresco/js-api';
import { DocumentLoaderNode } from '../models/document-folder.model';
import { Observable, from, forkJoin } from 'rxjs';
import { Observable, from, forkJoin, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { DocumentListLoader } from '../interfaces/document-list-loader.interface';
import { CustomResourcesService } from './custom-resources.service';
@@ -31,17 +31,34 @@ const ROOT_ID = '-root-';
providedIn: 'root'
})
export class DocumentListService implements DocumentListLoader {
private nodesApiService = inject(NodesApiService);
private apiService = inject(AlfrescoApiService);
private customResourcesService = inject(CustomResourcesService);
private _nodesApi: NodesApi;
get nodes(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi;
}
constructor(
private nodesApiService: NodesApiService,
private apiService: AlfrescoApiService,
private customResourcesService: CustomResourcesService
) {}
private _reload = new Subject<void>();
private _resetSelection = new Subject<void>();
/** Gets an observable that emits when the document list should be reloaded. */
reload$ = this._reload.asObservable();
/** Gets an observable that emits when the selection should be reset. */
resetSelection$ = this._resetSelection.asObservable();
/** Reloads the document list. */
reload() {
this._reload.next();
}
/** Resets the selection. */
resetSelection() {
this._resetSelection.next();
}
/**
* Deletes a node.