Skip to content

Commit

Permalink
remove usage of deprecated onError
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokaditya committed Oct 24, 2024
1 parent a194211 commit 4c8f844
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { css } from '@emotion/react';
import { EuiFlexGroup, EuiFlexItem, EuiLoadingElastic } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { Charts } from './charts';
import { useBreadcrumbs } from '../../utils/use_breadcrumbs';
import { useKibanaContextForPlugin } from '../../utils/use_kibana';
Expand All @@ -29,7 +30,7 @@ const FlexItemWithCss = ({ children }: { children: React.ReactNode }) => (

export const DataUsageMetrics = () => {
const {
services: { chrome, appParams },
services: { chrome, appParams, notifications },
} = useKibanaContextForPlugin();
useBreadcrumbs([{ text: PLUGIN_NAME }], appParams, chrome);

Expand All @@ -43,7 +44,11 @@ export const DataUsageMetrics = () => {
setUrlDateRangeFilter,
} = useDataUsageMetricsUrlParams();

const { data: dataStreams, isFetching: isFetchingDataStreams } = useGetDataUsageDataStreams({
const {
error: errorFetchingDataStreams,
data: dataStreams,
isFetching: isFetchingDataStreams,
} = useGetDataUsageDataStreams({
selectedDataStreams: dataStreamsFromUrl,
options: {
enabled: true,
Expand Down Expand Up @@ -93,6 +98,7 @@ export const DataUsageMetrics = () => {
const { dateRangePickerState, onRefreshChange, onTimeChange } = useDateRangePicker();

const {
error: errorFetchingDataUsageMetrics,
data,
isFetching,
isFetched,
Expand Down Expand Up @@ -157,6 +163,23 @@ export const DataUsageMetrics = () => {
onChangeMetricTypesFilter,
]);

if (errorFetchingDataUsageMetrics) {
notifications.toasts.addDanger({
title: i18n.translate('xpack.dataUsage.getMetrics.addFailure.toast.title', {
defaultMessage: 'Error getting usage metrics',
}),
text: errorFetchingDataUsageMetrics.message,
});
}
if (errorFetchingDataStreams) {
notifications.toasts.addDanger({
title: i18n.translate('xpack.dataUsage.getDataStreams.addFailure.toast.title', {
defaultMessage: 'Error getting data streams',
}),
text: errorFetchingDataStreams.message,
});
}

return (
<EuiFlexGroup alignItems="flexStart" direction="column">
<FlexItemWithCss>
Expand Down
12 changes: 0 additions & 12 deletions x-pack/plugins/data_usage/public/hooks/use_get_data_streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
import { i18n } from '@kbn/i18n';
import { useQuery } from '@tanstack/react-query';
import type { IHttpFetchError } from '@kbn/core-http-browser';
import { DATA_USAGE_DATA_STREAMS_API_ROUTE } from '../../common';
Expand All @@ -33,9 +32,6 @@ export const useGetDataUsageDataStreams = ({
options?: UseQueryOptions<GetDataUsageDataStreamsResponse, IHttpFetchError>;
}): UseQueryResult<GetDataUsageDataStreamsResponse, IHttpFetchError> => {
const http = useKibanaContextForPlugin().services.http;
const {
services: { notifications },
} = useKibanaContextForPlugin();

return useQuery<GetDataUsageDataStreamsResponse, IHttpFetchError>({
queryKey: ['get-data-usage-data-streams'],
Expand Down Expand Up @@ -87,13 +83,5 @@ export const useGetDataUsageDataStreams = ({
: PAGING_PARAMS.default
);
},
onError: (error: IHttpFetchError) => {
notifications.toasts.addDanger({
title: i18n.translate('xpack.dataUsage.getDataStreams.addFailure.toast.title', {
defaultMessage: 'Error getting data streams',
}),
text: error.message,
});
},
});
};
12 changes: 0 additions & 12 deletions x-pack/plugins/data_usage/public/hooks/use_get_usage_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
import { i18n } from '@kbn/i18n';
import { useQuery } from '@tanstack/react-query';
import type { IHttpFetchError } from '@kbn/core-http-browser';
import { UsageMetricsRequestBody, UsageMetricsResponseSchemaBody } from '../../common/rest_types';
Expand All @@ -23,9 +22,6 @@ export const useGetDataUsageMetrics = (
options: UseQueryOptions<UsageMetricsResponseSchemaBody, IHttpFetchError<ErrorType>> = {}
): UseQueryResult<UsageMetricsResponseSchemaBody, IHttpFetchError<ErrorType>> => {
const http = useKibanaContextForPlugin().services.http;
const {
services: { notifications },
} = useKibanaContextForPlugin();

return useQuery<UsageMetricsResponseSchemaBody, IHttpFetchError<ErrorType>>({
queryKey: ['get-data-usage-metrics', body],
Expand All @@ -43,13 +39,5 @@ export const useGetDataUsageMetrics = (
}),
});
},
onError: (error: IHttpFetchError<ErrorType>) => {
notifications.toasts.addDanger({
title: i18n.translate('xpack.dataUsage.getMetrics.addFailure.toast.title', {
defaultMessage: 'Error getting usage metrics',
}),
text: error.message,
});
},
});
};

0 comments on commit 4c8f844

Please sign in to comment.