Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent to open a node w/o children and empty viewUrl #2139

Merged
merged 6 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/src/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ class RoutingClass {
const pathUrlRaw = path && path.length ? GenericHelpers.getPathWithoutHash(path) : '';
const { nodeObject, pathData } = await Navigation.extractDataFromPath(path);
const viewUrl = nodeObject.viewUrl || '';
const hasChildrenNode = (nodeObject.children && nodeObject.children.length > 0) || false;
const intendToHaveEmptyViewUrl =
(nodeObject.intendToHaveEmptyViewUrl && nodeObject.intendToHaveEmptyViewUrl === true) || false;

if (viewUrl.trim() === '' && !hasChildrenNode && !intendToHaveEmptyViewUrl) {
console.warn('This node was configured an empty viewUrl. Please double check it.');

// redirect to root when this empty viewUrl node be reached directly
if (!previousCompData.viewUrl) {
const rootPathData = await Navigation.getNavigationPath(
LuigiConfig.getConfigValueAsync('navigation.nodes'),
'/'
);
const rootPath = await RoutingHelpers.getDefaultChildNode(rootPathData);
this.showPageNotFoundError(component, rootPath, pathUrlRaw);
this.navigateTo(rootPath);
}

return;
}

if (!viewUrl && !nodeObject.compound) {
const defaultChildNode = await RoutingHelpers.getDefaultChildNode(pathData, async (node, ctx) => {
Expand Down
3 changes: 3 additions & 0 deletions docs/navigation-parameters-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ Node parameters are all the parameters that can be added to an individual naviga
* dynamic path segments
* node parameters

### intendToHaveEmptyViewUrl
- **type**: boolean
- **description**: forces to navigate to the empty viewUrl node.
stanleychh marked this conversation as resolved.
Show resolved Hide resolved
### navigationContext
- **type**: string
- **description**: contains a named node that is mainly for use in combination with a dynamic **pathSegment** to start navigation from a dynamic node using ` LuigiClient.linkManager().fromContext('contextname')`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,29 @@ describe('Navigation', () => {
.should('be.visible');
});
});

it('Side nav does not broken while clicking empty viewUrl node', () => {
cy.get('.fd-shellbar')
.contains('Projects')
.click();

cy.get('.fd-app__sidebar .fd-nested-list__item')
.contains('Project One')
.click();

cy.get('.fd-side-nav')
.contains('Empty viewUrl node')
.click();

cy.get('.fd-side-nav').should('contain', 'Empty viewUrl node');
});

it('Redirect to root path while reaching empty viewUrl node directly', () => {
cy.visit('/projects/pr2/emptyViewUrl');

cy.get('[data-testid=luigi-alert]').should('have.class', 'fd-message-strip--error');
cy.expectPathToBe('/overview');
});
});

describe('Node activation hook', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ export const projectDetailNavStructure = projectId => [
hideSideNav: true,
icon: 'full-screen'
},
{
pathSegment: 'emptyViewUrl',
label: 'Empty viewUrl node',
viewUrl: ''
},
{
pathSegment: 'virtual-tree',
label: 'VirtualTree',
Expand Down