diff --git a/src/plugins/workspace/opensearch_dashboards.json b/src/plugins/workspace/opensearch_dashboards.json index 0273a579bfcb..0efc89373a94 100644 --- a/src/plugins/workspace/opensearch_dashboards.json +++ b/src/plugins/workspace/opensearch_dashboards.json @@ -4,6 +4,7 @@ "server": false, "ui": true, "requiredPlugins": ["savedObjects"], + "optionalPlugins": ["savedObjectsManagement"], "requiredBundles": [ "opensearchDashboardsReact" ] diff --git a/src/plugins/workspace/public/components/utils/workspace_column.tsx b/src/plugins/workspace/public/components/utils/workspace_column.tsx new file mode 100644 index 000000000000..b51a4d3178f6 --- /dev/null +++ b/src/plugins/workspace/public/components/utils/workspace_column.tsx @@ -0,0 +1,66 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { EuiText } from '@elastic/eui'; +import useObservable from 'react-use/lib/useObservable'; +import { i18n } from '@osd/i18n'; +import { WorkspaceAttribute, CoreSetup } from '../../../../../core/public'; +import { + SavedObjectsManagementColumn, + SavedObjectsManagementRecord, +} from '../../../../saved_objects_management/public'; + +interface WorkspaceColumnProps { + coreSetup: CoreSetup; + workspaces?: string[]; + record: SavedObjectsManagementRecord; +} + +function WorkspaceColumn({ coreSetup, workspaces, record }: WorkspaceColumnProps) { + const workspaceList = useObservable(coreSetup.workspaces.client.workspaceList$); + + const wsLookUp = workspaceList?.reduce((map, ws) => { + return map.set(ws.id, ws.name); + }, new Map()); + + const publicWsName = i18n.translate('workspace.public.name', { + defaultMessage: 'public', + }); + wsLookUp?.set('public', publicWsName); + + if (record.type === 'workspace') { + return null; + } + + if (!workspaces) { + return {publicWsName}; + } + + const workspaceNames = workspaces?.map((wsId) => wsLookUp?.get(wsId)).join(' | '); + + return {workspaceNames}; +} + +export function getWorkspaceColumn( + coreSetup: CoreSetup +): SavedObjectsManagementColumn { + return { + id: 'workspace_column', + euiColumn: { + align: 'left', + field: 'workspaces', + name: i18n.translate('savedObjectsManagement.objectsTable.table.columnWorkspacesName', { + defaultMessage: 'Workspaces', + }), + render: (workspaces: string[], record: SavedObjectsManagementRecord) => { + return ; + }, + }, + loadData: () => { + return Promise.resolve(undefined); + }, + }; +} diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index c221e892aa58..45e8d6deb036 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -4,6 +4,7 @@ */ import { i18n } from '@osd/i18n'; +import type { Subscription } from 'rxjs'; import { CoreSetup, CoreStart, @@ -14,9 +15,14 @@ import { import { WORKSPACE_APP_ID } from '../common/constants'; import { mountDropdownList } from './mount'; import { getWorkspaceIdFromUrl } from '../../../core/public/utils'; -import type { Subscription } from 'rxjs'; +import { SavedObjectsManagementPluginSetup } from '../../saved_objects_management/public'; +import { getWorkspaceColumn } from './components/utils/workspace_column'; + +interface WorkspacesPluginSetupDeps { + savedObjectsManagement?: SavedObjectsManagementPluginSetup; +} -export class WorkspacesPlugin implements Plugin<{}, {}> { +export class WorkspacesPlugin implements Plugin<{}, {}, WorkspacesPluginSetupDeps> { private coreSetup?: CoreSetup; private coreStart?: CoreStart; private currentWorkspaceSubscription?: Subscription; @@ -39,7 +45,7 @@ export class WorkspacesPlugin implements Plugin<{}, {}> { return newUrl.toString(); }; - public async setup(core: CoreSetup) { + public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacesPluginSetupDeps) { // If workspace feature is disabled, it will not load the workspace plugin if (core.uiSettings.get('workspace:enabled') === false) { return {}; @@ -63,6 +69,10 @@ export class WorkspacesPlugin implements Plugin<{}, {}> { ); } } + /** + * register workspace column into saved objects table + */ + savedObjectsManagement?.columns.register(getWorkspaceColumn(core)); core.application.register({ id: WORKSPACE_APP_ID,