Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace] Make dashboards management available #6575

Merged
73 changes: 71 additions & 2 deletions src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});
12 changes: 8 additions & 4 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ 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.
if (category?.id === DEFAULT_APP_CATEGORIES.management.id) {
return filterCondition && id === 'management';
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
}
return filterCondition;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add more comments of why we would like add an exception case for management

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the comments has been added.

});

return visibleApplications;
Expand Down
Loading