@awsui/collection-hooks
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -1,2 +0,2 @@ | ||
import { UseCollectionOptions, CollectionState } from '../interfaces'; | ||
import { UseCollectionOptions, CollectionState, TrackBy } from '../interfaces'; | ||
export declare function processItems<T>(items: ReadonlyArray<T>, { filteringText, sortingState, currentPageIndex, propertyFilteringQuery }: Partial<CollectionState<T>>, { filtering, sorting, pagination, propertyFiltering }: UseCollectionOptions<T>): { | ||
@@ -8,3 +8,3 @@ items: ReadonlyArray<T>; | ||
}; | ||
export declare const processSelectedItems: <T>(items: readonly T[], selectedItems: readonly T[], trackBy?: string | ((item: T) => string) | undefined) => T[]; | ||
export declare const itemsAreEqual: <T>(items1: readonly T[], items2: readonly T[], trackBy?: string | ((item: T) => string) | undefined) => boolean; | ||
export declare const processSelectedItems: <T>(items: readonly T[], selectedItems: readonly T[], trackBy?: TrackBy<T> | undefined) => T[]; | ||
export declare const itemsAreEqual: <T>(items1: readonly T[], items2: readonly T[], trackBy?: TrackBy<T> | undefined) => boolean; |
@@ -16,16 +16,16 @@ "use strict"; | ||
if (propertyFiltering) { | ||
result = property_filter_js_1.propertyFilter(result, propertyFilteringQuery || { tokens: [], operation: 'and' }, propertyFiltering); | ||
result = (0, property_filter_js_1.propertyFilter)(result, propertyFilteringQuery || { tokens: [], operation: 'and' }, propertyFiltering); | ||
filteredItemsCount = result.length; | ||
} | ||
if (filtering) { | ||
result = filter_js_1.filter(result, filteringText, filtering); | ||
result = (0, filter_js_1.filter)(result, filteringText, filtering); | ||
filteredItemsCount = result.length; | ||
} | ||
if (sorting) { | ||
result = sort_js_1.sort(result, sortingState); | ||
result = (0, sort_js_1.sort)(result, sortingState); | ||
} | ||
if (pagination) { | ||
pagesCount = paginate_js_1.getPagesCount(result, pagination.pageSize); | ||
actualPageIndex = paginate_js_1.normalizePageIndex(currentPageIndex, pagesCount); | ||
result = paginate_js_1.paginate(result, actualPageIndex, pagination.pageSize); | ||
pagesCount = (0, paginate_js_1.getPagesCount)(result, pagination.pageSize); | ||
actualPageIndex = (0, paginate_js_1.normalizePageIndex)(currentPageIndex, pagesCount); | ||
result = (0, paginate_js_1.paginate)(result, actualPageIndex, pagination.pageSize); | ||
} | ||
@@ -32,0 +32,0 @@ return { items: result, pagesCount: pagesCount, filteredItemsCount: filteredItemsCount, actualPageIndex: actualPageIndex }; |
@@ -40,3 +40,3 @@ "use strict"; | ||
} | ||
var itemValue = exports.fixupFalsyValues(item[token.propertyKey]); | ||
var itemValue = (0, exports.fixupFalsyValues)(item[token.propertyKey]); | ||
return filterUsingOperator(itemValue, token.value, token.operator); | ||
@@ -43,0 +43,0 @@ } |
@@ -8,3 +8,3 @@ "use strict"; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
var _k = react_1.useReducer(utils_js_1.collectionReducer, { | ||
var _k = (0, react_1.useReducer)(utils_js_1.collectionReducer, { | ||
selectedItems: (_b = (_a = options.selection) === null || _a === void 0 ? void 0 : _a.defaultSelectedItems) !== null && _b !== void 0 ? _b : [], | ||
@@ -18,3 +18,3 @@ sortingState: (_c = options.sorting) === null || _c === void 0 ? void 0 : _c.defaultState, | ||
state, | ||
utils_js_1.createActions({ | ||
(0, utils_js_1.createActions)({ | ||
dispatch: dispatch, | ||
@@ -21,0 +21,0 @@ collectionRef: collectionRef, |
@@ -20,8 +20,8 @@ "use strict"; | ||
function useCollection(allItems, options) { | ||
var collectionRef = react_1.useRef(null); | ||
var _a = use_collection_state_js_1.useCollectionState(options, collectionRef), state = _a[0], actions = _a[1]; | ||
var _b = index_js_1.processItems(allItems, state, options), items = _b.items, pagesCount = _b.pagesCount, filteredItemsCount = _b.filteredItemsCount, actualPageIndex = _b.actualPageIndex; | ||
var collectionRef = (0, react_1.useRef)(null); | ||
var _a = (0, use_collection_state_js_1.useCollectionState)(options, collectionRef), state = _a[0], actions = _a[1]; | ||
var _b = (0, index_js_1.processItems)(allItems, state, options), items = _b.items, pagesCount = _b.pagesCount, filteredItemsCount = _b.filteredItemsCount, actualPageIndex = _b.actualPageIndex; | ||
if (options.selection && !options.selection.keepSelection) { | ||
var newSelectedItems = index_js_1.processSelectedItems(items, state.selectedItems, options.selection.trackBy); | ||
if (!index_js_1.itemsAreEqual(newSelectedItems, state.selectedItems)) { | ||
var newSelectedItems = (0, index_js_1.processSelectedItems)(items, state.selectedItems, options.selection.trackBy); | ||
if (!(0, index_js_1.itemsAreEqual)(newSelectedItems, state.selectedItems)) { | ||
// This is a recommended pattern for how to handle the state, dependent on the incoming props | ||
@@ -32,5 +32,3 @@ // https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops | ||
} | ||
return __assign({ items: items, | ||
filteredItemsCount: filteredItemsCount, | ||
actions: actions }, utils_js_1.createSyncProps(options, state, actions, collectionRef, { | ||
return __assign({ items: items, filteredItemsCount: filteredItemsCount, actions: actions }, (0, utils_js_1.createSyncProps)(options, state, actions, collectionRef, { | ||
actualPageIndex: actualPageIndex, | ||
@@ -37,0 +35,0 @@ pagesCount: pagesCount, |
@@ -83,3 +83,3 @@ "use strict"; | ||
Object.keys(allItems.reduce(function (acc, item) { | ||
acc['' + property_filter_js_1.fixupFalsyValues(item[property.key])] = true; | ||
acc['' + (0, property_filter_js_1.fixupFalsyValues)(item[property.key])] = true; | ||
return acc; | ||
@@ -86,0 +86,0 @@ }, {})).forEach(function (value) { |
@@ -1,2 +0,2 @@ | ||
import { UseCollectionOptions, CollectionState } from '../interfaces'; | ||
import { UseCollectionOptions, CollectionState, TrackBy } from '../interfaces'; | ||
export declare function processItems<T>(items: ReadonlyArray<T>, { filteringText, sortingState, currentPageIndex, propertyFilteringQuery }: Partial<CollectionState<T>>, { filtering, sorting, pagination, propertyFiltering }: UseCollectionOptions<T>): { | ||
@@ -8,3 +8,3 @@ items: ReadonlyArray<T>; | ||
}; | ||
export declare const processSelectedItems: <T>(items: readonly T[], selectedItems: readonly T[], trackBy?: string | ((item: T) => string) | undefined) => T[]; | ||
export declare const itemsAreEqual: <T>(items1: readonly T[], items2: readonly T[], trackBy?: string | ((item: T) => string) | undefined) => boolean; | ||
export declare const processSelectedItems: <T>(items: readonly T[], selectedItems: readonly T[], trackBy?: TrackBy<T> | undefined) => T[]; | ||
export declare const itemsAreEqual: <T>(items1: readonly T[], items2: readonly T[], trackBy?: TrackBy<T> | undefined) => boolean; |
@@ -28,5 +28,3 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
return __assign({ items: items, | ||
filteredItemsCount: filteredItemsCount, | ||
actions: actions }, createSyncProps(options, state, actions, collectionRef, { | ||
return __assign({ items: items, filteredItemsCount: filteredItemsCount, actions: actions }, createSyncProps(options, state, actions, collectionRef, { | ||
actualPageIndex: actualPageIndex, | ||
@@ -33,0 +31,0 @@ pagesCount: pagesCount, |
{ | ||
"name": "@awsui/collection-hooks", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"type": "module", | ||
@@ -42,3 +42,3 @@ "main": "./dist/cjs/index.js", | ||
"ts-jest": { | ||
"tsConfig": "tsconfig.unit.json" | ||
"tsconfig": "tsconfig.unit.json" | ||
} | ||
@@ -45,0 +45,0 @@ }, |
65714
1215