Skip to content

Commit

Permalink
feat: do not register app when feature flag is off (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#56)

* feat: do not register app when feature flag is off

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: comply with the category name

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: opt according to PR

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize the comment

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Jul 24, 2023
1 parent 36e8e22 commit 3f7a55a
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 129 deletions.
4 changes: 2 additions & 2 deletions src/core/utils/default_app_categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import { AppCategory } from '../types';
export const DEFAULT_APP_CATEGORIES: Record<string, AppCategory> = Object.freeze({
opensearchDashboards: {
id: 'opensearchDashboards',
label: i18n.translate('core.ui.libraryNavList.label', {
defaultMessage: 'Library',
label: i18n.translate('core.ui.opensearchDashboardsNavList.label', {
defaultMessage: 'OpenSearch Dashboards',
}),
order: 1000,
},
Expand Down
102 changes: 55 additions & 47 deletions src/plugins/saved_objects_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,53 +105,10 @@ export class SavedObjectsManagementPlugin
private namespaceService = new SavedObjectsManagementNamespaceService();
private serviceRegistry = new SavedObjectsManagementServiceRegistry();

public setup(
core: CoreSetup<StartDependencies, SavedObjectsManagementPluginStart>,
{ home, management, uiActions }: SetupDependencies
): SavedObjectsManagementPluginSetup {
const actionSetup = this.actionService.setup();
const columnSetup = this.columnService.setup();
const namespaceSetup = this.namespaceService.setup();

if (home) {
home.featureCatalogue.register({
id: 'saved_objects',
title: i18n.translate('savedObjectsManagement.objects.savedObjectsTitle', {
defaultMessage: 'Saved Objects',
}),
description: i18n.translate('savedObjectsManagement.objects.savedObjectsDescription', {
defaultMessage:
'Import, export, and manage your saved searches, visualizations, and dashboards.',
}),
icon: 'savedObjectsApp',
path: '/app/management/opensearch-dashboards/objects',
showOnHomePage: false,
category: FeatureCatalogueCategory.ADMIN,
});
}

const opensearchDashboardsSection = management.sections.section.opensearchDashboards;
opensearchDashboardsSection.registerApp({
id: 'objects',
title: i18n.translate('savedObjectsManagement.managementSectionLabel', {
defaultMessage: 'Saved objects',
}),
order: 1,
mount: async (mountParams) => {
const { mountManagementSection } = await import('./management_section');
return mountManagementSection({
core,
serviceRegistry: this.serviceRegistry,
mountParams,
title: i18n.translate('savedObjectsManagement.managementSectionLabel', {
defaultMessage: 'Saved Objects',
}),
});
},
});

// sets up the context mappings and registers any triggers/actions for the plugin
bootstrap(uiActions);
private registerLibrarySubApp(
coreSetup: CoreSetup<StartDependencies, SavedObjectsManagementPluginStart>
) {
const core = coreSetup;
const mountWrapper = ({
title,
allowedObjectTypes,
Expand Down Expand Up @@ -208,6 +165,57 @@ export class SavedObjectsManagementPlugin
allowedObjectTypes: ['query'],
}),
});
}

public setup(
core: CoreSetup<StartDependencies, SavedObjectsManagementPluginStart>,
{ home, management, uiActions }: SetupDependencies
): SavedObjectsManagementPluginSetup {
const actionSetup = this.actionService.setup();
const columnSetup = this.columnService.setup();
const namespaceSetup = this.namespaceService.setup();
const isWorkspaceEnabled = core.uiSettings.get('workspace:enabled');

if (home) {
home.featureCatalogue.register({
id: 'saved_objects',
title: i18n.translate('savedObjectsManagement.objects.savedObjectsTitle', {
defaultMessage: 'Saved Objects',
}),
description: i18n.translate('savedObjectsManagement.objects.savedObjectsDescription', {
defaultMessage:
'Import, export, and manage your saved searches, visualizations, and dashboards.',
}),
icon: 'savedObjectsApp',
path: '/app/management/opensearch-dashboards/objects',
showOnHomePage: false,
category: FeatureCatalogueCategory.ADMIN,
});
}

const opensearchDashboardsSection = management.sections.section.opensearchDashboards;
opensearchDashboardsSection.registerApp({
id: 'objects',
title: i18n.translate('savedObjectsManagement.managementSectionLabel', {
defaultMessage: 'Saved objects',
}),
order: 1,
mount: async (mountParams) => {
const { mountManagementSection } = await import('./management_section');
return mountManagementSection({
core,
serviceRegistry: this.serviceRegistry,
mountParams,
title: SAVED_OBJECT_MANAGEMENT_TITLE_WORDINGS,
});
},
});

// sets up the context mappings and registers any triggers/actions for the plugin
bootstrap(uiActions);
if (isWorkspaceEnabled) {
this.registerLibrarySubApp(core);
}

// depends on `getStartServices`, should not be awaited
registerServices(this.serviceRegistry, core.getStartServices);
Expand Down
186 changes: 106 additions & 80 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { i18n } from '@osd/i18n';
import type { Subscription } from 'rxjs';
import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import {
ApplicationStart,
AppMountParameters,
Expand All @@ -16,6 +17,7 @@ import {
Plugin,
WorkspaceAttribute,
WorkspacesStart,
DEFAULT_APP_CATEGORIES,
} from '../../../core/public';
import { PATHS, WORKSPACE_APP_ID, WORKSPACE_NAV_CATEGORY } from '../common/constants';
import { mountDropdownList } from './mount';
Expand Down Expand Up @@ -157,90 +159,92 @@ export class WorkspacesPlugin implements Plugin<{}, {}, WorkspacesPluginSetupDep
if (workspaceEnabled) {
const workspaceList$ = core.workspaces.client.workspaceList$;
const currentWorkspace$ = core.workspaces.client.currentWorkspace$;
combineLatest([workspaceList$, chromeNavLinks$, currentWorkspace$]).subscribe(
([workspaceList, chromeNavLinks, currentWorkspace]) => {
const filteredNavLinks = new Map<string, ChromeNavLink>();
chromeNavLinks = this.filterByWorkspace(currentWorkspace, chromeNavLinks);
chromeNavLinks.forEach((chromeNavLink) => {
if (chromeNavLink.id === 'home') {
// set hidden, icon and order for home nav link
const homeNavLink: ChromeNavLink = {
...chromeNavLink,
hidden: currentWorkspace !== null,
euiIconType: 'logoOpenSearch',
order: 1000,
};
filteredNavLinks.set(chromeNavLink.id, homeNavLink);
} else {
filteredNavLinks.set(chromeNavLink.id, chromeNavLink);
}
});
workspaceList
.filter((value, index) => !currentWorkspace && index < 5)
.map((workspace) =>
this.workspaceToChromeNavLink(workspace, core.workspaces, core.application)
)
.forEach((workspaceNavLink) =>
filteredNavLinks.set(workspaceNavLink.id, workspaceNavLink)
);
// See more
const seeMoreId = WORKSPACE_APP_ID + PATHS.list;
const seeMoreUrl = WORKSPACE_APP_ID + PATHS.list;
const seeMoreNavLink: ChromeNavLink = {
id: seeMoreId,
title: i18n.translate('core.ui.workspaceNavList.seeMore', {
defaultMessage: 'SEE MORE',
}),
hidden: currentWorkspace !== null,
disabled: false,
baseUrl: seeMoreUrl,
href: seeMoreUrl,
category: WORKSPACE_NAV_CATEGORY,
};
filteredNavLinks.set(seeMoreId, seeMoreNavLink);
// Admin
const adminId = 'admin';
const adminUrl = '/app/admin';
const adminNavLink: ChromeNavLink = {
id: adminId,
title: i18n.translate('core.ui.workspaceNavList.admin', {
defaultMessage: 'Admin',
}),
hidden: currentWorkspace !== null,
disabled: true,
baseUrl: adminUrl,
href: adminUrl,
euiIconType: 'managementApp',
order: 9000,
};
filteredNavLinks.set(adminId, adminNavLink);
// Overview only inside workspace
if (currentWorkspace) {
const overviewId = WORKSPACE_APP_ID + PATHS.update;
const overviewUrl = core.workspaces.formatUrlWithWorkspaceId(
core.application.getUrlForApp(WORKSPACE_APP_ID, {
path: PATHS.update,
absolute: true,
}),
currentWorkspace.id
);
const overviewNavLink: ChromeNavLink = {
id: overviewId,
title: i18n.translate('core.ui.workspaceNavList.overview', {
defaultMessage: 'Overview',
}),
hidden: false,
disabled: false,
baseUrl: overviewUrl,
href: overviewUrl,
euiIconType: 'grid',
combineLatest([
workspaceList$,
chromeNavLinks$.pipe(map(this.changeCategoryNameByWorkspaceFeatureFlag)),
currentWorkspace$,
]).subscribe(([workspaceList, chromeNavLinks, currentWorkspace]) => {
const filteredNavLinks = new Map<string, ChromeNavLink>();
chromeNavLinks = this.filterByWorkspace(currentWorkspace, chromeNavLinks);
chromeNavLinks.forEach((chromeNavLink) => {
if (chromeNavLink.id === 'home') {
// set hidden, icon and order for home nav link
const homeNavLink: ChromeNavLink = {
...chromeNavLink,
hidden: currentWorkspace !== null,
euiIconType: 'logoOpenSearch',
order: 1000,
};
filteredNavLinks.set(overviewId, overviewNavLink);
filteredNavLinks.set(chromeNavLink.id, homeNavLink);
} else {
filteredNavLinks.set(chromeNavLink.id, chromeNavLink);
}
navLinksService.setFilteredNavLinks(filteredNavLinks);
});
workspaceList
.filter((value, index) => !currentWorkspace && index < 5)
.map((workspace) =>
this.workspaceToChromeNavLink(workspace, core.workspaces, core.application)
)
.forEach((workspaceNavLink) =>
filteredNavLinks.set(workspaceNavLink.id, workspaceNavLink)
);
// See more
const seeMoreId = WORKSPACE_APP_ID + PATHS.list;
const seeMoreUrl = WORKSPACE_APP_ID + PATHS.list;
const seeMoreNavLink: ChromeNavLink = {
id: seeMoreId,
title: i18n.translate('core.ui.workspaceNavList.seeMore', {
defaultMessage: 'SEE MORE',
}),
hidden: currentWorkspace !== null,
disabled: false,
baseUrl: seeMoreUrl,
href: seeMoreUrl,
category: WORKSPACE_NAV_CATEGORY,
};
filteredNavLinks.set(seeMoreId, seeMoreNavLink);
// Admin
const adminId = 'admin';
const adminUrl = '/app/admin';
const adminNavLink: ChromeNavLink = {
id: adminId,
title: i18n.translate('core.ui.workspaceNavList.admin', {
defaultMessage: 'Admin',
}),
hidden: currentWorkspace !== null,
disabled: true,
baseUrl: adminUrl,
href: adminUrl,
euiIconType: 'managementApp',
order: 9000,
};
filteredNavLinks.set(adminId, adminNavLink);
// Overview only inside workspace
if (currentWorkspace) {
const overviewId = WORKSPACE_APP_ID + PATHS.update;
const overviewUrl = core.workspaces.formatUrlWithWorkspaceId(
core.application.getUrlForApp(WORKSPACE_APP_ID, {
path: PATHS.update,
absolute: true,
}),
currentWorkspace.id
);
const overviewNavLink: ChromeNavLink = {
id: overviewId,
title: i18n.translate('core.ui.workspaceNavList.overview', {
defaultMessage: 'Overview',
}),
hidden: false,
disabled: false,
baseUrl: overviewUrl,
href: overviewUrl,
euiIconType: 'grid',
order: 1000,
};
filteredNavLinks.set(overviewId, overviewNavLink);
}
);
navLinksService.setFilteredNavLinks(filteredNavLinks);
});
} else {
chromeNavLinks$.subscribe((chromeNavLinks) => {
const filteredNavLinks = new Map<string, ChromeNavLink>();
Expand All @@ -252,6 +256,28 @@ export class WorkspacesPlugin implements Plugin<{}, {}, WorkspacesPluginSetupDep
}
}

/**
* The category "Opensearch Dashboards" needs to be renamed as "Library"
* when workspace feature flag is on, we need to do it here and generate
* a new item without polluting the original ChromeNavLink.
*/
private changeCategoryNameByWorkspaceFeatureFlag(chromeLinks: ChromeNavLink[]): ChromeNavLink[] {
return chromeLinks.map((item) => {
if (item.category?.id === DEFAULT_APP_CATEGORIES.opensearchDashboards.id) {
return {
...item,
category: {
...item.category,
label: i18n.translate('core.ui.libraryNavList.label', {
defaultMessage: 'Library',
}),
},
};
}
return item;
});
}

public start(core: CoreStart) {
// If workspace feature is disabled, it will not load the workspace plugin
if (core.uiSettings.get('workspace:enabled') === false) {
Expand Down

0 comments on commit 3f7a55a

Please sign in to comment.