Skip to content

Commit

Permalink
Refactor read-only component to cover more edge case
Browse files Browse the repository at this point in the history
Signed-off-by: Yuanqi(Ella) Zhu <zhyuanqi@amazon.com>
  • Loading branch information
zhyuanqi committed Apr 15, 2024
1 parent 476cffc commit 018c6d5
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [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))
- [BUG][Multiple Datasource]Read hideLocalCluster setting from yml and set in data source selector and data source menu ([#6361](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6361))
- [BUG][Multiple Datasource] Refactor read-only component to cover more edge cases ([#6416](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6416))
- [BUG] Fix for checkForFunctionProperty so that order does not matter ([#6248](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6248))
- [BUG][Multiple Datasource] Validation succeed as long as status code in response is 200 ([#6399](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6399))

Expand Down
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 @@ -47,6 +47,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 018c6d5

Please sign in to comment.