Skip to content

Commit

Permalink
Fix top nav children not rendered (#3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Jun 4, 2024
1 parent b6630bd commit ac64b47
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, OnDestroy } from '@angular/core';
import { ActivatedRouteSnapshot, NavigationEnd, ParamMap, Router, RouterEvent, convertToParamMap } from '@angular/router';
import { linkManager, uxManager } from '@luigi-project/client';
import { linkManager, uxManager, isLuigiClientInitialized } from '@luigi-project/client';
import { OperatorFunction, Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
import { LuigiActivatedRouteSnapshotHelper } from '../route/luigi-activated-route-snapshot-helper';
Expand Down Expand Up @@ -63,7 +63,7 @@ export class LuigiAutoRoutingService implements OnDestroy {
}
}
}
if (current?.data) {
if (current?.data && isLuigiClientInitialized()) {
const ux = uxManager();
let lm = linkManager().withoutSync();
let route: string | undefined;
Expand Down Expand Up @@ -130,7 +130,7 @@ export class LuigiAutoRoutingService implements OnDestroy {

getAllParamsFromParents(current: ActivatedRouteSnapshot): { [key: string]: string } | undefined {
let allParams: { [key: string]: string } = {};
let currentToCheck:ActivatedRouteSnapshot|null = current;
let currentToCheck: ActivatedRouteSnapshot | null = current;

while (currentToCheck) {
if (currentToCheck.params) {
Expand Down
3 changes: 1 addition & 2 deletions client/src/linkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ export class linkManager extends LuigiClientBase {
* LuigiClient.linkManager().fromClosestContext().navigate('/users/groups/stakeholders')
*/
fromClosestContext() {
const hasParentNavigationContext =
this.currentContext && this.currentContext.context.parentNavigationContexts.length > 0;
const hasParentNavigationContext = this.currentContext?.context.parentNavigationContexts.length > 0;
if (hasParentNavigationContext) {
this.options.fromContext = null;
this.options.fromClosestContext = true;
Expand Down
3 changes: 1 addition & 2 deletions core/src/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ class RoutingClass {
this.navigateTo(`${trimmedPathUrl ? `/${trimmedPathUrl}` : ''}/${defaultChildNode}`, {
keepBrowserHistory: false
});
// reset comp data
component.set({ navigationPath: [] });
return false;
} else {
if (defaultChildNode && pathData.navigationPath.length > 1) {
//last path segment was invalid but a default node could be in its place
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,32 @@ describe('JS-TEST-APP', () => {
});
});
});

describe('First topNav node has no viewURL and empty children', () => {
let newConfig;
beforeEach(() => {
newConfig = structuredClone(defaultLuigiConfig);
newConfig.navigation.nodes.unshift({
pathSegment: 'firstnode',
label: 'First Node',
children: []
});
});
it('TopNav nodes should be visible either first node has no view', () => {
cy.visitTestAppLoggedIn('/', newConfig);
cy.expectPathToBe('/firstnode/');
cy.get('.fd-app__sidebar .fd-nested-list')
.children()
.should('have.length', 0);
cy.get('.fd-shellbar').contains('First Node');
cy.get('.fd-shellbar')
.contains('Home')
.click();
cy.expectPathToBe('/home');
cy.get('.fd-app__sidebar .fd-nested-list')
.children()
.should('have.length', 2);
cy.get('.fd-app__sidebar').contains('Section one');
});
});
});

0 comments on commit ac64b47

Please sign in to comment.