Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
  • Loading branch information
yujin-emma committed Apr 23, 2024
1 parent 9de49fa commit 8de1750
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DataSourceBaseState, DataSourceOption } from '../data_source_menu/types
import {
getDataSourceById,
handleDataSourceFetchError,
handleDataSourceViewError,
handleNoAvailableDataSourceError,
} from '../utils';
import { DataSourceDropDownHeader } from '../drop_down_header';
Expand Down Expand Up @@ -118,10 +119,12 @@ export class DataSourceView extends React.Component<DataSourceViewProps, DataSou
if (defaultDataSource) {
this.setState({ defaultDataSource });

Check warning on line 120 in src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx#L120

Added line #L120 was not covered by tests
}
handleDataSourceFetchError(
handleDataSourceViewError(
this.onError.bind(this),
this.props.notifications!,
this.props.onSelectedDataSources
this.state.selectedOption[0].id,
this.state.defaultDataSource,
() => this.handleSwitchDefaultDatasource()

Check warning on line 127 in src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/data_source_view/data_source_view.tsx#L127

Added line #L127 was not covered by tests
);
}
} else if (this.props.onSelectedDataSources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@elastic/eui';
import { ErrorIcon } from '../custom_database_icon';
import { DataSourceDropDownHeader } from '../drop_down_header';
import { switchDefaultButton } from '../toast_button/switch_default_button';

interface DataSourceViewErrorProps {
application?: ApplicationStart;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiButton } from '@elastic/eui';
import React from 'react';
import { i18n } from '@osd/i18n';

export const switchDefaultButton = (handleSwitchDefaultDatasource: () => Promise<void>) => {
return (

Check warning on line 11 in src/plugins/data_source_management/public/components/toast_button/switch_default_button.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/toast_button/switch_default_button.tsx#L11

Added line #L11 was not covered by tests
<EuiButton
data-test-subj="dataSourceViewErrorSwitchButton"
fill={false}
size="s"
onClick={handleSwitchDefaultDatasource}
>
{i18n.translate('dataSourcesManagement.dataSourceViewError.switchToDefaultDataSource', {
defaultMessage: 'Switch to default data source',
})}
</EuiButton>
);
};
18 changes: 18 additions & 0 deletions src/plugins/data_source_management/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DataSourceGroupLabelOption } from './data_source_menu/types';
import { createGetterSetter } from '../../../opensearch_dashboards_utils/public';
import { toMountPoint } from '../../../opensearch_dashboards_react/public';
import { getManageDataSourceButton, getReloadButton } from './toast_button';
import { switchDefaultButton } from './toast_button/switch_default_button';

export async function getDataSources(savedObjectsClient: SavedObjectsClientContract) {
return savedObjectsClient
Expand Down Expand Up @@ -303,6 +304,23 @@ export const handleDataSourceFetchError = (
});
};

export const handleDataSourceViewError = (
changeState: (state: { showError: boolean }) => void,
notifications: ToastsStart,
failedDataSourceId: string,
defaultDataSource: string | null,
callback?: () => Promise<void>
) => {
changeState({ showError: true });
notifications.add({
title: i18n.translate('dataSource.dataSourceUnavailableError', {
defaultMessage: `Data source ${failedDataSourceId} is not available `,
}),
text: defaultDataSource && callback ? toMountPoint(switchDefaultButton(callback)) : '',
color: 'danger',
});
};

interface DataSourceOptionGroupLabel {
[key: string]: DataSourceGroupLabelOption;
}
Expand Down

0 comments on commit 8de1750

Please sign in to comment.