Skip to content

Commit 5bc6460

Browse files
committed
[ML] Reset paging when data changes.
1 parent e9f8ef7 commit 5bc6460

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

x-pack/legacy/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { useCallback, useMemo, useState } from 'react';
7+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
88

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

@@ -52,6 +52,8 @@ interface Props {
5252
query: PivotQuery;
5353
}
5454

55+
const defaultPagination = { pageIndex: 0, pageSize: 5 };
56+
5557
export const SourceIndexPreview: React.FC<Props> = React.memo(({ query }) => {
5658
const indexPattern = useCurrentIndexPattern();
5759
const allFields = indexPattern.fields.map(f => f.name);
@@ -72,7 +74,11 @@ export const SourceIndexPreview: React.FC<Props> = React.memo(({ query }) => {
7274
// Column visibility
7375
const [visibleColumns, setVisibleColumns] = useState<EsFieldName[]>(indexPatternFields);
7476

75-
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 5 });
77+
const [pagination, setPagination] = useState(defaultPagination);
78+
79+
useEffect(() => {
80+
setPagination(defaultPagination);
81+
}, [query]);
7682

7783
const { errorMessage, status, rowCount, tableItems: data } = useSourceIndexData(
7884
indexPattern,

x-pack/legacy/plugins/transform/public/app/sections/create_transform/components/step_define/pivot_preview.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ interface PivotPreviewProps {
106106
query: PivotQuery;
107107
}
108108

109+
const defaultPagination = { pageIndex: 0, pageSize: 5 };
110+
109111
export const PivotPreview: FC<PivotPreviewProps> = React.memo(({ aggs, groupBy, query }) => {
110112
const indexPattern = useCurrentIndexPattern();
111113

@@ -132,7 +134,13 @@ export const PivotPreview: FC<PivotPreviewProps> = React.memo(({ aggs, groupBy,
132134
// eslint-disable-next-line react-hooks/exhaustive-deps
133135
}, [JSON.stringify(columnKeys)]);
134136

135-
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 5 });
137+
const [pagination, setPagination] = useState(defaultPagination);
138+
139+
// Reset pagination if data changes. This is to avoid ending up with an empty table
140+
// when for example the user selected a page that is not available with the updated data.
141+
useEffect(() => {
142+
setPagination(defaultPagination);
143+
}, [data.length]);
136144

137145
// EuiDataGrid State
138146
const dataGridColumns = columnKeys.map(id => ({ id }));

0 commit comments

Comments
 (0)