Skip to content

Commit

Permalink
[ML] Initialize saved objects on trained model page load (elastic#201426
Browse files Browse the repository at this point in the history
)

Fixes elastic#201410

On page load, we now call the saved object initialization api which
creates any missing saved objects.
  • Loading branch information
jgowdyelastic authored Nov 27, 2024
1 parent 9e75f18 commit 6a649b2
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { FC } from 'react';
import { type FC, useCallback } from 'react';
import React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
Expand All @@ -19,6 +19,7 @@ import { useRouteResolver } from '../../use_resolver';
import { basicResolvers } from '../../resolvers';
import { getBreadcrumbWithUrlForApp } from '../../breadcrumbs';
import { MlPageHeader } from '../../../components/page_header';
import { useSavedObjectsApiService } from '../../../services/ml_api_service/saved_objects';

const ModelsList = dynamic(async () => ({
default: (await import('../../../model_management/models_list')).ModelsList,
Expand Down Expand Up @@ -48,7 +49,20 @@ export const modelsListRouteFactory = (
});

const PageWrapper: FC = () => {
const { context } = useRouteResolver('full', ['canGetTrainedModels'], basicResolvers());
const { initSavedObjects } = useSavedObjectsApiService();

const initSavedObjectsWrapper = useCallback(async () => {
try {
await initSavedObjects();
} catch (error) {
// ignore error as user may not have permission to sync
}
}, [initSavedObjects]);

const { context } = useRouteResolver('full', ['canGetTrainedModels'], {
...basicResolvers(),
initSavedObjectsWrapper,
});

return (
<PageLoader context={context}>
Expand Down

0 comments on commit 6a649b2

Please sign in to comment.