Skip to content

Commit 96b7c73

Browse files
[MNT-25285] Unable to change version preview from within the preview window (#4789)
1 parent 732a111 commit 96b7c73

File tree

2 files changed

+65
-31
lines changed

2 files changed

+65
-31
lines changed

projects/aca-content/src/lib/services/content-management.service.spec.ts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
SetSelectedNodesAction,
3838
ShareNodeAction,
3939
UnlockWriteAction,
40-
ViewNodeExtras,
4140
ViewNodeVersionAction
4241
} from '@alfresco/aca-shared/store';
4342
import { NodeEffects } from '../store/effects/node.effects';
@@ -62,6 +61,7 @@ import {
6261
} from '@alfresco/adf-content-services';
6362
import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component';
6463
import { provideEffects } from '@ngrx/effects';
64+
import { ActivatedRoute, Router } from '@angular/router';
6565

6666
describe('ContentManagementService', () => {
6767
let dialog: MatDialog;
@@ -77,6 +77,8 @@ describe('ContentManagementService', () => {
7777
let appHookService: AppHookService;
7878
let newVersionUploaderService: NewVersionUploaderService;
7979
let appSettingsService: AppSettingsService;
80+
let router: Router;
81+
let activatedRoute: ActivatedRoute;
8082
let showErrorSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>;
8183
let showInfoSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>;
8284
let showWarningSpy: jasmine.Spy<(message: string, action?: string, interpolateArgs?: any, showAction?: boolean) => MatSnackBarRef<any>>;
@@ -104,7 +106,8 @@ describe('ContentManagementService', () => {
104106
appHookService = TestBed.inject(AppHookService);
105107
newVersionUploaderService = TestBed.inject(NewVersionUploaderService);
106108
appSettingsService = TestBed.inject(AppSettingsService);
107-
109+
router = TestBed.inject(Router);
110+
activatedRoute = TestBed.inject(ActivatedRoute);
108111
dialog = TestBed.inject(MatDialog);
109112
});
110113

@@ -1618,12 +1621,47 @@ describe('ContentManagementService', () => {
16181621

16191622
it('should dispatch ViewNodeVersionAction if dialog emit view action', () => {
16201623
const fakeVersionId = '1';
1621-
const fakeLocation: ViewNodeExtras = {
1622-
location: '/'
1623-
};
1624+
const mockLocation = '/personal-files';
1625+
activatedRoute.snapshot.queryParams = { location: mockLocation };
1626+
16241627
spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion));
16251628
contentManagementService.manageVersions(fakeNodeIsFile);
1626-
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, fakeLocation));
1629+
1630+
expect(spyOnDispatch).toHaveBeenCalledOnceWith(
1631+
new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, {
1632+
location: mockLocation
1633+
})
1634+
);
1635+
});
1636+
1637+
it('should dispatch ViewNodeVersionAction with location value from router.url if location param doesnt exist already', () => {
1638+
const fakeVersionId = '1';
1639+
const currentUrl = '/current-page';
1640+
activatedRoute.snapshot.queryParams = {};
1641+
1642+
spyOnProperty(router, 'url', 'get').and.returnValue(currentUrl);
1643+
1644+
spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion));
1645+
1646+
contentManagementService.manageVersions(fakeNodeIsFile);
1647+
1648+
expect(spyOnDispatch).toHaveBeenCalledOnceWith(
1649+
new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, {
1650+
location: currentUrl
1651+
})
1652+
);
1653+
});
1654+
1655+
it('should dispatch ViewNodeVersionAction with the same location param if already exist', () => {
1656+
const fakeVersionId = '1';
1657+
const location = '/personal-files';
1658+
activatedRoute.snapshot.queryParams = { location: location };
1659+
1660+
spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.view, versionId: fakeVersionId } as ViewVersion));
1661+
1662+
contentManagementService.manageVersions(fakeNodeIsFile);
1663+
1664+
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new ViewNodeVersionAction(fakeNodeIsFile.entry.id, fakeVersionId, { location }));
16271665
});
16281666

16291667
it('should show permission error is node is not a file and does not have nodeId', () => {

projects/aca-content/src/lib/services/content-management.service.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ import {
4848
NodesApiService,
4949
ShareDialogComponent
5050
} from '@alfresco/adf-content-services';
51-
import { NotificationService, TranslationService, ConfirmDialogComponent, DialogComponent, DialogSize } from '@alfresco/adf-core';
51+
import { ConfirmDialogComponent, DialogComponent, DialogSize, NotificationService, TranslationService } from '@alfresco/adf-core';
5252
import { DeletedNodesPaging, Node, NodeEntry, PathInfo, SiteBodyCreate, SiteEntry } from '@alfresco/js-api';
5353
import { inject, Injectable } from '@angular/core';
5454
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
5555
import { Store } from '@ngrx/store';
5656
import { forkJoin, Observable, of, zip } from 'rxjs';
5757
import { catchError, map, mergeMap, take, tap } from 'rxjs/operators';
5858
import { NodeActionsService } from './node-actions.service';
59-
import { Router } from '@angular/router';
59+
import { ActivatedRoute, Router } from '@angular/router';
6060
import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component';
6161

6262
interface RestoredNode {
@@ -76,25 +76,23 @@ interface SnackbarMessageData {
7676
providedIn: 'root'
7777
})
7878
export class ContentManagementService {
79-
private notificationService = inject(NotificationService);
79+
private readonly notificationService = inject(NotificationService);
80+
private readonly nodesApiService = inject(NodesApiService);
81+
private readonly store = inject(Store<AppStore>);
82+
private readonly contentApi = inject(ContentApiService);
83+
private readonly permission = inject(NodePermissionService);
84+
private readonly dialogRef = inject(MatDialog);
85+
private readonly nodeActionsService = inject(NodeActionsService);
86+
private readonly translation = inject(TranslationService);
87+
private readonly nodeAspectService = inject(NodeAspectService);
88+
private readonly activatedRoute = inject(ActivatedRoute);
89+
private readonly appHookService = inject(AppHookService);
90+
private readonly newVersionUploaderService = inject(NewVersionUploaderService);
91+
private readonly router = inject(Router);
92+
private readonly appSettingsService = inject(AppSettingsService);
93+
private readonly documentListService = inject(DocumentListService);
8094
private readonly createMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.create"]';
8195

82-
constructor(
83-
private nodesApiService: NodesApiService,
84-
private store: Store<AppStore>,
85-
private contentApi: ContentApiService,
86-
private permission: NodePermissionService,
87-
private dialogRef: MatDialog,
88-
private nodeActionsService: NodeActionsService,
89-
private translation: TranslationService,
90-
private nodeAspectService: NodeAspectService,
91-
private appHookService: AppHookService,
92-
private newVersionUploaderService: NewVersionUploaderService,
93-
private router: Router,
94-
private appSettingsService: AppSettingsService,
95-
private documentListService: DocumentListService
96-
) {}
97-
9896
addFavorite(nodes: Array<NodeEntry>) {
9997
if (nodes && nodes.length > 0) {
10098
this.contentApi.addFavorite(nodes).subscribe(() => {
@@ -618,13 +616,11 @@ export class ContentManagementService {
618616
this.documentListService.reload();
619617
this.store.dispatch(new RefreshPreviewAction(newVersionUploaderData.node));
620618
break;
621-
case NewVersionUploaderDataAction.view:
622-
this.store.dispatch(
623-
new ViewNodeVersionAction(node.id, newVersionUploaderData.versionId, {
624-
location: this.router.url
625-
})
626-
);
619+
case NewVersionUploaderDataAction.view: {
620+
const location = this.activatedRoute.snapshot.queryParams['location'] || this.router.url;
621+
this.store.dispatch(new ViewNodeVersionAction(node.id, newVersionUploaderData.versionId, { location }));
627622
break;
623+
}
628624
default:
629625
break;
630626
}

0 commit comments

Comments
 (0)