Skip to content

Commit

Permalink
Merge pull request #6 from Hailong-am/feature/workspace
Browse files Browse the repository at this point in the history
workspace template init commit
  • Loading branch information
Hailong-am authored Jun 12, 2023
2 parents 62b34eb + 65363da commit 99fc9eb
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 1 deletion.
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;

/**
* template coverage image location
*/
coverImage?: 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
35 changes: 35 additions & 0 deletions src/plugins/workspace/public/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ApplicationStart, PublicAppInfo } from 'opensearch-dashboards/public';
import { useObservable } from 'react-use';
import { useMemo } from 'react';
import { WorkspaceTemplate } from '../../../core/types';

export function useWorkspaceTemplate(application: ApplicationStart) {
const applications = useObservable(application.applications$);

return useMemo(() => {
let workspaceTemplates = [] as WorkspaceTemplate[];
const templateFeatureMap = new Map<string, PublicAppInfo[]>();

if (applications) {
applications.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)];
workspaceTemplates.sort((a, b) => (a.order || 0) - (b.order || 0));
}

return { workspaceTemplates, templateFeatureMap };
}, [applications]);
}

0 comments on commit 99fc9eb

Please sign in to comment.