Skip to content

Commit dc1daf9

Browse files
committed
[ML] Use hook and add error toast for DFA job messages
1 parent 4c52eae commit dc1daf9

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row_messages_pane.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ml } from '../../../../../services/ml_api_service';
1212
import { useRefreshAnalyticsList } from '../../../../common';
1313
import { JobMessages } from '../../../../../components/job_messages';
1414
import { JobMessage } from '../../../../../../../common/types/audit_message';
15+
import { useToastNotificationService } from '../../../../../services/toast_notification_service';
1516

1617
interface Props {
1718
analyticsId: string;
@@ -21,6 +22,7 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
2122
const [messages, setMessages] = useState<JobMessage[]>([]);
2223
const [isLoading, setIsLoading] = useState(false);
2324
const [errorMessage, setErrorMessage] = useState('');
25+
const toastNotificationService = useToastNotificationService();
2426

2527
const getMessages = useCallback(async () => {
2628
try {
@@ -30,6 +32,16 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
3032
setMessages(messagesResp);
3133
} catch (error) {
3234
setIsLoading(false);
35+
toastNotificationService.displayErrorToast(
36+
error,
37+
i18n.translate(
38+
'xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorToastMessageTitle',
39+
{
40+
defaultMessage: 'Error loading job messages',
41+
}
42+
)
43+
);
44+
3345
setErrorMessage(
3446
i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', {
3547
defaultMessage: 'Messages could not be loaded',

x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/job_messages_pane.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { ml } from '../../../../services/ml_api_service';
1010
import { JobMessages } from '../../../../components/job_messages';
1111
import { JobMessage } from '../../../../../../common/types/audit_message';
1212
import { extractErrorMessage } from '../../../../../../common/util/errors';
13-
import { toastNotificationServiceProvider } from '../../../../services/toast_notification_service';
14-
import { useMlKibana } from '../../../../contexts/kibana';
13+
import { useToastNotificationService } from '../../../../services/toast_notification_service';
1514
interface JobMessagesPaneProps {
1615
jobId: string;
1716
}
@@ -20,11 +19,7 @@ export const JobMessagesPane: FC<JobMessagesPaneProps> = ({ jobId }) => {
2019
const [messages, setMessages] = useState<JobMessage[]>([]);
2120
const [isLoading, setIsLoading] = useState(false);
2221
const [errorMessage, setErrorMessage] = useState('');
23-
const {
24-
services: {
25-
notifications: { toasts },
26-
},
27-
} = useMlKibana();
22+
const toastNotificationService = useToastNotificationService();
2823

2924
const fetchMessages = async () => {
3025
setIsLoading(true);
@@ -33,11 +28,10 @@ export const JobMessagesPane: FC<JobMessagesPaneProps> = ({ jobId }) => {
3328
setIsLoading(false);
3429
} catch (error) {
3530
setIsLoading(false);
36-
const toastNotificationService = toastNotificationServiceProvider(toasts);
3731
toastNotificationService.displayErrorToast(
3832
error,
3933
i18n.translate('xpack.ml.jobService.jobAuditMessagesErrorTitle', {
40-
defaultMessage: 'Job Audit Messages Error',
34+
defaultMessage: 'Error loading job messages',
4135
})
4236
);
4337

0 commit comments

Comments
 (0)