Skip to content

Commit

Permalink
Refactor read-only component to cover more edge cases (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#6416) (opensearch-project#6466)

* Refactor read-only component to cover more edge case

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

* fix test

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

* fix snapshot

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>

---------

Signed-off-by: Yuanqi(Ella) Zhu <[email protected]>
(cherry picked from commit b9acf57)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent d33c0c9 commit 9cbfa64
Show file tree
Hide file tree
Showing 11 changed files with 414 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import React, { useState, useMemo } from 'react';
import {
EuiBasicTable,
EuiPageBody,
Expand Down Expand Up @@ -34,8 +34,11 @@ export const DataSourceViewExample = ({
dataSourceEnabled,
setActionMenu,
dataSourceManagement,
notifications,
savedObjects,
}: DataSourceViewExampleProps) => {
const DataSourceMenu = dataSourceManagement.ui.getDataSourceMenu<DataSourceViewConfig>();
const [selectedDataSources, setSelectedDataSources] = useState<string[]>([]);
const data: ComponentProp[] = [
{
name: 'savedObjects',
Expand Down Expand Up @@ -68,19 +71,31 @@ export const DataSourceViewExample = ({
},
];

const renderDataSourceComponent = useMemo(() => {
return (
<DataSourceMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceView'}
componentConfig={{
notifications,
savedObjects: savedObjects.client,
fullWidth: false,
activeOption: [{ id: '' }],
dataSourceFilter: (ds) => {
return true;
},
onSelectedDataSources: (ds) => {
setSelectedDataSources(ds);
},
}}
/>
);
}, [setActionMenu, notifications, savedObjects]);

return (
<EuiPageBody component="main">
<EuiPageHeader>
{dataSourceEnabled && (
<DataSourceMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceView'}
componentConfig={{
fullWidth: false,
activeOption: [{ id: 'example id', label: 'example data source' }],
}}
/>
)}
{dataSourceEnabled && renderDataSourceComponent}
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>Data Source View Example</h1>
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/data_source_management/public/components/constants.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import { DataSourceOption } from './data_source_menu/types';

export const LocalCluster: DataSourceOption = {
label: i18n.translate('dataSource.localCluster', {
defaultMessage: 'Local cluster',
}),
id: '',
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@ export function DataSourceMenu<T>(props: DataSourceMenuProps<T>): ReactElement |
const { componentType, componentConfig, uiSettings, hideLocalCluster } = props;

function renderDataSourceView(config: DataSourceViewConfig): ReactElement | null {
const { activeOption, fullWidth, savedObjects, notifications } = config;
const {
activeOption,
fullWidth,
savedObjects,
notifications,
dataSourceFilter,
onSelectedDataSources,
} = config;
return (
<DataSourceView
fullWidth={fullWidth}
selectedOption={activeOption}
savedObjectsClient={savedObjects}
notifications={notifications?.toasts}
hideLocalCluster={hideLocalCluster || false}
dataSourceFilter={dataSourceFilter}
onSelectedDataSources={onSelectedDataSources}
uiSettings={uiSettings}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface DataSourceViewConfig extends DataSourceBaseConfig {
activeOption: DataSourceOption[];
savedObjects?: SavedObjectsClientContract;
notifications?: NotificationsStart;
dataSourceFilter?: (dataSource: SavedObject<DataSourceAttributes>) => boolean;
onSelectedDataSources?: (dataSources: DataSourceOption[]) => void;
}

export interface DataSourceAggregatedViewConfig extends DataSourceBaseConfig {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9cbfa64

Please sign in to comment.