From ffc6dd9f8421ecdc1bcc6581ba4653e6891a691b Mon Sep 17 00:00:00 2001 From: yubonluo Date: Tue, 9 Apr 2024 11:00:01 +0800 Subject: [PATCH 1/8] hide dashboard overview when in any workspace Signed-off-by: yubonluo --- src/core/public/application/types.ts | 5 +++++ .../public/plugin.ts | 12 ++++++++++-- src/plugins/workspace/public/utils.test.ts | 15 +++++++++++++++ src/plugins/workspace/public/utils.ts | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/core/public/application/types.ts b/src/core/public/application/types.ts index 4744ab34cfd3..c42a5618dd1e 100644 --- a/src/core/public/application/types.ts +++ b/src/core/public/application/types.ts @@ -245,6 +245,11 @@ export interface App { * ``` */ exactRoute?: boolean; + + /** + * Prevent the page to be accessible when inside a workspace. Defaults to `false`. + */ + workspaceless?: boolean; } /** diff --git a/src/plugins/opensearch_dashboards_overview/public/plugin.ts b/src/plugins/opensearch_dashboards_overview/public/plugin.ts index e38282ff06d6..81674104017b 100644 --- a/src/plugins/opensearch_dashboards_overview/public/plugin.ts +++ b/src/plugins/opensearch_dashboards_overview/public/plugin.ts @@ -80,9 +80,17 @@ export class OpenSearchDashboardsOverviewPlugin map((hasOpenSearchDashboardsApp) => { return () => { if (!hasOpenSearchDashboardsApp) { - return { status: AppStatus.inaccessible, navLinkStatus: AppNavLinkStatus.hidden }; + return { + status: AppStatus.inaccessible, + navLinkStatus: AppNavLinkStatus.hidden, + workspaceless: true, + }; } else { - return { status: AppStatus.accessible, navLinkStatus: AppNavLinkStatus.default }; + return { + status: AppStatus.accessible, + navLinkStatus: AppNavLinkStatus.default, + workspaceless: true, + }; } }; }) diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index 5ce89d9fffc6..e8687f877613 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -121,6 +121,21 @@ describe('workspace utils: getSelectedFeatureQuantities', () => { 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, + workspaceless: true, + }, ] as PublicAppInfo[]; it('should support * rules and exclude management category', () => { const { total, selected } = getSelectedFeatureQuantities(['*'], defaultApplications); diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index 2c0ad62d7775..e703fa0c26fe 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -64,9 +64,10 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ // Get all apps excluding management category export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { return applications.filter( - ({ navLinkStatus, chromeless, category }) => + ({ navLinkStatus, chromeless, category, workspaceless }) => navLinkStatus !== AppNavLinkStatus.hidden && !chromeless && + !workspaceless && category?.id !== DEFAULT_APP_CATEGORIES.management.id ); }; From d69dfa798165d059fe8fe87b52680b48485f34ad Mon Sep 17 00:00:00 2001 From: yubonluo Date: Fri, 12 Apr 2024 13:59:42 +0800 Subject: [PATCH 2/8] Make dashboard mangement available in workspace Signed-off-by: yubonluo --- src/plugins/workspace/public/utils.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index e703fa0c26fe..099ed168af29 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -63,13 +63,15 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ // Get all apps excluding management category export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { - return applications.filter( - ({ navLinkStatus, chromeless, category, workspaceless }) => - navLinkStatus !== AppNavLinkStatus.hidden && - !chromeless && - !workspaceless && - category?.id !== DEFAULT_APP_CATEGORIES.management.id - ); + return applications.filter(({ navLinkStatus, chromeless, category, workspaceless, id }) => { + const filterCondition = + navLinkStatus !== AppNavLinkStatus.hidden && !chromeless && !workspaceless; + if (category?.id === DEFAULT_APP_CATEGORIES.management.id) { + return filterCondition && id === 'management'; + } else { + return filterCondition; + } + }); }; export const getSelectedFeatureQuantities = ( From 991971e0aac3df17937db2aa5f183d1146055fa0 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Mon, 15 Apr 2024 16:19:16 +0800 Subject: [PATCH 3/8] optimize code Signed-off-by: yubonluo --- .../public/plugin.ts | 4 ++-- src/plugins/workspace/public/utils.test.ts | 2 +- src/plugins/workspace/public/utils.ts | 20 +++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugins/opensearch_dashboards_overview/public/plugin.ts b/src/plugins/opensearch_dashboards_overview/public/plugin.ts index b7606034ac62..ae3061e512cc 100644 --- a/src/plugins/opensearch_dashboards_overview/public/plugin.ts +++ b/src/plugins/opensearch_dashboards_overview/public/plugin.ts @@ -84,13 +84,13 @@ export class OpenSearchDashboardsOverviewPlugin return { status: AppStatus.inaccessible, navLinkStatus: AppNavLinkStatus.hidden, - workspaceless: true, + workspaceAccessibility: WorkspaceAccessibility.NO, }; } else { return { status: AppStatus.accessible, navLinkStatus: AppNavLinkStatus.default, - workspaceless: true, + workspaceAccessibility: WorkspaceAccessibility.NO, }; } }; diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index 4f3ec9027bd6..80f278e8e284 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -139,7 +139,7 @@ describe('workspace utils: getSelectedFeatureQuantities', () => { navLinkStatus: 1, order: -2000, status: 0, - workspaceless: true, + workspaceAccessibility: WorkspaceAccessibility.NO, }, ] as PublicAppInfo[]; it('should support * rules and exclude management category', () => { diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index 86e501187a1f..a305e9334e12 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -71,15 +71,19 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ // Get all apps excluding management category export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { - return applications.filter(({ navLinkStatus, chromeless, category, workspaceless, id }) => { - const filterCondition = - navLinkStatus !== AppNavLinkStatus.hidden && !chromeless && !workspaceless; - if (category?.id === DEFAULT_APP_CATEGORIES.management.id) { - return filterCondition && id === 'management'; - } else { - return filterCondition; + return applications.filter( + ({ navLinkStatus, chromeless, category, workspaceAccessibility, id }) => { + const filterCondition = + navLinkStatus !== AppNavLinkStatus.hidden && + !chromeless && + workspaceAccessibility !== WorkspaceAccessibility.NO; + if (category?.id === DEFAULT_APP_CATEGORIES.management.id) { + return filterCondition && id === 'management'; + } else { + return filterCondition; + } } - }); + ); }; export const getSelectedFeatureQuantities = ( From 62e19b45df37426011e693bf7dce217c3dedcf89 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Mon, 15 Apr 2024 17:13:57 +0800 Subject: [PATCH 4/8] optimize code Signed-off-by: yubonluo --- .../workspace_feature_selector.tsx | 4 ++-- src/plugins/workspace/public/utils.test.ts | 23 +++++++++++++++---- src/plugins/workspace/public/utils.ts | 6 +++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx index e172b851f1f3..863449627b33 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx @@ -20,7 +20,7 @@ import { DEFAULT_APP_CATEGORIES, PublicAppInfo } from '../../../../../core/publi import { WorkspaceFeature, WorkspaceFeatureGroup } from './types'; import { isDefaultCheckedFeatureId, isWorkspaceFeatureGroup } from './utils'; -import { getAllExcludingManagementApps } from '../../utils'; +import { getAllIncludingDashboardsManagementApps } from '../../utils'; const libraryCategoryLabel = i18n.translate('core.ui.libraryNavList.label', { defaultMessage: 'Library', @@ -55,7 +55,7 @@ export const WorkspaceFeatureSelector = ({ Array >((previousValue, currentKey) => { const apps = category2Applications[currentKey]; - const features = getAllExcludingManagementApps(apps).map(({ id, title }) => ({ + const features = getAllIncludingDashboardsManagementApps(apps).map(({ id, title }) => ({ id, name: title, })); diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index 80f278e8e284..2aee3b2b94d8 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -141,19 +141,32 @@ describe('workspace utils: getSelectedFeatureQuantities', () => { status: 0, workspaceAccessibility: WorkspaceAccessibility.NO, }, + { + 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 support * rules and exclude management category', () => { + it('should support * rules and include dashboards management', () => { const { total, selected } = getSelectedFeatureQuantities(['*'], defaultApplications); - expect(total).toBe(1); - expect(selected).toBe(1); + expect(total).toBe(2); + expect(selected).toBe(2); }); - it('should get quantity normally and exclude management category', () => { + it('should get quantity normally and include dashboards management', () => { const { total, selected } = getSelectedFeatureQuantities( ['dev_tools', '!@management'], defaultApplications ); - expect(total).toBe(1); + expect(total).toBe(2); expect(selected).toBe(0); }); }); diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index a305e9334e12..0814c160eab9 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -70,7 +70,9 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ }; // Get all apps excluding management category -export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { +export const getAllIncludingDashboardsManagementApps = ( + applications: PublicAppInfo[] +): PublicAppInfo[] => { return applications.filter( ({ navLinkStatus, chromeless, category, workspaceAccessibility, id }) => { const filterCondition = @@ -90,7 +92,7 @@ export const getSelectedFeatureQuantities = ( featuresConfig: string[], applications: PublicAppInfo[] ) => { - const visibleApplications = getAllExcludingManagementApps(applications); + const visibleApplications = getAllIncludingDashboardsManagementApps(applications); const featureFilter = featureMatchesConfig(featuresConfig); const selectedApplications = visibleApplications.filter((app) => featureFilter(app)); return { From 7dfaca8ec566e9925bf44cbfa77b865fa72455b2 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Tue, 16 Apr 2024 13:34:58 +0800 Subject: [PATCH 5/8] optimize code Signed-off-by: yubonluo --- .../opensearch_dashboards_overview/public/plugin.ts | 2 -- .../workspace_form/workspace_feature_selector.tsx | 4 ++-- src/plugins/workspace/public/utils.ts | 12 +++++------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/plugins/opensearch_dashboards_overview/public/plugin.ts b/src/plugins/opensearch_dashboards_overview/public/plugin.ts index ae3061e512cc..d64c4256ba7a 100644 --- a/src/plugins/opensearch_dashboards_overview/public/plugin.ts +++ b/src/plugins/opensearch_dashboards_overview/public/plugin.ts @@ -84,13 +84,11 @@ export class OpenSearchDashboardsOverviewPlugin return { status: AppStatus.inaccessible, navLinkStatus: AppNavLinkStatus.hidden, - workspaceAccessibility: WorkspaceAccessibility.NO, }; } else { return { status: AppStatus.accessible, navLinkStatus: AppNavLinkStatus.default, - workspaceAccessibility: WorkspaceAccessibility.NO, }; } }; diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx index 863449627b33..51badcba5360 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_feature_selector.tsx @@ -20,7 +20,7 @@ import { DEFAULT_APP_CATEGORIES, PublicAppInfo } from '../../../../../core/publi import { WorkspaceFeature, WorkspaceFeatureGroup } from './types'; import { isDefaultCheckedFeatureId, isWorkspaceFeatureGroup } from './utils'; -import { getAllIncludingDashboardsManagementApps } from '../../utils'; +import { getAllFilterApps } from '../../utils'; const libraryCategoryLabel = i18n.translate('core.ui.libraryNavList.label', { defaultMessage: 'Library', @@ -55,7 +55,7 @@ export const WorkspaceFeatureSelector = ({ Array >((previousValue, currentKey) => { const apps = category2Applications[currentKey]; - const features = getAllIncludingDashboardsManagementApps(apps).map(({ id, title }) => ({ + const features = getAllFilterApps(apps).map(({ id, title }) => ({ id, name: title, })); diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index 0814c160eab9..f7b78a4c2cbf 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -69,21 +69,19 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ return matched; }; -// Get all apps excluding management category -export const getAllIncludingDashboardsManagementApps = ( - applications: PublicAppInfo[] -): PublicAppInfo[] => { +// Get all apps excluding that should not be displayed in workspace. +export const getAllFilterApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { return applications.filter( ({ navLinkStatus, chromeless, category, workspaceAccessibility, id }) => { const filterCondition = navLinkStatus !== AppNavLinkStatus.hidden && !chromeless && workspaceAccessibility !== WorkspaceAccessibility.NO; + // If the category is management, only retain dashboards management. if (category?.id === DEFAULT_APP_CATEGORIES.management.id) { return filterCondition && id === 'management'; - } else { - return filterCondition; } + return filterCondition; } ); }; @@ -92,7 +90,7 @@ export const getSelectedFeatureQuantities = ( featuresConfig: string[], applications: PublicAppInfo[] ) => { - const visibleApplications = getAllIncludingDashboardsManagementApps(applications); + const visibleApplications = getAllFilterApps(applications); const featureFilter = featureMatchesConfig(featuresConfig); const selectedApplications = visibleApplications.filter((app) => featureFilter(app)); return { From 74ca6675437626ae2c462bc56667591a061cf4bb Mon Sep 17 00:00:00 2001 From: yubonluo Date: Tue, 16 Apr 2024 13:36:58 +0800 Subject: [PATCH 6/8] delete useless modify Signed-off-by: yubonluo --- .../opensearch_dashboards_overview/public/plugin.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/plugins/opensearch_dashboards_overview/public/plugin.ts b/src/plugins/opensearch_dashboards_overview/public/plugin.ts index d64c4256ba7a..69b0e9616452 100644 --- a/src/plugins/opensearch_dashboards_overview/public/plugin.ts +++ b/src/plugins/opensearch_dashboards_overview/public/plugin.ts @@ -81,15 +81,9 @@ export class OpenSearchDashboardsOverviewPlugin map((hasOpenSearchDashboardsApp) => { return () => { if (!hasOpenSearchDashboardsApp) { - return { - status: AppStatus.inaccessible, - navLinkStatus: AppNavLinkStatus.hidden, - }; + return { status: AppStatus.inaccessible, navLinkStatus: AppNavLinkStatus.hidden }; } else { - return { - status: AppStatus.accessible, - navLinkStatus: AppNavLinkStatus.default, - }; + return { status: AppStatus.accessible, navLinkStatus: AppNavLinkStatus.default }; } }; }) From cd40b0e6fa06fb1dc65d085bcb46af41d07ba4cb Mon Sep 17 00:00:00 2001 From: yubonluo Date: Tue, 16 Apr 2024 17:44:54 +0800 Subject: [PATCH 7/8] add unit test Signed-off-by: yubonluo --- src/plugins/workspace/public/utils.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/workspace/public/utils.test.ts b/src/plugins/workspace/public/utils.test.ts index 2aee3b2b94d8..ad30ccf6c2c0 100644 --- a/src/plugins/workspace/public/utils.test.ts +++ b/src/plugins/workspace/public/utils.test.ts @@ -5,6 +5,7 @@ import { featureMatchesConfig, + getAllFilterApps, getSelectedFeatureQuantities, isAppAccessibleInWorkspace, } from './utils'; @@ -155,6 +156,14 @@ describe('workspace utils: getSelectedFeatureQuantities', () => { navLinkStatus: 1, }, ] as PublicAppInfo[]; + + it('should filter out apps correctly', () => { + const filterApps = getAllFilterApps(defaultApplications); + expect(filterApps.length).toBe(2); + expect(filterApps[0].id).toBe('dashboards'); + expect(filterApps[1].id).toBe('management'); + }); + it('should support * rules and include dashboards management', () => { const { total, selected } = getSelectedFeatureQuantities(['*'], defaultApplications); expect(total).toBe(2); From f9c4dc9d3e4edda2193c67f30a18a7ff622c8d4f Mon Sep 17 00:00:00 2001 From: yubonluo Date: Wed, 17 Apr 2024 10:09:10 +0800 Subject: [PATCH 8/8] modify comment Signed-off-by: yubonluo --- src/plugins/workspace/public/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/workspace/public/utils.ts b/src/plugins/workspace/public/utils.ts index f7b78a4c2cbf..48b85db1fbc2 100644 --- a/src/plugins/workspace/public/utils.ts +++ b/src/plugins/workspace/public/utils.ts @@ -69,7 +69,7 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({ return matched; }; -// Get all apps excluding that should not be displayed in workspace. +// Get all apps that should be displayed in workspace. export const getAllFilterApps = (applications: PublicAppInfo[]): PublicAppInfo[] => { return applications.filter( ({ navLinkStatus, chromeless, category, workspaceAccessibility, id }) => {