diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.tsx index 5f98c0136cc1a..dad0f0e5ee282 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.tsx @@ -82,13 +82,7 @@ export const TransformList: FC = ({ const { refresh } = useRefreshTransformList({ isLoading: setIsLoading }); const [searchQueryText, setSearchQueryText] = useState(''); - const [filteredTransforms, setFilteredTransforms] = useState<{ - active: boolean; - items: TransformListRow[]; - }>({ - active: false, - items: [], - }); + const [filteredTransforms, setFilteredTransforms] = useState([]); const [expandedRowItemIds, setExpandedRowItemIds] = useState([]); const [transformSelection, setTransformSelection] = useState([]); const [isActionsMenuOpen, setIsActionsMenuOpen] = useState(false); @@ -109,12 +103,12 @@ export const TransformList: FC = ({ transformSelection ); - const setQueryClauses = (queryClauses: any) => { + const updateFilteredItems = (queryClauses: any) => { if (queryClauses.length) { const filtered = filterTransforms(transforms, queryClauses); - setFilteredTransforms({ active: true, items: filtered }); + setFilteredTransforms(filtered); } else { - setFilteredTransforms({ active: false, items: [] }); + setFilteredTransforms(transforms); } }; @@ -126,18 +120,18 @@ export const TransformList: FC = ({ if (query && query.ast !== undefined && query.ast.clauses !== undefined) { clauses = query.ast.clauses; } - setQueryClauses(clauses); + updateFilteredItems(clauses); } else { - setQueryClauses([]); + updateFilteredItems([]); } }; filterList(); // eslint-disable-next-line - }, [searchQueryText, transforms]); // missing dependency setQueryClauses + }, [searchQueryText, transforms]); // missing dependency updateFilteredItems - const { onTableChange, pageOfItems, pagination, sorting } = useTableSettings( + const { onTableChange, pageOfItems, pagination, sorting } = useTableSettings( TRANSFORM_LIST_COLUMN.ID, - filteredTransforms.active ? filteredTransforms.items : transforms + filteredTransforms ); // Before the transforms have been loaded for the first time, display the loading indicator only. diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_search_bar.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_search_bar.tsx index 8c6e66ca0ac19..fab591f881310 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_search_bar.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_search_bar.tsx @@ -12,6 +12,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiFormRow, + SearchFilterConfig, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { TermClause, FieldClause, Value } from './common'; @@ -19,12 +20,12 @@ import { TRANSFORM_STATE } from '../../../../../../common'; import { TRANSFORM_MODE, TransformListRow } from '../../../../common'; import { getTaskStateBadge } from './use_columns'; -const filters = [ +const filters: SearchFilterConfig[] = [ { - type: 'field_value_selection' as const, + type: 'field_value_selection', field: 'state.state', name: i18n.translate('xpack.transform.statusFilter', { defaultMessage: 'Status' }), - multiSelect: 'or' as const, + multiSelect: 'or', options: Object.values(TRANSFORM_STATE).map((val) => ({ value: val, name: val, @@ -32,7 +33,7 @@ const filters = [ })), }, { - type: 'field_value_selection' as const, + type: 'field_value_selection', field: 'mode', name: i18n.translate('xpack.transform.modeFilter', { defaultMessage: 'Mode' }), multiSelect: false, @@ -116,7 +117,7 @@ export const filterTransforms = ( function getError(errorMessage: string | null) { if (errorMessage) { - return i18n.translate('xpack.ml.transformList.searchBar.invalidSearchErrorMessage', { + return i18n.translate('xpack.transform.transformList.searchBar.invalidSearchErrorMessage', { defaultMessage: 'Invalid search: {errorMessage}', values: { errorMessage }, }); diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_table_settings.ts b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_table_settings.ts index d742940fa14c1..ad40a3f8103b9 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_table_settings.ts +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_table_settings.ts @@ -8,7 +8,6 @@ import { useState } from 'react'; import { Direction, EuiBasicTableProps, EuiTableSortingType } from '@elastic/eui'; import sortBy from 'lodash/sortBy'; import get from 'lodash/get'; -import { TransformListRow } from '../../../../common'; const PAGE_SIZE = 10; const PAGE_SIZE_OPTIONS = [10, 25, 50]; @@ -17,27 +16,46 @@ const propertyMap = { Mode: 'mode', }; -interface AnalyticsBasicTableSettings { +// Copying from EUI EuiBasicTable types as type is not correctly picked up for table's onChange +// Can be removed when https://github.com/elastic/eui/issues/4011 is addressed in EUI +export interface Criteria { + page?: { + index: number; + size: number; + }; + sort?: { + field: keyof T; + direction: Direction; + }; +} +export interface CriteriaWithPagination extends Criteria { + page: { + index: number; + size: number; + }; +} + +interface AnalyticsBasicTableSettings { pageIndex: number; pageSize: number; totalItemCount: number; hidePerPageOptions: boolean; - sortField: string; + sortField: keyof T; sortDirection: Direction; } -interface UseTableSettingsReturnValue { - onTableChange: EuiBasicTableProps['onChange']; - pageOfItems: TransformListRow[]; - pagination: EuiBasicTableProps['pagination']; +interface UseTableSettingsReturnValue { + onTableChange: EuiBasicTableProps['onChange']; + pageOfItems: T[]; + pagination: EuiBasicTableProps['pagination']; sorting: EuiTableSortingType; } -export function useTableSettings( - sortByField: string, - items: TransformListRow[] -): UseTableSettingsReturnValue { - const [tableSettings, setTableSettings] = useState({ +export function useTableSettings( + sortByField: keyof TypeOfItem, + items: TypeOfItem[] +): UseTableSettingsReturnValue { + const [tableSettings, setTableSettings] = useState>({ pageIndex: 0, pageSize: PAGE_SIZE, totalItemCount: 0, @@ -47,10 +65,10 @@ export function useTableSettings( }); const getPageOfItems = ( - list: any[], + list: TypeOfItem[], index: number, size: number, - sortField: string, + sortField: keyof TypeOfItem, sortDirection: Direction ) => { list = sortBy(list, (item) => @@ -73,13 +91,10 @@ export function useTableSettings( }; }; - const onTableChange = ({ + const onTableChange: EuiBasicTableProps['onChange'] = ({ page = { index: 0, size: PAGE_SIZE }, sort = { field: sortByField, direction: 'asc' }, - }: { - page?: { index: number; size: number }; - sort?: { field: string; direction: Direction }; - }) => { + }: CriteriaWithPagination) => { const { index, size } = page; const { field, direction } = sort;