Skip to content

Commit

Permalink
workspace template init commit
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Jun 9, 2023
1 parent 11a5ad4 commit 2b5e689
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { OverlayStart } from '../overlays';
import { PluginOpaqueId } from '../plugins';
import { IUiSettingsClient } from '../ui_settings';
import { SavedObjectsStart } from '../saved_objects';
import { AppCategory } from '../../types';
import { AppCategory, WorkspaceTemplate } from '../../types';
import { ScopedHistory } from './scoped_history';

/**
Expand Down Expand Up @@ -123,6 +123,12 @@ export interface App<HistoryLocationState = unknown> {
*/
category?: AppCategory;

/**
* The template definition of features belongs to
* See {@link WorkspaceTemplate}
*/
workspaceTemplate?: WorkspaceTemplate[];

/**
* The initial status of the application.
* Defaulting to `accessible`
Expand Down
1 change: 1 addition & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export { PackageInfo, EnvironmentMode } from '../server/types';
/** @interal */
export { CoreContext, CoreSystem } from './core_system';
export { DEFAULT_APP_CATEGORIES } from '../utils';
export { DEFAULT_WORKSPACE_TEMPLATES } from '../utils';
export {
AppCategory,
UiSettingsParams,
Expand Down
1 change: 1 addition & 0 deletions src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
export * from './core_service';
export * from './capabilities';
export * from './app_category';
export * from './workspace_template';
export * from './ui_settings';
export * from './saved_objects';
export * from './serializable';
Expand Down
31 changes: 31 additions & 0 deletions src/core/types/workspace_template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export interface WorkspaceTemplate {
/**
* Unique identifier for the workspace template
*/
id: string;

/**
* Label used for workspace template name.
*/
label: string;

/**
* The order that workspace template will be sorted in
*/
order?: number;

/**
* Introduction of the template
*/
description: string;

/**
* Sample screenshot image location
*/
screenshot?: string;
}
38 changes: 38 additions & 0 deletions src/core/utils/default_workspace_templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { WorkspaceTemplate } from '../types';

/** @internal */
export const DEFAULT_WORKSPACE_TEMPLATES: Record<string, WorkspaceTemplate> = Object.freeze({
search: {
id: 'search',
label: 'Search',
order: 1000,
description:
"Intro paragraph blur about search, key features, and why you'd want to create ana search workspace",
},
observability: {
id: 'observability',
label: 'Observability',
order: 2000,
description:
"Intro paragraph blur about observability, key features, and why you'd want to create ana observability workspace",
},
security_analytics: {
id: 'security_analytics',
label: 'Security Analytics',
order: 3000,
description:
"Intro paragraph blur about security analytics, key features, and why you'd want to create ana security analytics workspace",
},
general_analysis: {
id: 'general_analysis',
label: 'General Analytics',
order: 4000,
description:
"Intro paragraph blur about analytics, key features, and why you'd want to create ana analytics workspace",
},
});
1 change: 1 addition & 0 deletions src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export {
IContextProvider,
} from './context';
export { DEFAULT_APP_CATEGORIES } from './default_app_categories';
export { DEFAULT_WORKSPACE_TEMPLATES } from './default_workspace_templates';
2 changes: 2 additions & 0 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
} from '../../opensearch_dashboards_legacy/public';
import { FeatureCatalogueCategory, HomePublicPluginSetup } from '../../../plugins/home/public';
import { DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { DEFAULT_WORKSPACE_TEMPLATES } from '../../../core/public';

import {
ACTION_CLONE_PANEL,
Expand Down Expand Up @@ -366,6 +367,7 @@ export class DashboardPlugin
defaultPath: `#${DashboardConstants.LANDING_PAGE_PATH}`,
updater$: this.appStateUpdater,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
workspaceTemplate: [DEFAULT_WORKSPACE_TEMPLATES.search],
mount: async (params: AppMountParameters) => {
const [coreStart, pluginsStart, dashboardStart] = await core.getStartServices();
this.currentHistory = params.history;
Expand Down
27 changes: 24 additions & 3 deletions src/plugins/workspace/public/components/workspace_app.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect } from 'react';
import { EuiPage, EuiPageBody } from '@elastic/eui';
import { I18nProvider } from '@osd/i18n/react';
import { matchPath, Route, Switch, useLocation } from 'react-router-dom';

import { ROUTES } from './routes';
import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public';
import { ChromeBreadcrumb } from '../../../../core/public';
import { ChromeBreadcrumb, PublicAppInfo } from '../../../../core/public';
import { WORKSPACE_APP_NAME } from '../../common/constants';
import { WorkspaceTemplate } from '../../../../core/types';

export const WorkspaceApp = ({ appBasePath }: { appBasePath: string }) => {
const {
services: { chrome },
services: { chrome, application },
} = useOpenSearchDashboards();
const location = useLocation();
let workspaceTemplates = [] as WorkspaceTemplate[];
const templateFeatureMap = new Map<string, PublicAppInfo[]>();
application?.applications$.subscribe((map) =>
map.forEach((app) => {
const { workspaceTemplate: templates = [] } = app;
workspaceTemplates.push(...templates);
for (const template of templates) {
const features = templateFeatureMap.get(template.id) || [];
features.push(app);
templateFeatureMap.set(template.id, features);
}
})
);

workspaceTemplates = [...new Set(workspaceTemplates)];

/**
* map the current pathname to breadcrumbs
Expand Down Expand Up @@ -41,7 +62,7 @@ export const WorkspaceApp = ({ appBasePath }: { appBasePath: string }) => {
}
breadcrumbs.unshift({ text: WORKSPACE_APP_NAME, href: appBasePath });
chrome?.setBreadcrumbs(breadcrumbs);
}, [appBasePath, location.pathname, chrome?.setBreadcrumbs]);
}, [appBasePath, location.pathname, chrome?.setBreadcrumbs, chrome]);

return (
<I18nProvider>
Expand Down

0 comments on commit 2b5e689

Please sign in to comment.