diff --git a/packages/shared-ux/table_persist/src/types.ts b/packages/shared-ux/table_persist/src/types.ts index 280b8a9bf9321..be6a32459b440 100644 --- a/packages/shared-ux/table_persist/src/types.ts +++ b/packages/shared-ux/table_persist/src/types.ts @@ -6,11 +6,12 @@ * Side Public License, v 1. */ -import { Criteria } from '@elastic/eui'; - -export type PropertySort = Criteria['sort']; +export interface PropertySort { + field: keyof T; + direction: 'asc' | 'desc'; +} export interface PersistData { pageSize?: number; - sort?: PropertySort; + sort?: PropertySort; } diff --git a/packages/shared-ux/table_persist/src/use_table_persist.ts b/packages/shared-ux/table_persist/src/use_table_persist.ts index f1b093e361868..98a161376de32 100644 --- a/packages/shared-ux/table_persist/src/use_table_persist.ts +++ b/packages/shared-ux/table_persist/src/use_table_persist.ts @@ -19,7 +19,7 @@ export interface EuiTablePersistProps { /** (Optional) Specifies a custom onTableChange handler. */ customOnTableChange?: (change: Criteria) => void; /** (Optional) Specifies a custom initial table sorting. */ - initialSort?: PropertySort; + initialSort?: PropertySort; /** (Optional) Specifies a custom initial page size for the table. Defaults to 50. */ initialPageSize?: number; /** (Optional) Specifies custom page size options for the table. @@ -50,7 +50,7 @@ export const useEuiTablePersist = ({ const [pageSize, setPageSize] = useState( storagePageSize ?? initialPageSize ?? DEFAULT_INITIAL_PAGE_SIZE ); - const [sort, setSort] = useState(storageSort ?? initialSort); + const [sort, setSort] = useState | undefined>(storageSort ?? initialSort); const sorting = sort && { sort }; const onTableChange = useCallback( @@ -59,7 +59,7 @@ export const useEuiTablePersist = ({ customOnTableChange(nextValues); } - let nextSort: PropertySort | undefined; + let nextSort: PropertySort | undefined; if (nextValues.sort?.field && nextValues.sort?.direction) { // Both field and direction are needed for a valid sort criteria nextSort = nextValues.sort;