Skip to content

Commit

Permalink
[navigation]feat: add sample data menu back (#8076) (#8098)
Browse files Browse the repository at this point in the history
* feat: add sample data back

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

* Changeset file for PR #8076 created/updated

* fix: unit test failure

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 faac756)
(cherry picked from commit 0a42d64)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 3b06093 commit 6e43765
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8076.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [navigation] Add `sample data` menu back ([#8076](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8076))
5 changes: 4 additions & 1 deletion src/core/server/utils/auth_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PrincipalType, Principals } from '../saved_objects/permission_control/a
export interface AuthInfo {
backend_roles?: string[];
user_name?: string;
user_id?: string;
}

export const getPrincipalsFromRequest = (
Expand All @@ -31,7 +32,9 @@ export const getPrincipalsFromRequest = (
if (authState?.authInfo?.backend_roles) {
payload[PrincipalType.Groups] = authState.authInfo.backend_roles;
}
if (authState?.authInfo?.user_name) {
if (authState?.authInfo?.user_id) {
payload[PrincipalType.Users] = [authState.authInfo.user_id];

Check warning on line 36 in src/core/server/utils/auth_info.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/utils/auth_info.ts#L36

Added line #L36 was not covered by tests
} else if (authState?.authInfo?.user_name) {
payload[PrincipalType.Users] = [authState.authInfo.user_name];
}
return payload;
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/home/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
export const PLUGIN_ID = 'home';
export const HOME_APP_BASE_PATH = `/app/${PLUGIN_ID}`;
export const USE_NEW_HOME_PAGE = 'home:useNewHomePage';

/**
* The id is used in src/plugins/workspace/public/plugin.ts and please change that accordingly if you change the id here.
*/
export const IMPORT_SAMPLE_DATA_APP_ID = 'import_sample_data';
4 changes: 3 additions & 1 deletion src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export class HomePublicPlugin
title: i18n.translate('home.tutorialDirectory.featureCatalogueTitle', {
defaultMessage: 'Add sample data',
}),
navLinkStatus: AppNavLinkStatus.hidden,
navLinkStatus: core.chrome.navGroup.getNavGroupEnabled()
? AppNavLinkStatus.default
: AppNavLinkStatus.hidden,
mount: async (params: AppMountParameters) => {
const [coreStart] = await core.getStartServices();
setCommonService();
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/workspace/public/services/use_case_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,30 @@ describe('UseCaseService', () => {
await waitFor(() => {
expect(coreSetup.chrome.navGroup.addNavLinksToGroup).toBeCalledWith(navGroupInfo, [
{
id: 'dataSources',
id: 'objects',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 100,
},
{
id: 'indexPatterns',
id: 'dataSources',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 200,
},
{
id: 'objects',
id: 'indexPatterns',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 300,
},
{
id: WORKSPACE_DETAIL_APP_ID,
id: 'import_sample_data',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 400,
title: 'Sample data',
},
{
id: WORKSPACE_DETAIL_APP_ID,
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 500,
title: 'Workspace settings',
},
]);
Expand Down
16 changes: 12 additions & 4 deletions src/plugins/workspace/public/services/use_case_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,32 @@ export class UseCaseService {
if (navGroupInfo) {
setupDeps.chrome.navGroup.addNavLinksToGroup(navGroupInfo, [
{
id: 'dataSources',
id: 'objects',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 100,
},
{
id: 'indexPatterns',
id: 'dataSources',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 200,
},
{
id: 'objects',
id: 'indexPatterns',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 300,
},
{
id: WORKSPACE_DETAIL_APP_ID,
id: 'import_sample_data',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 400,
title: i18n.translate('workspace.left.sampleData.label', {
defaultMessage: 'Sample data',
}),
},
{
id: WORKSPACE_DETAIL_APP_ID,
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 500,
title: i18n.translate('workspace.settings.workspaceSettings', {
defaultMessage: 'Workspace settings',
}),
Expand Down

0 comments on commit 6e43765

Please sign in to comment.