[ACA-4374] FE - [ADW] Navigate to Smart Folder subfolders throws "This item no longer exists or you don't have permission to view it." (#2083)

* [ACA-4374] FE - [ADW] Navigate to Smart Folder subfolders throws "This item no longer exists or you don't have permission to view it."

* * Modified Unit test based on recent changes

* * FIxed lint error

* * Divided navigate logic into small methods

* * Changed method names

* * Changed method names
This commit is contained in:
siva kumar 2021-04-13 21:37:16 +05:30 committed by GitHub
parent e07a93c60f
commit 21fbb69ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 22 deletions

View File

@ -25,7 +25,7 @@
import { TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { Router, ActivatedRoute, convertToParamMap } from '@angular/router';
import { NodeFavoriteDirective, DataTableComponent, UploadService, AppConfigModule, DataTableModule, PaginationModule } from '@alfresco/adf-core';
import { DocumentListComponent, DocumentListService, FilterSearch } from '@alfresco/adf-content-services';
import { NodeActionsService } from '../../services/node-actions.service';
@ -44,6 +44,7 @@ describe('FilesComponent', () => {
let uploadService: UploadService;
let nodeActionsService: NodeActionsService;
let contentApi: ContentApiService;
let route: ActivatedRoute;
let router: any = {
url: '',
navigate: jasmine.createSpy('navigate')
@ -74,7 +75,7 @@ describe('FilesComponent', () => {
{
provide: ActivatedRoute,
useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } },
snapshot: { data: { preferencePrefix: 'prefix' }, paramMap: convertToParamMap({ folderId: undefined }) },
params: of({ folderId: 'someId' }),
queryParamMap: of({})
}
@ -94,6 +95,7 @@ describe('FilesComponent', () => {
uploadService = TestBed.inject(UploadService);
router = TestBed.inject(Router);
route = TestBed.get(ActivatedRoute);
nodeActionsService = TestBed.inject(NodeActionsService);
contentApi = TestBed.inject(ContentApiService);
spyContent = spyOn(contentApi, 'getNode');
@ -283,6 +285,7 @@ describe('FilesComponent', () => {
});
it('should navigate home if node is root also if it contain a uuid', () => {
spyOn(route.snapshot.paramMap, 'get').and.returnValue('some-node-id');
component.node = {
path: {
elements: [{ id: 'node-id' }]
@ -294,6 +297,21 @@ describe('FilesComponent', () => {
expect(router.navigate).toHaveBeenCalledWith(['personal-files']);
});
it('should navigate to sub folder from a parent folder', () => {
router.url = '/personal-files/parent-folder-node-id';
const childFolderNodeId = node.id;
spyOn(route.snapshot.paramMap, 'get').and.returnValue('parent-folder-node-id');
component.navigate(childFolderNodeId);
expect(router.navigate).toHaveBeenCalledWith(['personal-files', childFolderNodeId]);
});
it('should navigate to smart folder content', () => {
router.url = '/libraries/vH1-6-1-1-115wji7092f0-41-MTg%3D-1-115hpo76l3h2e1f';
spyOn(route.snapshot.paramMap, 'get').and.returnValue('vH1-6-1-1-115wji7092f0-41-MTg=-1-115hpo76l3h2e1f');
component.navigate(node.id);
expect(router.navigate).toHaveBeenCalledWith(['libraries', node.id]);
});
});
describe('isSiteContainer', () => {

View File

@ -123,29 +123,49 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
}
navigate(nodeId: string = null) {
const uuidRegEx = /[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-4[0-9A-Za-z]{3}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12}/gi;
let urlToNavigate: string[];
const urlWithoutParams = this.router.url.split('?')[0];
if (urlWithoutParams.match(uuidRegEx)) {
if (nodeId && !this.isRootNode(nodeId)) {
urlToNavigate = urlWithoutParams.replace(uuidRegEx, nodeId).split('/');
} else {
urlToNavigate = urlWithoutParams.replace(uuidRegEx, '').split('/');
urlToNavigate.pop();
}
urlToNavigate.shift();
} else {
urlToNavigate = urlWithoutParams.split('/');
if (nodeId && !this.isRootNode(nodeId)) {
urlToNavigate.push(nodeId);
}
urlToNavigate.shift();
}
const currentNodeId = this.route.snapshot.paramMap.get('folderId');
const urlWithoutParams = decodeURIComponent(this.router.url).split('?')[0];
const urlToNavigate: string[] = this.getUrlToNavigate(urlWithoutParams, currentNodeId, nodeId);
this.router.navigate(urlToNavigate);
}
private getUrlToNavigate(currentURL: string, currentNodeId: string, nextNodeId: string): string[] {
return currentNodeId ? this.getNextNodeUrlToNavigate(currentURL, currentNodeId, nextNodeId) : this.appendNextNodeIdToUrl(currentURL, nextNodeId);
}
private getNextNodeUrlToNavigate(currentURL: string, currentNodeId: string, nextNodeId: string): string[] {
const urlToNavigate: string[] =
nextNodeId && !this.isRootNode(nextNodeId)
? this.replaceCurrentNodeIdWithNextNodeId(currentURL, currentNodeId, nextNodeId)
: this.removeNodeIdFromUrl(currentURL, currentNodeId);
urlToNavigate.shift();
return urlToNavigate;
}
private replaceCurrentNodeIdWithNextNodeId(currentURL: string, currentNodeId: string, nextNodeId: string): string[] {
const nextNodeUrlToNavigate = currentURL.split('/');
const index = nextNodeUrlToNavigate.indexOf(currentNodeId);
if (index > 0) {
nextNodeUrlToNavigate[index] = nextNodeId;
}
return nextNodeUrlToNavigate;
}
private removeNodeIdFromUrl(currentURL: string, currentNodeId: string): string[] {
const rootUrl: string[] = currentURL.replace(currentNodeId, '').split('/');
rootUrl.pop();
return rootUrl;
}
private appendNextNodeIdToUrl(currentURL: string, nodeId: string): string[] {
const navigateToNodeUrl = currentURL.split('/');
if (nodeId && !this.isRootNode(nodeId)) {
navigateToNodeUrl.push(nodeId);
}
navigateToNodeUrl.shift();
return navigateToNodeUrl;
}
onUploadNewVersion(ev: CustomEvent) {
this.store.dispatch(new UploadFileVersionAction(ev));
}