Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multiple Datasource] Create examples about how to consume data source components #6302

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/multiple_data_source_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Developer examples

The multiple data source examples adds a few pages to the developer example which is a landing page where developers go to search for working, tested examples of various developer
services. This example using the developerExamples `register` function offered on the `setup` contract to register the app.

To run the example in OpenSearch Dashboards with developer examples:

```
yarn start --run-examples
```

Then navigate to "Developer examples" and click on "Multiple Data Source Integration"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "multipleDataSourceExamples",
"version": "0.0.1",
"opensearchDashboardsVersion": "opensearchDashboards",
"server": false,
"ui": true,
"requiredPlugins": ["developerExamples", "navigation"],
"optionalPlugins": ["dataSource", "dataSourceManagement"]
}

36 changes: 36 additions & 0 deletions examples/multiple_data_source_examples/public/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import ReactDOM from 'react-dom';
import { DataSourcePluginSetup } from 'src/plugins/data_source/public';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the relative path for the import?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { DataSourceManagementPluginSetup } from 'src/plugins/data_source_management/public';
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
import { CoreStart, AppMountParameters } from '../../../src/core/public';
import { Home } from './components/home';

export const renderApp = (
{ notifications, http, savedObjects, application }: CoreStart,
dataSource: DataSourcePluginSetup,
dataSourceManagement: DataSourceManagementPluginSetup,
{ appBasePath, element, setHeaderActionMenu }: AppMountParameters,
navigation: NavigationPublicPluginStart
) => {
ReactDOM.render(
<Home
basename={appBasePath}
notifications={notifications}
http={http}
savedObjects={savedObjects}
dataSourceEnabled={dataSource.dataSourceEnabled}
setActionMenu={setHeaderActionMenu}
dataSourceManagement={dataSourceManagement}
navigateToApp={application.navigateToApp}
navigation={navigation}
/>,
element
);

return () => ReactDOM.unmountComponentAtNode(element);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { EuiBasicTableColumn } from '@elastic/eui';
import { ComponentProp } from './types';

export const COLUMNS: Array<EuiBasicTableColumn<ComponentProp>> = [
{
field: 'name',
name: 'Name',
},
{
field: 'required',
name: 'Required',
},
{
field: 'defaultValue',
name: 'Default Value',
},
{
field: 'description',
name: 'Description',
},
{
field: 'deprecated',
name: 'Deprecated',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import {
EuiBasicTable,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
EuiPageHeader,
EuiPageHeaderSection,
EuiSpacer,
EuiText,
EuiTitle,
} from '@elastic/eui';
import { MountPoint, CoreStart } from 'opensearch-dashboards/public';
import {
DataSourceAggregatedViewConfig,
DataSourceManagementPluginSetup,
} from 'src/plugins/data_source_management/public';
import { ComponentProp } from './types';
import { COLUMNS } from './constants';

interface DataSourceListActiveExampleProps {
savedObjects: CoreStart['savedObjects'];
dataSourceEnabled: boolean;
notifications: CoreStart['notifications'];
setActionMenu?: (menuMount: MountPoint | undefined) => void;
dataSourceManagement: DataSourceManagementPluginSetup;
}

export const DataSourceListActiveExample = ({
savedObjects,
dataSourceEnabled,
notifications,
setActionMenu,
dataSourceManagement,
}: DataSourceListActiveExampleProps) => {
const DataSourceMenu = dataSourceManagement.ui.getDataSourceMenu<
DataSourceAggregatedViewConfig
>();
const data: ComponentProp[] = [
{
name: 'savedObjects',
required: true,
defaultValue: '-',
description: 'The saved object client is used to fetch available data sources',
deprecated: false,
},
{
name: 'notifications',
required: true,
defaultValue: '-',
description: 'The notifications toasts object exposes interfaces to show toasts',
deprecated: false,
},
{
name: 'hideLocalCluster',
required: false,
defaultValue: 'false',
description: 'The property to hide local cluster from the data source selector',
deprecated: false,
},
{
name: 'fullWidth',
required: true,
defaultValue: '-',
description:
'The property of OutComboBox and when specified to true would expand to the entire width available',
deprecated: false,
},
{
name: 'displayAllCompatibleDataSources',
required: false,
defaultValue: 'undefined',
description: 'When specified to true, it will show all compatible data sources',
deprecated: false,
},
{
name: 'dataSourceFilter',
required: false,
defaultValue: 'undefined',
description:
'When specified, the filter function will be used to filter the available options before rendering',
deprecated: false,
},
{
name: 'activeDataSourceIds',
required: false,
defaultValue: 'undefined',
description:
'This property is only assessed when displayAllCompatibleDataSources is set to false, it is used to specify the active data source ids and the component will show active data sources',
deprecated: false,
},
];

return (
<EuiPageBody component="main">
<EuiPageHeader>
{dataSourceEnabled && (
<DataSourceMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceAggregatedView'}
componentConfig={{
fullWidth: false,
savedObjects: savedObjects.client,
notifications,
displayAllCompatibleDataSources: true,
}}
/>
)}
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>Data Source Aggregated View To List Active Example</h1>
</EuiTitle>
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentBody>
<EuiText>
The data source aggregated view component is introduced in 2.14 which uses
OuiContextMenu and OuiPopOver as the base components. When multi data source feature is
enabled, this component can be consumed by adding dataSourceManagement as option plugin,
and then mounted to the navigation bar by passing setHeaderActionMenu from
AppMountParameters to the getDataSourceMenu function exposed from the plugin. This
component can be used to show active connected data sources in the page. Find the
mounted example in the navigation bar
</EuiText>
<EuiSpacer />
<EuiText>
The component exposes a few properties via the DataSourceMenu component:
</EuiText>
<EuiBasicTable
tableCaption="dataSourceListActiveEuiBasicTable"
items={data}
rowHeader="name"
columns={COLUMNS}
/>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import {
EuiBasicTable,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
EuiPageHeader,
EuiPageHeaderSection,
EuiText,
EuiTitle,
EuiSpacer,
} from '@elastic/eui';
import { CoreStart, MountPoint } from 'opensearch-dashboards/public';
import {
DataSourceAggregatedViewConfig,
DataSourceManagementPluginSetup,
} from 'src/plugins/data_source_management/public';
import { ComponentProp } from './types';
import { COLUMNS } from './constants';

interface DataSourceListAllExampleProps {
savedObjects: CoreStart['savedObjects'];
dataSourceEnabled: boolean;
notifications: CoreStart['notifications'];
setActionMenu?: (menuMount: MountPoint | undefined) => void;
dataSourceManagement: DataSourceManagementPluginSetup;
}

export const DataSourceListAllExample = ({
savedObjects,
dataSourceEnabled,
notifications,
setActionMenu,
dataSourceManagement,
}: DataSourceListAllExampleProps) => {
const DataSourceMenu = dataSourceManagement.ui.getDataSourceMenu<
DataSourceAggregatedViewConfig
>();

const data: ComponentProp[] = [
{
name: 'savedObjects',
required: true,
defaultValue: '-',
description: 'The saved object client is used to fetch available data sources',
deprecated: false,
},
{
name: 'notifications',
required: true,
defaultValue: '-',
description: 'The notifications toasts object exposes interfaces to show toasts',
deprecated: false,
},
{
name: 'hideLocalCluster',
required: false,
defaultValue: 'false',
description: 'The property to hide local cluster from the data source selector',
deprecated: false,
},
{
name: 'fullWidth',
required: true,
defaultValue: '-',
description:
'The property of OutComboBox and when specified to true would expand to the entire width available',
deprecated: false,
},
{
name: 'displayAllCompatibleDataSources',
required: false,
defaultValue: 'undefined',
description: 'When specified to true, it will show all compatible data sources',
deprecated: false,
},
{
name: 'dataSourceFilter',
required: false,
defaultValue: 'undefined',
description:
'When specified, the filter function will be used to filter the available options before rendering',
deprecated: false,
},
];

return (
<EuiPageBody component="main">
<EuiPageHeader>
{dataSourceEnabled && (
<DataSourceMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceAggregatedView'}
componentConfig={{
fullWidth: false,
savedObjects: savedObjects.client,
notifications,
displayAllCompatibleDataSources: true,
}}
/>
)}
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>Data Source Aggregated View To List All Example</h1>
</EuiTitle>
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiPageContent>
<EuiPageContentBody>
<EuiText>
The data source aggregated view component is introduced in 2.14 which uses
OuiContextMenu and OuiPopOver as the base components. When multi data source feature is
enabled, this component can be consumed by adding dataSourceManagement as option plugin,
and then mounted to the navigation bar by passing setHeaderActionMenu from
AppMountParameters to the getDataSourceMenu function exposed from the plugin. This
component can be used to show all qualified connected data sources in the page. Find the
mounted example in the navigation bar
</EuiText>
<EuiSpacer />
<EuiText>
The component exposes a few properties via the DataSourceMenu component:
</EuiText>
<EuiBasicTable
tableCaption="dataSourceListAllEuiBasicTable"
items={data}
rowHeader="name"
columns={COLUMNS}
/>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
);
};
Loading
Loading