[AAE-5145] Update node actions to use enum (#2149)

* [AAE-5145] Update node actions to use enum

* Made it so BatchOperationType only narrows NodeActionsEnum

* [link-adf:dev-thunter-AAE-5145]

* Rename to NodeAction

* update adf

* Update unit tests
This commit is contained in:
Thomas Hunter
2021-05-26 18:07:58 +02:00
committed by GitHub
parent 50b33f5c3a
commit b4197ea965
5 changed files with 47 additions and 49 deletions

36
package-lock.json generated
View File

@@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@alfresco/adf-cli": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@alfresco/adf-cli/-/adf-cli-4.4.0.tgz",
"integrity": "sha512-3+Ouiy0xtM2nltLY+BA+XrTEXhEygj3T88VWsua6wbAUNpSY4tFMqCYKGhccmYs0DhZE8U3NenrNJT5daYTmag==",
"version": "4.5.0-32658",
"resolved": "https://registry.npmjs.org/@alfresco/adf-cli/-/adf-cli-4.5.0-32658.tgz",
"integrity": "sha512-+HVlakCDW7JTDRlwaBBA6NehEnRwD2/evEwv/Ga75Esj+uz/AmHogifC7sAtCyAKuNnMFo+hnIoWEvpSzDq0xg==",
"dev": true,
"requires": {
"@alfresco/js-api": "4.4.0",
@@ -41,43 +41,43 @@
}
},
"@alfresco/adf-content-services": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@alfresco/adf-content-services/-/adf-content-services-4.4.0.tgz",
"integrity": "sha512-ChOC+E+I6EmAa9RuwpzxrJNlpFpcFLYrnhpomqMgVLyDo0J2GaImp3xdMAFjvAGS+ys4MirGYvxRE3vI04Q3kw==",
"version": "4.5.0-32653",
"resolved": "https://registry.npmjs.org/@alfresco/adf-content-services/-/adf-content-services-4.5.0-32653.tgz",
"integrity": "sha512-MVcDzQaJIHFlARgmcCaPc6Zp9xGuf4ZIwO1Y/h+xbJ4nY+GZb2A4PUC07kea5Pau1nWKOOg8se3t+Yzc/IPgIg==",
"requires": {
"tslib": "^2.0.0"
}
},
"@alfresco/adf-core": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@alfresco/adf-core/-/adf-core-4.4.0.tgz",
"integrity": "sha512-6E4mh+vH9o+c0K6tFhfaLZ1z8O+1YV7ctdZpzodWjU949g+uCRDsCalwAUHbD2/YmOTJTQTmODofibqOK7oGSw==",
"version": "4.5.0-32658",
"resolved": "https://registry.npmjs.org/@alfresco/adf-core/-/adf-core-4.5.0-32658.tgz",
"integrity": "sha512-BmEspa7/UAQhrGZNqgbhAjVKvDYhAuAtN2b6OObQW4SOXmR04pMTRpB7c+DxuV22Y/YKQtfRQ8Y+CP79B+b/DA==",
"requires": {
"cropperjs": "1.5.11",
"tslib": "^2.0.0"
}
},
"@alfresco/adf-extensions": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@alfresco/adf-extensions/-/adf-extensions-4.4.0.tgz",
"integrity": "sha512-p/uuGK5MGM9JcLKvT8QgcCDm0Qy83opOXubKp55KB7U5w7ynlwcNiuKmZksotUEX2U/kfmbSi8NPLN1HDV5Z7w==",
"version": "4.5.0-32653",
"resolved": "https://registry.npmjs.org/@alfresco/adf-extensions/-/adf-extensions-4.5.0-32653.tgz",
"integrity": "sha512-AiWXlsxv9XrpBDU1BqthFCIYhn03NCqADcULSGBcAymokUJUKDlby60Giv2/3Sq1ANpVrJCDo5s300ZkS5vhCw==",
"requires": {
"tslib": "^2.0.0"
}
},
"@alfresco/adf-testing": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@alfresco/adf-testing/-/adf-testing-4.4.0.tgz",
"integrity": "sha512-XWSNFgkK2Full0R+doEtioFvNlP93ZcWJLEwR+s6Yd29BtPpH18vTOFZa3faVzQGp2PKsEWmQw3A7XUgHL3vNg==",
"version": "4.5.0-32658",
"resolved": "https://registry.npmjs.org/@alfresco/adf-testing/-/adf-testing-4.5.0-32658.tgz",
"integrity": "sha512-yX8QnHg71zeWRjATHkD6j6ecgSMer9lNLb8Esf+QqLAa7CHdlzGOT0KI9+HOWKLgScwiBsVW6ney2u+rWj1vjQ==",
"dev": true,
"requires": {
"tslib": "^2.0.0"
}
},
"@alfresco/js-api": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-4.4.0.tgz",
"integrity": "sha512-TLBXPc01Hi23gOCkkQy2p9lcBZgcCsymOkRPG0exclDaQnpgWBPFn0e+ykm7WA51hHusgZC2sUoZv1Y95nq6MA==",
"version": "4.4.0-3508",
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-4.4.0-3508.tgz",
"integrity": "sha512-12PJiwWn6MetnKam7ASiulooBg0Eo1JpEVwRA4JR5fKKSFnKiyNY55CAEiZ9VNI1moH5GkG65T/OP8fXuDRJuw==",
"requires": {
"event-emitter": "^0.3.5",
"minimatch": "3.0.4",

View File

@@ -24,10 +24,10 @@
},
"private": true,
"dependencies": {
"@alfresco/adf-content-services": "4.4.0",
"@alfresco/adf-core": "4.4.0",
"@alfresco/adf-extensions": "4.4.0",
"@alfresco/js-api": "4.4.0",
"@alfresco/adf-content-services": "4.5.0-32653",
"@alfresco/adf-core": "4.5.0-32658",
"@alfresco/adf-extensions": "4.5.0-32653",
"@alfresco/js-api": "4.4.0-3508",
"@angular/animations": "10.0.4",
"@angular/cdk": "^10.0.2",
"@angular/common": "10.0.4",
@@ -56,8 +56,8 @@
"zone.js": "~0.10.2"
},
"devDependencies": {
"@alfresco/adf-cli": "4.4.0",
"@alfresco/adf-testing": "4.4.0",
"@alfresco/adf-cli": "4.5.0-32658",
"@alfresco/adf-testing": "4.5.0-32658",
"@angular-custom-builders/lite-serve": "^0.2.3",
"@angular-devkit/build-angular": "^0.1002.0",
"@angular-devkit/build-ng-packagr": "^0.1002.0",

View File

@@ -27,8 +27,8 @@ import { TestBed, async } from '@angular/core/testing';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { of, throwError, Subject, Observable } from 'rxjs';
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { DocumentListService } from '@alfresco/adf-content-services';
import { NodeActionsService, BatchOperationType } from './node-actions.service';
import { DocumentListService, NodeAction } from '@alfresco/adf-content-services';
import { NodeActionsService } from './node-actions.service';
import { MinimalNodeEntryEntity, NodeChildAssociationEntry, NodeEntry } from '@alfresco/js-api';
import { AppTestingModule } from '../testing/app-testing.module';
import { ContentApiService } from '@alfresco/aca-shared';
@@ -119,7 +119,7 @@ describe('NodeActionsService', () => {
it('should validate selection when allowableOperation has `create`', () => {
spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }];
service.getContentNodeSelection('', contentEntities as NodeEntry[]);
service.getContentNodeSelection(NodeAction.CHOOSE, contentEntities as NodeEntry[]);
const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template',
@@ -135,7 +135,7 @@ describe('NodeActionsService', () => {
it('should invalidate selection when allowableOperation does not have `create`', () => {
spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }];
service.getContentNodeSelection('', contentEntities as NodeEntry[]);
service.getContentNodeSelection(NodeAction.CHOOSE, contentEntities as NodeEntry[]);
const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template',
@@ -151,7 +151,7 @@ describe('NodeActionsService', () => {
it('should invalidate selection if isSite', () => {
spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }];
service.getContentNodeSelection('', contentEntities as NodeEntry[]);
service.getContentNodeSelection(NodeAction.CHOOSE, contentEntities as NodeEntry[]);
const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template',
@@ -168,7 +168,7 @@ describe('NodeActionsService', () => {
it('should validate selection if not a Site', () => {
spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }];
service.getContentNodeSelection('', contentEntities as NodeEntry[]);
service.getContentNodeSelection(NodeAction.CHOOSE, contentEntities as NodeEntry[]);
const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template',
@@ -336,7 +336,7 @@ describe('NodeActionsService', () => {
subject.next([destinationFolder.entry]);
expect(spyOnBatchOperation.calls.count()).toEqual(1);
expect(spyOnBatchOperation).toHaveBeenCalledWith(BatchOperationType.copy, [fileToCopy, folderToCopy], undefined);
expect(spyOnBatchOperation).toHaveBeenCalledWith(NodeAction.COPY, [fileToCopy, folderToCopy], undefined);
});
it('should use the custom data object with custom rowFilter & imageResolver & title with destination picker', () => {
@@ -352,7 +352,7 @@ describe('NodeActionsService', () => {
service.copyNodes([fileToCopy, folderToCopy]);
expect(spyOnBatchOperation).toHaveBeenCalledWith(BatchOperationType.copy, [fileToCopy, folderToCopy], undefined);
expect(spyOnBatchOperation).toHaveBeenCalledWith(NodeAction.COPY, [fileToCopy, folderToCopy], undefined);
expect(spyOnDestinationPicker.calls.count()).toEqual(1);
expect(spyOnDialog.calls.count()).toEqual(1);
@@ -731,7 +731,7 @@ describe('NodeActionsService', () => {
service.moveNodes([fileToMove, folderToMove], permissionToMove);
subject.next([destinationFolder.entry]);
expect(spyOnBatchOperation).toHaveBeenCalledWith(BatchOperationType.move, [fileToMove, folderToMove], permissionToMove);
expect(spyOnBatchOperation).toHaveBeenCalledWith(NodeAction.MOVE, [fileToMove, folderToMove], permissionToMove);
expect(spyOnDestinationPicker).toHaveBeenCalled();
});
@@ -744,7 +744,7 @@ describe('NodeActionsService', () => {
service.moveNodes([fileToMove, folderToMove], permissionToMove);
subject.next([destinationFolder.entry]);
expect(spyOnBatchOperation).toHaveBeenCalledWith(BatchOperationType.move, [fileToMove, folderToMove], permissionToMove);
expect(spyOnBatchOperation).toHaveBeenCalledWith(NodeAction.MOVE, [fileToMove, folderToMove], permissionToMove);
expect(spyOnDestinationPicker).not.toHaveBeenCalled();
});

View File

@@ -32,16 +32,14 @@ import {
ContentNodeSelectorComponent,
ContentNodeSelectorComponentData,
ContentNodeDialogService,
ShareDataRow
ShareDataRow,
NodeAction
} from '@alfresco/adf-content-services';
import { MinimalNodeEntity, MinimalNodeEntryEntity, SitePaging, NodeChildAssociationPaging, NodeChildAssociationEntry } from '@alfresco/js-api';
import { ContentApiService } from '@alfresco/aca-shared';
import { catchError, map, mergeMap } from 'rxjs/operators';
export enum BatchOperationType {
copy = 'copy',
move = 'move'
}
type BatchOperationType = Extract<NodeAction, NodeAction.COPY | NodeAction.MOVE>;
@Injectable({
providedIn: 'root'
@@ -69,7 +67,7 @@ export class NodeActionsService {
* @param permission permission which is needed to apply the action
*/
copyNodes(contentEntities: any[], permission?: string): Subject<string> {
return this.doBatchOperation(BatchOperationType.copy, contentEntities, permission);
return this.doBatchOperation(NodeAction.COPY, contentEntities, permission);
}
/**
@@ -79,7 +77,7 @@ export class NodeActionsService {
* @param permission permission which is needed to apply the action
*/
moveNodes(contentEntities: any[], permission?: string): Subject<string> {
return this.doBatchOperation(BatchOperationType.move, contentEntities, permission);
return this.doBatchOperation(NodeAction.MOVE, contentEntities, permission);
}
/**
@@ -107,12 +105,12 @@ export class NodeActionsService {
const selection = selections[0];
let action$: Observable<any>;
if (action === BatchOperationType.move && contentEntities.length === 1 && type === 'content') {
if (action === NodeAction.MOVE && contentEntities.length === 1 && type === 'content') {
action$ = this.documentListService.moveNode(contentEntryId, selection.id);
} else {
contentEntities.forEach((node) => {
// batch.push(this.copyNodeAction(node.entry, selection.id));
batch.push(this[`${action}NodeAction`](node.entry, selection.id));
batch.push(this[`${action.toLowerCase()}NodeAction`](node.entry, selection.id));
});
action$ = zip(...batch);
}
@@ -121,9 +119,9 @@ export class NodeActionsService {
observable.next(`OPERATION.SUCCESS.${type.toUpperCase()}.${action.toUpperCase()}`);
const processedData = this.processResponse(newContent);
if (action === BatchOperationType.copy) {
if (action === NodeAction.COPY) {
this.contentCopied.next(processedData.succeeded);
} else if (action === BatchOperationType.move) {
} else if (action === NodeAction.MOVE) {
this.contentMoved.next(processedData);
}
}, observable.error.bind(observable));
@@ -160,7 +158,7 @@ export class NodeActionsService {
return entryParentId;
}
getContentNodeSelection(action: string, contentEntities: MinimalNodeEntity[]): Subject<MinimalNodeEntryEntity[]> {
getContentNodeSelection(action: NodeAction, contentEntities: MinimalNodeEntity[]): Subject<MinimalNodeEntryEntity[]> {
const currentParentFolderId = this.getEntryParentId(contentEntities[0].entry);
const customDropdown = new SitePaging({
@@ -536,7 +534,7 @@ export class NodeActionsService {
}
private isActionAllowed(action: BatchOperationType, node: MinimalNodeEntryEntity, permission?: string): boolean {
if (action === BatchOperationType.copy) {
if (action === NodeAction.COPY) {
return true;
}
return this.contentService.hasAllowableOperations(node, permission);

View File

@@ -32,7 +32,7 @@ import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { switchMap, catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, ShareDataRow } from '@alfresco/adf-content-services';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, ShareDataRow, NodeAction } from '@alfresco/adf-content-services';
export interface TemplateDialogConfig {
primaryPathName: string;
@@ -64,7 +64,7 @@ export class NodeTemplateService {
const data: ContentNodeSelectorComponentData = {
selectionMode: 'single',
title: this.title(config.selectionType),
actionName: 'NEXT',
actionName: NodeAction.NEXT,
dropdownHideMyFiles: true,
currentFolderId: null,
dropdownSiteList: null,