Skip to content

Commit

Permalink
[navigation] Left navigation collective (#7655) (#7728)
Browse files Browse the repository at this point in the history
* feat: change nav groups

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* Changeset file for PR #7655 created/updated

* feat: move visualizations to all use case

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: change the scrollable area

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: register manage workspace category when in a workspace

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: register index patterns to settings and setup

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: show correct icon in top

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: use gap to replace margin

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: make new left nav work in mobile mode

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: bootstrap error

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: unit test error

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: justify content

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: unit test

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: unit test

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: add descriptions to core features

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: add description to index pattern

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: use smaller font size in left nav

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: append navLinks inside second level to custom category if no  entry for the nav group

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: some optimize

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: fix unit test

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: filter all use case

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* fix: unit test

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 6877bea)
  • Loading branch information
SuZhou-Joe committed Aug 19, 2024
1 parent 1e5addb commit 4a7375b
Show file tree
Hide file tree
Showing 25 changed files with 703 additions and 598 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7655.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [navigation] Left navigation collective ([#7655](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7655))
1 change: 1 addition & 0 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ export class ChromeService {
navGroupsMap$={navGroup.getNavGroupsMap$()}
setCurrentNavGroup={navGroup.setCurrentNavGroup}
workspaceList$={workspaces.workspaceList$}
currentWorkspace$={workspaces.currentWorkspace$}
useUpdatedHeader={this.useUpdatedHeader}
/>
),
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
border-right: $euiBorderThin;
}

.scrollable-container {
.flex-1-container {
flex: 1;
}

Expand All @@ -66,14 +66,19 @@
&.bottom-container-collapsed {
flex-direction: column;
align-items: center;
gap: $euiSize;
padding-top: $euiSizeS;
padding-bottom: $euiSizeS;

> * {
margin: $euiSizeS 0;
justify-content: center;
}
}
}

.nav-controls-padding {
padding: $euiSize;
&.bottom-container-expanded {
gap: 16px;
padding-top: $euiSize;
padding-bottom: $euiSize;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ import { ChromeNavLink } from '../../nav_links';
import { ChromeRegistrationNavLink, NavGroupItemInMap } from '../../nav_group';
import { httpServiceMock } from '../../../mocks';
import { getLogos } from '../../../../common';
import { ALL_USE_CASE_ID, DEFAULT_NAV_GROUPS } from '../../../../public';
import { CollapsibleNavTopProps } from './collapsible_nav_group_enabled_top';
import { ALL_USE_CASE_ID, DEFAULT_NAV_GROUPS, WorkspaceObject } from '../../../../public';
import { capabilitiesServiceMock } from '../../../application/capabilities/capabilities_service.mock';

jest.mock('./collapsible_nav_group_enabled_top', () => ({
CollapsibleNavTop: (props: CollapsibleNavTopProps) => (
<button data-test-subj="back" onClick={props.onClickBack}>
go back
</button>
),
CollapsibleNavTop: () => <button data-test-subj="back">go back</button>,
}));

const mockBasePath = httpServiceMock.createSetupContract({ basePath: '/test' }).basePath;
Expand Down Expand Up @@ -99,6 +94,28 @@ describe('<NavGroups />', () => {
});
});

const defaultNavGroupMap = {
[ALL_USE_CASE_ID]: {
...DEFAULT_NAV_GROUPS[ALL_USE_CASE_ID],
navLinks: [
{
id: 'link-in-all',
title: 'link-in-all',
},
],
},
[DEFAULT_NAV_GROUPS.observability.id]: {
...DEFAULT_NAV_GROUPS.observability,
navLinks: [
{
id: 'link-in-observability',
title: 'link-in-observability',
showInAllNavGroup: true,
},
],
},
};

describe('<CollapsibleNavGroupEnabled />', () => {
function mockProps(
props?: Partial<CollapsibleNavGroupEnabledProps> & {
Expand All @@ -107,28 +124,9 @@ describe('<CollapsibleNavGroupEnabled />', () => {
navLinks?: ChromeNavLink[];
}
): CollapsibleNavGroupEnabledProps {
const navGroupsMap$ = new BehaviorSubject<Record<string, NavGroupItemInMap>>({
[ALL_USE_CASE_ID]: {
...DEFAULT_NAV_GROUPS[ALL_USE_CASE_ID],
navLinks: [
{
id: 'link-in-all',
title: 'link-in-all',
},
],
},
[DEFAULT_NAV_GROUPS.observability.id]: {
...DEFAULT_NAV_GROUPS.observability,
navLinks: [
{
id: 'link-in-observability',
title: 'link-in-observability',
showInAllNavGroup: true,
},
],
},
...props?.navGroupsMap,
});
const navGroupsMap$ = new BehaviorSubject<Record<string, NavGroupItemInMap>>(
props?.navGroupsMap || defaultNavGroupMap
);
const currentNavGroup$ = new BehaviorSubject<NavGroupItemInMap | undefined>(
props?.currentNavGroupId ? navGroupsMap$.getValue()[props.currentNavGroupId] : undefined
);
Expand All @@ -138,6 +136,7 @@ describe('<CollapsibleNavGroupEnabled />', () => {
id: 'collapsibe-nav',
isLocked: false,
isNavOpen: false,
currentWorkspace$: new BehaviorSubject<WorkspaceObject | null>({ id: 'test', name: 'test' }),
navLinks$: new BehaviorSubject([
{
id: 'link-in-all',
Expand Down Expand Up @@ -187,6 +186,7 @@ describe('<CollapsibleNavGroupEnabled />', () => {
const props = mockProps({
isNavOpen: true,
navGroupsMap: {
...defaultNavGroupMap,
[DEFAULT_NAV_GROUPS.essentials.id]: {
...DEFAULT_NAV_GROUPS.essentials,
navLinks: [
Expand All @@ -208,14 +208,20 @@ describe('<CollapsibleNavGroupEnabled />', () => {
});

it('should render correctly when only one visible use case is provided', () => {
const props = mockProps();
const props = mockProps({
navGroupsMap: {
[DEFAULT_NAV_GROUPS.observability.id]:
defaultNavGroupMap[DEFAULT_NAV_GROUPS.observability.id],
},
});
const { getAllByTestId } = render(<CollapsibleNavGroupEnabled {...props} isNavOpen />);
expect(getAllByTestId('collapsibleNavAppLink-link-in-observability').length).toEqual(1);
});

it('should show all use case by default and able to click see all', async () => {
const props = mockProps({
navGroupsMap: {
...defaultNavGroupMap,
[DEFAULT_NAV_GROUPS.essentials.id]: {
...DEFAULT_NAV_GROUPS.essentials,
navLinks: [
Expand All @@ -228,20 +234,19 @@ describe('<CollapsibleNavGroupEnabled />', () => {
},
},
});
const { container, getAllByTestId, getByTestId } = render(
const { container, getAllByTestId } = render(
<CollapsibleNavGroupEnabled {...props} isNavOpen />
);
fireEvent.click(getAllByTestId('collapsibleNavAppLink-link-in-essentials')[1]);
expect(getAllByTestId('collapsibleNavAppLink-link-in-essentials').length).toEqual(1);
expect(container).toMatchSnapshot();
fireEvent.click(getByTestId('back'));
expect(getAllByTestId('collapsibleNavAppLink-link-in-essentials').length).toEqual(2);
});

it('should show all use case when current nav group is `all`', async () => {
const props = mockProps({
currentNavGroupId: ALL_USE_CASE_ID,
navGroupsMap: {
...defaultNavGroupMap,
[DEFAULT_NAV_GROUPS.essentials.id]: {
...DEFAULT_NAV_GROUPS.essentials,
navLinks: [
Expand All @@ -254,20 +259,19 @@ describe('<CollapsibleNavGroupEnabled />', () => {
},
},
});
const { container, getAllByTestId, getByTestId } = render(
const { container, getAllByTestId } = render(
<CollapsibleNavGroupEnabled {...props} isNavOpen />
);
fireEvent.click(getAllByTestId('collapsibleNavAppLink-link-in-essentials')[1]);
expect(getAllByTestId('collapsibleNavAppLink-link-in-essentials').length).toEqual(1);
expect(container).toMatchSnapshot();
fireEvent.click(getByTestId('back'));
expect(getAllByTestId('collapsibleNavAppLink-link-in-essentials').length).toEqual(2);
});

it('should not show group if the nav link is hidden', async () => {
const props = mockProps({
currentNavGroupId: ALL_USE_CASE_ID,
navGroupsMap: {
...defaultNavGroupMap,
[DEFAULT_NAV_GROUPS.essentials.id]: {
...DEFAULT_NAV_GROUPS.essentials,
navLinks: [
Expand Down Expand Up @@ -295,4 +299,47 @@ describe('<CollapsibleNavGroupEnabled />', () => {
);
expect(queryAllByTestId('collapsibleNavAppLink-link-in-all').length).toEqual(1);
});

it('should show links with custom category if the nav link is inside second level but no entry in all use case', async () => {
const props = mockProps({
currentNavGroupId: ALL_USE_CASE_ID,
navGroupsMap: {
...defaultNavGroupMap,
[DEFAULT_NAV_GROUPS.essentials.id]: {
...DEFAULT_NAV_GROUPS.essentials,
navLinks: [
{
id: 'link-in-essentials',
title: 'link-in-essentials',
},
{
id: 'link-in-all',
title: 'link-in-all',
},
],
},
},
navLinks: [
{
id: 'link-in-essentials',
title: 'link-in-essentials',
baseUrl: '',
href: '',
},
{
id: 'link-in-all',
title: 'link-in-all',
baseUrl: '',
href: '',
},
],
});
const { queryAllByTestId, getByText, getByTestId } = render(
<CollapsibleNavGroupEnabled {...props} isNavOpen />
);
// Should render custom category
expect(getByText('Custom')).toBeInTheDocument();
expect(getByTestId('collapsibleNavAppLink-link-in-essentials')).toBeInTheDocument();
expect(queryAllByTestId('collapsibleNavAppLink-link-in-all').length).toEqual(1);
});
});
Loading

0 comments on commit 4a7375b

Please sign in to comment.