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

[navigation] Add workspace icon to left nav / workspace picker menu / home page. #7823

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6ed3b51
feat: show workspace picker content in left nav
SuZhou-Joe Aug 16, 2024
f320ab4
fix: bootstrap error
SuZhou-Joe Aug 16, 2024
9b4cd49
fix: unit test error
SuZhou-Joe Aug 16, 2024
d914b00
feat: finish picker content
SuZhou-Joe Aug 16, 2024
78a2e03
feat: finish picker content
SuZhou-Joe Aug 16, 2024
c06c63d
feat: only register index patterns to settings and setup when workspa…
SuZhou-Joe Aug 16, 2024
e13f81a
fix: unit test
SuZhou-Joe Aug 19, 2024
cf1efbb
feat: put discover 2.0 behind discover
SuZhou-Joe Aug 19, 2024
346171e
feat: add coverage
SuZhou-Joe Aug 21, 2024
584ab22
feat: improve test coverage
SuZhou-Joe Aug 21, 2024
d8e0c5e
feat: merge
SuZhou-Joe Aug 22, 2024
dd99295
feat: merge conflict
SuZhou-Joe Aug 22, 2024
e6ed00c
feat: optimize code based on comment
SuZhou-Joe Aug 23, 2024
83fa36d
feat: merge
SuZhou-Joe Aug 23, 2024
65126b5
Merge branch 'main' into feature/display-workspace-picker-content
SuZhou-Joe Aug 24, 2024
68a56ec
feat: merge
SuZhou-Joe Aug 27, 2024
0e5a883
feat: optimize code based on comment
SuZhou-Joe Aug 27, 2024
2a2672a
feat: optimize filter code
SuZhou-Joe Aug 27, 2024
26dd50b
feat: merge
SuZhou-Joe Aug 27, 2024
3096bea
feat: update
SuZhou-Joe Aug 27, 2024
c1e028e
feat: add new icon to left navigation and workspace picker menu
SuZhou-Joe Aug 23, 2024
cd775ec
feat: change use case card in home
SuZhou-Joe Aug 23, 2024
b8e4072
feat: merge
SuZhou-Joe Aug 28, 2024
8a6c907
feat: optimize alignment
SuZhou-Joe Aug 28, 2024
1d55add
Changeset file for PR #7823 created/updated
opensearch-changeset-bot[bot] Aug 28, 2024
d689957
feat: alignment optimize
SuZhou-Joe Aug 28, 2024
7bc3d80
feat: use new icons in workspace picker
SuZhou-Joe Aug 28, 2024
51f8ce9
feat: optimize color
SuZhou-Joe Aug 28, 2024
d2fe953
fix: unit test error
SuZhou-Joe Aug 28, 2024
1a32aaf
fix: unit test
SuZhou-Joe Aug 28, 2024
eacae53
fix: unit test
SuZhou-Joe Aug 28, 2024
2e69181
feat: increase test coverage
SuZhou-Joe Aug 28, 2024
ed8499d
feat: remove useless code
SuZhou-Joe Sep 2, 2024
d5a7b4f
Merge branch 'main' into feature/add-workspace-icon
SuZhou-Joe Sep 2, 2024
9bd3052
Add workspace icon in workspace creator (#19)
wanglam Sep 2, 2024
f6edf1c
feat: merge
SuZhou-Joe Sep 3, 2024
85a7d3a
fix: fatal error when visibleUseCases is empty
SuZhou-Joe Sep 3, 2024
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
2 changes: 2 additions & 0 deletions changelogs/fragments/7823.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add workspace icon to left nav / workspace picker menu / home page. ([#7823](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7823))
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ export function CollapsibleNavGroupEnabled({
const appId = useObservable(observables.appId$, '');
const navGroupsMap = useObservable(observables.navGroupsMap$, {});
const currentNavGroup = useObservable(observables.currentNavGroup$, undefined);
const firstVisibleNavLinkOfAllUseCase = useMemo(
() =>
fulfillRegistrationLinksToChromeNavLinks(
navGroupsMap[ALL_USE_CASE_ID]?.navLinks || [],
navLinks
)[0],
[navGroupsMap, navLinks]
);

const visibleUseCases = useMemo(() => getVisibleUseCases(navGroupsMap), [navGroupsMap]);

Expand Down Expand Up @@ -303,7 +295,8 @@ export function CollapsibleNavGroupEnabled({
>
<CollapsibleNavTop
homeLink={homeLink}
firstVisibleNavLinkOfAllUseCase={firstVisibleNavLinkOfAllUseCase}
navGroupsMap={navGroupsMap}
navLinks={navLinks}
navigateToApp={navigateToApp}
logos={logos}
setCurrentNavGroup={setCurrentNavGroup}
Expand All @@ -326,7 +319,7 @@ export function CollapsibleNavGroupEnabled({
{shouldShowCollapsedNavHeaderContent && collapsibleNavHeaderRender ? (
<>
{collapsibleNavHeaderRender()}
<EuiSpacer size="l" />
<EuiSpacer />
</>
) : null}
<NavGroups
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.leftNavTopIcon {
color: $euiColorMediumShade;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { ChromeNavLink } from '../../nav_links';
import { ChromeRegistrationNavLink } from '../../nav_group';
import { httpServiceMock } from '../../../mocks';
import { getLogos } from '../../../../common';
import { CollapsibleNavTop } from './collapsible_nav_group_enabled_top';
import { CollapsibleNavTop, CollapsibleNavTopProps } from './collapsible_nav_group_enabled_top';
import { BehaviorSubject } from 'rxjs';
import { WorkspaceObject } from 'src/core/public/workspace';
import { ALL_USE_CASE_ID } from '../../../';
import { ALL_USE_CASE_ID, DEFAULT_NAV_GROUPS } from '../../../';

const mockBasePath = httpServiceMock.createSetupContract({ basePath: '/test' }).basePath;

Expand All @@ -33,44 +33,66 @@ describe('<CollapsibleNavTop />', () => {
logos: getLogos({}, mockBasePath.serverBasePath),
shouldShrinkNavigation: false,
visibleUseCases: [],
navGroupsMap: {},
navLinks: [],
currentWorkspace$: new BehaviorSubject<WorkspaceObject | null>(null),
setCurrentNavGroup: jest.fn(),
};
};

it('should render back icon when inside a workspace of all use case', async () => {
const props = {
const props: CollapsibleNavTopProps = {
...getMockedProps(),
currentWorkspace$: new BehaviorSubject<WorkspaceObject | null>({ id: 'foo', name: 'foo' }),
visibleUseCases: [
{
id: ALL_USE_CASE_ID,
...DEFAULT_NAV_GROUPS.all,
title: 'navGroupFoo',
description: 'navGroupFoo',
navLinks: [],
navLinks: [
{
id: 'firstVisibleNavLinkOfAllUseCase',
},
],
},
],
navGroupsMap: {
[DEFAULT_NAV_GROUPS.all.id]: {
...DEFAULT_NAV_GROUPS.all,
title: 'navGroupFoo',
description: 'navGroupFoo',
navLinks: [
{
id: 'firstVisibleNavLinkOfAllUseCase',
},
],
},
},
navLinks: [
getMockedNavLink({
id: 'firstVisibleNavLinkOfAllUseCase',
}),
],
currentNavGroup: {
id: 'navGroupFoo',
title: 'navGroupFoo',
description: 'navGroupFoo',
navLinks: [],
},
firstVisibleNavLinkOfAllUseCase: getMockedNavLink({
id: 'firstVisibleNavLinkOfAllUseCase',
}),
};
const { findByTestId, findByText, getByTestId } = render(<CollapsibleNavTop {...props} />);
await findByTestId('collapsibleNavBackButton');
await findByText('Back');
fireEvent.click(getByTestId('collapsibleNavBackButton'));
const { findByTestId, getByTestId } = render(<CollapsibleNavTop {...props} />);
await findByTestId(`collapsibleNavIcon-${DEFAULT_NAV_GROUPS.all.icon}`);
fireEvent.click(getByTestId(`collapsibleNavIcon-${DEFAULT_NAV_GROUPS.all.icon}`));
expect(props.navigateToApp).toBeCalledWith('firstVisibleNavLinkOfAllUseCase');
expect(props.setCurrentNavGroup).toBeCalledWith(ALL_USE_CASE_ID);
});

it('should render home icon when not in a workspace', async () => {
const { findByTestId } = render(<CollapsibleNavTop {...getMockedProps()} />);
const props = getMockedProps();
const { findByTestId, getByTestId } = render(<CollapsibleNavTop {...props} />);
await findByTestId('collapsibleNavHome');
fireEvent.click(getByTestId('collapsibleNavHome'));
expect(props.navigateToApp).toBeCalledWith('home');
});

it('should render expand icon when collapsed', async () => {
Expand All @@ -79,4 +101,18 @@ describe('<CollapsibleNavTop />', () => {
);
await findByTestId('collapsibleNavShrinkButton');
});

it('should render successfully without error when visibleUseCases is empty but inside a workspace', async () => {
expect(() =>
render(
<CollapsibleNavTop
{...getMockedProps()}
currentWorkspace$={
new BehaviorSubject<WorkspaceObject | null>({ id: 'foo', name: 'bar' })
}
shouldShrinkNavigation
/>
)
).not.toThrow();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Logos, WorkspacesStart } from 'opensearch-dashboards/public';
import {
Expand All @@ -12,19 +12,21 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiPanel,
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { InternalApplicationStart } from 'src/core/public/application';
import { i18n } from '@osd/i18n';
import { createEuiListItem } from './nav_link';
import { ChromeNavGroupServiceStartContract, NavGroupItemInMap } from '../../nav_group';
import { ChromeNavLink } from '../../nav_links';
import { ALL_USE_CASE_ID } from '../../../../../core/utils';
import { fulfillRegistrationLinksToChromeNavLinks } from '../../utils';
import './collapsible_nav_group_enabled_top.scss';

export interface CollapsibleNavTopProps {
homeLink?: ChromeNavLink;
firstVisibleNavLinkOfAllUseCase?: ChromeNavLink;
navGroupsMap: Record<string, NavGroupItemInMap>;
currentNavGroup?: NavGroupItemInMap;
navigateToApp: InternalApplicationStart['navigateToApp'];
logos: Logos;
Expand All @@ -33,6 +35,7 @@ export interface CollapsibleNavTopProps {
visibleUseCases: NavGroupItemInMap[];
currentWorkspace$: WorkspacesStart['currentWorkspace$'];
setCurrentNavGroup: ChromeNavGroupServiceStartContract['setCurrentNavGroup'];
navLinks: ChromeNavLink[];
}

export const CollapsibleNavTop = ({
Expand All @@ -45,10 +48,20 @@ export const CollapsibleNavTop = ({
currentWorkspace$,
setCurrentNavGroup,
homeLink,
firstVisibleNavLinkOfAllUseCase,
navGroupsMap,
navLinks,
}: CollapsibleNavTopProps) => {
const currentWorkspace = useObservable(currentWorkspace$);

const firstVisibleNavLinkInFirstVisibleUseCase = useMemo(
() =>
fulfillRegistrationLinksToChromeNavLinks(
navGroupsMap[visibleUseCases[0]?.id]?.navLinks || [],
navLinks
)[0],
[navGroupsMap, navLinks, visibleUseCases]
);

/**
* We can ensure that left nav is inside second level once all the following conditions are met:
* 1. Inside a workspace
Expand All @@ -57,9 +70,15 @@ export const CollapsibleNavTop = ({
*/
const isInsideSecondLevelOfAllWorkspace =
!!currentWorkspace &&
visibleUseCases[0].id === ALL_USE_CASE_ID &&
visibleUseCases[0]?.id === ALL_USE_CASE_ID &&
currentNavGroup?.id !== ALL_USE_CASE_ID;

const homeIcon = logos.Mark.url;
const icon =
!!currentWorkspace && visibleUseCases.length === 1
? visibleUseCases[0].icon || homeIcon
: homeIcon;

const shouldShowBackButton = !shouldShrinkNavigation && isInsideSecondLevelOfAllWorkspace;
const shouldShowHomeLink = !shouldShrinkNavigation && !shouldShowBackButton;

Expand All @@ -74,47 +93,55 @@ export const CollapsibleNavTop = ({
return {
'data-test-subj': propsForHomeIcon['data-test-subj'],
onClick: propsForHomeIcon.onClick,
href: propsForHomeIcon.href,
};
}

return {};
}, [homeLink, navigateToApp]);

const onIconClick = useCallback(
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
if (shouldShowBackButton || visibleUseCases.length === 1) {
if (firstVisibleNavLinkInFirstVisibleUseCase) {
navigateToApp(firstVisibleNavLinkInFirstVisibleUseCase.id);
}

setCurrentNavGroup(visibleUseCases[0].id);
} else if (shouldShowHomeLink) {
homeLinkProps.onClick?.(e);
}
},
[
homeLinkProps,
shouldShowBackButton,
firstVisibleNavLinkInFirstVisibleUseCase,
navigateToApp,
setCurrentNavGroup,
visibleUseCases,
shouldShowHomeLink,
]
);

return (
<div>
<EuiPanel hasBorder={false} hasShadow={false}>
<EuiFlexGroup responsive={false} alignItems="center" justifyContent="spaceBetween">
{shouldShowHomeLink ? (
<EuiFlexItem grow={false}>
<EuiButtonEmpty size="l" {...homeLinkProps}>
<EuiIcon type={logos.Mark.url} size="l" />
</EuiButtonEmpty>
</EuiFlexItem>
) : null}
{shouldShowBackButton ? (
{!shouldShrinkNavigation ? (
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="l"
onClick={() => {
if (firstVisibleNavLinkOfAllUseCase) {
navigateToApp(firstVisibleNavLinkOfAllUseCase.id);
}
setCurrentNavGroup(ALL_USE_CASE_ID);
}}
data-test-subj="collapsibleNavBackButton"
>
<EuiIcon type="arrowLeft" />
{i18n.translate('core.ui.primaryNav.backButtonLabel', {
defaultMessage: 'Back',
})}
<EuiButtonEmpty flush="both" {...homeLinkProps} onClick={onIconClick}>
<EuiIcon
type={icon}
size="l"
className="leftNavTopIcon"
data-test-subj={`collapsibleNavIcon-${icon}`}
/>
</EuiButtonEmpty>
</EuiFlexItem>
) : null}
<EuiFlexItem grow={false}>
<EuiButtonIcon
onClick={onClickShrink}
iconType={shouldShrinkNavigation ? 'menu' : 'menuLeft'}
color="text"
color="subdued"
display={shouldShrinkNavigation ? 'empty' : 'base'}
aria-label="shrink-button"
data-test-subj="collapsibleNavShrinkButton"
Expand All @@ -124,13 +151,9 @@ export const CollapsibleNavTop = ({
{currentNavGroup?.title && (
<>
<EuiSpacer />
<EuiText>
<div className="nav-link-item" style={{ fontWeight: 'normal' }}>
{currentNavGroup?.title}
</div>
</EuiText>
<EuiText>{currentNavGroup?.title}</EuiText>
</>
)}
</div>
</EuiPanel>
);
};
4 changes: 2 additions & 2 deletions src/plugins/content_management/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import { ContentManagementPluginSetup, ContentManagementPluginStart } from './types';

const createStartContract = (): ContentManagementPluginStart => {
const createStartContract = (): jest.Mocked<ContentManagementPluginStart> => {
return {
registerContentProvider: jest.fn(),
renderPage: jest.fn(),
updatePageSection: jest.fn(),
};
};

const createSetupContract = (): ContentManagementPluginSetup => {
const createSetupContract = (): jest.Mocked<ContentManagementPluginSetup> => {
return {
registerPage: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.homeGettingStartedWorkspaceCardsIcon {
color: $euiColorMediumShade;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { WorkspaceUseCase } from '../../types';
import { getFirstUseCaseOfFeatureConfigs, getUseCaseUrl } from '../../utils';
import { UseCaseCardTitle } from './use_case_card_title';
import './setup_get_start_card.scss';

const createContentCard = (useCase: WorkspaceUseCase, core: CoreStart) => {
const { workspaces, application, http } = core;
Expand Down Expand Up @@ -66,7 +67,12 @@
order: (index + 1) * 1000,
description: useCase.description,
...content,
getIcon: () => React.createElement(EuiIcon, { size: 'xl', type: 'logoOpenSearch' }),
getIcon: () =>
React.createElement(EuiIcon, {

Check warning on line 71 in src/plugins/workspace/public/components/home_get_start_card/setup_get_start_card.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/home_get_start_card/setup_get_start_card.tsx#L71

Added line #L71 was not covered by tests
size: 'xl',
type: useCase.icon || 'logoOpenSearch',
className: 'homeGettingStartedWorkspaceCardsIcon',
}),
cardProps: {
layout: 'horizontal',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.analyticsGettingStartedWorkspaceCardsIcon {
color: $euiColorMediumShade;
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { getStartedCards } from './get_started_cards';
import { DEFAULT_NAV_GROUPS } from '../../../../../core/public';
import { Content } from '../../../../../plugins/content_management/public';
import './setup_overview.scss';

const recentlyViewSectionRender = (contents: Content[]) => {
return (
Expand Down Expand Up @@ -133,7 +134,11 @@
id: card.id,
kind: 'card',
getIcon: () =>
React.createElement(EuiIcon, { size: 'xl', type: card.icon || 'wsSelector' }),
React.createElement(EuiIcon, {

Check warning on line 137 in src/plugins/workspace/public/components/use_case_overview/setup_overview.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/use_case_overview/setup_overview.tsx#L137

Added line #L137 was not covered by tests
size: 'xl',
type: card.icon || 'wsSelector',
className: 'analyticsGettingStartedWorkspaceCardsIcon',
}),
order: card.order || index,
description: card.description,
title: card.title,
Expand Down
Loading
Loading