diff --git a/CHANGELOG.md b/CHANGELOG.md index a1561c476f35..4d8df6292852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,8 +71,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Workspace] Add create workspace page ([#6179](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6179)) - [Multiple Datasource] Make sure customer always have a default datasource ([#6237](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6237)) - [Workspace] Add workspace list page ([#6182](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6182)) -- [Workspace] Add permission control logic ([#6052](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6052)) +- [Workspace] Add workspaces column to saved objects page ([#6225](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6225)) - [Multiple Datasource] Add multi data source support to sample vega visualizations ([#6218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6218)) +- [Workspace] Add permission control logic ([#6052](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6052)) ### 🐛 Bug Fixes @@ -94,6 +95,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [BUG][Multiple Datasource] Fix obsolete snapshots for test within data source management plugin ([#6185](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6185)) - [Workspace] Add base path when parse url in http service ([#6233](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6233)) - [Multiple Datasource] Fix sslConfig for multiple datasource to handle when certificateAuthorities is unset ([#6282](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6282)) +- [BUG][Multiple Datasource]Fix bug in data source aggregated view to change it to depend on displayAllCompatibleDataSources property to show the badge value ([#6291](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6291)) ### 🚞 Infrastructure @@ -125,6 +127,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### 🪛 Refactoring - Remove unused Sass in `tile_map` plugin ([#4110](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4110)) +- [Multiple Datasource] Move data source selectable to its own folder, fix test and a few type errors for data source selectable component ([#6287](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6287)) ### 🔩 Tests diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap index 2c789f04da12..e4f4b1f67c67 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap @@ -1,7 +1,49 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DataSourceAggregatedView should render normally with data source filter 1`] = ` - + - Data sources + - All + + All + - +
+
+ + + +
+
-
+ `; exports[`DataSourceAggregatedView should render normally with local cluster and actice selections 1`] = ` - + - Data sources + - 1 + + 1 + - +
+
+ + + +
+
-
+ `; exports[`DataSourceAggregatedView should render normally with local cluster hidden and all options 1`] = ` - + - Data sources + - All + + 0 + - +
+
+ + + +
+
-
+ `; exports[`DataSourceAggregatedView should render normally with local cluster not hidden and all options 1`] = ` diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx index 3f44bac61e5b..5bb518af2d06 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ShallowWrapper, shallow } from 'enzyme'; +import { ShallowWrapper, mount, shallow } from 'enzyme'; import React from 'react'; import { DataSourceAggregatedView } from './data_source_aggregated_view'; import { SavedObjectsClientContract } from '../../../../../core/public'; @@ -43,26 +43,29 @@ describe('DataSourceAggregatedView', () => { }); it('should render normally with local cluster hidden and all options', () => { - component = shallow( + const container = mount( ); - expect(component).toMatchSnapshot(); + expect(container).toMatchSnapshot(); expect(client.find).toBeCalledWith({ fields: ['id', 'title', 'auth.type'], perPage: 10000, type: 'data-source', }); expect(toasts.addWarning).toBeCalledTimes(0); + const badge = container.find('EuiNotificationBadge').text(); + expect(badge).toEqual('0'); }); it('should render normally with local cluster and actice selections', () => { - component = shallow( + const container = mount( { activeDataSourceIds={['test1']} /> ); - expect(component).toMatchSnapshot(); + expect(container).toMatchSnapshot(); expect(client.find).toBeCalledWith({ fields: ['id', 'title', 'auth.type'], perPage: 10000, type: 'data-source', }); expect(toasts.addWarning).toBeCalledTimes(0); + const badge = container.find('EuiNotificationBadge').text(); + expect(badge).toEqual('1'); }); it('should render normally with data source filter', () => { - component = shallow( + const container = mount( ds.attributes.auth.type !== 'no_auth'} /> ); - expect(component).toMatchSnapshot(); + expect(container).toMatchSnapshot(); expect(client.find).toBeCalledWith({ fields: ['id', 'title', 'auth.type'], perPage: 10000, type: 'data-source', }); expect(toasts.addWarning).toBeCalledTimes(0); + const badge = container.find('EuiNotificationBadge').text(); + expect(badge).toEqual('All'); }); it('should render popup when clicking on info icon', async () => { diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx index 015441773600..7c039c2f64f3 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx @@ -111,17 +111,17 @@ export class DataSourceAggregatedView extends React.Component< let items = []; // only display active data sources - if (this.props.activeDataSourceIds && this.props.activeDataSourceIds.length > 0) { - items = this.props.activeDataSourceIds.map((id) => { + if (this.props.displayAllCompatibleDataSources) { + items = [...this.state.allDataSourcesIdToTitleMap.values()].map((title) => { return { - name: this.state.allDataSourcesIdToTitleMap.get(id), + name: title, disabled: true, }; }); } else { - items = [...this.state.allDataSourcesIdToTitleMap.values()].map((title) => { + items = this.props.activeDataSourceIds!.map((id) => { return { - name: title, + name: this.state.allDataSourcesIdToTitleMap.get(id), disabled: true, }; }); @@ -155,7 +155,8 @@ export class DataSourceAggregatedView extends React.Component< {'Data sources'} - {this.props.activeDataSourceIds?.length || 'All'} + {(this.props.displayAllCompatibleDataSources && 'All') || + this.props.activeDataSourceIds!.length}
-
+
+
+
+ + + 0 + +
+
+
, - "container":
, + "container":
+
+
+ + + 0 + +
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], diff --git a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx index 4f7914148ca8..538d579c4b6b 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx +++ b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx @@ -74,6 +74,7 @@ describe('DataSourceMenu', () => { hideLocalCluster: true, savedObjects: client, notifications, + displayAllCompatibleDataSources: true, }} /> ); @@ -98,12 +99,12 @@ describe('DataSourceMenu', () => { it('should render data source multi select component', () => { const container = render( ); expect(container).toMatchSnapshot(); diff --git a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx index 4015e246853f..70ca70fd5ce3 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx +++ b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx @@ -5,10 +5,9 @@ import React, { ReactElement } from 'react'; -import { DataSourceSelectable } from './data_source_selectable'; import { DataSourceAggregatedView } from '../data_source_aggregated_view'; import { DataSourceView } from '../data_source_view'; -import { DataSourceMultiSelectable } from '../data_source_multi_selectable/data_source_multi_selectable'; +import { DataSourceMultiSelectable } from '../data_source_multi_selectable'; import { DataSourceAggregatedViewConfig, DataSourceComponentType, @@ -17,6 +16,7 @@ import { DataSourceSelectableConfig, DataSourceViewConfig, } from './types'; +import { DataSourceSelectable } from '../data_source_selectable'; export function DataSourceMenu(props: DataSourceMenuProps): ReactElement | null { const { componentType, componentConfig } = props; diff --git a/src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/data_source_selectable.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_selectable/__snapshots__/data_source_selectable.test.tsx.snap similarity index 97% rename from src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/data_source_selectable.test.tsx.snap rename to src/plugins/data_source_management/public/components/data_source_selectable/__snapshots__/data_source_selectable.test.tsx.snap index 56c0e85d0219..2cb8dff8a94d 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/data_source_selectable.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_selectable/__snapshots__/data_source_selectable.test.tsx.snap @@ -20,6 +20,7 @@ exports[`DataSourceSelectable should filter options if configured 1`] = ` } closePopover={[Function]} + data-test-subj="dataSourceSelectableContextMenuPopover" display="inlineBlock" hasArrow={true} id="dataSourceSelectableContextMenuPopover" @@ -51,7 +52,7 @@ exports[`DataSourceSelectable should filter options if configured 1`] = ` }, Object { "id": "test2", - "label": "test3", + "label": "test2", }, Object { "id": "test3", @@ -94,6 +95,7 @@ exports[`DataSourceSelectable should render normally with local cluster is hidde } closePopover={[Function]} + data-test-subj="dataSourceSelectableContextMenuPopover" display="inlineBlock" hasArrow={true} id="dataSourceSelectableContextMenuPopover" @@ -153,6 +155,7 @@ exports[`DataSourceSelectable should render normally with local cluster not hidd } closePopover={[Function]} + data-test-subj="dataSourceSelectableContextMenuPopover" display="inlineBlock" hasArrow={true} id="dataSourceSelectableContextMenuPopover" @@ -199,6 +202,7 @@ Object {
{ ds.attributes.auth.type !== AuthType.NoAuth} /> ); + + await nextTick(); + const button = await container.findByTestId('dataSourceSelectableContextMenuHeaderLink'); button.click(); + + expect(container.getByTestId('dataSourceSelectableContextMenuPopover')).toBeVisible(); expect(container).toMatchSnapshot(); }); + + it('should callback if changed state', async () => { + const onSelectedDataSource = jest.fn(); + const container = mount( + ds.attributes.auth.type !== AuthType.NoAuth} + /> + ); + await nextTick(); + + const containerInstance = container.instance(); + + containerInstance.onChange([{ id: 'test2', label: 'test2' }]); + expect(onSelectedDataSource).toBeCalledTimes(0); + expect(containerInstance.state).toEqual({ + dataSourceOptions: [ + { + id: 'test2', + label: 'test2', + }, + ], + isPopoverOpen: false, + selectedOption: [ + { + id: '', + label: 'Local cluster', + }, + ], + }); + + containerInstance.onChange([{ id: 'test2', label: 'test2', checked: 'on' }]); + expect(containerInstance.state).toEqual({ + dataSourceOptions: [ + { + checked: 'on', + id: 'test2', + label: 'test2', + }, + ], + isPopoverOpen: false, + selectedOption: [ + { + checked: 'on', + id: 'test2', + label: 'test2', + }, + ], + }); + expect(onSelectedDataSource).toBeCalledWith([{ id: 'test2', label: 'test2' }]); + expect(onSelectedDataSource).toBeCalledTimes(1); + }); }); diff --git a/src/plugins/data_source_management/public/components/data_source_menu/data_source_selectable.tsx b/src/plugins/data_source_management/public/components/data_source_selectable/data_source_selectable.tsx similarity index 86% rename from src/plugins/data_source_management/public/components/data_source_menu/data_source_selectable.tsx rename to src/plugins/data_source_management/public/components/data_source_selectable/data_source_selectable.tsx index b2c8cdbe9db0..e0fccf9aa226 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/data_source_selectable.tsx +++ b/src/plugins/data_source_management/public/components/data_source_selectable/data_source_selectable.tsx @@ -6,7 +6,6 @@ import React from 'react'; import { i18n } from '@osd/i18n'; import { - EuiIcon, EuiPopover, EuiContextMenuPanel, EuiPanel, @@ -19,7 +18,7 @@ import { getDataSourcesWithFields } from '../utils'; import { LocalCluster } from '../data_source_selector/data_source_selector'; import { SavedObject } from '../../../../../core/public'; import { DataSourceAttributes } from '../../types'; -import { DataSourceOption } from './types'; +import { DataSourceOption } from '../data_source_menu/types'; interface DataSourceSelectableProps { savedObjectsClient: SavedObjectsClientContract; @@ -33,9 +32,13 @@ interface DataSourceSelectableProps { } interface DataSourceSelectableState { - dataSourceOptions: DataSourceOption[]; - selectedOption: DataSourceOption[]; + dataSourceOptions: SelectedDataSourceOption[]; isPopoverOpen: boolean; + selectedOption?: SelectedDataSourceOption[]; +} + +interface SelectedDataSourceOption extends DataSourceOption { + checked?: boolean; } export class DataSourceSelectable extends React.Component< @@ -48,6 +51,7 @@ export class DataSourceSelectable extends React.Component< super(props); this.state = { + dataSourceOptions: [], isPopoverOpen: false, selectedOption: this.props.selectedOption ? this.props.selectedOption @@ -76,7 +80,7 @@ export class DataSourceSelectable extends React.Component< getDataSourcesWithFields(this.props.savedObjectsClient, ['id', 'title', 'auth.type']) .then((fetchedDataSources) => { if (fetchedDataSources?.length) { - let filteredDataSources = []; + let filteredDataSources: Array> = []; if (this.props.dataSourceFilter) { filteredDataSources = fetchedDataSources.filter((ds) => this.props.dataSourceFilter!(ds) @@ -113,15 +117,21 @@ export class DataSourceSelectable extends React.Component< }); } - onChange(options) { + onChange(options: SelectedDataSourceOption[]) { if (!this._isMounted) return; const selectedDataSource = options.find(({ checked }) => checked); - this.setState({ - selectedOption: [selectedDataSource], - }); + this.setState({ dataSourceOptions: options }); + + if (selectedDataSource) { + this.setState({ + selectedOption: [selectedDataSource], + }); - this.props.onSelectedDataSources([selectedDataSource]); + this.props.onSelectedDataSources([ + { id: selectedDataSource.id!, label: selectedDataSource.label }, + ]); + } } render() { @@ -155,6 +165,7 @@ export class DataSourceSelectable extends React.Component< closePopover={this.closePopover.bind(this)} panelPaddingSize="none" anchorPosition="downLeft" + data-test-subj={'dataSourceSelectableContextMenuPopover'} > diff --git a/src/plugins/data_source_management/public/components/data_source_selectable/index.ts b/src/plugins/data_source_management/public/components/data_source_selectable/index.ts new file mode 100644 index 000000000000..5ddc2d2ba751 --- /dev/null +++ b/src/plugins/data_source_management/public/components/data_source_selectable/index.ts @@ -0,0 +1,5 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +export { DataSourceSelectable } from './data_source_selectable'; diff --git a/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/data_source_selector.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/data_source_selector.test.tsx.snap index 2b8e3eba860d..7306d202ff7b 100644 --- a/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/data_source_selector.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/data_source_selector.test.tsx.snap @@ -82,7 +82,7 @@ exports[`DataSourceSelector: check dataSource options should always place local }, Object { "id": "test2", - "label": "test3", + "label": "test2", }, Object { "id": "test3", @@ -127,7 +127,7 @@ exports[`DataSourceSelector: check dataSource options should filter options if c }, Object { "id": "test2", - "label": "test3", + "label": "test2", }, Object { "id": "test3", @@ -176,7 +176,7 @@ exports[`DataSourceSelector: check dataSource options should hide prepend if rem }, Object { "id": "test2", - "label": "test3", + "label": "test2", }, Object { "id": "test3", @@ -247,7 +247,7 @@ exports[`DataSourceSelector: check dataSource options should show custom placeho }, Object { "id": "test2", - "label": "test3", + "label": "test2", }, Object { "id": "test3", diff --git a/src/plugins/data_source_management/public/mocks.ts b/src/plugins/data_source_management/public/mocks.ts index d04fc2a362d3..13ccbf4e8f26 100644 --- a/src/plugins/data_source_management/public/mocks.ts +++ b/src/plugins/data_source_management/public/mocks.ts @@ -141,7 +141,7 @@ export const getDataSourcesWithFieldsResponse = { type: 'data-source', description: 'test datasource2', attributes: { - title: 'test3', + title: 'test2', auth: { type: AuthType.UsernamePasswordType, }, diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap index 1183c4cccd68..f074f9715c99 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap @@ -257,6 +257,7 @@ exports[`SavedObjectsTable should render normally 1`] = ` "has": [MockFunction], } } + availableWorkspaces={Array []} basePath={ BasePath { "basePath": "", @@ -276,6 +277,7 @@ exports[`SavedObjectsTable should render normally 1`] = ` "has": [MockFunction], } } + currentWorkspaceId="" filters={ Array [ Object { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx index 7e5bb318f4d0..3cc6d04cfac2 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx @@ -37,6 +37,7 @@ import { actionServiceMock } from '../../../services/action_service.mock'; import { columnServiceMock } from '../../../services/column_service.mock'; import { SavedObjectsManagementAction } from '../../..'; import { Table, TableProps } from './table'; +import { WorkspaceAttribute } from 'opensearch-dashboards/public'; const defaultProps: TableProps = { basePath: httpServiceMock.createSetupContract().basePath, @@ -115,6 +116,52 @@ describe('Table', () => { expect(component).toMatchSnapshot(); }); + it('should render gotoApp link correctly for workspace', () => { + const item = { + id: 'dashboard-1', + type: 'dashboard', + workspaces: ['ws-1'], + attributes: {}, + references: [], + meta: { + title: `My-Dashboard-test`, + icon: 'indexPatternApp', + editUrl: '/management/opensearch-dashboards/objects/savedDashboards/dashboard-1', + inAppUrl: { + path: '/app/dashboards#/view/dashboard-1', + uiCapabilitiesPath: 'dashboard.show', + }, + }, + }; + const props = { + ...defaultProps, + availableWorkspaces: [{ id: 'ws-1', name: 'My workspace' } as WorkspaceAttribute], + items: [item], + }; + // not in a workspace + let component = shallowWithI18nProvider(); + + let table = component.find('EuiBasicTable'); + let columns = table.prop< + Array<{ render: (id: string, record: unknown) => React.ReactElement }> + >('columns'); + let content = columns[1].render('My-Dashboard-test', item); + expect(content.props.href).toEqual('http://localhost/w/ws-1/app/dashboards#/view/dashboard-1'); + + // in a workspace + const currentWorkspaceId = 'foo-ws'; + component = shallowWithI18nProvider( +
+ ); + + table = component.find('EuiBasicTable'); + columns = table.prop('columns'); + content = columns[1].render('My-Dashboard-test', item); + expect(content.props.href).toEqual( + `http://localhost/w/${currentWorkspaceId}/app/dashboards#/view/dashboard-1` + ); + }); + it('should handle query parse error', () => { const onQueryChangeMock = jest.fn(); const customizedProps = { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx index 636933d449df..56606711db98 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx @@ -28,7 +28,7 @@ * under the License. */ -import { IBasePath } from 'src/core/public'; +import { IBasePath, WorkspaceAttribute } from 'src/core/public'; import React, { PureComponent, Fragment } from 'react'; import moment from 'moment'; import { @@ -56,6 +56,7 @@ import { SavedObjectsManagementAction, SavedObjectsManagementColumnServiceStart, } from '../../../services'; +import { formatUrlWithWorkspaceId } from '../../../../../../core/public/utils'; export interface TableProps { basePath: IBasePath; @@ -83,6 +84,8 @@ export interface TableProps { onShowRelationships: (object: SavedObjectWithMetadata) => void; canGoInApp: (obj: SavedObjectWithMetadata) => boolean; dateFormat: string; + availableWorkspaces?: WorkspaceAttribute[]; + currentWorkspaceId?: string; } interface TableState { @@ -177,8 +180,12 @@ export class Table extends PureComponent { columnRegistry, namespaceRegistry, dateFormat, + availableWorkspaces, + currentWorkspaceId, } = this.props; + const visibleWsIds = availableWorkspaces?.map((ws) => ws.id) || []; + const pagination = { pageIndex, pageSize, @@ -231,9 +238,19 @@ export class Table extends PureComponent { if (!canGoInApp) { return {title || getDefaultTitle(object)}; } - return ( - {title || getDefaultTitle(object)} - ); + let inAppUrl = basePath.prepend(path); + if (object.workspaces?.length) { + if (currentWorkspaceId) { + inAppUrl = formatUrlWithWorkspaceId(path, currentWorkspaceId, basePath); + } else { + // find first workspace user have permission + const workspaceId = object.workspaces.find((wsId) => visibleWsIds.includes(wsId)); + if (workspaceId) { + inAppUrl = formatUrlWithWorkspaceId(path, workspaceId, basePath); + } + } + } + return {title || getDefaultTitle(object)}; }, } as EuiTableFieldDataColumnType>, { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx index 5a6bf0713d95..74ae23c34dcb 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx @@ -48,6 +48,7 @@ import { notificationServiceMock, savedObjectsServiceMock, applicationServiceMock, + workspacesServiceMock, } from '../../../../../core/public/mocks'; import { dataPluginMock } from '../../../../data/public/mocks'; import { serviceRegistryMock } from '../../services/service_registry.mock'; @@ -102,6 +103,7 @@ describe('SavedObjectsTable', () => { let notifications: ReturnType; let savedObjects: ReturnType; let search: ReturnType['search']; + let workspaces: ReturnType; const shallowRender = (overrides: Partial = {}) => { return (shallowWithI18nProvider( @@ -121,6 +123,7 @@ describe('SavedObjectsTable', () => { notifications = notificationServiceMock.createStartContract(); savedObjects = savedObjectsServiceMock.createStartContract(); search = dataPluginMock.createStartContract().search; + workspaces = workspacesServiceMock.createStartContract(); const applications = applicationServiceMock.createStartContract(); applications.capabilities = { @@ -161,6 +164,7 @@ describe('SavedObjectsTable', () => { goInspectObject: () => {}, canGoInApp: () => true, search, + workspaces, }; findObjectsMock.mockImplementation(() => ({ diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx index 955482cc0676..127ed08423e3 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx @@ -65,7 +65,10 @@ import { OverlayStart, NotificationsStart, ApplicationStart, + WorkspacesStart, + WorkspaceAttribute, } from 'src/core/public'; +import { Subscription } from 'rxjs'; import { RedirectAppLinks } from '../../../../opensearch_dashboards_react/public'; import { IndexPatternsContract } from '../../../../data/public'; import { @@ -110,6 +113,7 @@ export interface SavedObjectsTableProps { overlays: OverlayStart; notifications: NotificationsStart; applications: ApplicationStart; + workspaces: WorkspacesStart; perPageConfig: number; goInspectObject: (obj: SavedObjectWithMetadata) => void; canGoInApp: (obj: SavedObjectWithMetadata) => boolean; @@ -137,10 +141,13 @@ export interface SavedObjectsTableState { exportAllOptions: ExportAllOption[]; exportAllSelectedOptions: Record; isIncludeReferencesDeepChecked: boolean; + currentWorkspaceId?: string; + availableWorkspaces?: WorkspaceAttribute[]; } - export class SavedObjectsTable extends Component { private _isMounted = false; + private currentWorkspaceIdSubscription?: Subscription; + private workspacesSubscription?: Subscription; constructor(props: SavedObjectsTableProps) { super(props); @@ -172,6 +179,7 @@ export class SavedObjectsTable extends Component { @@ -246,6 +255,24 @@ export class SavedObjectsTable extends Component { + const workspace = this.props.workspaces; + this.currentWorkspaceIdSubscription = workspace.currentWorkspaceId$.subscribe((workspaceId) => + this.setState({ + currentWorkspaceId: workspaceId, + }) + ); + + this.workspacesSubscription = workspace.workspaceList$.subscribe((workspaceList) => { + this.setState({ availableWorkspaces: workspaceList }); + }); + }; + + unSubscribeWorkspace = () => { + this.currentWorkspaceIdSubscription?.unsubscribe(); + this.workspacesSubscription?.unsubscribe(); + }; + fetchSavedObject = (type: string, id: string) => { this.setState({ isSearching: true }, () => this.debouncedFetchObject(type, id)); }; @@ -802,6 +829,8 @@ export class SavedObjectsTable extends Component diff --git a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx index b3ef976d8283..42889d6d8095 100644 --- a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx +++ b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx @@ -92,6 +92,7 @@ const SavedObjectsTablePage = ({ overlays={coreStart.overlays} notifications={coreStart.notifications} applications={coreStart.application} + workspaces={coreStart.workspaces} perPageConfig={itemsPerPage} goInspectObject={(savedObject) => { const { editUrl } = savedObject.meta; diff --git a/src/plugins/workspace/opensearch_dashboards.json b/src/plugins/workspace/opensearch_dashboards.json index efb5cef5fdbe..e6ff1e2d0173 100644 --- a/src/plugins/workspace/opensearch_dashboards.json +++ b/src/plugins/workspace/opensearch_dashboards.json @@ -7,6 +7,6 @@ "savedObjects", "opensearchDashboardsReact" ], - "optionalPlugins": [], + "optionalPlugins": ["savedObjectsManagement"], "requiredBundles": ["opensearchDashboardsReact"] } diff --git a/src/plugins/workspace/public/components/workspace_column/index.ts b/src/plugins/workspace/public/components/workspace_column/index.ts new file mode 100644 index 000000000000..a9325eb49279 --- /dev/null +++ b/src/plugins/workspace/public/components/workspace_column/index.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export { getWorkspaceColumn, WorkspaceColumn } from './workspace_column'; diff --git a/src/plugins/workspace/public/components/workspace_column/workspace_colum.test.tsx b/src/plugins/workspace/public/components/workspace_column/workspace_colum.test.tsx new file mode 100644 index 000000000000..655bd9e57f2c --- /dev/null +++ b/src/plugins/workspace/public/components/workspace_column/workspace_colum.test.tsx @@ -0,0 +1,59 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import React from 'react'; +import { coreMock } from '../../../../../core/public/mocks'; +import { render } from '@testing-library/react'; +import { WorkspaceColumn } from './workspace_column'; + +describe('workspace column in saved objects page', () => { + const coreSetup = coreMock.createSetup(); + const workspaceList = [ + { + id: 'ws-1', + name: 'foo', + }, + { + id: 'ws-2', + name: 'bar', + }, + ]; + coreSetup.workspaces.workspaceList$.next(workspaceList); + + it('should show workspace name correctly', () => { + const workspaces = ['ws-1', 'ws-2']; + const { container } = render(); + expect(container).toMatchInlineSnapshot(` +
+
+ foo | bar +
+
+ `); + }); + + it('show empty when no workspace', () => { + const { container } = render(); + expect(container).toMatchInlineSnapshot(` +
+
+
+ `); + }); + + it('show empty when workspace can not found', () => { + const { container } = render(); + expect(container).toMatchInlineSnapshot(` +
+
+
+ `); + }); +}); diff --git a/src/plugins/workspace/public/components/workspace_column/workspace_column.tsx b/src/plugins/workspace/public/components/workspace_column/workspace_column.tsx new file mode 100644 index 000000000000..3d964009ee86 --- /dev/null +++ b/src/plugins/workspace/public/components/workspace_column/workspace_column.tsx @@ -0,0 +1,49 @@ +/* + * 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 } from '../../../../saved_objects_management/public'; + +interface WorkspaceColumnProps { + coreSetup: CoreSetup; + workspaces?: string[]; +} + +export function WorkspaceColumn({ coreSetup, workspaces }: WorkspaceColumnProps) { + const workspaceList = useObservable(coreSetup.workspaces.workspaceList$); + + const wsLookUp = workspaceList?.reduce((map, ws) => { + return map.set(ws.id, ws.name); + }, new Map()); + + 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[]) => { + return ; + }, + }, + loadData: () => { + return Promise.resolve(undefined); + }, + }; +} diff --git a/src/plugins/workspace/public/plugin.test.ts b/src/plugins/workspace/public/plugin.test.ts index 793ed5e0f09f..83572ae761e3 100644 --- a/src/plugins/workspace/public/plugin.test.ts +++ b/src/plugins/workspace/public/plugin.test.ts @@ -9,6 +9,7 @@ import { workspaceClientMock, WorkspaceClientMock } from './workspace_client.moc import { applicationServiceMock, chromeServiceMock, coreMock } from '../../../core/public/mocks'; import { WorkspacePlugin } from './plugin'; import { WORKSPACE_FATAL_ERROR_APP_ID, WORKSPACE_OVERVIEW_APP_ID } from '../common/constants'; +import { savedObjectsManagementPluginMock } from '../../saved_objects_management/public/mocks'; describe('Workspace plugin', () => { const getSetupMock = () => ({ @@ -21,17 +22,21 @@ describe('Workspace plugin', () => { }); it('#setup', async () => { const setupMock = getSetupMock(); + const savedObjectManagementSetupMock = savedObjectsManagementPluginMock.createSetupContract(); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock); + await workspacePlugin.setup(setupMock, { + savedObjectsManagement: savedObjectManagementSetupMock, + }); expect(setupMock.application.register).toBeCalledTimes(3); expect(WorkspaceClientMock).toBeCalledTimes(1); + expect(savedObjectManagementSetupMock.columns.register).toBeCalledTimes(1); }); it('#call savedObjectsClient.setCurrentWorkspace when current workspace id changed', async () => { const workspacePlugin = new WorkspacePlugin(); const setupMock = getSetupMock(); const coreStart = coreMock.createStart(); - await workspacePlugin.setup(setupMock); + await workspacePlugin.setup(setupMock, {}); workspacePlugin.start(coreStart); coreStart.workspaces.currentWorkspaceId$.next('foo'); expect(coreStart.savedObjects.client.setCurrentWorkspace).toHaveBeenCalledWith('foo'); @@ -69,7 +74,7 @@ describe('Workspace plugin', () => { }); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock); + await workspacePlugin.setup(setupMock, {}); expect(setupMock.application.register).toBeCalledTimes(3); expect(WorkspaceClientMock).toBeCalledTimes(1); expect(workspaceClientMock.enterWorkspace).toBeCalledWith('workspaceId'); @@ -123,7 +128,7 @@ describe('Workspace plugin', () => { }); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock); + await workspacePlugin.setup(setupMock, {}); currentAppIdSubscriber?.next(WORKSPACE_FATAL_ERROR_APP_ID); expect(applicationStartMock.navigateToApp).toBeCalledWith(WORKSPACE_OVERVIEW_APP_ID); windowSpy.mockRestore(); @@ -132,7 +137,7 @@ describe('Workspace plugin', () => { it('#setup register workspace dropdown menu when setup', async () => { const setupMock = coreMock.createSetup(); const workspacePlugin = new WorkspacePlugin(); - await workspacePlugin.setup(setupMock); + await workspacePlugin.setup(setupMock, {}); expect(setupMock.chrome.registerCollapsibleNavHeader).toBeCalledTimes(1); }); }); diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index bce606583b85..c28bc2f1cb1a 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -22,11 +22,17 @@ import { import { getWorkspaceIdFromUrl } from '../../../core/public/utils'; import { Services } from './types'; import { WorkspaceClient } from './workspace_client'; +import { SavedObjectsManagementPluginSetup } from '../../../plugins/saved_objects_management/public'; import { WorkspaceMenu } from './components/workspace_menu/workspace_menu'; +import { getWorkspaceColumn } from './components/workspace_column'; type WorkspaceAppType = (params: AppMountParameters, services: Services) => () => void; -export class WorkspacePlugin implements Plugin<{}, {}, {}> { +interface WorkspacePluginSetupDeps { + savedObjectsManagement?: SavedObjectsManagementPluginSetup; +} + +export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> { private coreStart?: CoreStart; private currentWorkspaceSubscription?: Subscription; private _changeSavedObjectCurrentWorkspace() { @@ -39,7 +45,7 @@ export class WorkspacePlugin implements Plugin<{}, {}, {}> { } } - public async setup(core: CoreSetup) { + public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacePluginSetupDeps) { const workspaceClient = new WorkspaceClient(core.http, core.workspaces); await workspaceClient.init(); @@ -140,6 +146,11 @@ export class WorkspacePlugin implements Plugin<{}, {}, {}> { }, }); + /** + * register workspace column into saved objects table + */ + savedObjectsManagement?.columns.register(getWorkspaceColumn(core)); + return {}; }