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

View File

@@ -24,10 +24,10 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@alfresco/adf-content-services": "4.4.0", "@alfresco/adf-content-services": "4.5.0-32653",
"@alfresco/adf-core": "4.4.0", "@alfresco/adf-core": "4.5.0-32658",
"@alfresco/adf-extensions": "4.4.0", "@alfresco/adf-extensions": "4.5.0-32653",
"@alfresco/js-api": "4.4.0", "@alfresco/js-api": "4.4.0-3508",
"@angular/animations": "10.0.4", "@angular/animations": "10.0.4",
"@angular/cdk": "^10.0.2", "@angular/cdk": "^10.0.2",
"@angular/common": "10.0.4", "@angular/common": "10.0.4",
@@ -56,8 +56,8 @@
"zone.js": "~0.10.2" "zone.js": "~0.10.2"
}, },
"devDependencies": { "devDependencies": {
"@alfresco/adf-cli": "4.4.0", "@alfresco/adf-cli": "4.5.0-32658",
"@alfresco/adf-testing": "4.4.0", "@alfresco/adf-testing": "4.5.0-32658",
"@angular-custom-builders/lite-serve": "^0.2.3", "@angular-custom-builders/lite-serve": "^0.2.3",
"@angular-devkit/build-angular": "^0.1002.0", "@angular-devkit/build-angular": "^0.1002.0",
"@angular-devkit/build-ng-packagr": "^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 { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { of, throwError, Subject, Observable } from 'rxjs'; import { of, throwError, Subject, Observable } from 'rxjs';
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core'; import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { DocumentListService } from '@alfresco/adf-content-services'; import { DocumentListService, NodeAction } from '@alfresco/adf-content-services';
import { NodeActionsService, BatchOperationType } from './node-actions.service'; import { NodeActionsService } from './node-actions.service';
import { MinimalNodeEntryEntity, NodeChildAssociationEntry, NodeEntry } from '@alfresco/js-api'; import { MinimalNodeEntryEntity, NodeChildAssociationEntry, NodeEntry } from '@alfresco/js-api';
import { AppTestingModule } from '../testing/app-testing.module'; import { AppTestingModule } from '../testing/app-testing.module';
import { ContentApiService } from '@alfresco/aca-shared'; import { ContentApiService } from '@alfresco/aca-shared';
@@ -119,7 +119,7 @@ describe('NodeActionsService', () => {
it('should validate selection when allowableOperation has `create`', () => { it('should validate selection when allowableOperation has `create`', () => {
spyOn(dialog, 'open'); spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }]; 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({ const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template', name: 'some-folder-template',
@@ -135,7 +135,7 @@ describe('NodeActionsService', () => {
it('should invalidate selection when allowableOperation does not have `create`', () => { it('should invalidate selection when allowableOperation does not have `create`', () => {
spyOn(dialog, 'open'); spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }]; 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({ const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template', name: 'some-folder-template',
@@ -151,7 +151,7 @@ describe('NodeActionsService', () => {
it('should invalidate selection if isSite', () => { it('should invalidate selection if isSite', () => {
spyOn(dialog, 'open'); spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }]; 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({ const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template', name: 'some-folder-template',
@@ -168,7 +168,7 @@ describe('NodeActionsService', () => {
it('should validate selection if not a Site', () => { it('should validate selection if not a Site', () => {
spyOn(dialog, 'open'); spyOn(dialog, 'open');
const contentEntities = [new TestNode(), { entry: { nodeId: '1234' } }]; 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({ const isSelectionValid = dialog.open['calls'].argsFor(0)[1].data.isSelectionValid({
name: 'some-folder-template', name: 'some-folder-template',
@@ -336,7 +336,7 @@ describe('NodeActionsService', () => {
subject.next([destinationFolder.entry]); subject.next([destinationFolder.entry]);
expect(spyOnBatchOperation.calls.count()).toEqual(1); 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', () => { 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]); 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(spyOnDestinationPicker.calls.count()).toEqual(1);
expect(spyOnDialog.calls.count()).toEqual(1); expect(spyOnDialog.calls.count()).toEqual(1);
@@ -731,7 +731,7 @@ describe('NodeActionsService', () => {
service.moveNodes([fileToMove, folderToMove], permissionToMove); service.moveNodes([fileToMove, folderToMove], permissionToMove);
subject.next([destinationFolder.entry]); subject.next([destinationFolder.entry]);
expect(spyOnBatchOperation).toHaveBeenCalledWith(BatchOperationType.move, [fileToMove, folderToMove], permissionToMove); expect(spyOnBatchOperation).toHaveBeenCalledWith(NodeAction.MOVE, [fileToMove, folderToMove], permissionToMove);
expect(spyOnDestinationPicker).toHaveBeenCalled(); expect(spyOnDestinationPicker).toHaveBeenCalled();
}); });
@@ -744,7 +744,7 @@ describe('NodeActionsService', () => {
service.moveNodes([fileToMove, folderToMove], permissionToMove); service.moveNodes([fileToMove, folderToMove], permissionToMove);
subject.next([destinationFolder.entry]); subject.next([destinationFolder.entry]);
expect(spyOnBatchOperation).toHaveBeenCalledWith(BatchOperationType.move, [fileToMove, folderToMove], permissionToMove); expect(spyOnBatchOperation).toHaveBeenCalledWith(NodeAction.MOVE, [fileToMove, folderToMove], permissionToMove);
expect(spyOnDestinationPicker).not.toHaveBeenCalled(); expect(spyOnDestinationPicker).not.toHaveBeenCalled();
}); });

View File

@@ -32,16 +32,14 @@ import {
ContentNodeSelectorComponent, ContentNodeSelectorComponent,
ContentNodeSelectorComponentData, ContentNodeSelectorComponentData,
ContentNodeDialogService, ContentNodeDialogService,
ShareDataRow ShareDataRow,
NodeAction
} from '@alfresco/adf-content-services'; } from '@alfresco/adf-content-services';
import { MinimalNodeEntity, MinimalNodeEntryEntity, SitePaging, NodeChildAssociationPaging, NodeChildAssociationEntry } from '@alfresco/js-api'; import { MinimalNodeEntity, MinimalNodeEntryEntity, SitePaging, NodeChildAssociationPaging, NodeChildAssociationEntry } from '@alfresco/js-api';
import { ContentApiService } from '@alfresco/aca-shared'; import { ContentApiService } from '@alfresco/aca-shared';
import { catchError, map, mergeMap } from 'rxjs/operators'; import { catchError, map, mergeMap } from 'rxjs/operators';
export enum BatchOperationType { type BatchOperationType = Extract<NodeAction, NodeAction.COPY | NodeAction.MOVE>;
copy = 'copy',
move = 'move'
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -69,7 +67,7 @@ export class NodeActionsService {
* @param permission permission which is needed to apply the action * @param permission permission which is needed to apply the action
*/ */
copyNodes(contentEntities: any[], permission?: string): Subject<string> { 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 * @param permission permission which is needed to apply the action
*/ */
moveNodes(contentEntities: any[], permission?: string): Subject<string> { 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]; const selection = selections[0];
let action$: Observable<any>; 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); action$ = this.documentListService.moveNode(contentEntryId, selection.id);
} else { } else {
contentEntities.forEach((node) => { contentEntities.forEach((node) => {
// batch.push(this.copyNodeAction(node.entry, selection.id)); // 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); action$ = zip(...batch);
} }
@@ -121,9 +119,9 @@ export class NodeActionsService {
observable.next(`OPERATION.SUCCESS.${type.toUpperCase()}.${action.toUpperCase()}`); observable.next(`OPERATION.SUCCESS.${type.toUpperCase()}.${action.toUpperCase()}`);
const processedData = this.processResponse(newContent); const processedData = this.processResponse(newContent);
if (action === BatchOperationType.copy) { if (action === NodeAction.COPY) {
this.contentCopied.next(processedData.succeeded); this.contentCopied.next(processedData.succeeded);
} else if (action === BatchOperationType.move) { } else if (action === NodeAction.MOVE) {
this.contentMoved.next(processedData); this.contentMoved.next(processedData);
} }
}, observable.error.bind(observable)); }, observable.error.bind(observable));
@@ -160,7 +158,7 @@ export class NodeActionsService {
return entryParentId; return entryParentId;
} }
getContentNodeSelection(action: string, contentEntities: MinimalNodeEntity[]): Subject<MinimalNodeEntryEntity[]> { getContentNodeSelection(action: NodeAction, contentEntities: MinimalNodeEntity[]): Subject<MinimalNodeEntryEntity[]> {
const currentParentFolderId = this.getEntryParentId(contentEntities[0].entry); const currentParentFolderId = this.getEntryParentId(contentEntities[0].entry);
const customDropdown = new SitePaging({ const customDropdown = new SitePaging({
@@ -536,7 +534,7 @@ export class NodeActionsService {
} }
private isActionAllowed(action: BatchOperationType, node: MinimalNodeEntryEntity, permission?: string): boolean { private isActionAllowed(action: BatchOperationType, node: MinimalNodeEntryEntity, permission?: string): boolean {
if (action === BatchOperationType.copy) { if (action === NodeAction.COPY) {
return true; return true;
} }
return this.contentService.hasAllowableOperations(node, permission); 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 { switchMap, catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/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 { export interface TemplateDialogConfig {
primaryPathName: string; primaryPathName: string;
@@ -64,7 +64,7 @@ export class NodeTemplateService {
const data: ContentNodeSelectorComponentData = { const data: ContentNodeSelectorComponentData = {
selectionMode: 'single', selectionMode: 'single',
title: this.title(config.selectionType), title: this.title(config.selectionType),
actionName: 'NEXT', actionName: NodeAction.NEXT,
dropdownHideMyFiles: true, dropdownHideMyFiles: true,
currentFolderId: null, currentFolderId: null,
dropdownSiteList: null, dropdownSiteList: null,