From 8db96881c4a4e710e522e4459fa6a3a656c70699 Mon Sep 17 00:00:00 2001 From: yuboluo <15242088755@163.com> Date: Mon, 22 Apr 2024 14:07:42 +0800 Subject: [PATCH] [Workspace] Make dashboards management available (#6575) * [Workspace] Make dashboards management available Signed-off-by: yubonluo * [Workspace] optimize the code Signed-off-by: yubonluo * [Workspace] optimize the code Signed-off-by: yubonluo * [Workspace] modify requiredPlugins Signed-off-by: yubonluo * Changeset file for PR #6575 created/updated * [Workspace] add more comments Signed-off-by: yubonluo * [Workspace] delete useless code Signed-off-by: yubonluo * [Workspace] delete useless code Signed-off-by: yubonluo --------- Signed-off-by: yubonluo Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/6575.yml | 2 + src/plugins/workspace/public/utils.test.ts | 73 +++++++++++++++++++++- src/plugins/workspace/public/utils.ts | 13 ++-- 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/6575.yml diff --git a/changelogs/fragments/6575.yml b/changelogs/fragments/6575.yml new file mode 100644 index 000000000000..964c04770a83 --- /dev/null +++ b/changelogs/fragments/6575.yml @@ -0,0 +1,2 @@ +feat: +- [Workspace] Make dashboards management available ([#6575](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6575)) \ No newline at end of file diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index f81e248c4469..ae622a170254 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -3,8 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { AppNavLinkStatus } from '../../../core/public'; -import { featureMatchesConfig, isAppAccessibleInWorkspace } from './utils'; +import { AppNavLinkStatus, PublicAppInfo } from '../../../core/public'; +import { + featureMatchesConfig, + filterWorkspaceConfigurableApps, + isAppAccessibleInWorkspace, +} from './utils'; describe('workspace utils: featureMatchesConfig', () => { it('feature configured with `*` should match any features', () => { @@ -149,3 +153,68 @@ describe('workspace utils: isAppAccessibleInWorkspace', () => { ).toBe(true); }); }); + +describe('workspace utils: filterWorkspaceConfigurableApps', () => { + const defaultApplications = [ + { + appRoute: '/app/dashboards', + id: 'dashboards', + title: 'Dashboards', + category: { + id: 'opensearchDashboards', + label: 'OpenSearch Dashboards', + euiIconType: 'inputOutput', + order: 1000, + }, + status: 0, + navLinkStatus: 1, + }, + { + appRoute: '/app/dev_tools', + id: 'dev_tools', + title: 'Dev Tools', + category: { + id: 'management', + label: 'Management', + order: 5000, + euiIconType: 'managementApp', + }, + status: 0, + navLinkStatus: 1, + }, + { + appRoute: '/app/opensearch_dashboards_overview', + id: 'opensearchDashboardsOverview', + title: 'Overview', + category: { + id: 'opensearchDashboards', + label: 'Library', + euiIconType: 'inputOutput', + order: 1000, + }, + navLinkStatus: 1, + order: -2000, + status: 0, + }, + { + appRoute: '/app/management', + id: 'management', + title: 'Dashboards Management', + category: { + id: 'management', + label: 'Management', + order: 5000, + euiIconType: 'managementApp', + }, + status: 0, + navLinkStatus: 1, + }, + ] as PublicAppInfo[]; + it('should filters out apps that are not accessible in the workspace', () => { + const filteredApps = filterWorkspaceConfigurableApps(defaultApplications); + expect(filteredApps.length).toEqual(3); + expect(filteredApps[0].id).toEqual('dashboards'); + expect(filteredApps[1].id).toEqual('opensearchDashboardsOverview'); + expect(filteredApps[2].id).toEqual('management'); + }); +}); diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index dd0cb8275469..54f5fbad5912 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -108,14 +108,19 @@ export function isAppAccessibleInWorkspace(app: App, workspace: WorkspaceObject) return false; } +// Get all apps that should be displayed in workspace when create/update a workspace. export const filterWorkspaceConfigurableApps = (applications: PublicAppInfo[]) => { const visibleApplications = applications.filter(({ navLinkStatus, chromeless, category, id }) => { - return ( + const filterCondition = navLinkStatus !== AppNavLinkStatus.hidden && !chromeless && - !DEFAULT_SELECTED_FEATURES_IDS.includes(id) && - category?.id !== DEFAULT_APP_CATEGORIES.management.id - ); + !DEFAULT_SELECTED_FEATURES_IDS.includes(id); + // If the category is management, only retain Dashboards Management which contains saved objets and index patterns. + // Saved objets can show all saved objects in the current workspace and index patterns is at workspace level. + if (category?.id === DEFAULT_APP_CATEGORIES.management.id) { + return filterCondition && id === 'management'; + } + return filterCondition; }); return visibleApplications;