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

Hide dashboard overview and make dashboards management available #329

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getAllFilterApps } from '../../utils';

const libraryCategoryLabel = i18n.translate('core.ui.libraryNavList.label', {
defaultMessage: 'Library',
Expand Down Expand Up @@ -55,7 +55,7 @@ export const WorkspaceFeatureSelector = ({
Array<WorkspaceFeature | WorkspaceFeatureGroup>
>((previousValue, currentKey) => {
const apps = category2Applications[currentKey];
const features = getAllExcludingManagementApps(apps).map(({ id, title }) => ({
const features = getAllFilterApps(apps).map(({ id, title }) => ({
id,
name: title,
}));
Expand Down
47 changes: 42 additions & 5 deletions src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
featureMatchesConfig,
getAllFilterApps,
getSelectedFeatureQuantities,
isAppAccessibleInWorkspace,
} from './utils';
Expand Down Expand Up @@ -126,19 +127,55 @@ 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,
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 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(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);
});
});
Expand Down
21 changes: 14 additions & 7 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,28 @@ export const featureMatchesConfig = (featureConfigs: string[]) => ({
return matched;
};

// Get all apps excluding management category
export const getAllExcludingManagementApps = (applications: PublicAppInfo[]): PublicAppInfo[] => {
// Get all apps that should be displayed in workspace.
export const getAllFilterApps = (applications: PublicAppInfo[]): PublicAppInfo[] => {
return applications.filter(
({ navLinkStatus, chromeless, category }) =>
navLinkStatus !== AppNavLinkStatus.hidden &&
!chromeless &&
category?.id !== DEFAULT_APP_CATEGORIES.management.id
({ 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';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add some comment here to elaborate?

Copy link
Author

Choose a reason for hiding this comment

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

The comment has been added

}
return filterCondition;
}
);
};

export const getSelectedFeatureQuantities = (
featuresConfig: string[],
applications: PublicAppInfo[]
) => {
const visibleApplications = getAllExcludingManagementApps(applications);
const visibleApplications = getAllFilterApps(applications);
const featureFilter = featureMatchesConfig(featuresConfig);
const selectedApplications = visibleApplications.filter((app) => featureFilter(app));
return {
Expand Down
Loading