Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaStoeva committed Aug 15, 2024
1 parent 096abab commit a2aa291
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/shared-ux/table_persist/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
* Side Public License, v 1.
*/

import { Criteria } from '@elastic/eui';

export type PropertySort = Criteria<any>['sort'];
export interface PropertySort<T> {
field: keyof T;
direction: 'asc' | 'desc';
}

export interface PersistData<T> {
pageSize?: number;
sort?: PropertySort;
sort?: PropertySort<T>;
}
6 changes: 3 additions & 3 deletions packages/shared-ux/table_persist/src/use_table_persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface EuiTablePersistProps<T> {
/** (Optional) Specifies a custom onTableChange handler. */
customOnTableChange?: (change: Criteria<T>) => void;
/** (Optional) Specifies a custom initial table sorting. */
initialSort?: PropertySort;
initialSort?: PropertySort<T>;
/** (Optional) Specifies a custom initial page size for the table. Defaults to 50. */
initialPageSize?: number;
/** (Optional) Specifies custom page size options for the table.
Expand Down Expand Up @@ -50,7 +50,7 @@ export const useEuiTablePersist = <T extends object>({
const [pageSize, setPageSize] = useState<number>(
storagePageSize ?? initialPageSize ?? DEFAULT_INITIAL_PAGE_SIZE
);
const [sort, setSort] = useState<PropertySort | undefined>(storageSort ?? initialSort);
const [sort, setSort] = useState<PropertySort<T> | undefined>(storageSort ?? initialSort);
const sorting = sort && { sort };

const onTableChange = useCallback(
Expand All @@ -59,7 +59,7 @@ export const useEuiTablePersist = <T extends object>({
customOnTableChange(nextValues);
}

let nextSort: PropertySort | undefined;
let nextSort: PropertySort<T> | undefined;
if (nextValues.sort?.field && nextValues.sort?.direction) {
// Both field and direction are needed for a valid sort criteria
nextSort = nextValues.sort;
Expand Down

0 comments on commit a2aa291

Please sign in to comment.