mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
Optmise injections and imports (#3174)
* cleanup base page injections * optimise breakpoint observer * cleanup subscriptions * optimise upload service injections * optimise router imports * fix test setup * fix tests
This commit is contained in:
@@ -22,10 +22,10 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { DocumentListComponent, ShareDataRow } from '@alfresco/adf-content-services';
|
||||
import { DocumentListComponent, ShareDataRow, UploadService } from '@alfresco/adf-content-services';
|
||||
import { ShowHeaderMode } from '@alfresco/adf-core';
|
||||
import { ContentActionRef, DocumentListPresetRef, SelectionState } from '@alfresco/adf-extensions';
|
||||
import { OnDestroy, OnInit, OnChanges, ViewChild, SimpleChanges, Directive } from '@angular/core';
|
||||
import { OnDestroy, OnInit, OnChanges, ViewChild, SimpleChanges, Directive, inject } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from '@alfresco/js-api';
|
||||
import { Observable, Subject, Subscription } from 'rxjs';
|
||||
@@ -46,6 +46,8 @@ import {
|
||||
import { AppExtensionService } from '../../services/app.extension.service';
|
||||
import { isLibrary, isLocked } from '../../utils/node.utils';
|
||||
import { AcaFileAutoDownloadService } from '../../services/aca-file-auto-download.service';
|
||||
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
/* eslint-disable @angular-eslint/directive-class-suffix */
|
||||
@Directive()
|
||||
@@ -69,16 +71,18 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
|
||||
showHeader = ShowHeaderMode.Data;
|
||||
filterSorting = 'name-asc';
|
||||
createActions: Array<ContentActionRef> = [];
|
||||
isSmallScreen = false;
|
||||
|
||||
protected extensions = inject(AppExtensionService);
|
||||
protected content = inject(DocumentBasePageService);
|
||||
protected store = inject<Store<AppStore>>(Store<AppStore>);
|
||||
protected breakpointObserver = inject(BreakpointObserver);
|
||||
protected uploadService = inject(UploadService);
|
||||
protected router = inject(Router);
|
||||
private fileAutoDownloadService = inject(AcaFileAutoDownloadService, { optional: true });
|
||||
|
||||
protected subscriptions: Subscription[] = [];
|
||||
|
||||
protected constructor(
|
||||
protected store: Store<AppStore>,
|
||||
protected extensions: AppExtensionService,
|
||||
protected content: DocumentBasePageService,
|
||||
private fileAutoDownloadService: AcaFileAutoDownloadService = null
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.extensions
|
||||
.getCreateActions()
|
||||
@@ -120,6 +124,13 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
|
||||
.subscribe((node) => {
|
||||
this.canUpload = node && this.content.canUploadContent(node);
|
||||
});
|
||||
|
||||
this.breakpointObserver
|
||||
.observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape])
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe((result) => {
|
||||
this.isSmallScreen = result.matches;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
|
@@ -24,20 +24,20 @@
|
||||
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { PageComponent } from './document-base-page.component';
|
||||
import { ReloadDocumentListAction, SetSelectedNodesAction, AppState, AppStore, ViewNodeAction } from '@alfresco/aca-shared/store';
|
||||
import { ReloadDocumentListAction, SetSelectedNodesAction, AppState, ViewNodeAction } from '@alfresco/aca-shared/store';
|
||||
import { AppExtensionService } from '@alfresco/aca-shared';
|
||||
import { MinimalNodeEntity, Node, NodePaging } from '@alfresco/js-api';
|
||||
import { MinimalNodeEntity, NodePaging, RepositoryInfo } from '@alfresco/js-api';
|
||||
import { DocumentBasePageService } from './document-base-page.service';
|
||||
import { Store, StoreModule } from '@ngrx/store';
|
||||
import { Component, Injectable } from '@angular/core';
|
||||
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||
import { DiscoveryApiService, DocumentListComponent } from '@alfresco/adf-content-services';
|
||||
import { MockStore, provideMockStore } from '@ngrx/store/testing';
|
||||
import { MaterialModule, PipeModule } from '@alfresco/adf-core';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { BehaviorSubject, Observable, Subscription, of } from 'rxjs';
|
||||
|
||||
export const INITIAL_APP_STATE: AppState = {
|
||||
appName: 'Alfresco Content Application',
|
||||
@@ -77,10 +77,10 @@ export const INITIAL_APP_STATE: AppState = {
|
||||
|
||||
@Injectable()
|
||||
class DocumentBasePageServiceMock extends DocumentBasePageService {
|
||||
canUpdateNode(_node: MinimalNodeEntity): boolean {
|
||||
canUpdateNode(): boolean {
|
||||
return true;
|
||||
}
|
||||
canUploadContent(_node: Node): boolean {
|
||||
canUploadContent(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -92,8 +92,8 @@ class DocumentBasePageServiceMock extends DocumentBasePageService {
|
||||
class TestComponent extends PageComponent {
|
||||
node: any;
|
||||
|
||||
constructor(store: Store<AppStore>, extensions: AppExtensionService, content: DocumentBasePageService) {
|
||||
super(store, extensions, content);
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
addSubscription(entry: Subscription) {
|
||||
@@ -138,6 +138,13 @@ describe('PageComponent', () => {
|
||||
provide: DocumentBasePageService,
|
||||
useClass: DocumentBasePageServiceMock
|
||||
},
|
||||
{
|
||||
provide: DiscoveryApiService,
|
||||
useValue: {
|
||||
ecmProductInfo$: new BehaviorSubject<RepositoryInfo | null>(null),
|
||||
getEcmProductInfo: (): Observable<RepositoryInfo> => of(new RepositoryInfo({ version: '10.0.0' }))
|
||||
}
|
||||
},
|
||||
AppExtensionService
|
||||
]
|
||||
});
|
||||
@@ -283,11 +290,18 @@ describe('Info Drawer state', () => {
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NoopAnimationsModule, HttpClientModule, RouterTestingModule],
|
||||
imports: [NoopAnimationsModule, HttpClientModule, RouterTestingModule, MaterialModule],
|
||||
declarations: [TestComponent],
|
||||
providers: [
|
||||
{ provide: DocumentBasePageService, useClass: DocumentBasePageServiceMock },
|
||||
AppExtensionService,
|
||||
{
|
||||
provide: DiscoveryApiService,
|
||||
useValue: {
|
||||
ecmProductInfo$: new BehaviorSubject<RepositoryInfo | null>(null),
|
||||
getEcmProductInfo: (): Observable<RepositoryInfo> => of(new RepositoryInfo({ version: '10.0.0' }))
|
||||
}
|
||||
},
|
||||
provideMockStore({
|
||||
initialState: { app: appState }
|
||||
})
|
||||
|
Reference in New Issue
Block a user