@snack-uikit/table 0.37.27 → 0.37.28-preview-b0a70f1c.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/dist/cjs/components/Table/Table.js +7 -5
- package/dist/cjs/components/Table/styles.module.css +4 -1
- package/dist/cjs/components/Table/utils/saveTableState/mappers.d.ts +2 -2
- package/dist/cjs/components/Table/utils/saveTableState/mappers.js +3 -3
- package/dist/cjs/components/Table/utils/saveTableState/validators.d.ts +1 -1
- package/dist/esm/components/Table/Table.js +6 -5
- package/dist/esm/components/Table/styles.module.css +4 -1
- package/dist/esm/components/Table/utils/saveTableState/mappers.d.ts +2 -2
- package/dist/esm/components/Table/utils/saveTableState/mappers.js +3 -3
- package/dist/esm/components/Table/utils/saveTableState/validators.d.ts +1 -1
- package/package.json +4 -4
- package/src/components/Table/Table.tsx +10 -5
- package/src/components/Table/styles.module.scss +5 -1
- package/src/components/Table/utils/saveTableState/mappers.ts +5 -5
- package/src/components/Table/utils/saveTableState/validators.ts +2 -2
package/README.md
CHANGED
|
@@ -242,11 +242,11 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
242
242
|
### Props
|
|
243
243
|
| name | type | default value | description |
|
|
244
244
|
|------|------|---------------|-------------|
|
|
245
|
-
| __@unscopables@
|
|
246
|
-
| __@iterator@
|
|
245
|
+
| __@unscopables@2312* | `{ [x: number]: boolean; length?: boolean; toString?: boolean; toLocaleString?: boolean; pop?: boolean; push?: boolean; concat?: boolean; join?: boolean; reverse?: boolean; shift?: boolean; slice?: boolean; sort?: boolean; ... 29 more ...; readonly [Symbol.unscopables]?: boolean; }` | - | Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement. |
|
|
246
|
+
| __@iterator@1606* | `() => ArrayIterator<ColumnDefinition<TData>>` | - | Iterator |
|
|
247
247
|
| with* | `(index: number, value: ColumnDefinition<TData>) => ColumnDefinition<TData>[]` | - | Copies an array, then overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the array. @param index The index of the value to overwrite. If the index is negative, then it replaces from the end of the array. @param value The value to write into the copied array. @returns The copied array with the updated value. |
|
|
248
248
|
| toSpliced* | `{ (start: number, deleteCount: number, ...items: ColumnDefinition<TData>[]): ColumnDefinition<TData>[]; (start: number, deleteCount?: number): ColumnDefinition<...>[]; }` | - | Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array. Copies an array and removes elements while returning the remaining elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @param items Elements to insert into the copied array in place of the deleted elements. @returns The copied array. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @returns A copy of the original array with the remaining elements. |
|
|
249
|
-
| toSorted* | `(compareFn?: (a: ColumnDefinition<TData>, b: ColumnDefinition<TData>) => number) => ColumnDefinition<TData>[]` | - | Returns a copy of an array with its elements sorted. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending,
|
|
249
|
+
| toSorted* | `(compareFn?: (a: ColumnDefinition<TData>, b: ColumnDefinition<TData>) => number) => ColumnDefinition<TData>[]` | - | Returns a copy of an array with its elements sorted. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order. ```ts [11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22] ``` |
|
|
250
250
|
| toReversed* | `() => ColumnDefinition<TData>[]` | - | Returns a copy of an array with its elements reversed. |
|
|
251
251
|
| findLastIndex* | `(predicate: (value: ColumnDefinition<TData>, index: number, array: ColumnDefinition<TData>[]) => unknown, thisArg?: any) => number` | - | Returns the index of the last element in the array where predicate is true, and -1 otherwise. @param predicate findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
252
252
|
| findLast* | `{ <S extends ColumnDefinition<TData>>(predicate: (value: ColumnDefinition<TData>, index: number, array: ColumnDefinition<TData>[]) => value is S, thisArg?: any): S; (predicate: (value: ColumnDefinition<...>, index: number, array: ColumnDefinition<...>[]) => unknown, thisArg?: any): ColumnDefinition<...>; }` | - | Returns the value of the last element in the array where predicate is true, and undefined otherwise. @param predicate findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
@@ -254,9 +254,9 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
254
254
|
| flat* | `<A, D extends number = 1>(this: A, depth?: D) => FlatArray<A, D>[]` | - | Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth. @param depth The maximum recursion depth |
|
|
255
255
|
| flatMap* | `<U, This = undefined>(callback: (this: This, value: ColumnDefinition<TData>, index: number, array: ColumnDefinition<TData>[]) => U \| readonly U[], thisArg?: This) => U[]` | - | Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1. @param callback A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value. |
|
|
256
256
|
| includes* | `(searchElement: ColumnDefinition<TData>, fromIndex?: number) => boolean` | - | Determines whether an array includes a certain element, returning true or false as appropriate. @param searchElement The element to search for. @param fromIndex The position in this array at which to begin searching for searchElement. |
|
|
257
|
-
| values* | `() =>
|
|
258
|
-
| keys* | `() =>
|
|
259
|
-
| entries* | `() =>
|
|
257
|
+
| values* | `() => ArrayIterator<ColumnDefinition<TData>>` | - | Returns an iterable of values in the array |
|
|
258
|
+
| keys* | `() => ArrayIterator<number>` | - | Returns an iterable of keys in the array |
|
|
259
|
+
| entries* | `() => ArrayIterator<[number, ColumnDefinition<TData>]>` | - | Returns an iterable of key, value pairs for every entry in the array |
|
|
260
260
|
| copyWithin* | `(target: number, start: number, end?: number) => ColumnDefinition<TData>[]` | - | Returns the this object after copying a section of the array identified by start and end to the same array starting at position target @param target If target is negative, it is treated as length+target where length is the length of the array. @param start If start is negative, it is treated as length+start. If end is negative, it is treated as length+end. @param end If not specified, length of the this object is used as its default value. |
|
|
261
261
|
| fill* | `(value: ColumnDefinition<TData>, start?: number, end?: number) => ColumnDefinition<TData>[]` | - | Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @param value value to fill array section with @param start index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array. @param end index to stop filling the array at. If end is negative, it is treated as length+end. |
|
|
262
262
|
| findIndex* | `(predicate: (value: ColumnDefinition<TData>, index: number, obj: ColumnDefinition<TData>[]) => unknown, thisArg?: any) => number` | - | Returns the index of the first element in the array where predicate is true, and -1 otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
@@ -271,8 +271,8 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
271
271
|
| lastIndexOf* | `(searchElement: ColumnDefinition<TData>, fromIndex?: number) => number` | - | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array. |
|
|
272
272
|
| indexOf* | `(searchElement: ColumnDefinition<TData>, fromIndex?: number) => number` | - | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. |
|
|
273
273
|
| unshift* | `(...items: ColumnDefinition<TData>[]) => number` | - | Inserts new elements at the start of an array, and returns the new length of the array. @param items Elements to insert at the start of the array. |
|
|
274
|
-
| splice* | `{ (start: number, deleteCount?: number): ColumnDefinition<TData>[]; (start: number, deleteCount: number, ...items: ColumnDefinition<TData>[]): ColumnDefinition<...>[]; }` | - | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @returns An array containing the elements that were deleted. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @param items Elements to insert into the array in place of the deleted elements. @returns An array containing the elements that were deleted. |
|
|
275
|
-
| sort* | `(compareFn?: (a: ColumnDefinition<TData>, b: ColumnDefinition<TData>) => number) => ColumnDefinition<TData>[]` | - | Sorts an array in place. This method mutates the array and returns a reference to the same array. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending,
|
|
274
|
+
| splice* | `{ (start: number, deleteCount?: number): ColumnDefinition<TData>[]; (start: number, deleteCount: number, ...items: ColumnDefinition<TData>[]): ColumnDefinition<...>[]; }` | - | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements. @returns An array containing the elements that were deleted. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements. @param items Elements to insert into the array in place of the deleted elements. @returns An array containing the elements that were deleted. |
|
|
275
|
+
| sort* | `(compareFn?: (a: ColumnDefinition<TData>, b: ColumnDefinition<TData>) => number) => ColumnDefinition<TData>[]` | - | Sorts an array in place. This method mutates the array and returns a reference to the same array. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order. ```ts [11,2,22,1].sort((a, b) => a - b) ``` |
|
|
276
276
|
| slice* | `(start?: number, end?: number) => ColumnDefinition<TData>[]` | - | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. @param start The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0. @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array. |
|
|
277
277
|
| shift* | `() => ColumnDefinition<TData>` | - | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
|
|
278
278
|
| reverse* | `() => ColumnDefinition<TData>[]` | - | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. |
|
|
@@ -298,6 +298,7 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
298
298
|
| name | type | default value | description |
|
|
299
299
|
|------|------|---------------|-------------|
|
|
300
300
|
| filter | `FiltersState` | - | |
|
|
301
|
+
| ordering | `FieldSort[]` | - | |
|
|
301
302
|
| search | `string` | - | |
|
|
302
303
|
| pagination | `PaginationState \| PaginationParams` | - | |
|
|
303
304
|
| sorting | `SortingState` | - | |
|
|
@@ -108,7 +108,7 @@ function Table(_a) {
|
|
|
108
108
|
const validatePersistedState = (0, react_1.useMemo)(() => data => {
|
|
109
109
|
const dataAsSettings = data;
|
|
110
110
|
const isPaginationValid = (0, validators_1.validatePaging)(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.pagination);
|
|
111
|
-
const isSortingValid = (0, validators_1.validateSorting)(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.
|
|
111
|
+
const isSortingValid = (0, validators_1.validateSorting)(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.ordering);
|
|
112
112
|
const isSearchValid = !(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.search) || typeof (dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.search) === 'string';
|
|
113
113
|
const isFilterValid = Boolean((columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.filters) && (0, validators_1.validateFilter)(dataAsSettings.filter, columnFilters.filters));
|
|
114
114
|
return isPaginationValid && isSortingValid && isSearchValid && isFilterValid;
|
|
@@ -379,8 +379,10 @@ function Table(_a) {
|
|
|
379
379
|
updateCellMap
|
|
380
380
|
} = (0, contexts_1.useCellAutoResizeController)(table);
|
|
381
381
|
const showToolbar = !suppressToolbar;
|
|
382
|
+
const showPagination = !infiniteLoading && !suppressPagination;
|
|
382
383
|
return (0, jsx_runtime_1.jsxs)("div", Object.assign({
|
|
383
|
-
className: (0, classnames_1.default)(styles_module_scss_1.default.wrapper, className)
|
|
384
|
+
className: (0, classnames_1.default)(styles_module_scss_1.default.wrapper, className),
|
|
385
|
+
"data-with-toolbar": showToolbar || undefined
|
|
384
386
|
}, (0, utils_1.extractSupportProps)(rest), {
|
|
385
387
|
children: [showToolbar && (0, jsx_runtime_1.jsx)("div", {
|
|
386
388
|
className: styles_module_scss_1.default.header,
|
|
@@ -399,14 +401,14 @@ function Table(_a) {
|
|
|
399
401
|
validateData: validatePersistedState,
|
|
400
402
|
state: {
|
|
401
403
|
pagination: (0, mappers_1.mapPaginationToRequestPayload)(pagination),
|
|
402
|
-
|
|
404
|
+
ordering: (0, mappers_1.mapSortToRequestPayload)(sorting),
|
|
403
405
|
filter,
|
|
404
406
|
search: globalFilter || ''
|
|
405
407
|
},
|
|
406
408
|
onLoad: state => {
|
|
407
409
|
state.pagination && onPaginationChange((0, mappers_1.mapPaginationToTableState)(state.pagination));
|
|
408
410
|
state.search && onGlobalFilterChange(state.search);
|
|
409
|
-
state.
|
|
411
|
+
state.ordering && onSortingChange((0, mappers_1.mapSortToTableState)(state.ordering));
|
|
410
412
|
if (state.filter) {
|
|
411
413
|
setFilter(state.filter);
|
|
412
414
|
setFilterVisibility(Object.keys(state.filter));
|
|
@@ -509,7 +511,7 @@ function Table(_a) {
|
|
|
509
511
|
className: styles_module_scss_1.default.scrollStub,
|
|
510
512
|
ref: scrollRef
|
|
511
513
|
})]
|
|
512
|
-
}),
|
|
514
|
+
}), showPagination && (0, jsx_runtime_1.jsx)(helperComponents_1.TablePagination, {
|
|
513
515
|
table: table,
|
|
514
516
|
options: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.options,
|
|
515
517
|
optionsLabel: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsLabel,
|
|
@@ -46,10 +46,13 @@
|
|
|
46
46
|
|
|
47
47
|
.wrapper{
|
|
48
48
|
display:grid;
|
|
49
|
-
grid-template-rows:
|
|
49
|
+
grid-template-rows:minmax(auto, 100%) max-content;
|
|
50
50
|
max-width:100%;
|
|
51
51
|
max-height:100%;
|
|
52
52
|
}
|
|
53
|
+
.wrapper[data-with-toolbar]{
|
|
54
|
+
grid-template-rows:max-content minmax(auto, 100%) max-content;
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
.scrollStub{
|
|
55
58
|
height:calc(var(--dimension-025m, 2px) / 2);
|
|
@@ -3,9 +3,9 @@ import { RequestPayloadParams } from '@cloud-ru/ft-request-payload-transform';
|
|
|
3
3
|
import { FiltersState } from '@snack-uikit/chips';
|
|
4
4
|
import { PersistedFilterState } from '@snack-uikit/toolbar';
|
|
5
5
|
export declare const mapPaginationToTableState: (value?: RequestPayloadParams["pagination"]) => PaginationState;
|
|
6
|
-
export declare const mapSortToTableState: (value?: RequestPayloadParams["
|
|
6
|
+
export declare const mapSortToTableState: (value?: RequestPayloadParams["ordering"]) => SortingState;
|
|
7
7
|
export declare const mapPaginationToRequestPayload: (value?: PaginationState | RequestPayloadParams["pagination"]) => RequestPayloadParams["pagination"];
|
|
8
|
-
export declare const mapSortToRequestPayload: (value?: SortingState) => RequestPayloadParams["
|
|
8
|
+
export declare const mapSortToRequestPayload: (value?: SortingState) => RequestPayloadParams["ordering"];
|
|
9
9
|
/** Вспомогательная функция для преобразования состояния таблицы к формату RequestPayloadParams */
|
|
10
10
|
export declare const formatTableStateToRequestPayload: <T extends FiltersState>({ pagination, sorting, search, filter, }: Omit<PersistedFilterState<T>, "pagination" | "sorting"> & {
|
|
11
11
|
pagination?: PaginationState | RequestPayloadParams["pagination"];
|
|
@@ -23,7 +23,7 @@ const mapSortToTableState = function () {
|
|
|
23
23
|
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
24
24
|
return value.map(column => ({
|
|
25
25
|
id: column.field,
|
|
26
|
-
desc: column.direction === '
|
|
26
|
+
desc: column.direction === '-'
|
|
27
27
|
}));
|
|
28
28
|
};
|
|
29
29
|
exports.mapSortToTableState = mapSortToTableState;
|
|
@@ -40,7 +40,7 @@ const mapPaginationToRequestPayload = value => {
|
|
|
40
40
|
exports.mapPaginationToRequestPayload = mapPaginationToRequestPayload;
|
|
41
41
|
const mapSortToRequestPayload = value => value === null || value === void 0 ? void 0 : value.map(column => ({
|
|
42
42
|
field: column.id,
|
|
43
|
-
direction: column.desc ? '
|
|
43
|
+
direction: column.desc ? '-' : '+'
|
|
44
44
|
}));
|
|
45
45
|
exports.mapSortToRequestPayload = mapSortToRequestPayload;
|
|
46
46
|
/** Вспомогательная функция для преобразования состояния таблицы к формату RequestPayloadParams */
|
|
@@ -55,7 +55,7 @@ const formatTableStateToRequestPayload = _ref => {
|
|
|
55
55
|
filter,
|
|
56
56
|
search,
|
|
57
57
|
pagination: (0, exports.mapPaginationToRequestPayload)(pagination),
|
|
58
|
-
|
|
58
|
+
ordering: (0, exports.mapSortToRequestPayload)(sorting)
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
exports.formatTableStateToRequestPayload = formatTableStateToRequestPayload;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestPayloadParams } from '@cloud-ru/ft-request-payload-transform';
|
|
2
2
|
import { ChipChoiceRowProps } from '@snack-uikit/chips';
|
|
3
3
|
export declare const validatePaging: (value: unknown) => value is RequestPayloadParams["pagination"];
|
|
4
|
-
export declare const validateSorting: (value: unknown) => value is RequestPayloadParams["
|
|
4
|
+
export declare const validateSorting: (value: unknown) => value is RequestPayloadParams["ordering"];
|
|
5
5
|
export declare const validateFilter: <TFilters extends Record<string, unknown>>(value: unknown, filterSettings: ChipChoiceRowProps<TFilters>["filters"]) => value is TFilters;
|
|
@@ -47,7 +47,7 @@ export function Table(_a) {
|
|
|
47
47
|
const validatePersistedState = useMemo(() => (data) => {
|
|
48
48
|
const dataAsSettings = data;
|
|
49
49
|
const isPaginationValid = validatePaging(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.pagination);
|
|
50
|
-
const isSortingValid = validateSorting(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.
|
|
50
|
+
const isSortingValid = validateSorting(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.ordering);
|
|
51
51
|
const isSearchValid = !(dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.search) || typeof (dataAsSettings === null || dataAsSettings === void 0 ? void 0 : dataAsSettings.search) === 'string';
|
|
52
52
|
const isFilterValid = Boolean((columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.filters) && validateFilter(dataAsSettings.filter, columnFilters.filters));
|
|
53
53
|
return isPaginationValid && isSortingValid && isSearchValid && isFilterValid;
|
|
@@ -276,7 +276,8 @@ export function Table(_a) {
|
|
|
276
276
|
});
|
|
277
277
|
const { updateCellMap } = useCellAutoResizeController(table);
|
|
278
278
|
const showToolbar = !suppressToolbar;
|
|
279
|
-
|
|
279
|
+
const showPagination = !infiniteLoading && !suppressPagination;
|
|
280
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className), "data-with-toolbar": showToolbar || undefined }, extractSupportProps(rest), { children: [showToolbar && (_jsx("div", { className: styles.header, children: _jsx(Toolbar, { search: suppressSearch
|
|
280
281
|
? undefined
|
|
281
282
|
: {
|
|
282
283
|
value: globalFilter,
|
|
@@ -290,21 +291,21 @@ export function Table(_a) {
|
|
|
290
291
|
validateData: validatePersistedState,
|
|
291
292
|
state: {
|
|
292
293
|
pagination: mapPaginationToRequestPayload(pagination),
|
|
293
|
-
|
|
294
|
+
ordering: mapSortToRequestPayload(sorting),
|
|
294
295
|
filter,
|
|
295
296
|
search: globalFilter || '',
|
|
296
297
|
},
|
|
297
298
|
onLoad: state => {
|
|
298
299
|
state.pagination && onPaginationChange(mapPaginationToTableState(state.pagination));
|
|
299
300
|
state.search && onGlobalFilterChange(state.search);
|
|
300
|
-
state.
|
|
301
|
+
state.ordering && onSortingChange(mapSortToTableState(state.ordering));
|
|
301
302
|
if (state.filter) {
|
|
302
303
|
setFilter(state.filter);
|
|
303
304
|
setFilterVisibility(Object.keys(state.filter));
|
|
304
305
|
}
|
|
305
306
|
},
|
|
306
307
|
}
|
|
307
|
-
: undefined, bulkActions: bulkActions, selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), onCheck: enableSelection ? handleOnToolbarCheck : undefined, outline: outline, after: toolbarAfter || exportSettings || areColumnsSettingsEnabled ? (_jsxs(_Fragment, { children: [toolbarAfter, exportSettings && (_jsx(ExportButton, { settings: exportSettings, columnDefinitions: columnDefinitions, data: data, topRows: filteredTopRows, centerRows: centerRows })), areColumnsSettingsEnabled && (_jsx(ColumnsSettings, { columnsSettings: columnsSettings, enabledColumns: enabledColumns, setEnabledColumns: setEnabledColumns }))] })) : undefined, moreActions: moreActions, filterRow: patchedFilter, "data-test-id": TEST_IDS.toolbar }) })), _jsxs(Scroll, { size: 's', className: styles.table, ref: scrollContainerRef, "data-outline": outline || undefined, children: [_jsx("div", { className: styles.tableContent, style: columnSizes.vars, children: _jsx(CellAutoResizeContext.Provider, { value: { updateCellMap }, children: _jsx(DndContext, Object.assign({}, dndContextProps, { children: _jsx(TableContext.Provider, { value: { table, getRowBackgroundColor }, children: (!infiniteLoading || !data.length) && loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight, columnOrder: columnOrder }), loadingTableRows.map(row => (_jsx(BodyRow, { row: row, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? (_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag })) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id))) })) : null, centerRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id))), data.length > 0 && infiniteLoading && loading && !dataError && (_jsx(SkeletonContextProvider, { loading: true, children: loadingTableRows.slice(0, 3).map(row => (_jsx(BodyRow, { row: row, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id))) })), _jsx(TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length + filteredTopRows.length })] })) }) })) }) }), _jsx("div", { className: styles.scrollStub, ref: scrollRef })] }),
|
|
308
|
+
: undefined, bulkActions: bulkActions, selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), onCheck: enableSelection ? handleOnToolbarCheck : undefined, outline: outline, after: toolbarAfter || exportSettings || areColumnsSettingsEnabled ? (_jsxs(_Fragment, { children: [toolbarAfter, exportSettings && (_jsx(ExportButton, { settings: exportSettings, columnDefinitions: columnDefinitions, data: data, topRows: filteredTopRows, centerRows: centerRows })), areColumnsSettingsEnabled && (_jsx(ColumnsSettings, { columnsSettings: columnsSettings, enabledColumns: enabledColumns, setEnabledColumns: setEnabledColumns }))] })) : undefined, moreActions: moreActions, filterRow: patchedFilter, "data-test-id": TEST_IDS.toolbar }) })), _jsxs(Scroll, { size: 's', className: styles.table, ref: scrollContainerRef, "data-outline": outline || undefined, children: [_jsx("div", { className: styles.tableContent, style: columnSizes.vars, children: _jsx(CellAutoResizeContext.Provider, { value: { updateCellMap }, children: _jsx(DndContext, Object.assign({}, dndContextProps, { children: _jsx(TableContext.Provider, { value: { table, getRowBackgroundColor }, children: (!infiniteLoading || !data.length) && loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight, columnOrder: columnOrder }), loadingTableRows.map(row => (_jsx(BodyRow, { row: row, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? (_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag })) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id))) })) : null, centerRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id))), data.length > 0 && infiniteLoading && loading && !dataError && (_jsx(SkeletonContextProvider, { loading: true, children: loadingTableRows.slice(0, 3).map(row => (_jsx(BodyRow, { row: row, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag, disabledRowAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance }, row.id))) })), _jsx(TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length + filteredTopRows.length })] })) }) })) }) }), _jsx("div", { className: styles.scrollStub, ref: scrollRef })] }), showPagination && (_jsx(TablePagination, { table: table, options: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.options, optionsLabel: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsLabel, pageCount: pageCount, optionsRender: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsRender }))] })));
|
|
308
309
|
}
|
|
309
310
|
Table.getStatusColumnDef = getStatusColumnDef;
|
|
310
311
|
Table.statusAppearances = STATUS_APPEARANCE;
|
|
@@ -46,10 +46,13 @@
|
|
|
46
46
|
|
|
47
47
|
.wrapper{
|
|
48
48
|
display:grid;
|
|
49
|
-
grid-template-rows:
|
|
49
|
+
grid-template-rows:minmax(auto, 100%) max-content;
|
|
50
50
|
max-width:100%;
|
|
51
51
|
max-height:100%;
|
|
52
52
|
}
|
|
53
|
+
.wrapper[data-with-toolbar]{
|
|
54
|
+
grid-template-rows:max-content minmax(auto, 100%) max-content;
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
.scrollStub{
|
|
55
58
|
height:calc(var(--dimension-025m, 2px) / 2);
|
|
@@ -3,9 +3,9 @@ import { RequestPayloadParams } from '@cloud-ru/ft-request-payload-transform';
|
|
|
3
3
|
import { FiltersState } from '@snack-uikit/chips';
|
|
4
4
|
import { PersistedFilterState } from '@snack-uikit/toolbar';
|
|
5
5
|
export declare const mapPaginationToTableState: (value?: RequestPayloadParams["pagination"]) => PaginationState;
|
|
6
|
-
export declare const mapSortToTableState: (value?: RequestPayloadParams["
|
|
6
|
+
export declare const mapSortToTableState: (value?: RequestPayloadParams["ordering"]) => SortingState;
|
|
7
7
|
export declare const mapPaginationToRequestPayload: (value?: PaginationState | RequestPayloadParams["pagination"]) => RequestPayloadParams["pagination"];
|
|
8
|
-
export declare const mapSortToRequestPayload: (value?: SortingState) => RequestPayloadParams["
|
|
8
|
+
export declare const mapSortToRequestPayload: (value?: SortingState) => RequestPayloadParams["ordering"];
|
|
9
9
|
/** Вспомогательная функция для преобразования состояния таблицы к формату RequestPayloadParams */
|
|
10
10
|
export declare const formatTableStateToRequestPayload: <T extends FiltersState>({ pagination, sorting, search, filter, }: Omit<PersistedFilterState<T>, "pagination" | "sorting"> & {
|
|
11
11
|
pagination?: PaginationState | RequestPayloadParams["pagination"];
|
|
@@ -11,7 +11,7 @@ export const mapPaginationToTableState = (value) => {
|
|
|
11
11
|
};
|
|
12
12
|
export const mapSortToTableState = (value = []) => value.map(column => ({
|
|
13
13
|
id: column.field,
|
|
14
|
-
desc: column.direction === '
|
|
14
|
+
desc: column.direction === '-',
|
|
15
15
|
}));
|
|
16
16
|
export const mapPaginationToRequestPayload = (value) => {
|
|
17
17
|
if (!value)
|
|
@@ -26,12 +26,12 @@ export const mapPaginationToRequestPayload = (value) => {
|
|
|
26
26
|
};
|
|
27
27
|
export const mapSortToRequestPayload = (value) => value === null || value === void 0 ? void 0 : value.map(column => ({
|
|
28
28
|
field: column.id,
|
|
29
|
-
direction: (column.desc ? '
|
|
29
|
+
direction: (column.desc ? '-' : '+'),
|
|
30
30
|
}));
|
|
31
31
|
/** Вспомогательная функция для преобразования состояния таблицы к формату RequestPayloadParams */
|
|
32
32
|
export const formatTableStateToRequestPayload = ({ pagination, sorting, search, filter, }) => formatFilterStateToRequestPayload({
|
|
33
33
|
filter,
|
|
34
34
|
search,
|
|
35
35
|
pagination: mapPaginationToRequestPayload(pagination),
|
|
36
|
-
|
|
36
|
+
ordering: mapSortToRequestPayload(sorting),
|
|
37
37
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestPayloadParams } from '@cloud-ru/ft-request-payload-transform';
|
|
2
2
|
import { ChipChoiceRowProps } from '@snack-uikit/chips';
|
|
3
3
|
export declare const validatePaging: (value: unknown) => value is RequestPayloadParams["pagination"];
|
|
4
|
-
export declare const validateSorting: (value: unknown) => value is RequestPayloadParams["
|
|
4
|
+
export declare const validateSorting: (value: unknown) => value is RequestPayloadParams["ordering"];
|
|
5
5
|
export declare const validateFilter: <TFilters extends Record<string, unknown>>(value: unknown, filterSettings: ChipChoiceRowProps<TFilters>["filters"]) => value is TFilters;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Table",
|
|
7
|
-
"version": "0.37.
|
|
7
|
+
"version": "0.37.28-preview-b0a70f1c.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@cloud-ru/ft-request-payload-transform": "0.2.
|
|
39
|
+
"@cloud-ru/ft-request-payload-transform": "0.2.3-preview-cf7ab64.0",
|
|
40
40
|
"@dnd-kit/core": "6.3.1",
|
|
41
41
|
"@dnd-kit/modifiers": "9.0.0",
|
|
42
42
|
"@dnd-kit/sortable": "10.0.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@snack-uikit/scroll": "0.10.5",
|
|
51
51
|
"@snack-uikit/skeleton": "0.6.9",
|
|
52
52
|
"@snack-uikit/toggles": "0.13.23",
|
|
53
|
-
"@snack-uikit/toolbar": "0.14.
|
|
53
|
+
"@snack-uikit/toolbar": "0.14.15-preview-b0a70f1c.0",
|
|
54
54
|
"@snack-uikit/truncate-string": "0.7.6",
|
|
55
55
|
"@snack-uikit/typography": "0.8.11",
|
|
56
56
|
"@snack-uikit/utils": "4.0.0",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@snack-uikit/locale": "*"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "1774f0c9df0d494748518bcfa073eb3f52392282"
|
|
69
69
|
}
|
|
@@ -154,7 +154,7 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
154
154
|
(data: unknown): data is PersistedFilterState<TFilters> => {
|
|
155
155
|
const dataAsSettings = data as PersistedFilterState<TFilters>;
|
|
156
156
|
const isPaginationValid = validatePaging(dataAsSettings?.pagination);
|
|
157
|
-
const isSortingValid = validateSorting(dataAsSettings?.
|
|
157
|
+
const isSortingValid = validateSorting(dataAsSettings?.ordering);
|
|
158
158
|
const isSearchValid = !dataAsSettings?.search || typeof dataAsSettings?.search === 'string';
|
|
159
159
|
const isFilterValid = Boolean(
|
|
160
160
|
columnFilters?.filters && validateFilter(dataAsSettings.filter, columnFilters.filters),
|
|
@@ -448,9 +448,14 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
448
448
|
const { updateCellMap } = useCellAutoResizeController(table);
|
|
449
449
|
|
|
450
450
|
const showToolbar = !suppressToolbar;
|
|
451
|
+
const showPagination = !infiniteLoading && !suppressPagination;
|
|
451
452
|
|
|
452
453
|
return (
|
|
453
|
-
<div
|
|
454
|
+
<div
|
|
455
|
+
className={cn(styles.wrapper, className)}
|
|
456
|
+
data-with-toolbar={showToolbar || undefined}
|
|
457
|
+
{...extractSupportProps(rest)}
|
|
458
|
+
>
|
|
454
459
|
{showToolbar && (
|
|
455
460
|
<div className={styles.header}>
|
|
456
461
|
<Toolbar
|
|
@@ -474,14 +479,14 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
474
479
|
validateData: validatePersistedState,
|
|
475
480
|
state: {
|
|
476
481
|
pagination: mapPaginationToRequestPayload(pagination),
|
|
477
|
-
|
|
482
|
+
ordering: mapSortToRequestPayload(sorting),
|
|
478
483
|
filter,
|
|
479
484
|
search: globalFilter || '',
|
|
480
485
|
},
|
|
481
486
|
onLoad: state => {
|
|
482
487
|
state.pagination && onPaginationChange(mapPaginationToTableState(state.pagination));
|
|
483
488
|
state.search && onGlobalFilterChange(state.search);
|
|
484
|
-
state.
|
|
489
|
+
state.ordering && onSortingChange(mapSortToTableState(state.ordering));
|
|
485
490
|
if (state.filter) {
|
|
486
491
|
setFilter(state.filter as TFilters);
|
|
487
492
|
setFilterVisibility(Object.keys(state.filter));
|
|
@@ -612,7 +617,7 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
612
617
|
<div className={styles.scrollStub} ref={scrollRef as RefObject<HTMLDivElement>} />
|
|
613
618
|
</Scroll>
|
|
614
619
|
|
|
615
|
-
{
|
|
620
|
+
{showPagination && (
|
|
616
621
|
<TablePagination
|
|
617
622
|
table={table}
|
|
618
623
|
options={paginationProp?.options}
|
|
@@ -53,9 +53,13 @@
|
|
|
53
53
|
|
|
54
54
|
.wrapper {
|
|
55
55
|
display: grid;
|
|
56
|
-
grid-template-rows:
|
|
56
|
+
grid-template-rows: minmax(auto, 100%) max-content;
|
|
57
57
|
max-width: 100%;
|
|
58
58
|
max-height: 100%;
|
|
59
|
+
|
|
60
|
+
&[data-with-toolbar] {
|
|
61
|
+
grid-template-rows: max-content minmax(auto, 100%) max-content;
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
.scrollStub {
|
|
@@ -17,10 +17,10 @@ export const mapPaginationToTableState = (value?: RequestPayloadParams['paginati
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const mapSortToTableState = (value: RequestPayloadParams['
|
|
20
|
+
export const mapSortToTableState = (value: RequestPayloadParams['ordering'] = []): SortingState =>
|
|
21
21
|
value.map(column => ({
|
|
22
22
|
id: column.field,
|
|
23
|
-
desc: column.direction === '
|
|
23
|
+
desc: column.direction === '-',
|
|
24
24
|
}));
|
|
25
25
|
|
|
26
26
|
export const mapPaginationToRequestPayload = (
|
|
@@ -38,10 +38,10 @@ export const mapPaginationToRequestPayload = (
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export const mapSortToRequestPayload = (value?: SortingState): RequestPayloadParams['
|
|
41
|
+
export const mapSortToRequestPayload = (value?: SortingState): RequestPayloadParams['ordering'] =>
|
|
42
42
|
value?.map(column => ({
|
|
43
43
|
field: column.id,
|
|
44
|
-
direction: (column.desc ? '
|
|
44
|
+
direction: (column.desc ? '-' : '+') as SortDirection,
|
|
45
45
|
}));
|
|
46
46
|
|
|
47
47
|
/** Вспомогательная функция для преобразования состояния таблицы к формату RequestPayloadParams */
|
|
@@ -58,5 +58,5 @@ export const formatTableStateToRequestPayload = <T extends FiltersState>({
|
|
|
58
58
|
filter,
|
|
59
59
|
search,
|
|
60
60
|
pagination: mapPaginationToRequestPayload(pagination),
|
|
61
|
-
|
|
61
|
+
ordering: mapSortToRequestPayload(sorting),
|
|
62
62
|
});
|
|
@@ -5,9 +5,9 @@ export const validatePaging = (value: unknown): value is RequestPayloadParams['p
|
|
|
5
5
|
typeof (value as RequestPayloadParams['pagination'])?.limit === 'number' &&
|
|
6
6
|
typeof (value as RequestPayloadParams['pagination'])?.offset === 'number';
|
|
7
7
|
|
|
8
|
-
export const validateSorting = (value: unknown): value is RequestPayloadParams['
|
|
8
|
+
export const validateSorting = (value: unknown): value is RequestPayloadParams['ordering'] =>
|
|
9
9
|
!value ||
|
|
10
|
-
(value as NonNullable<RequestPayloadParams['
|
|
10
|
+
(value as NonNullable<RequestPayloadParams['ordering']>).every(
|
|
11
11
|
column => typeof column?.field === 'string' && typeof column?.direction === 'string',
|
|
12
12
|
);
|
|
13
13
|
|