From deba28c8e0379b6e7910c7272308cb1d1837ef8a Mon Sep 17 00:00:00 2001 From: Mykyta Maliarchuk <84377976+nikita-web-ua@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:44:24 +0200 Subject: [PATCH] [ACS-5563] Fixed incorrect initial loading of security marks (#3405) * [ACS-5563] fixed incorrect initial loading of security marks * [ACS-5563] added DoneFn --- .../components/files/files.component.spec.ts | 25 ++++++++++++++-- .../lib/components/files/files.component.ts | 5 +++- .../services/app.extension.service.spec.ts | 29 ++++++++++++------- .../src/lib/services/app.extension.service.ts | 6 ++-- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/projects/aca-content/src/lib/components/files/files.component.spec.ts b/projects/aca-content/src/lib/components/files/files.component.spec.ts index dd7e6bfb33..c321956cae 100644 --- a/projects/aca-content/src/lib/components/files/files.component.spec.ts +++ b/projects/aca-content/src/lib/components/files/files.component.spec.ts @@ -29,7 +29,7 @@ import { DocumentListService, FilterSearch, PathElementEntity, UploadService } f import { NodeActionsService } from '../../services/node-actions.service'; import { FilesComponent } from './files.component'; import { AppTestingModule } from '../../testing/app-testing.module'; -import { ContentApiService } from '@alfresco/aca-shared'; +import { AppExtensionService, ContentApiService } from '@alfresco/aca-shared'; import { of, Subject, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; import { NodeEntry, NodePaging, Node } from '@alfresco/js-api'; @@ -39,6 +39,7 @@ describe('FilesComponent', () => { let fixture: ComponentFixture; let component: FilesComponent; let uploadService: UploadService; + let extensions: AppExtensionService; let nodeActionsService: NodeActionsService; let contentApi: ContentApiService; let route: ActivatedRoute; @@ -77,7 +78,8 @@ describe('FilesComponent', () => { params: of({ folderId: 'someId' }), queryParamMap: of({}) } - } + }, + AppExtensionService ], schemas: [NO_ERRORS_SCHEMA] }); @@ -96,6 +98,7 @@ describe('FilesComponent', () => { route = TestBed.inject(ActivatedRoute); nodeActionsService = TestBed.inject(NodeActionsService); contentApi = TestBed.inject(ContentApiService); + extensions = TestBed.inject(AppExtensionService); spyContent = spyOn(contentApi, 'getNode'); }); @@ -148,6 +151,24 @@ describe('FilesComponent', () => { expect(component.node).toBe(node); }); + it('should set columns', () => { + const filesDocumentListPresetMock = [ + { + id: 'app.files.modifiedOn', + key: 'modifiedAt', + type: 'date', + sortable: true, + desktopOnly: true, + template: 'template', + sortingKey: 'sorting-key' + } + ]; + + extensions.filesDocumentListPreset$ = of(filesDocumentListPresetMock); + fixture.detectChanges(); + expect(component.columns).toEqual(filesDocumentListPresetMock); + }); + it('should navigate to parent if node is not a folder', () => { const nodeEntry = { isFolder: false, parentId: 'parent-id' }; spyContent.and.returnValue(of({ entry: nodeEntry } as any)); diff --git a/projects/aca-content/src/lib/components/files/files.component.ts b/projects/aca-content/src/lib/components/files/files.component.ts index 112dc64b1f..a5043f6e97 100644 --- a/projects/aca-content/src/lib/components/files/files.component.ts +++ b/projects/aca-content/src/lib/components/files/files.component.ts @@ -127,7 +127,10 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { this.isAdmin = value; }); - this.columns = this.extensions.documentListPresets.files || []; + this.extensions.filesDocumentListPreset$.pipe(takeUntil(this.onDestroy$)).subscribe((preset) => { + this.columns = preset; + }); + if (this.queryParams && Object.keys(this.queryParams).length > 0) { this.isFilterHeaderActive = true; } diff --git a/projects/aca-shared/src/lib/services/app.extension.service.spec.ts b/projects/aca-shared/src/lib/services/app.extension.service.spec.ts index a562b37936..e934155d32 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.spec.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.spec.ts @@ -174,7 +174,7 @@ describe('AppExtensionService', () => { }); }); - it('should support column orders', () => { + it('should support column orders', (done) => { applyConfig({ $id: 'test', $name: 'test', @@ -228,19 +228,23 @@ describe('AppExtensionService', () => { } }); - const { files, libraries } = service.documentListPresets; + const { libraries } = service.documentListPresets; + const files = service.filesDocumentListPreset$; - expect(files.length).toBe(3); - expect(files[0].id).toBe('app.files.thumbnail'); - expect(files[1].id).toBe('app.files.name'); - expect(files[2].id).toBe('app.files.securityMarks'); + files.subscribe((columns) => { + expect(columns.length).toBe(3); + expect(columns[0].id).toBe('app.files.thumbnail'); + expect(columns[1].id).toBe('app.files.name'); + expect(columns[2].id).toBe('app.files.securityMarks'); + done(); + }); expect(libraries.length).toBe(2); expect(libraries[0].id).toBe('app.libraries.name'); expect(libraries[1].id).toBe('app.libraries.thumbnail'); }); - it('should ignore column if visibility in rules is false', () => { + it('should ignore column if visibility in rules is false', (done) => { applyConfig({ $id: 'test', $name: 'test', @@ -279,11 +283,14 @@ describe('AppExtensionService', () => { } }); - const { files } = service.documentListPresets; + const files = service.filesDocumentListPreset$; - expect(files.length).toBe(2); - expect(files[0].id).toBe('app.files.thumbnail'); - expect(files[1].id).toBe('app.files.name'); + files.subscribe((columns) => { + expect(columns.length).toBe(2); + expect(columns[0].id).toBe('app.files.thumbnail'); + expect(columns[1].id).toBe('app.files.name'); + done(); + }); }); }); diff --git a/projects/aca-shared/src/lib/services/app.extension.service.ts b/projects/aca-shared/src/lib/services/app.extension.service.ts index d28abdee0e..bb32e031ab 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.ts @@ -80,9 +80,9 @@ export class AppExtensionService implements RuleContext { private _createActions = new BehaviorSubject>([]); private _mainActions = new BehaviorSubject(null); private _sidebarActions = new BehaviorSubject>([]); + private _filesDocumentListPreset = new BehaviorSubject>([]); documentListPresets: { - files: Array; libraries: Array; favoriteLibraries: Array; shared: Array; @@ -91,7 +91,6 @@ export class AppExtensionService implements RuleContext { trashcan: Array; searchLibraries: Array; } = { - files: [], libraries: [], favoriteLibraries: [], shared: [], @@ -108,6 +107,7 @@ export class AppExtensionService implements RuleContext { withCredentials: boolean; references$: Observable; + filesDocumentListPreset$: Observable = this._filesDocumentListPreset.asObservable(); config: ExtensionConfig; @@ -158,6 +158,7 @@ export class AppExtensionService implements RuleContext { this._openWithActions.next(this.loader.getContentActions(config, 'features.viewer.openWith')); this._createActions.next(this.loader.getElements(config, 'features.create')); this._mainActions.next(this.loader.getFeatures(config).mainAction); + this._filesDocumentListPreset.next(this.getDocumentListPreset(config, 'files')); this.navbar = this.loadNavBar(config); this.sidebarTabs = this.loader.getElements(config, 'features.sidebar.tabs'); @@ -165,7 +166,6 @@ export class AppExtensionService implements RuleContext { this.search = this.loadSearchForms(config); this.documentListPresets = { - files: this.getDocumentListPreset(config, 'files'), libraries: this.getDocumentListPreset(config, 'libraries'), favoriteLibraries: this.getDocumentListPreset(config, 'favoriteLibraries'), shared: this.getDocumentListPreset(config, 'shared'),