@snack-uikit/table 0.17.2 → 0.17.3
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/CHANGELOG.md +11 -0
- package/dist/components/Table/Table.js +2 -5
- package/dist/components/Table/hooks/usePageReset.d.ts +8 -0
- package/dist/components/Table/hooks/usePageReset.js +10 -0
- package/package.json +2 -2
- package/src/components/Table/Table.tsx +2 -5
- package/src/components/Table/hooks/usePageReset.ts +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.17.3 (2024-05-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **PDS-135:** prevent loop in page number changing ([2da818f](https://github.com/cloud-ru-tech/snack-uikit/commit/2da818f89c175782eeb2323f30e9f3459594fece))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.17.2 (2024-05-13)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
|
@@ -23,6 +23,7 @@ import { DEFAULT_PAGE_SIZE } from '../../constants';
|
|
|
23
23
|
import { BodyRow, ExportButton, getColumnId, getRowActionsColumnDef, getSelectionCellColumnDef, getStatusColumnDef, HeaderRow, STATUS_APPEARANCE, TableContext, TableEmptyState, TablePagination, useEmptyState, } from '../../helperComponents';
|
|
24
24
|
import { fuzzyFilter } from '../../utils';
|
|
25
25
|
import { useLoadingTable, useStateControl } from './hooks';
|
|
26
|
+
import { usePageReset } from './hooks/usePageReset';
|
|
26
27
|
import styles from './styles.module.css';
|
|
27
28
|
import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth } from './utils';
|
|
28
29
|
/** Компонент таблицы */
|
|
@@ -37,11 +38,7 @@ export function Table(_a) {
|
|
|
37
38
|
const { state: sorting, onStateChange: onSortingChange } = useStateControl(sortingProp, []);
|
|
38
39
|
const { state: pagination, onStateChange: onPaginationChange } = useStateControl(paginationProp, defaultPaginationState);
|
|
39
40
|
const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
|
|
40
|
-
|
|
41
|
-
if (pagination.pageIndex >= data.length / pagination.pageSize) {
|
|
42
|
-
onPaginationChange(Object.assign(Object.assign({}, pagination), { pageIndex: 0 }));
|
|
43
|
-
}
|
|
44
|
-
}, [data.length, onPaginationChange, pagination]);
|
|
41
|
+
usePageReset({ data, pagination, onPaginationChange });
|
|
45
42
|
const tableColumns = useMemo(() => {
|
|
46
43
|
let cols = columnDefinitions;
|
|
47
44
|
if (enableSelection) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PaginationState } from '@tanstack/react-table';
|
|
2
|
+
type UsePageResetProps<TData extends object> = {
|
|
3
|
+
data: TData[];
|
|
4
|
+
pagination: PaginationState;
|
|
5
|
+
onPaginationChange(state: PaginationState): void;
|
|
6
|
+
};
|
|
7
|
+
export declare function usePageReset<TData extends object>({ pagination, data, onPaginationChange }: UsePageResetProps<TData>): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export function usePageReset({ pagination, data, onPaginationChange }) {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
const { pageIndex } = pagination;
|
|
5
|
+
const maximumAvailablePage = data.length / pagination.pageSize;
|
|
6
|
+
if (pageIndex > 0 && pageIndex >= maximumAvailablePage) {
|
|
7
|
+
onPaginationChange(Object.assign(Object.assign({}, pagination), { pageIndex: 0 }));
|
|
8
|
+
}
|
|
9
|
+
}, [data.length, onPaginationChange, pagination]);
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Table",
|
|
7
|
-
"version": "0.17.
|
|
7
|
+
"version": "0.17.3",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@snack-uikit/locale": "*"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "ef7c38971275539431807881d3f80e00b393d34d"
|
|
61
61
|
}
|
|
@@ -39,6 +39,7 @@ import { ColumnDefinition } from '../../types';
|
|
|
39
39
|
import { fuzzyFilter } from '../../utils';
|
|
40
40
|
import { TableProps } from '../types';
|
|
41
41
|
import { useLoadingTable, useStateControl } from './hooks';
|
|
42
|
+
import { usePageReset } from './hooks/usePageReset';
|
|
42
43
|
import styles from './styles.module.scss';
|
|
43
44
|
import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth } from './utils';
|
|
44
45
|
|
|
@@ -99,11 +100,7 @@ export function Table<TData extends object>({
|
|
|
99
100
|
);
|
|
100
101
|
const enableSelection = Boolean(rowSelectionProp?.enable);
|
|
101
102
|
|
|
102
|
-
|
|
103
|
-
if (pagination.pageIndex >= data.length / pagination.pageSize) {
|
|
104
|
-
onPaginationChange({ ...pagination, pageIndex: 0 });
|
|
105
|
-
}
|
|
106
|
-
}, [data.length, onPaginationChange, pagination]);
|
|
103
|
+
usePageReset({ data, pagination, onPaginationChange });
|
|
107
104
|
|
|
108
105
|
const tableColumns: ColumnDefinition<TData>[] = useMemo(() => {
|
|
109
106
|
let cols: ColumnDefinition<TData>[] = columnDefinitions;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PaginationState } from '@tanstack/react-table';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
type UsePageResetProps<TData extends object> = {
|
|
5
|
+
data: TData[];
|
|
6
|
+
pagination: PaginationState;
|
|
7
|
+
onPaginationChange(state: PaginationState): void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function usePageReset<TData extends object>({ pagination, data, onPaginationChange }: UsePageResetProps<TData>) {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const { pageIndex } = pagination;
|
|
13
|
+
const maximumAvailablePage = data.length / pagination.pageSize;
|
|
14
|
+
|
|
15
|
+
if (pageIndex > 0 && pageIndex >= maximumAvailablePage) {
|
|
16
|
+
onPaginationChange({ ...pagination, pageIndex: 0 });
|
|
17
|
+
}
|
|
18
|
+
}, [data.length, onPaginationChange, pagination]);
|
|
19
|
+
}
|