@equinor/fusion
Advanced tools
Comparing version 0.1.79 to 0.1.80
export declare type PropertyAccessorFunction<T> = (item: T) => string | null; | ||
export declare type PropertyAccessor<T> = keyof T | PropertyAccessorFunction<T>; | ||
export declare type SortDirection = "asc" | "desc"; | ||
export declare const applySorting: <T>(data: T[], sortBy?: PropertyAccessorFunction<T> | keyof T | null, direction?: "desc" | "asc" | null) => T[]; | ||
declare const _default: <T>(data: T[], defaultSortBy?: PropertyAccessorFunction<T> | keyof T | null, defaultDirection?: "desc" | "asc" | null) => { | ||
sortedData: T[]; | ||
export declare const applySorting: <T>(data: readonly T[], sortBy?: PropertyAccessorFunction<T> | keyof T | null, direction?: "desc" | "asc" | null) => readonly T[]; | ||
declare const _default: <T>(data: readonly T[], defaultSortBy?: PropertyAccessorFunction<T> | keyof T | null, defaultDirection?: "desc" | "asc" | null) => { | ||
sortedData: readonly T[]; | ||
sortBy: PropertyAccessorFunction<T> | keyof T | null; | ||
direction: "desc" | "asc" | null; | ||
set: (newSortBy: PropertyAccessorFunction<T> | keyof T | null, newDirection: "desc" | "asc" | null) => void; | ||
reset: () => void; | ||
setSortBy: (newSortBy: PropertyAccessorFunction<T> | keyof T | null, newDirection: "desc" | "asc" | null) => void; | ||
resetSorting: () => void; | ||
}; | ||
export default _default; |
@@ -18,3 +18,3 @@ import { useState, useEffect } from "react"; | ||
} | ||
const comparer = new Intl.Collator().compare; | ||
const comparer = new Intl.Collator('co', { numeric: true }).compare; | ||
return data.slice().sort((a, b) => { | ||
@@ -51,7 +51,7 @@ const aValue = getValue(a, sortBy); | ||
}, [data, sortBy, direction]); | ||
const reset = () => { | ||
const resetSorting = () => { | ||
setSortBy(null); | ||
setDirection(null); | ||
}; | ||
const set = (newSortBy, newDirection) => { | ||
const updateSortBy = (newSortBy, newDirection) => { | ||
newDirection = | ||
@@ -68,5 +68,5 @@ newDirection || sortBy === newSortBy || !newSortBy | ||
direction, | ||
set, | ||
reset, | ||
setSortBy: updateSortBy, | ||
resetSorting, | ||
}; | ||
}; |
@@ -38,2 +38,2 @@ export declare type Page = { | ||
}; | ||
export declare const useAsyncPagination: <T>(fetchAsync: (pagination: Pagination) => Promise<PagedResult<T>>, initialPerPage: number, initialCurrentPageIndex?: number, padding?: number) => AsyncPaginationHook<T>; | ||
export declare const useAsyncPagination: <T>(fetchAsync: (pagination: Pagination) => Promise<PagedResult<T>>, initialPerPage: number, initialCurrentPageIndex?: number, padding?: number, deps?: readonly any[]) => AsyncPaginationHook<T>; |
@@ -90,3 +90,3 @@ import { useState, useEffect, useCallback } from "react"; | ||
}; | ||
export const useAsyncPagination = (fetchAsync, initialPerPage, initialCurrentPageIndex = 0, padding = 3) => { | ||
export const useAsyncPagination = (fetchAsync, initialPerPage, initialCurrentPageIndex = 0, padding = 3, deps = []) => { | ||
const [currentPageIndex, setCurrentPageIndex] = useState(initialCurrentPageIndex); | ||
@@ -121,3 +121,3 @@ const [perPage, setPerPage] = useState(initialPerPage); | ||
return applyPaginationAsync(); | ||
}, [currentPageIndex, perPage]); | ||
}, [currentPageIndex, perPage, ...deps]); | ||
const setCurrentPage = useCallback((index, perPage) => { | ||
@@ -124,0 +124,0 @@ setCurrentPageIndex(index); |
{ | ||
"name": "@equinor/fusion", | ||
"version": "0.1.79", | ||
"version": "0.1.80", | ||
"description": "Everything a Fusion app needs to communicate with the core", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
149994