From 2e8b09904bd3ec105362b924abb333f2020d99ec Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:51:05 +0800 Subject: [PATCH] [navigation]feat: add `sample data` menu back (#8076) (#8098) (#8101) * feat: add sample data back * Changeset file for PR #8076 created/updated * fix: unit test failure --------- (cherry picked from commit faac756e4c6985e7a3dd7a62dc25e9a3b624b0d9) (cherry picked from commit 0a42d64d3e21f4ce0f56c9caf3ad2d5ac71472f6) Signed-off-by: SuZhou-Joe Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/8076.yml | 2 ++ src/core/server/utils/auth_info.ts | 5 ++++- src/plugins/home/common/constants.ts | 4 ++++ src/plugins/home/public/plugin.ts | 4 +++- .../public/services/use_case_service.test.ts | 14 ++++++++++---- .../public/services/use_case_service.ts | 16 ++++++++++++---- 6 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/8076.yml diff --git a/changelogs/fragments/8076.yml b/changelogs/fragments/8076.yml new file mode 100644 index 000000000000..13920d42c75f --- /dev/null +++ b/changelogs/fragments/8076.yml @@ -0,0 +1,2 @@ +feat: +- [navigation] Add `sample data` menu back ([#8076](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8076)) \ No newline at end of file diff --git a/src/core/server/utils/auth_info.ts b/src/core/server/utils/auth_info.ts index 7d965ad05ca9..f37632807daa 100644 --- a/src/core/server/utils/auth_info.ts +++ b/src/core/server/utils/auth_info.ts @@ -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 = ( @@ -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]; + } else if (authState?.authInfo?.user_name) { payload[PrincipalType.Users] = [authState.authInfo.user_name]; } return payload; diff --git a/src/plugins/home/common/constants.ts b/src/plugins/home/common/constants.ts index 25c78c59c4ac..2760cc328b5b 100644 --- a/src/plugins/home/common/constants.ts +++ b/src/plugins/home/common/constants.ts @@ -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'; diff --git a/src/plugins/home/public/plugin.ts b/src/plugins/home/public/plugin.ts index 59be17d70c1c..7ede9a32ecdb 100644 --- a/src/plugins/home/public/plugin.ts +++ b/src/plugins/home/public/plugin.ts @@ -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(); diff --git a/src/plugins/workspace/public/services/use_case_service.test.ts b/src/plugins/workspace/public/services/use_case_service.test.ts index 203cb48fe842..bdd819145f82 100644 --- a/src/plugins/workspace/public/services/use_case_service.test.ts +++ b/src/plugins/workspace/public/services/use_case_service.test.ts @@ -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', }, ]); diff --git a/src/plugins/workspace/public/services/use_case_service.ts b/src/plugins/workspace/public/services/use_case_service.ts index 630ba9f15e29..31e15977d9a5 100644 --- a/src/plugins/workspace/public/services/use_case_service.ts +++ b/src/plugins/workspace/public/services/use_case_service.ts @@ -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', }),