Various code fixes (#1704)

* fix typings and missing lib

* fix i18n typo, add typings

* code improvements

* fix missing awaits

* more fixes

* fix bug in the evaluators, simplify code

* more fixes
This commit is contained in:
Denys Vuika
2020-10-04 18:09:27 +01:00
committed by GitHub
parent bf11489e0f
commit 9c7ac17161
46 changed files with 133 additions and 142 deletions

View File

@@ -36,6 +36,7 @@ import { SetCurrentFolderAction, isAdmin, AppStore, UploadFileVersionAction } fr
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { FilterSearch, ShareDataRow } from '@alfresco/adf-content-services';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
@Component({
templateUrl: './files.component.html'
@@ -49,7 +50,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
private nodePath: PathElement[];
columns: any[] = [];
columns: DocumentListPresetRef[] = [];
constructor(
private router: Router,

View File

@@ -28,6 +28,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { NodePermissionService } from '@alfresco/aca-shared';
import { Node } from '@alfresco/js-api';
describe('CommentsTabComponent', () => {
let component: CommentsTabComponent;
@@ -66,44 +67,40 @@ describe('CommentsTabComponent', () => {
});
it('should return [false] if node selected is neither file or folder', () => {
const testNode: any = {
component.node = {
id: 'test-node-id',
isFile: false,
isFolder: false
};
component.node = testNode;
} as Node;
expect(component.canUpdateNode).toBe(false);
});
it('should return [false] if node selected is a locked file', () => {
const testNode: any = {
component.node = {
id: 'test-node-id',
isFile: true,
isFolder: false,
isLocked: true
};
component.node = testNode;
} as Node;
expect(component.canUpdateNode).toBe(false);
});
it('should check [update] permission if node selected is a not locked file', () => {
const testNode: any = {
component.node = {
id: 'test-node-id',
isFile: true,
isFolder: false
};
component.node = testNode;
} as Node;
expect(component.canUpdateNode).toBe(true);
expect(checked).toContain('update');
});
it('should check [update] permission if node selected is a folder', () => {
const testNode: any = {
component.node = {
id: 'test-node-id',
isFile: false,
isFolder: true
};
component.node = testNode;
} as Node;
expect(component.canUpdateNode).toBe(true);
expect(checked).toContain('update');
});

View File

@@ -70,7 +70,7 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
protected subscriptions: Subscription[] = [];
constructor(protected store: Store<AppStore>, protected extensions: AppExtensionService, protected content: ContentManagementService) {}
protected constructor(protected store: Store<AppStore>, protected extensions: AppExtensionService, protected content: ContentManagementService) {}
ngOnInit() {
this.sharedPreviewUrl$ = this.store.select(getSharedUrl);

View File

@@ -177,10 +177,10 @@ export class PreviewComponent extends PageComponent implements OnInit, OnDestroy
this.nodeId = this.node.id;
return;
}
this.router.navigate([this.previewLocation, id]);
await this.router.navigate([this.previewLocation, id]);
} catch (err) {
if (!err || err.status !== 401) {
this.router.navigate([this.previewLocation, id]);
await this.router.navigate([this.previewLocation, id]);
}
}
}

View File

@@ -31,7 +31,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { forkJoin, from, of } from 'rxjs';
import { catchError, flatMap } from 'rxjs/operators';
import { catchError, mergeMap } from 'rxjs/operators';
import { AppExtensionService } from '@alfresco/aca-shared';
@Component({
@@ -55,8 +55,10 @@ export class SharedLinkViewComponent implements OnInit {
ngOnInit() {
this.route.params
.pipe(
flatMap((params) =>
forkJoin(from(this.alfrescoApiService.sharedLinksApi.getSharedLink(params.id)), of(params.id)).pipe(catchError(() => of([null, params.id])))
mergeMap((params) =>
forkJoin([from(this.alfrescoApiService.sharedLinksApi.getSharedLink(params.id)), of(params.id)]).pipe(
catchError(() => of([null, params.id]))
)
)
)
.subscribe(([sharedEntry, sharedId]: [SharedLinkEntry, string]) => {

View File

@@ -56,7 +56,10 @@ describe('ButtonMenuComponent', () => {
it('should render action item', () => {
component.item = {
id: 'test-action-button',
url: 'dummy'
url: 'dummy',
icon: null,
title: null,
route: null
};
fixture.detectChanges();
@@ -68,16 +71,23 @@ describe('ButtonMenuComponent', () => {
it('should render action item with children', () => {
component.item = {
id: 'test-action-button',
icon: null,
title: null,
route: null,
children: [
{
id: 'child-1',
title: 'child-1',
url: 'dummy'
url: 'dummy',
icon: null,
route: null
},
{
id: 'child-2',
title: 'child-2',
url: 'dummy'
url: 'dummy',
icon: null,
route: null
}
]
};

View File

@@ -25,6 +25,7 @@
import { Component, Input, ViewEncapsulation, OnInit, ChangeDetectorRef } from '@angular/core';
import { OverlayContainer } from '@angular/cdk/overlay';
import { NavBarLinkRef } from '@alfresco/adf-extensions';
@Component({
selector: 'app-button-menu',
@@ -33,7 +34,8 @@ import { OverlayContainer } from '@angular/cdk/overlay';
encapsulation: ViewEncapsulation.None
})
export class ButtonMenuComponent implements OnInit {
@Input() item;
@Input()
item: NavBarLinkRef;
constructor(private cd: ChangeDetectorRef, private overlayContainer: OverlayContainer) {
this.overlayContainer.getContainerElement().classList.add('aca-menu-panel');

View File

@@ -52,7 +52,7 @@ import { SharedLinkEntry } from '@alfresco/js-api';
host: { class: 'app-view-node' }
})
export class ViewNodeComponent {
@Input() data: any;
@Input() data: { title?: string; menuButton?: boolean; iconButton?: boolean };
constructor(private store: Store<AppStore>, private router: Router) {}

View File

@@ -102,7 +102,7 @@ describe('ContentManagementService', () => {
store.dispatch(new CopyNodesAction(selection));
nodeActions.contentCopied.next(createdItems);
subject.next('OPERATION.SUCCES.CONTENT.COPY');
subject.next('OPERATION.SUCCESS.CONTENT.COPY');
expect(nodeActions.copyNodes).toHaveBeenCalled();
expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.SINGULAR');
@@ -116,7 +116,7 @@ describe('ContentManagementService', () => {
store.dispatch(new CopyNodesAction(selection));
nodeActions.contentCopied.next(createdItems);
subject.next('OPERATION.SUCCES.CONTENT.COPY');
subject.next('OPERATION.SUCCESS.CONTENT.COPY');
expect(nodeActions.copyNodes).toHaveBeenCalled();
expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PLURAL');
@@ -130,7 +130,7 @@ describe('ContentManagementService', () => {
store.dispatch(new CopyNodesAction(selection));
nodeActions.contentCopied.next(createdItems);
subject.next('OPERATION.SUCCES.CONTENT.COPY');
subject.next('OPERATION.SUCCESS.CONTENT.COPY');
expect(nodeActions.copyNodes).toHaveBeenCalled();
expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PARTIAL_SINGULAR');
@@ -148,7 +148,7 @@ describe('ContentManagementService', () => {
store.dispatch(new CopyNodesAction(selection));
nodeActions.contentCopied.next(createdItems);
subject.next('OPERATION.SUCCES.CONTENT.COPY');
subject.next('OPERATION.SUCCESS.CONTENT.COPY');
expect(nodeActions.copyNodes).toHaveBeenCalled();
expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PARTIAL_PLURAL');
@@ -166,7 +166,7 @@ describe('ContentManagementService', () => {
store.dispatch(new CopyNodesAction(selection));
nodeActions.contentCopied.next(createdItems);
subject.next('OPERATION.SUCCES.CONTENT.COPY');
subject.next('OPERATION.SUCCESS.CONTENT.COPY');
expect(nodeActions.copyNodes).toHaveBeenCalled();
expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.FAIL_PLURAL');
@@ -180,7 +180,7 @@ describe('ContentManagementService', () => {
store.dispatch(new CopyNodesAction(selection));
nodeActions.contentCopied.next(createdItems);
subject.next('OPERATION.SUCCES.CONTENT.COPY');
subject.next('OPERATION.SUCCESS.CONTENT.COPY');
expect(nodeActions.copyNodes).toHaveBeenCalled();
expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.FAIL_SINGULAR');
@@ -242,7 +242,7 @@ describe('ContentManagementService', () => {
const createdItems: any[] = [{ entry: { id: 'copy-id', name: 'name' } }];
store.dispatch(new CopyNodesAction(selection));
nodeActions.copyNodes(null).next('OPERATION.SUCCES.CONTENT.COPY');
nodeActions.copyNodes(null).next('OPERATION.SUCCESS.CONTENT.COPY');
nodeActions.contentCopied.next(createdItems);
expect(nodeActions.copyNodes).toHaveBeenCalled();
@@ -279,7 +279,7 @@ describe('ContentManagementService', () => {
];
store.dispatch(new CopyNodesAction(selection));
nodeActions.copyNodes(null).next('OPERATION.SUCCES.CONTENT.COPY');
nodeActions.copyNodes(null).next('OPERATION.SUCCESS.CONTENT.COPY');
nodeActions.contentCopied.next(createdItems);
expect(nodeActions.copyNodes).toHaveBeenCalled();
@@ -299,7 +299,7 @@ describe('ContentManagementService', () => {
const createdItems: any[] = [{ entry: { id: 'copy-id', name: 'name' } }];
store.dispatch(new CopyNodesAction(selection));
nodeActions.copyNodes(null).next('OPERATION.SUCCES.CONTENT.COPY');
nodeActions.copyNodes(null).next('OPERATION.SUCCESS.CONTENT.COPY');
nodeActions.contentCopied.next(createdItems);
expect(nodeActions.copyNodes).toHaveBeenCalled();
@@ -314,7 +314,7 @@ describe('ContentManagementService', () => {
const createdItems: any[] = [{ entry: { id: 'copy-id', name: 'name' } }];
store.dispatch(new CopyNodesAction(selection));
nodeActions.copyNodes(null).next('OPERATION.SUCCES.CONTENT.COPY');
nodeActions.copyNodes(null).next('OPERATION.SUCCESS.CONTENT.COPY');
nodeActions.contentCopied.next(createdItems);
expect(nodeActions.copyNodes).toHaveBeenCalled();
@@ -329,7 +329,7 @@ describe('ContentManagementService', () => {
const createdItems: any[] = [{ entry: { id: 'copy-id', name: 'name' } }];
store.dispatch(new CopyNodesAction(selection));
nodeActions.copyNodes(null).next('OPERATION.SUCCES.CONTENT.COPY');
nodeActions.copyNodes(null).next('OPERATION.SUCCESS.CONTENT.COPY');
nodeActions.contentCopied.next(createdItems);
expect(nodeActions.copyNodes).toHaveBeenCalled();
@@ -375,7 +375,7 @@ describe('ContentManagementService', () => {
const selection: any = node;
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -396,7 +396,7 @@ describe('ContentManagementService', () => {
const selection: any = nodes;
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -414,10 +414,8 @@ describe('ContentManagementService', () => {
spyOn(nodeActions, 'moveNodes').and.returnValue(subject);
spyOn(nodeActions, 'processResponse').and.returnValue(moveResponse);
const selection = nodes;
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
store.dispatch(new MoveNodesAction(nodes));
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -435,10 +433,8 @@ describe('ContentManagementService', () => {
spyOn(nodeActions, 'moveNodes').and.returnValue(subject);
spyOn(nodeActions, 'processResponse').and.returnValue(moveResponse);
const selection = nodes;
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
store.dispatch(new MoveNodesAction(nodes));
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -457,7 +453,7 @@ describe('ContentManagementService', () => {
spyOn(nodeActions, 'processResponse').and.returnValue(moveResponse);
store.dispatch(new MoveNodesAction(nodes));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -476,7 +472,7 @@ describe('ContentManagementService', () => {
spyOn(nodeActions, 'processResponse').and.returnValue(moveResponse);
store.dispatch(new MoveNodesAction(nodes));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -546,7 +542,7 @@ describe('ContentManagementService', () => {
spyOn(nodeActions, 'processResponse').and.returnValue(moveResponse);
store.dispatch(new MoveNodesAction(nodes));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(moveResponse);
expect(nodeActions.moveNodes).toHaveBeenCalled();
@@ -592,7 +588,7 @@ describe('ContentManagementService', () => {
spyOn(nodeActions, 'moveNodeAction').and.returnValue(of({}));
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
const movedItems = {
failed: [],
partiallySucceeded: [],
@@ -625,7 +621,7 @@ describe('ContentManagementService', () => {
};
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(movedItems);
expect(nodeActions.moveNodeAction).toHaveBeenCalledWith(node.entry, initialParent);
@@ -657,7 +653,7 @@ describe('ContentManagementService', () => {
};
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(movedItems);
expect(contentApi.restoreNode).toHaveBeenCalled();
@@ -699,7 +695,7 @@ describe('ContentManagementService', () => {
};
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(movedItems);
expect(contentApi.restoreNode).toHaveBeenCalled();
@@ -731,7 +727,7 @@ describe('ContentManagementService', () => {
};
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(movedItems);
expect(contentApi.restoreNode).toHaveBeenCalled();
@@ -763,7 +759,7 @@ describe('ContentManagementService', () => {
};
store.dispatch(new MoveNodesAction(selection));
nodeActions.moveNodes(null).next('OPERATION.SUCCES.CONTENT.MOVE');
nodeActions.moveNodes(null).next('OPERATION.SUCCESS.CONTENT.MOVE');
nodeActions.contentMoved.next(movedItems);
expect(nodeActions.moveNodes).toHaveBeenCalled();

View File

@@ -59,7 +59,7 @@ import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Store } from '@ngrx/store';
import { forkJoin, Observable, of, Subject, zip } from 'rxjs';
import { catchError, flatMap, map, mergeMap, take, tap } from 'rxjs/operators';
import { catchError, map, mergeMap, take, tap } from 'rxjs/operators';
import { NodePermissionsDialogComponent } from '../components/permissions/permission-dialog/node-permissions.dialog';
import { NodeVersionsDialogComponent } from '../dialogs/node-versions/node-versions.dialog';
import { NodeActionsService } from './node-actions.service';
@@ -1031,7 +1031,7 @@ export class ContentManagementService {
getNodeInfo(): Observable<MinimalNodeEntryEntity> {
return this.store.select(getAppSelection).pipe(
take(1),
flatMap(({ file }) => {
mergeMap(({ file }) => {
const id = (file as any).entry.nodeId || (file as any).entry.guid;
if (!id) {
return of(file.entry);

View File

@@ -356,7 +356,7 @@ describe('NodeActionsService', () => {
const spyOnDestinationPicker = spyOn(service, 'getContentNodeSelection').and.callThrough();
spyOn(service, 'getEntryParentId').and.returnValue('parent-id');
let dialogData: any;
let dialogData = null;
const spyOnDialog = spyOn(dialog, 'open').and.callFake((_contentNodeSelectorComponent: any, data: any) => {
dialogData = data;
return { componentInstance: {} } as MatDialogRef<any>;

View File

@@ -118,7 +118,7 @@ export class NodeActionsService {
}
action$.subscribe((newContent) => {
observable.next(`OPERATION.SUCCES.${type.toUpperCase()}.${action.toUpperCase()}`);
observable.next(`OPERATION.SUCCESS.${type.toUpperCase()}.${action.toUpperCase()}`);
const processedData = this.processResponse(newContent);
if (action === BatchOperationType.copy) {

View File

@@ -62,7 +62,7 @@ export class AppEffects {
})
);
private redirectToLogin() {
this.router.navigate(['login']);
private redirectToLogin(): Promise<boolean> {
return this.router.navigate(['login']);
}
}

View File

@@ -212,7 +212,7 @@ function updateSelectedNodes(state: AppState, action: SetSelectedNodesAction): A
if (nodes.length === 1) {
file = nodes.find((entity: any) => {
// workaround Shared
return entity.entry.isFile || entity.entry.nodeId || entity.entry.sharedByUser ? true : false;
return !!(entity.entry.isFile || entity.entry.nodeId || entity.entry.sharedByUser);
});
folder = nodes.find((entity: any) => entity.entry.isFolder);
}
@@ -266,7 +266,7 @@ function handleSettingsUpdate(state: AppState, action: SetSettingsParameterActio
const { payload } = action;
if (payload.name === 'languagePicker') {
newState.languagePicker = payload.value ? true : false;
newState.languagePicker = !!payload.value;
}
return newState;
}