Skip to content

Commit f0860c4

Browse files
opensearch-trigger-bot[bot]github-actions[bot]SuZhou-Joeruanyl
committed
[workspace]feat/add workspace selector to left nav bar. (opensearch-project#8364) (opensearch-project#8418)
* feat/add_workspace_selector * Add_workspace_selector_to_left_nav, adjust style * Add_workspace_selector_to_left_nav, adjust styles * Add_workspace_selector_to_left_nav, keep the origin width of nav bar * Add_workspace_selector_to_left_nav, keep the origin width of nav bar, and adjust width * fix/the_UI_of_recent_assets, resolve comments * fix/the_UI_of_recent_assets, add tests * fix/the_UI_of_recent_assets, set scss * fix/the_UI_of_recent_assets, resolve conflicts * fix/the_UI_of_recent_assets, delete workspace list * feat: show nav group when not in a workspace * feat: format scss file * feat: optimize code * Update src/plugins/workspace/public/components/workspace_menu/workspace_menu.tsx * fix: unit test --------- (cherry picked from commit 0831c99) Signed-off-by: Qxisylolo <[email protected]> Signed-off-by: SuZhou-Joe <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: SuZhou-Joe <[email protected]> Co-authored-by: Yulong Ruan <[email protected]>
1 parent 9b57f0c commit f0860c4

File tree

10 files changed

+722
-207
lines changed

10 files changed

+722
-207
lines changed

src/core/public/chrome/ui/header/collapsible_nav_group_enabled.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
EuiFlyout,
99
EuiPanel,
1010
EuiHorizontalRule,
11-
EuiSpacer,
1211
EuiHideFor,
1312
EuiFlyoutProps,
1413
EuiShowFor,
@@ -79,6 +78,7 @@ export function CollapsibleNavGroupEnabled({
7978
id,
8079
isNavOpen,
8180
storage = window.localStorage,
81+
currentWorkspace$,
8282
closeNav,
8383
navigateToApp,
8484
navigateToUrl,
@@ -94,7 +94,6 @@ export function CollapsibleNavGroupEnabled({
9494
const appId = useObservable(observables.appId$, '');
9595
const navGroupsMap = useObservable(observables.navGroupsMap$, {});
9696
const currentNavGroup = useObservable(observables.currentNavGroup$, undefined);
97-
9897
const visibleUseCases = useMemo(() => getVisibleUseCases(navGroupsMap), [navGroupsMap]);
9998

10099
const currentNavGroupId = useMemo(() => {
@@ -115,9 +114,6 @@ export function CollapsibleNavGroupEnabled({
115114
? !currentNavGroupId
116115
: currentNavGroupId === ALL_USE_CASE_ID;
117116

118-
const shouldShowCollapsedNavHeaderContent =
119-
isNavOpen && !!collapsibleNavHeaderRender && !currentNavGroupId;
120-
121117
const navLinksForRender: ChromeNavLink[] = useMemo(() => {
122118
const getSystemNavGroups = () => {
123119
const result: ChromeNavLink[] = [];
@@ -300,6 +296,7 @@ export function CollapsibleNavGroupEnabled({
300296
<CollapsibleNavTop
301297
homeLink={homeLink}
302298
navGroupsMap={navGroupsMap}
299+
collapsibleNavHeaderRender={collapsibleNavHeaderRender}
303300
navLinks={navLinks}
304301
navigateToApp={navigateToApp}
305302
logos={logos}
@@ -308,7 +305,7 @@ export function CollapsibleNavGroupEnabled({
308305
shouldShrinkNavigation={!isNavOpen}
309306
onClickShrink={closeNav}
310307
visibleUseCases={visibleUseCases}
311-
currentWorkspace$={observables.currentWorkspace$}
308+
currentWorkspace$={currentWorkspace$}
312309
/>
313310
</EuiPanel>
314311
)}
@@ -320,12 +317,6 @@ export function CollapsibleNavGroupEnabled({
320317
hasShadow={false}
321318
className="eui-yScroll flex-1-container"
322319
>
323-
{shouldShowCollapsedNavHeaderContent && collapsibleNavHeaderRender ? (
324-
<>
325-
{collapsibleNavHeaderRender()}
326-
<EuiSpacer />
327-
</>
328-
) : null}
329320
<NavGroups
330321
navLinks={navLinksForRender}
331322
navigateToApp={navigateToApp}

src/core/public/chrome/ui/header/collapsible_nav_group_enabled_top.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
EuiButtonIcon,
1212
EuiFlexGroup,
1313
EuiFlexItem,
14+
EuiText,
1415
EuiIcon,
1516
EuiPanel,
1617
EuiSpacer,
17-
EuiText,
1818
} from '@elastic/eui';
1919
import { InternalApplicationStart } from 'src/core/public/application';
2020
import { createEuiListItem } from './nav_link';
@@ -25,6 +25,7 @@ import { fulfillRegistrationLinksToChromeNavLinks } from '../../utils';
2525
import './collapsible_nav_group_enabled_top.scss';
2626

2727
export interface CollapsibleNavTopProps {
28+
collapsibleNavHeaderRender?: () => JSX.Element | null;
2829
homeLink?: ChromeNavLink;
2930
navGroupsMap: Record<string, NavGroupItemInMap>;
3031
currentNavGroup?: NavGroupItemInMap;
@@ -39,6 +40,7 @@ export interface CollapsibleNavTopProps {
3940
}
4041

4142
export const CollapsibleNavTop = ({
43+
collapsibleNavHeaderRender,
4244
currentNavGroup,
4345
navigateToApp,
4446
logos,
@@ -52,7 +54,6 @@ export const CollapsibleNavTop = ({
5254
navLinks,
5355
}: CollapsibleNavTopProps) => {
5456
const currentWorkspace = useObservable(currentWorkspace$);
55-
5657
const firstVisibleNavLinkInFirstVisibleUseCase = useMemo(
5758
() =>
5859
fulfillRegistrationLinksToChromeNavLinks(
@@ -148,12 +149,19 @@ export const CollapsibleNavTop = ({
148149
/>
149150
</EuiFlexItem>
150151
</EuiFlexGroup>
151-
{currentNavGroup?.title && (
152-
<>
153-
<EuiSpacer />
154-
<EuiText>{currentNavGroup?.title}</EuiText>
155-
</>
156-
)}
152+
{
153+
// Nav groups with type are system(global) nav group and we should show title for those nav groups
154+
(currentNavGroup?.type || collapsibleNavHeaderRender) && (
155+
<>
156+
<EuiSpacer />
157+
{currentNavGroup?.type ? (
158+
<EuiText>{currentNavGroup?.title}</EuiText>
159+
) : (
160+
collapsibleNavHeaderRender?.()
161+
)}
162+
</>
163+
)
164+
}
157165
</EuiPanel>
158166
);
159167
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.workspaceMenuHeader {
2+
padding: $ouiSizeL;
3+
}

src/plugins/workspace/public/components/workspace_menu/workspace_menu.test.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import React from 'react';
77
import { fireEvent, render, screen } from '@testing-library/react';
8-
8+
import moment from 'moment';
99
import { WorkspaceMenu } from './workspace_menu';
1010
import { coreMock } from '../../../../../core/public/mocks';
1111
import { CoreStart, DEFAULT_NAV_GROUPS } from '../../../../../core/public';
@@ -64,16 +64,14 @@ describe('<WorkspaceMenu />', () => {
6464
const selectButton = screen.getByTestId('workspace-select-button');
6565
fireEvent.click(selectButton);
6666

67-
expect(screen.getByText(/all workspaces/i)).toBeInTheDocument();
68-
expect(screen.getByTestId('workspace-menu-item-all-workspace-1')).toBeInTheDocument();
69-
expect(screen.getByTestId('workspace-menu-item-all-workspace-2')).toBeInTheDocument();
67+
expect(screen.getByTestId('workspace-menu-item-workspace-1')).toBeInTheDocument();
68+
expect(screen.getByTestId('workspace-menu-item-workspace-2')).toBeInTheDocument();
7069
});
7170

72-
it('should display a list of recent workspaces in the dropdown', () => {
73-
jest.spyOn(recentWorkspaceManager, 'getRecentWorkspaces').mockReturnValue([
74-
{ id: 'workspace-1', timestamp: 1234567890 },
75-
{ id: 'workspace-2', timestamp: 1234567899 },
76-
]);
71+
it('should display viewed xx ago for recent workspaces', () => {
72+
jest
73+
.spyOn(recentWorkspaceManager, 'getRecentWorkspaces')
74+
.mockReturnValue([{ id: 'workspace-1', timestamp: 1234567890 }]);
7775

7876
coreStartMock.workspaces.workspaceList$.next([
7977
{ id: 'workspace-1', name: 'workspace 1', features: [] },
@@ -85,9 +83,7 @@ describe('<WorkspaceMenu />', () => {
8583
const selectButton = screen.getByTestId('workspace-select-button');
8684
fireEvent.click(selectButton);
8785

88-
expect(screen.getByText(/recent workspaces/i)).toBeInTheDocument();
89-
expect(screen.getByTestId('workspace-menu-item-recent-workspace-1')).toBeInTheDocument();
90-
expect(screen.getByTestId('workspace-menu-item-recent-workspace-2')).toBeInTheDocument();
86+
expect(screen.getByText(`viewed ${moment(1234567890).fromNow()}`)).toBeInTheDocument();
9187
});
9288

9389
it('should be able to display empty state when the workspace list is empty', () => {
@@ -98,7 +94,7 @@ describe('<WorkspaceMenu />', () => {
9894
expect(screen.getByText(/no workspace available/i)).toBeInTheDocument();
9995
});
10096

101-
it('should be able to perform search and filter and the results will be shown in both all and recent section', () => {
97+
it('should be able to perform search and filter and the results will be shown', () => {
10298
coreStartMock.workspaces.workspaceList$.next([
10399
{ id: 'workspace-1', name: 'workspace 1', features: [] },
104100
{ id: 'test-2', name: 'test 2', features: [] },
@@ -113,8 +109,8 @@ describe('<WorkspaceMenu />', () => {
113109

114110
const searchInput = screen.getByRole('searchbox');
115111
fireEvent.change(searchInput, { target: { value: 'works' } });
116-
expect(screen.getByTestId('workspace-menu-item-recent-workspace-1')).toBeInTheDocument();
117-
expect(screen.getByTestId('workspace-menu-item-recent-workspace-1')).toBeInTheDocument();
112+
expect(screen.getByTestId('workspace-menu-item-workspace-1')).toBeInTheDocument();
113+
expect(screen.queryByText('workspace-menu-item-workspace-1')).not.toBeInTheDocument();
118114
});
119115

120116
it('should be able to display empty state when seach is not found', () => {
@@ -145,7 +141,7 @@ describe('<WorkspaceMenu />', () => {
145141

146142
fireEvent.click(screen.getByTestId('workspace-select-button'));
147143
expect(screen.getByTestId('workspace-menu-current-workspace-name')).toBeInTheDocument();
148-
expect(screen.getByTestId('workspace-menu-current-use-case')).toBeInTheDocument();
144+
expect(screen.getByTestId('workspace-menu-current-workspace-use-case')).toBeInTheDocument();
149145
expect(screen.getByTestId('current-workspace-icon-wsObservability')).toBeInTheDocument();
150146
expect(screen.getByText('Observability')).toBeInTheDocument();
151147
});

0 commit comments

Comments
 (0)