[ML] Fix Trained models list crashes on browser refresh if not on page 1 (#164163)

## Summary

Fixes https://github.com/elastic/kibana/issues/162618

There was an issue with setting pagination for the EUI table before
models are fetched. Providing a page index while the items count is 0
caused pagination to reset with an uninitialized URL state callback.
This PR adds a check to verify model list has been retrieved.

Also, the Kibana `_stats` endpoint has been updated to provide a `size`
parameter.
This commit is contained in:
Dima Arnautov 2023-08-17 18:55:33 +02:00 committed by GitHub
parent 0a331f1023
commit 24baf38eaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View file

@ -37,6 +37,7 @@ import {
GetAnalyticsModelIdArg,
} from './types';
import type { MlClient } from '../../lib/ml_client';
import { DEFAULT_TRAINED_MODELS_PAGE_SIZE } from '../../routes/trained_models';
export class AnalyticsManager {
private _trainedModels: estypes.MlTrainedModelConfig[] = [];
@ -47,7 +48,7 @@ export class AnalyticsManager {
private async initData() {
const [models, jobs] = await Promise.all([
this._mlClient.getTrainedModels(),
this._mlClient.getTrainedModels({ size: DEFAULT_TRAINED_MODELS_PAGE_SIZE }),
this._mlClient.getDataFrameAnalytics({ size: 1000 }),
]);
this._trainedModels = models.trained_model_configs;