[ACA-3669] Incorrect Version Number Displayed (#2281)

* [ACA-3669] Incorrect Version Number Displayed

* * fixed lint

* * test fixed
This commit is contained in:
Dharan 2021-09-06 11:00:45 +05:30 committed by GitHub
parent 8afedd6e1f
commit 65826c27f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 75 deletions

View File

@ -50,7 +50,8 @@ import {
ContentApi,
SitesApi,
SearchApi,
PeopleApi
PeopleApi,
VersionsApi
} from '@alfresco/js-api';
import { map } from 'rxjs/operators';
@ -112,6 +113,11 @@ export class ContentApiService {
return this._peopleApi;
}
_versionsApi: VersionsApi;
get versionsApi(): VersionsApi {
this._versionsApi = this._versionsApi ?? new VersionsApi(this.api.getInstance());
return this._versionsApi;
}
constructor(private api: AlfrescoApiService, private preferences: UserPreferencesService) {}
/**
@ -341,4 +347,8 @@ export class ContentApiService {
unlockNode(nodeId: string, opts?: any) {
return this.nodesApi.unlockNode(nodeId, opts);
}
getNodeVersions(nodeId: string, opts?: any) {
return from(this.versionsApi.listVersionHistory(nodeId, opts));
}
}

View File

@ -1,23 +1,23 @@
<header mat-dialog-title *ngIf="isTypeList">{{ 'VERSION.DIALOG_ADF.TITLE' | translate }}</header>
<header mat-dialog-title *ngIf="!isTypeList">{{ 'VERSION.DIALOG.TITLE' | translate }}</header>
<section mat-dialog-content *ngIf="!isTypeList">
<adf-version-comparison id="adf-version-comparison" [newFileVersion]="file" [node]="node"></adf-version-comparison>
<header mat-dialog-title>{{ data.title | translate }}</header>
<section mat-dialog-content *ngIf="!data.showVersionsOnly">
<adf-version-comparison id="adf-version-comparison" [newFileVersion]="data.file" [node]="data.node"></adf-version-comparison>
<adf-version-upload
id="adf-version-upload-button"
[node]="node"
[newFileVersion]="file"
[node]="data.node"
[newFileVersion]="data.file"
[currentVersion]="data.currentVersion"
(success)="handleUpload($event)"
(cancel)="handleCancel()"
(error)="onUploadError($event)"
>
</adf-version-upload>
</section>
<ng-container *ngIf="isTypeList">
<ng-container *ngIf="data.showVersionsOnly">
<section mat-dialog-content>
<div class="adf-version-list-container">
<div class="adf-version-list-table">
<adf-version-list
[node]="node"
[node]="data.node"
[showComments]="'adf-version-manager.allowComments' | adfAppConfig: true"
[allowDownload]="'adf-version-manager.allowDownload' | adfAppConfig: true"
(deleted)="refresh($event)"

View File

@ -44,6 +44,31 @@ describe('NodeVersionsDialogComponent', () => {
let fixture: ComponentFixture<NodeVersionsDialogComponent>;
let component: NodeVersionsDialogComponent;
let store: Store<AppStore>;
const node = {
id: '1234',
name: 'TEST-NODE',
isFile: true,
nodeType: 'FAKE',
isFolder: false,
modifiedAt: new Date(),
modifiedByUser: null,
createdAt: new Date(),
createdByUser: null,
content: {
mimeType: 'text/html',
mimeTypeName: 'HTML',
sizeInBytes: 13
}
};
const showVersionsOnly = true;
const file = {
name: 'Fake New file',
type: 'application/pdf',
lastModified: 13,
size: 1351,
slice: null
} as File;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreModule.forRoot(), TranslateModule.forRoot(), MatDialogModule, RouterTestingModule.withRoutes([]), AppTestingModule],
@ -68,55 +93,31 @@ describe('NodeVersionsDialogComponent', () => {
dispatch: jasmine.createSpy('dispatch')
}
},
{ provide: MAT_DIALOG_DATA, useValue: {} }
{ provide: MAT_DIALOG_DATA, useValue: { node, showVersionsOnly, file } }
]
});
store = TestBed.inject(Store);
fixture = TestBed.createComponent(NodeVersionsDialogComponent);
component = fixture.componentInstance;
component.node = {
id: '1234',
name: 'TEST-NODE',
isFile: true,
nodeType: 'FAKE',
isFolder: false,
modifiedAt: new Date(),
modifiedByUser: null,
createdAt: new Date(),
createdByUser: null,
content: {
mimeType: 'text/html',
mimeTypeName: 'HTML',
sizeInBytes: 13
}
};
component.isTypeList = true;
component.file = {
name: 'Fake New file',
type: 'application/pdf',
lastModified: 13,
size: 1351,
slice: null
} as File;
});
it('should display adf upload version if isTypeList is passed as false from parent component', () => {
component.isTypeList = false;
component.data.showVersionsOnly = false;
fixture.detectChanges();
const adfVersionComponent = document.querySelector('#adf-version-upload-button');
expect(adfVersionComponent).not.toEqual(null);
});
it('should display adf version comparison if isTypeList is passed as false from parent component', () => {
component.isTypeList = false;
component.data.showVersionsOnly = false;
fixture.detectChanges();
const adfVersionComparisonComponent = document.querySelector('#adf-version-comparison');
expect(adfVersionComparisonComponent).not.toEqual(null);
});
it('should unlock node if is locked when uploading a file', () => {
component.isTypeList = false;
component.data.showVersionsOnly = false;
const nodeEvent: NodeEntityEvent = new NodeEntityEvent({
entry: {
id: 'a8b2caff-a58c-40f1-8c47-0b8e63ceaa0e',
@ -138,12 +139,12 @@ describe('NodeVersionsDialogComponent', () => {
});
it('should view a previous version of a node', () => {
component.isTypeList = false;
component.data.showVersionsOnly = false;
const versionId = '1.0';
const location: ViewNodeExtras = {
location: '/'
};
component.onViewingVersion(versionId);
expect(store.dispatch).toHaveBeenCalledWith(new ViewNodeVersionAction(component.node.id, versionId, location));
expect(store.dispatch).toHaveBeenCalledWith(new ViewNodeVersionAction(component.data.node.id, versionId, location));
});
});

View File

@ -24,13 +24,21 @@
*/
import { AppStore, SnackbarErrorAction, UnlockWriteAction, ViewNodeVersionAction } from '@alfresco/aca-shared/store';
import { MinimalNodeEntryEntity, Node } from '@alfresco/js-api';
import { MinimalNodeEntryEntity, Node, Version } from '@alfresco/js-api';
import { Component, EventEmitter, Inject, Output, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { NodeEntityEvent } from '@alfresco/adf-content-services';
import { Router } from '@angular/router';
export interface NodeVersionDialogData {
title: string;
node: MinimalNodeEntryEntity;
file?: File;
currentVersion?: Version;
showVersionsOnly?: boolean;
}
@Component({
templateUrl: './node-versions.dialog.html',
styleUrls: ['./node-versions.dialog.scss'],
@ -38,24 +46,16 @@ import { Router } from '@angular/router';
host: { class: 'aca-node-versions-dialog' }
})
export class NodeVersionsDialogComponent {
node: MinimalNodeEntryEntity;
file: File;
isTypeList = true;
/** Emitted when a version is restored or deleted. */
@Output()
refreshEvent = new EventEmitter<Node>();
constructor(
@Inject(MAT_DIALOG_DATA) data: any,
@Inject(MAT_DIALOG_DATA) public data: NodeVersionDialogData,
private store: Store<AppStore>,
private dialogRef: MatDialogRef<NodeVersionsDialogComponent>,
private router: Router
) {
this.node = data.node;
this.file = data.file;
this.isTypeList = data.isTypeList !== undefined ? data.isTypeList : true;
}
) {}
onUploadError(errorMessage: any) {
this.store.dispatch(new SnackbarErrorAction(errorMessage));
@ -78,7 +78,7 @@ export class NodeVersionsDialogComponent {
onViewingVersion(versionId: string) {
this.store.dispatch(
new ViewNodeVersionAction(this.node.id, versionId, {
new ViewNodeVersionAction(this.data.node.id, versionId, {
location: this.router.url
})
);

View File

@ -53,7 +53,7 @@ import { NodeActionsService } from './node-actions.service';
import { TranslationService, AlfrescoApiService, FileModel } from '@alfresco/adf-core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
import { NodeEntry, Node } from '@alfresco/js-api';
import { NodeEntry, Node, VersionPaging } from '@alfresco/js-api';
import { NodeAspectService } from '@alfresco/adf-content-services';
describe('ContentManagementService', () => {
@ -1462,6 +1462,11 @@ describe('ContentManagementService', () => {
});
describe('versionUpdateDialog', () => {
beforeEach(() => {
const fakeVersion = { list: { entries: [{ entry: { id: '1.0' } }] } } as VersionPaging;
spyOn(contentApi, 'getNodeVersions').and.returnValue(of(fakeVersion));
});
it('should open dialog with NodeVersionUploadDialogComponent instance', () => {
spyOn(dialog, 'open');
const fakeNode = {
@ -1473,23 +1478,12 @@ describe('ContentManagementService', () => {
contentManagementService.versionUpdateDialog(fakeNode, fakeFile);
expect(dialog.open['calls'].argsFor(0)[0].name).toBe('NodeVersionsDialogComponent');
});
it('should return dialog instance reference', () => {
const mockDialogInstance: any = {
afterClose: () => {}
};
const fakeNode = {
name: 'lights.jpg',
id: 'f5e5cb54-200e-41a8-9c21-b5ee77da3992'
};
const fakeFile = new FileModel({ name: 'file1.png', size: 10 } as File, null, 'file1');
spyOn(dialog, 'open').and.returnValue(mockDialogInstance);
const dialogRef = contentManagementService.versionUpdateDialog(fakeNode, fakeFile);
expect(dialogRef).toBe(mockDialogInstance);
expect(dialog.open['calls'].argsFor(0)[1].data).toEqual({
node: fakeNode,
file: fakeFile,
currentVersion: { id: '1.0' },
title: 'VERSION.DIALOG.TITLE'
});
});
});

View File

@ -66,7 +66,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { Store } from '@ngrx/store';
import { forkJoin, Observable, of, zip } from 'rxjs';
import { catchError, map, mergeMap, take, tap } from 'rxjs/operators';
import { NodeVersionsDialogComponent } from '../dialogs/node-versions/node-versions.dialog';
import { NodeVersionsDialogComponent, NodeVersionDialogData } from '../dialogs/node-versions/node-versions.dialog';
import { NodeActionsService } from './node-actions.service';
interface RestoredNode {
@ -139,7 +139,7 @@ export class ContentManagementService {
// workaround Shared
if (node.isFile || node.nodeId) {
const dialogRef = this.dialogRef.open(NodeVersionsDialogComponent, {
data: { node },
data: { node, showVersionsOnly: true, title: 'VERSION.DIALOG_ADF.TITLE' } as NodeVersionDialogData,
panelClass: 'adf-version-manager-dialog-panel',
width: '630px'
});
@ -176,10 +176,12 @@ export class ContentManagementService {
}
versionUpdateDialog(node, file) {
return this.dialogRef.open(NodeVersionsDialogComponent, {
data: { node, file, isTypeList: false },
panelClass: 'adf-version-manager-dialog-panel-upload',
width: '600px'
this.contentApi.getNodeVersions(node.id).subscribe(({ list }) => {
this.dialogRef.open(NodeVersionsDialogComponent, {
data: { node, file, currentVersion: list.entries[0].entry, title: 'VERSION.DIALOG.TITLE' } as NodeVersionDialogData,
panelClass: 'adf-version-manager-dialog-panel-upload',
width: '600px'
});
});
}