Skip to content

Commit

Permalink
[ML] DF Analytics list: ensure job messages and jobs load correctly (#…
Browse files Browse the repository at this point in the history
…75676) (#75774)

* ensure messages load on first open

* ensure analytics management list does not load infinitely
  • Loading branch information
alvarezmelissa87 authored Aug 24, 2020
1 parent f0ce720 commit 4186553
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC, useState, useEffect } from 'react';
import React, { FC, useCallback, useState, useEffect } from 'react';

import { i18n } from '@kbn/i18n';

Expand Down Expand Up @@ -119,11 +119,13 @@ export const DataFrameAnalyticsList: FC<Props> = ({
}
}, [selectedIdFromUrlInitialized, analytics]);

const getAnalyticsCallback = useCallback(() => getAnalytics(true), []);

// Subscribe to the refresh observable to trigger reloading the analytics list.
useRefreshAnalyticsList(
{
isLoading: setIsLoading,
onRefresh: () => getAnalytics(true),
onRefresh: getAnalyticsCallback,
},
isManagementTable
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC, useState } from 'react';
import React, { FC, useState, useEffect, useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { ml } from '../../../../../services/ml_api_service';
import { useRefreshAnalyticsList } from '../../../../common';
Expand All @@ -20,45 +20,34 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState('');

const getMessagesFactory = () => {
let concurrentLoads = 0;
return async function getMessages() {
try {
concurrentLoads++;

if (concurrentLoads > 1) {
return;
}

setIsLoading(true);
const messagesResp = await ml.dataFrameAnalytics.getAnalyticsAuditMessages(analyticsId);
setIsLoading(false);
setMessages(messagesResp);

concurrentLoads--;

if (concurrentLoads > 0) {
concurrentLoads = 0;
getMessages();
}
} catch (error) {
setIsLoading(false);
setErrorMessage(
i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', {
defaultMessage: 'Messages could not be loaded',
})
);
}
};
};
useRefreshAnalyticsList({ onRefresh: getMessagesFactory() });
const getMessages = useCallback(async () => {
try {
setIsLoading(true);
const messagesResp = await ml.dataFrameAnalytics.getAnalyticsAuditMessages(analyticsId);
setIsLoading(false);
setMessages(messagesResp);
} catch (error) {
setIsLoading(false);
setErrorMessage(
i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', {
defaultMessage: 'Messages could not be loaded',
})
);
}
}, []);

useEffect(() => {
getMessages();
}, []);

useRefreshAnalyticsList({ onRefresh: getMessages });

return (
<JobMessages
messages={messages}
loading={isLoading}
error={errorMessage}
refreshMessage={getMessagesFactory()}
refreshMessage={getMessages}
/>
);
};

0 comments on commit 4186553

Please sign in to comment.