-
Notifications
You must be signed in to change notification settings - Fork 916
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
10 changes: 10 additions & 0 deletions
10
examples/multiple_data_source_examples/opensearch_dashboards.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
examples/multiple_data_source_examples/public/application.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
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); | ||
}; |
29 changes: 29 additions & 0 deletions
29
examples/multiple_data_source_examples/public/components/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
]; |
144 changes: 144 additions & 0 deletions
144
examples/multiple_data_source_examples/public/components/data_source_list_active_example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
137 changes: 137 additions & 0 deletions
137
examples/multiple_data_source_examples/public/components/data_source_list_all_example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to, similar here https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/examples/search_examples/server/routes/server_search_route.ts#L31