Skip to content

Commit

Permalink
[ACA-2047] navigate to restored library content folder (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
pionnegru authored and DenysVuika committed Nov 28, 2018
1 parent 6e0bfe8 commit 9b717c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/app/services/content-management.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
SNACKBAR_WARNING,
PurgeDeletedNodesAction,
RestoreDeletedNodesAction,
NavigateToParentFolder,
NavigateRouteAction,
NAVIGATE_ROUTE,
DeleteNodesAction,
Expand Down Expand Up @@ -1205,6 +1206,45 @@ describe('ContentManagementService', () => {
expect(contentApi.restoreNode).toHaveBeenCalled();
}));

it('should navigate to library folder when node is a library content', fakeAsync(() => {
spyOn(store, 'dispatch').and.callThrough();
spyOn(contentApi, 'restoreNode').and.returnValue(of({}));
spyOn(contentApi, 'getDeletedNodes').and.returnValue(
of({
list: { entries: [] }
})
);

const path = {
elements: [
{
id: '1-1',
name: 'Company Home'
},
{
id: '1-2',
name: 'Sites'
}
]
};

const selection = [
{
entry: {
id: '1',
path
}
}
];

store.dispatch(new RestoreDeletedNodesAction(selection));

expect(
store.dispatch['calls'].argsFor(1)[0].userAction.action instanceof
NavigateToParentFolder
).toBe(true);
}));

describe('refresh()', () => {
it('dispatch event on finish', fakeAsync(done => {
spyOn(contentApi, 'restoreNode').and.returnValue(of({}));
Expand Down
25 changes: 23 additions & 2 deletions src/app/services/content-management.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SnackbarAction,
SnackbarWarningAction,
NavigateRouteAction,
NavigateToParentFolder,
SnackbarUserAction,
UndoDeleteNodesAction,
SetSelectedNodesAction
Expand Down Expand Up @@ -874,9 +875,17 @@ export class ContentManagementService {
const isSite = this.isSite(status.success[0].entry);
const path: PathInfoEntity = status.success[0].entry.path;
const parent = path.elements[path.elements.length - 1];
const route = isSite ? ['/libraries'] : ['/personal-files', parent.id];
const route = isSite
? ['/libraries', parent.id]
: ['/personal-files', parent.id];

const navigate = new NavigateRouteAction(route);
let navigate;

if (this.isLibraryContent(path)) {
navigate = new NavigateToParentFolder(status.success[0]);
} else {
navigate = new NavigateRouteAction(route);
}

message.userAction = new SnackbarUserAction(
'APP.ACTIONS.VIEW',
Expand All @@ -892,6 +901,18 @@ export class ContentManagementService {
return entry.nodeType === 'st:site';
}

private isLibraryContent(path: PathInfoEntity): boolean {
if (
path &&
path.elements.length >= 2 &&
path.elements[1].name === 'Sites'
) {
return true;
}

return false;
}

private getRestoreMessage(status: DeleteStatus): SnackbarAction {
if (status.someFailed && !status.oneFailed) {
return new SnackbarErrorAction(
Expand Down

0 comments on commit 9b717c2

Please sign in to comment.