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

[Serverless] Improve cases breadcrumbs in oblt project #169401

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function NavigationGroupInternalComp<
return null;
}

if (navNodeWithChildren.sideNavStatus === 'hidden') return null;

if (unstyled) {
// No UI for unstyled groups
return children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,129 @@ describe('<DefaultNavigation />', () => {
`);
});

test("shouldn't render hidden deeplink", async () => {
const navLinks$: Observable<ChromeNavLink[]> = of([
...navLinksMock,
{
id: 'item1',
title: 'Item 1',
baseUrl: '',
url: '',
href: '',
},
{
id: 'item',
title: 'Item 2',
hidden: true,
baseUrl: '',
url: '',
href: '',
},
]);

const onProjectNavigationChange = jest.fn();

const navigationBody: Array<RootNavigationItemDefinition<any>> = [
{
type: 'navGroup',
id: 'root',
children: [
{
id: 'group1',
children: [
{
id: 'item1',
link: 'item1',
},
{
id: 'item2',
link: 'item2', // this should be hidden from sidenav
},
],
},
],
},
];

const { queryByTestId } = render(
<NavigationProvider
{...services}
navLinks$={navLinks$}
onProjectNavigationChange={onProjectNavigationChange}
>
<DefaultNavigation navigationTree={{ body: navigationBody }} />
</NavigationProvider>
);

await act(async () => {
jest.advanceTimersByTime(SET_NAVIGATION_DELAY);
});

expect(onProjectNavigationChange).toHaveBeenCalled();
const lastCall =
onProjectNavigationChange.mock.calls[onProjectNavigationChange.mock.calls.length - 1];
const [navTreeGenerated] = lastCall;

expect(navTreeGenerated.navigationTree).toMatchInlineSnapshot(`
Array [
Object {
"children": Array [
Object {
"children": Array [
Object {
"children": undefined,
"deepLink": Object {
"baseUrl": "",
"href": "",
"id": "item1",
"title": "Item 1",
"url": "",
},
"href": undefined,
"id": "item1",
"isActive": false,
"isGroup": false,
"path": Array [
"root",
"group1",
"item1",
],
"sideNavStatus": "visible",
"title": "Item 1",
},
],
"deepLink": undefined,
"href": undefined,
"id": "group1",
"isActive": false,
"isGroup": true,
"path": Array [
"root",
"group1",
],
"sideNavStatus": "visible",
"title": "",
},
],
"deepLink": undefined,
"href": undefined,
"id": "root",
"isActive": false,
"isGroup": true,
"path": Array [
"root",
],
"sideNavStatus": "visible",
"title": "",
"type": "navGroup",
},
]
`);

expect(await queryByTestId(/nav-item-deepLinkId-item1/)).not.toBeNull();
expect(await queryByTestId(/nav-item-deepLinkId-item2/)).toBeNull();
});

test('should allow href for absolute links', async () => {
const onProjectNavigationChange = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getNodeStatus(
if (!hasUserAccessToCloudLink()) return 'remove';
}

if (deepLink && deepLink.hidden) return 'remove';
if (deepLink && deepLink.hidden) return 'hidden';
Copy link
Contributor Author

@Dosant Dosant Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebelga, the newly added

{
               link: 'observability-overview:cases_configure',
             },
             {
               link: 'observability-overview:cases_create',
             },

are used for the breadcrumbs, but their deep links are "hidden".

The fix I did is to keep such links in the navigation tree for the breadcrumbs, but filter them out when rendering the side nav to keep them hidden from the navigation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 👍


return sideNavStatus ?? 'visible';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ const navigationTree: NavigationTreeDefinition = {
},
{
link: 'observability-overview:cases',
renderAs: 'item',
children: [
{
link: 'observability-overview:cases_configure',
},
{
link: 'observability-overview:cases_create',
},
],
},
{
link: 'observability-overview:slos',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
const svlCommonPage = getPageObject('svlCommonPage');
const svlCommonNavigation = getPageObject('svlCommonNavigation');
const browser = getService('browser');
const testSubjects = getService('testSubjects');

describe('navigation', function () {
before(async () => {
Expand Down Expand Up @@ -100,6 +101,23 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
deepLinkId: 'observability-overview:cases',
});
expect(await browser.getCurrentUrl()).contain('/app/observability/cases');
await svlCommonNavigation.breadcrumbs.expectBreadcrumbTexts(['Cases']);

await testSubjects.click('createNewCaseBtn');
expect(await browser.getCurrentUrl()).contain('app/observability/cases/create');
await svlCommonNavigation.sidenav.expectLinkActive({
deepLinkId: 'observability-overview:cases',
});
await svlCommonNavigation.breadcrumbs.expectBreadcrumbTexts(['Cases', 'Create New Case']);

await svlCommonNavigation.sidenav.clickLink({ deepLinkId: 'observability-overview:cases' });

await testSubjects.click('configure-case-button');
expect(await browser.getCurrentUrl()).contain('app/observability/cases/configure');
await svlCommonNavigation.sidenav.expectLinkActive({
deepLinkId: 'observability-overview:cases',
});
await svlCommonNavigation.breadcrumbs.expectBreadcrumbTexts(['Cases', 'Configure Cases']);
});
});
}
Loading