[ACA-2745] Viewer - return to location on close (#1196)

* use viewNodeExtras when calling action

* open viewer based on ViewNodeExtras data

* resolve closing destination based on ViewNodeExtras query params

* remove unused param

* call ViewNodeAction with correct params

* update tests

* update docs
This commit is contained in:
Cilibiu Bogdan
2019-09-06 14:17:29 +03:00
committed by GitHub
parent cbe9cf4690
commit edf1e52e94
19 changed files with 186 additions and 82 deletions
@@ -185,9 +185,8 @@ describe('FavoritesComponent', () => {
fixture.detectChanges();
component.onNodeDoubleClick(nodeEntity);
expect(component.showPreview).toHaveBeenCalledWith(
nodeEntity,
mockRouter.url
);
expect(component.showPreview).toHaveBeenCalledWith(nodeEntity, {
location: mockRouter.url
});
});
});
@@ -112,7 +112,7 @@ export class FavoritesComponent extends PageComponent implements OnInit {
}
if (node.entry.isFile) {
this.showPreview(node, this.router.url);
this.showPreview(node, { location: this.router.url });
}
}
}
+1 -1
View File
@@ -151,7 +151,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
return;
}
this.showPreview(node, this.router.url);
this.showPreview(node, { location: this.router.url });
}
}
+4 -3
View File
@@ -43,7 +43,8 @@ import {
getDocumentDisplayMode,
isInfoDrawerOpened,
getSharedUrl,
ViewNodeAction
ViewNodeAction,
ViewNodeExtras
} from '@alfresco/aca-shared/store';
import { isLocked, isLibrary } from '../utils/node.utils';
@@ -105,12 +106,12 @@ export abstract class PageComponent implements OnInit, OnDestroy {
this.onDestroy$.complete();
}
showPreview(node: MinimalNodeEntity, location?: string) {
showPreview(node: MinimalNodeEntity, extras?: ViewNodeExtras) {
if (node && node.entry) {
const id =
(<any>node).entry.nodeId || (<any>node).entry.guid || node.entry.id;
this.store.dispatch(new ViewNodeAction(id, location));
this.store.dispatch(new ViewNodeAction(id, extras));
}
}
@@ -124,6 +124,8 @@ describe('RecentFilesComponent', () => {
fixture.detectChanges();
component.onNodeDoubleClick(node);
expect(component.showPreview).toHaveBeenCalledWith(node, mockRouter.url);
expect(component.showPreview).toHaveBeenCalledWith(node, {
location: mockRouter.url
});
});
});
@@ -77,7 +77,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit {
onNodeDoubleClick(node: MinimalNodeEntity) {
if (node && node.entry) {
this.showPreview(node, this.router.url);
this.showPreview(node, { location: this.router.url });
}
}
@@ -126,7 +126,7 @@ export class SearchResultsRowComponent implements OnInit, OnDestroy {
showPreview(event: MouseEvent) {
event.stopPropagation();
this.store.dispatch(
new ViewNodeAction(this.node.entry.id, this.router.url)
new ViewNodeAction(this.node.entry.id, { location: this.router.url })
);
}
@@ -305,7 +305,9 @@ describe('SearchComponent', () => {
component.onNodeDoubleClick(node);
expect(component.showPreview).toHaveBeenCalledWith(node, router.url);
expect(component.showPreview).toHaveBeenCalledWith(node, {
location: router.url
});
});
it('should re-run search on pagination change', () => {
@@ -253,7 +253,7 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
return;
}
this.showPreview(node, this.router.url);
this.showPreview(node, { location: this.router.url });
}
}
@@ -131,6 +131,8 @@ describe('SharedFilesComponent', () => {
fixture.detectChanges();
component.preview(node);
expect(component.showPreview).toHaveBeenCalledWith(node, mockRouter.url);
expect(component.showPreview).toHaveBeenCalledWith(node, {
location: mockRouter.url
});
});
});
@@ -79,6 +79,6 @@ export class SharedFilesComponent extends PageComponent implements OnInit {
}
preview(node: MinimalNodeEntity) {
this.showPreview(node, this.router.url);
this.showPreview(node, { location: this.router.url });
}
}
@@ -69,7 +69,9 @@ export class ViewNodeComponent {
(<any>selection.file).entry.guid ||
selection.file.entry.id;
this.store.dispatch(new ViewNodeAction(id, this.router.url));
this.store.dispatch(
new ViewNodeAction(id, { location: this.router.url })
);
});
}
}
@@ -11,7 +11,7 @@
[allowDownload]="false"
[allowFullScreen]="false"
[overlayMode]="true"
(showViewerChange)="onViewerVisibilityChanged($event)"
(showViewerChange)="onViewerVisibilityChanged()"
[canNavigateBefore]="previousNodeId"
[canNavigateNext]="nextNodeId"
(navigateBefore)="onNavigateBefore()"
@@ -59,6 +59,8 @@ import { ReloadDocumentListAction } from '@alfresco/aca-shared/store';
host: { class: 'app-viewer' }
})
export class AppViewerComponent implements OnInit, OnDestroy {
private navigationPath: string;
onDestroy$ = new Subject<boolean>();
folderId: string = null;
@@ -149,6 +151,10 @@ export class AppViewerComponent implements OnInit, OnDestroy {
}
});
this.route.queryParams.subscribe(params => {
this.navigationPath = params.path;
});
if (this.route.snapshot.data && this.route.snapshot.data.navigateSource) {
const source = this.route.snapshot.data.navigateSource.toLowerCase();
if (this.navigationSources.includes(source)) {
@@ -231,12 +237,12 @@ export class AppViewerComponent implements OnInit, OnDestroy {
onNavigateBefore(): void {
const location = this.getFileLocation();
this.store.dispatch(new ViewNodeAction(this.previousNodeId, location));
this.store.dispatch(new ViewNodeAction(this.previousNodeId, { location }));
}
onNavigateNext(): void {
const location = this.getFileLocation();
this.store.dispatch(new ViewNodeAction(this.nextNodeId, location));
this.store.dispatch(new ViewNodeAction(this.nextNodeId, { location }));
}
/**
@@ -425,7 +431,7 @@ export class AppViewerComponent implements OnInit, OnDestroy {
private getFileLocation(): string {
return this.router
.parseUrl(this.router.url)
.parseUrl(this.navigationPath || this.router.url)
.root.children[PRIMARY_OUTLET].toString();
}
}
+14 -3
View File
@@ -74,12 +74,14 @@ describe('ViewerEffects', () => {
});
describe('ViewNode', () => {
it('should open viewer from file location', fakeAsync(() => {
store.dispatch(new ViewNodeAction('nodeId', 'some-location'));
it('should open viewer from file location if', fakeAsync(() => {
store.dispatch(
new ViewNodeAction('nodeId', { location: 'some-location' })
);
tick(100);
expect(router.navigateByUrl['calls'].argsFor(0)[0].toString()).toEqual(
'/some-location/(viewer:view/nodeId)?source=some-location'
'/some-location/(viewer:view/nodeId)?location=some-location'
);
}));
@@ -91,5 +93,14 @@ describe('ViewerEffects', () => {
'/view/(viewer:nodeId)'
);
}));
it('should navigate to viewer route with query param if path is passed', fakeAsync(() => {
store.dispatch(new ViewNodeAction('nodeId', { path: 'absolute-path' }));
tick(100);
expect(router.navigateByUrl['calls'].argsFor(0)[0].toString()).toEqual(
'/view/(viewer:nodeId)?path=absolute-path'
);
}));
});
});
+20 -9
View File
@@ -77,17 +77,28 @@ export class ViewerEffects {
viewNode$ = this.actions$.pipe(
ofType<ViewNodeAction>(ViewerActionTypes.ViewNode),
map(action => {
if (action.location) {
const location = this.getNavigationCommands(action.location);
if (action.viewNodeExtras) {
const { location, path } = action.viewNodeExtras;
this.router.navigate(
[...location, { outlets: { viewer: ['view', action.nodeId] } }],
{
queryParams: {
source: action.location
if (location) {
const navigation = this.getNavigationCommands(location);
this.router.navigate(
[...navigation, { outlets: { viewer: ['view', action.nodeId] } }],
{
queryParams: { location }
}
}
);
);
}
if (path) {
this.router.navigate(
['view', { outlets: { viewer: [action.nodeId] } }],
{
queryParams: { path }
}
);
}
} else {
this.router.navigate([
'view',