Skip to content

Commit

Permalink
workspace list card on home
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Jul 19, 2024
1 parent 92fc98d commit 3c06e1a
Show file tree
Hide file tree
Showing 15 changed files with 537 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/core/public/chrome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export {
} from './ui/header/header_help_menu';
export { NavType, RightNavigationButton, RightNavigationButtonProps } from './ui';
export { ChromeNavLink, ChromeNavLinks, ChromeNavLinkUpdateableFields } from './nav_links';
export { ChromeRecentlyAccessed, ChromeRecentlyAccessedHistoryItem } from './recently_accessed';
export {
ChromeRecentlyAccessed,
ChromeRecentlyAccessedHistoryItem,
PersistedLog,
} from './recently_accessed';
export { ChromeNavControl, ChromeNavControls } from './nav_controls';
export { ChromeDocTitle } from './doc_title';
export { RightNavigationOrder } from './constants';
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/chrome/recently_accessed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ export {
ChromeRecentlyAccessedHistoryItem,
RecentlyAccessedService,
} from './recently_accessed_service';

export { PersistedLog } from './persisted_log';
2 changes: 2 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
ChromeNavGroupUpdater,
NavGroupItemInMap,
fulfillRegistrationLinksToChromeNavLinks,
PersistedLog,
} from './chrome';
import { FatalErrorsSetup, FatalErrorsStart, FatalErrorInfo } from './fatal_errors';
import { HttpSetup, HttpStart } from './http';
Expand Down Expand Up @@ -377,6 +378,7 @@ export {
ChromeNavGroupUpdater,
NavGroupItemInMap,
fulfillRegistrationLinksToChromeNavLinks,
PersistedLog,
};

export { __osdBootstrap__ } from './osd_bootstrap';
Expand Down
1 change: 1 addition & 0 deletions src/core/types/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface WorkspaceAttribute {
icon?: string;
reserved?: boolean;
uiSettings?: Record<string, any>;
lastUpdatedTime?: string;
}

export interface WorkspaceAttributeWithPermission extends WorkspaceAttribute {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/home/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ import { HomePublicPlugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext) =>
new HomePublicPlugin(initializerContext);

export { HOME_PAGE_ID, HOME_CONTENT_AREAS } from '../common/constants';
2 changes: 2 additions & 0 deletions src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,5 @@ export const WORKSPACE_USE_CASES = Object.freeze({
});

export const CURRENT_USER_PLACEHOLDER = '%me%';
export const MAX_WORKSPACE_NAME_LENGTH = 25;
export const RECENT_WORKSPACES_KEY = 'recentWorkspaces';
4 changes: 2 additions & 2 deletions src/plugins/workspace/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"savedObjects",
"opensearchDashboardsReact"
],
"optionalPlugins": ["savedObjectsManagement","management","dataSourceManagement"],
"requiredBundles": ["opensearchDashboardsReact"]
"optionalPlugins": ["savedObjectsManagement","management","dataSourceManagement","contentManagement"],
"requiredBundles": ["opensearchDashboardsReact","home"]
}

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

6 changes: 6 additions & 0 deletions src/plugins/workspace/public/components/service_card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { WorkspaceListCard } from './workspace_list_card';
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { coreMock } from '../../../../../core/public/mocks';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { WorkspaceListCard } from './workspace_list_card';
import { recentWorkspaceManager } from '../../recent_workspace_manager';

describe('workspace list card render normally', () => {
const coreStart = coreMock.createStart();

beforeAll(() => {
const workspaceList = [
{
id: 'ws-1',
name: 'foo',
lastUpdatedTime: new Date().toISOString(),
},
{
id: 'ws-2',
name: 'bar',
lastUpdatedTime: new Date().toISOString(),
},
];
coreStart.workspaces.workspaceList$.next(workspaceList);
});

it('should show workspace list card correctly', () => {
const { container } = render(<WorkspaceListCard core={coreStart} />);
expect(container).toMatchSnapshot();
});

it('should show empty state if no recently viewed workspace', () => {
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

// empty statue for recently viewed
expect(getByText('Workspaces you have recently viewed will appear here.')).toBeInTheDocument();
});

it('should show default filter as recently viewed', () => {
recentWorkspaceManager.addRecentWorkspace('foo');
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

waitFor(() => {
expect(getByText('foo')).toBeInTheDocument();
});
});

it('should show updated filter correctly', () => {
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

const filterSelector = getByTestId('workspace_filter');
fireEvent.change(filterSelector, { target: { value: 'updated' } });
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently updated');

// workspace list
expect(getByText('foo')).toBeInTheDocument();
expect(getByText('bar')).toBeInTheDocument();
});
});
Loading

0 comments on commit 3c06e1a

Please sign in to comment.