mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[MNT-25732] Improvements to "Repository Access Feature" (#5241)
This commit is contained in:
@@ -89,7 +89,37 @@ describe('NodeEffects', () => {
|
||||
elements: [
|
||||
{
|
||||
id: 'mock-id-1',
|
||||
name: 'mock-name-1',
|
||||
name: 'Company Home',
|
||||
nodeType: 'mock-node-type'
|
||||
},
|
||||
{
|
||||
id: 'mock-id-2',
|
||||
name: 'User Homes',
|
||||
nodeType: 'mock-node-type'
|
||||
},
|
||||
{
|
||||
id: 'mock-id-3',
|
||||
name: 'mock-name-3',
|
||||
nodeType: 'mock-node-type'
|
||||
}
|
||||
]
|
||||
}
|
||||
} as Node;
|
||||
spyOn(router, 'navigate');
|
||||
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||
tick(10);
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id']);
|
||||
}));
|
||||
|
||||
it('should navigate to folder inside repository when path elements are not personal files nor libraries', fakeAsync(() => {
|
||||
const node = {
|
||||
id: 'mock-id',
|
||||
path: {
|
||||
name: 'mock-path-name',
|
||||
elements: [
|
||||
{
|
||||
id: 'mock-id-1',
|
||||
name: 'Company Home',
|
||||
nodeType: 'mock-node-type'
|
||||
},
|
||||
{
|
||||
@@ -108,7 +138,7 @@ describe('NodeEffects', () => {
|
||||
spyOn(router, 'navigate');
|
||||
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||
tick(10);
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id']);
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/repository', 'mock-id']);
|
||||
}));
|
||||
|
||||
it('should navigate to folder nested libraries when path elements are found and are inside libraries', fakeAsync(() => {
|
||||
@@ -197,7 +227,37 @@ describe('NodeEffects', () => {
|
||||
elements: [
|
||||
{
|
||||
id: 'mock-id-1',
|
||||
name: 'mock-name-1',
|
||||
name: 'Company Home',
|
||||
nodeType: 'mock-node-type'
|
||||
},
|
||||
{
|
||||
id: 'mock-id-2',
|
||||
name: 'User Homes',
|
||||
nodeType: 'mock-node-type'
|
||||
},
|
||||
{
|
||||
id: 'mock-id-3',
|
||||
name: 'mock-name-3',
|
||||
nodeType: 'mock-node-type'
|
||||
}
|
||||
]
|
||||
}
|
||||
} as Node;
|
||||
spyOn(router, 'navigate');
|
||||
store.dispatch(new NavigateToParentFolder({ entry: node }));
|
||||
tick(10);
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id-3']);
|
||||
}));
|
||||
|
||||
it('should navigate to parent folder inside repository when path elements are not personal files nor libraries', fakeAsync(() => {
|
||||
const node = {
|
||||
id: 'mock-id',
|
||||
path: {
|
||||
name: 'mock-path-name',
|
||||
elements: [
|
||||
{
|
||||
id: 'mock-id-1',
|
||||
name: 'Company Home',
|
||||
nodeType: 'mock-node-type'
|
||||
},
|
||||
{
|
||||
@@ -216,7 +276,7 @@ describe('NodeEffects', () => {
|
||||
spyOn(router, 'navigate');
|
||||
store.dispatch(new NavigateToParentFolder({ entry: node }));
|
||||
tick(10);
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id-3']);
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/repository', 'mock-id-3']);
|
||||
}));
|
||||
|
||||
it('should navigate to folder nested libraries when path elements are found and are inside libraries', fakeAsync(() => {
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
||||
import { Node, PathInfo } from '@alfresco/js-api';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Location } from '@angular/common';
|
||||
import { NavigateRouteAction, NavigateToFolder, NavigateToParentFolder, NavigateToPreviousPage, NavigateUrlAction } from '../actions/router.actions';
|
||||
import { RouterActionTypes } from '../actions/router-action-types';
|
||||
import { NotificationService } from '@alfresco/adf-core';
|
||||
import { getNodeContentSource } from '../utils/node-path.utils';
|
||||
|
||||
@Injectable()
|
||||
export class RouterEffects {
|
||||
@@ -103,10 +104,10 @@ export class RouterEffects {
|
||||
const { path, id } = node;
|
||||
|
||||
if (path?.name && path?.elements) {
|
||||
const isLibraryPath = this.isLibraryContent(path);
|
||||
const area = `/${getNodeContentSource(path)}`;
|
||||
const isLibraryPath = area === '/libraries';
|
||||
|
||||
const parent = path.elements[path.elements.length - 1];
|
||||
const area = isLibraryPath ? '/libraries' : '/personal-files';
|
||||
|
||||
if (!isLibraryPath) {
|
||||
link = [area, id];
|
||||
@@ -128,10 +129,10 @@ export class RouterEffects {
|
||||
const { path } = node;
|
||||
|
||||
if (path?.name && path?.elements) {
|
||||
const isLibraryPath = this.isLibraryContent(path);
|
||||
const area = `/${getNodeContentSource(path)}`;
|
||||
const isLibraryPath = area === '/libraries';
|
||||
|
||||
const parent = path.elements[path.elements.length - 1];
|
||||
const area = isLibraryPath ? '/libraries' : '/personal-files';
|
||||
|
||||
if (!isLibraryPath) {
|
||||
link = [area, parent.id];
|
||||
@@ -147,8 +148,4 @@ export class RouterEffects {
|
||||
this.notificationService.showError('APP.MESSAGES.ERRORS.CANNOT_NAVIGATE_LOCATION');
|
||||
}
|
||||
}
|
||||
|
||||
private isLibraryContent(path: PathInfo): boolean {
|
||||
return path && path.elements.length >= 2 && path.elements[1].name === 'Sites';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,3 +50,5 @@ export * from './models/modal-configuration';
|
||||
export * from './selectors/app.selectors';
|
||||
|
||||
export * from './states/app.state';
|
||||
|
||||
export * from './utils/node-path.utils';
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { PathInfo } from '@alfresco/js-api';
|
||||
import { getNodeContentSource } from './node-path.utils';
|
||||
|
||||
describe('getNodeContentSource', () => {
|
||||
it('should return [personal-files] when no path information is available', () => {
|
||||
expect(getNodeContentSource(undefined)).toBe('personal-files');
|
||||
expect(getNodeContentSource({} as PathInfo)).toBe('personal-files');
|
||||
expect(getNodeContentSource({ elements: [] } as PathInfo)).toBe('personal-files');
|
||||
});
|
||||
|
||||
it('should return [personal-files] when User Homes is the second path element', () => {
|
||||
const path = {
|
||||
name: '/Company Home/User Homes/user1',
|
||||
elements: [{ name: 'Company Home' }, { name: 'User Homes' }, { name: 'user1' }]
|
||||
} as PathInfo;
|
||||
expect(getNodeContentSource(path)).toBe('personal-files');
|
||||
});
|
||||
|
||||
it('should return [personal-files] when User Homes is present in the path name', () => {
|
||||
const path = { name: '/Company Home/User Homes/user1/folder', elements: [{ name: 'Company Home' }, { name: 'User Homes' }] } as PathInfo;
|
||||
expect(getNodeContentSource(path)).toBe('personal-files');
|
||||
});
|
||||
|
||||
it('should return [libraries] for a site path', () => {
|
||||
const path = { name: '/Company Home/Sites/my-site', elements: [{ name: 'Company Home' }, { name: 'Sites' }, { name: 'my-site' }] } as PathInfo;
|
||||
expect(getNodeContentSource(path)).toBe('libraries');
|
||||
});
|
||||
|
||||
it('should return [repository] when only the repository root is present', () => {
|
||||
const path = { name: '/Company Home', elements: [{ name: 'Company Home' }] } as PathInfo;
|
||||
expect(getNodeContentSource(path)).toBe('repository');
|
||||
});
|
||||
|
||||
it('should return [repository] for any other path nested under the repository root', () => {
|
||||
const path = { name: '/Company Home/Some Folder', elements: [{ name: 'Company Home' }, { name: 'Some Folder' }] } as PathInfo;
|
||||
expect(getNodeContentSource(path)).toBe('repository');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
/*!
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { PathInfo } from '@alfresco/js-api';
|
||||
|
||||
/**
|
||||
* The browsing area a node belongs to, derived from its primary path. The values match the
|
||||
* application routes (`/personal-files`, `/libraries`, `/repository`).
|
||||
*/
|
||||
export type NodeContentSource = 'personal-files' | 'libraries' | 'repository';
|
||||
|
||||
const PERSONAL_FILES_FOLDER = 'User Homes';
|
||||
const LIBRARIES_FOLDER = 'Sites';
|
||||
|
||||
/**
|
||||
* Resolves the browsing area of a node from its path. When no path information is available the default of
|
||||
* `personal-files` is kept.
|
||||
*
|
||||
* @param path path of the node
|
||||
* @returns The content source the node should be navigated to
|
||||
*/
|
||||
export function getNodeContentSource(path: PathInfo): NodeContentSource {
|
||||
const elements = path?.elements ?? [];
|
||||
|
||||
if (elements.length === 0) {
|
||||
return 'personal-files';
|
||||
}
|
||||
|
||||
if (elements[1]?.name === LIBRARIES_FOLDER) {
|
||||
return 'libraries';
|
||||
}
|
||||
|
||||
if (path?.name?.includes(PERSONAL_FILES_FOLDER) || elements[1]?.name === PERSONAL_FILES_FOLDER) {
|
||||
return 'personal-files';
|
||||
}
|
||||
|
||||
return 'repository';
|
||||
}
|
||||
Reference in New Issue
Block a user