[ML] Fix pagination and sorting on trained models list page (#99061) (#99082)

This commit is contained in:
Dima Arnautov 2021-05-03 21:29:57 +02:00 committed by GitHub
parent 59b716db72
commit fb52647084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View file

@ -28,6 +28,7 @@ import { EuiDescriptionListProps } from '@elastic/eui/src/components/description
import { ModelItemFull } from './models_list';
import { useMlKibana } from '../../../../../contexts/kibana';
import { timeFormatter } from '../../../../../../../common/util/date_utils';
import { isDefined } from '../../../../../../../common/types/guards';
interface ExpandedRowProps {
item: ModelItemFull;
@ -81,6 +82,7 @@ export const ExpandedRow: FC<ExpandedRowProps> = ({ item }) => {
function formatToListItems(items: Record<string, any>): EuiDescriptionListProps['listItems'] {
return Object.entries(items)
.filter(([, value]) => isDefined(value))
.map(([title, value]) => {
if (title in formatterDictionary) {
return {
@ -102,12 +104,9 @@ export const ExpandedRow: FC<ExpandedRowProps> = ({ item }) => {
{JSON.stringify(value, null, 2)}
</EuiCodeBlock>
) : (
value
value.toString()
),
};
})
.filter(({ description: d }) => {
return d !== undefined;
});
}

View file

@ -53,6 +53,7 @@ import { timeFormatter } from '../../../../../../../common/util/date_utils';
import { ListingPageUrlState } from '../../../../../../../common/types/common';
import { usePageUrlState } from '../../../../../util/url_state';
import { BUILT_IN_MODEL_TAG } from '../../../../../../../common/constants/data_frame_analytics';
import { useTableSettings } from '../analytics_list/use_table_settings';
type Stats = Omit<TrainedModelStat, 'model_id'>;
@ -90,12 +91,6 @@ export const ModelsList: FC = () => {
);
const searchQueryText = pageState.queryText ?? '';
const setSearchQueryText = useCallback(
(value) => {
updatePageState({ queryText: value });
},
[updatePageState]
);
const canDeleteDataFrameAnalytics = capabilities.ml.canDeleteDataFrameAnalytics as boolean;
@ -521,13 +516,19 @@ export const ModelsList: FC = () => {
}
: undefined;
const { onTableChange, pagination, sorting } = useTableSettings<ModelItem>(
items,
pageState,
updatePageState
);
const search: EuiSearchBarProps = {
query: searchQueryText,
onChange: (searchChange) => {
if (searchChange.error !== null) {
return false;
}
setSearchQueryText(searchChange.queryText);
updatePageState({ queryText: searchChange.queryText, pageIndex: 0 });
return true;
},
box: {
@ -572,6 +573,9 @@ export const ModelsList: FC = () => {
rowProps={(item) => ({
'data-test-subj': `mlModelsTableRow row-${item.model_id}`,
})}
pagination={pagination}
onTableChange={onTableChange}
sorting={sorting}
/>
</div>
{modelsToDelete.length > 0 && (