@snack-uikit/table 0.14.0 → 0.14.1
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 +12 -0
- package/dist/components/Table/Table.js +4 -5
- package/dist/components/Table/hooks.js +5 -5
- package/dist/components/TablePagination/TablePagination.js +2 -2
- package/dist/helperComponents/ExportButton/ExportButton.js +3 -3
- package/package.json +6 -4
- package/src/components/Table/Table.tsx +4 -10
- package/src/components/Table/hooks.tsx +7 -5
- package/src/components/TablePagination/TablePagination.tsx +2 -2
- package/src/helperComponents/ExportButton/ExportButton.tsx +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.14.1 (2024-02-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-4205:** table default cell for columnDefs ([84cfc41](https://github.com/cloud-ru-tech/snack-uikit/commit/84cfc41d43a605500ec3ef1757e5fb4515d40457))
|
|
12
|
+
* **FF-4205:** update locale usage ([bd4095b](https://github.com/cloud-ru-tech/snack-uikit/commit/bd4095bc875c2efc95a0549a366d5b40dd424741))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
# 0.14.0 (2024-02-09)
|
|
7
19
|
|
|
8
20
|
|
|
@@ -39,9 +39,7 @@ export function Table(_a) {
|
|
|
39
39
|
const { state: pagination, onStateChange: onPaginationChange } = useStateControl(paginationProp, defaultPaginationState);
|
|
40
40
|
const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
|
|
41
41
|
const tableColumns = useMemo(() => {
|
|
42
|
-
let cols = columnDefinitions
|
|
43
|
-
? column
|
|
44
|
-
: Object.assign(Object.assign({}, column), { cell: (cell) => _jsx(TruncateString, { text: String(cell.getValue()), maxLines: 1 }) }));
|
|
42
|
+
let cols = columnDefinitions;
|
|
45
43
|
if (enableSelection) {
|
|
46
44
|
cols = [getSelectionCellColumnDef(), ...cols];
|
|
47
45
|
}
|
|
@@ -73,6 +71,7 @@ export function Table(_a) {
|
|
|
73
71
|
enableSorting: false,
|
|
74
72
|
enableResizing: false,
|
|
75
73
|
minSize: 40,
|
|
74
|
+
cell: (cell) => _jsx(TruncateString, { text: String(cell.getValue()), maxLines: 1 }),
|
|
76
75
|
},
|
|
77
76
|
manualSorting: Boolean(pageCount),
|
|
78
77
|
manualPagination: pageCount !== undefined,
|
|
@@ -142,7 +141,7 @@ export function Table(_a) {
|
|
|
142
141
|
const tableRows = table.getRowModel().rows;
|
|
143
142
|
const loadingTableRows = loadingTable.getRowModel().rows;
|
|
144
143
|
const tablePagination = table.getState().pagination;
|
|
145
|
-
const
|
|
144
|
+
const { t } = useLocale('Table');
|
|
146
145
|
const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
|
|
147
146
|
const cssPageSize = useMemo(() => {
|
|
148
147
|
const tempPageSize = !suppressPagination ? tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize : pageSize;
|
|
@@ -154,7 +153,7 @@ export function Table(_a) {
|
|
|
154
153
|
value: globalFilter,
|
|
155
154
|
onChange: onGlobalFilterChange,
|
|
156
155
|
loading: search === null || search === void 0 ? void 0 : search.loading,
|
|
157
|
-
placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) ||
|
|
156
|
+
placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || t('searchPlaceholder'),
|
|
158
157
|
}, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), className: styles.toolbar, onRefresh: onRefresh ? handleOnRefresh : undefined, onDelete: enableSelection && onDelete ? handleOnDelete : undefined, onCheck: enableSelection ? handleOnCheck : undefined, outline: outline, selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', before: toolbarBefore, after: exportFileName ? (_jsx(ExportButton, { fileName: exportFileName, columnDefinitions: columnDefinitions, data: data })) : undefined, moreActions: moreActions }), columnFiltersProp && _jsxs("div", { className: styles.filtersWrapper, children: [" ", columnFiltersProp, " "] })] })), _jsx("div", { className: styles.scrollWrapper, "data-outline": outline || undefined, children: _jsx(Scroll, { size: 's', className: styles.table, children: _jsx("div", { className: styles.tableContent, style: columnSizeVars, children: _jsx(TableContext.Provider, { value: { table }, children: loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, {}), loadingTableRows.map(row => (_jsx(BodyRow, { row: row }, row.id)))] })) : (_jsxs(_Fragment, { children: [tableRows.length ? _jsx(HeaderRow, {}) : null, tableRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick }, row.id))), _jsx(TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(globalFilter), tableRowsLength: tableRows.length })] })) }) }) }) }), !suppressPagination && (_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 }))] })) }));
|
|
159
158
|
}
|
|
160
159
|
Table.getStatusColumnDef = getStatusColumnDef;
|
|
@@ -38,15 +38,15 @@ export function useLoadingTable({ pageSize, columnDefinitions, columnPinning })
|
|
|
38
38
|
return { loadingTable };
|
|
39
39
|
}
|
|
40
40
|
export function useEmptyState({ noDataState: noDataStateProp, noResultsState: noResultsStateProp, errorDataState: errorDataStateProp, }) {
|
|
41
|
-
const
|
|
41
|
+
const { t } = useLocale('Table');
|
|
42
42
|
return useMemo(() => {
|
|
43
|
-
const noDataState = Object.assign(
|
|
44
|
-
const noResultsState = Object.assign(
|
|
45
|
-
const errorDataState = Object.assign(
|
|
43
|
+
const noDataState = Object.assign({ icon: { icon: SearchSVG, appearance: 'neutral', decor: true }, title: t('noData.title') }, noDataStateProp);
|
|
44
|
+
const noResultsState = Object.assign({ icon: { icon: SearchSVG, appearance: 'neutral', decor: true }, title: t('noResults.title'), description: t('noResults.description') }, noResultsStateProp);
|
|
45
|
+
const errorDataState = Object.assign({ icon: { icon: CrossSVG, appearance: 'red', decor: true }, title: t('errorData.title'), description: t('errorData.description') }, errorDataStateProp);
|
|
46
46
|
return {
|
|
47
47
|
noDataState,
|
|
48
48
|
noResultsState,
|
|
49
49
|
errorDataState,
|
|
50
50
|
};
|
|
51
|
-
}, [errorDataStateProp,
|
|
51
|
+
}, [errorDataStateProp, noDataStateProp, noResultsStateProp, t]);
|
|
52
52
|
}
|
|
@@ -5,8 +5,8 @@ import { useLocale } from '@snack-uikit/locale';
|
|
|
5
5
|
import { Pagination } from '@snack-uikit/pagination';
|
|
6
6
|
import styles from './styles.module.css';
|
|
7
7
|
export function TablePagination({ table, options: optionsProp, optionsLabel: optionsLabelProp, }) {
|
|
8
|
-
const
|
|
9
|
-
const optionsLabel = optionsLabelProp !== null && optionsLabelProp !== void 0 ? optionsLabelProp :
|
|
8
|
+
const { t } = useLocale('Table');
|
|
9
|
+
const optionsLabel = optionsLabelProp !== null && optionsLabelProp !== void 0 ? optionsLabelProp : t('rowsOptionsLabel');
|
|
10
10
|
const handlePaginationOnChange = useCallback((pageIndex) => {
|
|
11
11
|
table.setPageIndex(pageIndex - 1);
|
|
12
12
|
}, [table]);
|
|
@@ -7,17 +7,17 @@ import { useLocale } from '@snack-uikit/locale';
|
|
|
7
7
|
import { exportToCSV, exportToXLSX } from '../../exportTable';
|
|
8
8
|
export function ExportButton({ fileName, data, columnDefinitions }) {
|
|
9
9
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
-
const
|
|
10
|
+
const { t } = useLocale('Table');
|
|
11
11
|
return (_jsx(Droplist, { trigger: 'clickAndFocusVisible', open: isOpen, onOpenChange: setIsOpen, scroll: true, placement: 'bottom-end', items: [
|
|
12
12
|
{
|
|
13
|
-
content: { option:
|
|
13
|
+
content: { option: t('export') + 'CSV' },
|
|
14
14
|
onClick: () => {
|
|
15
15
|
exportToCSV({ fileName, columnDefinitions, data });
|
|
16
16
|
setIsOpen(false);
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
content: { option:
|
|
20
|
+
content: { option: t('export') + 'XLSX' },
|
|
21
21
|
onClick: () => {
|
|
22
22
|
exportToXLSX({ fileName, columnDefinitions, data });
|
|
23
23
|
setIsOpen(false);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Table",
|
|
7
|
-
"version": "0.14.
|
|
7
|
+
"version": "0.14.1",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -33,12 +33,11 @@
|
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/button": "0.16.0",
|
|
36
|
-
"@snack-uikit/chips": "0.11.
|
|
36
|
+
"@snack-uikit/chips": "0.11.6",
|
|
37
37
|
"@snack-uikit/icon-predefined": "0.4.1",
|
|
38
38
|
"@snack-uikit/icons": "0.20.1",
|
|
39
39
|
"@snack-uikit/info-block": "0.1.2",
|
|
40
40
|
"@snack-uikit/list": "0.3.2",
|
|
41
|
-
"@snack-uikit/locale": "0.3.0",
|
|
42
41
|
"@snack-uikit/pagination": "0.6.3",
|
|
43
42
|
"@snack-uikit/scroll": "0.5.1",
|
|
44
43
|
"@snack-uikit/skeleton": "0.3.2",
|
|
@@ -56,5 +55,8 @@
|
|
|
56
55
|
"uncontrollable": "8.0.0",
|
|
57
56
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz"
|
|
58
57
|
},
|
|
59
|
-
"
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@snack-uikit/locale": "*"
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "5e7b0b6d34f40c4266070bf918e9cdf127ac882c"
|
|
60
62
|
}
|
|
@@ -212,14 +212,7 @@ export function Table<TData extends object>({
|
|
|
212
212
|
const enableSelection = Boolean(rowSelectionProp?.enable);
|
|
213
213
|
|
|
214
214
|
const tableColumns: ColumnDefinition<TData>[] = useMemo(() => {
|
|
215
|
-
let cols: ColumnDefinition<TData>[] = columnDefinitions
|
|
216
|
-
column.cell
|
|
217
|
-
? column
|
|
218
|
-
: {
|
|
219
|
-
...column,
|
|
220
|
-
cell: (cell: CellContext<TData, unknown>) => <TruncateString text={String(cell.getValue())} maxLines={1} />,
|
|
221
|
-
},
|
|
222
|
-
);
|
|
215
|
+
let cols: ColumnDefinition<TData>[] = columnDefinitions;
|
|
223
216
|
|
|
224
217
|
if (enableSelection) {
|
|
225
218
|
cols = [getSelectionCellColumnDef(), ...cols];
|
|
@@ -260,6 +253,7 @@ export function Table<TData extends object>({
|
|
|
260
253
|
enableSorting: false,
|
|
261
254
|
enableResizing: false,
|
|
262
255
|
minSize: 40,
|
|
256
|
+
cell: (cell: CellContext<TData, unknown>) => <TruncateString text={String(cell.getValue())} maxLines={1} />,
|
|
263
257
|
},
|
|
264
258
|
|
|
265
259
|
manualSorting: Boolean(pageCount),
|
|
@@ -354,7 +348,7 @@ export function Table<TData extends object>({
|
|
|
354
348
|
const loadingTableRows = loadingTable.getRowModel().rows;
|
|
355
349
|
const tablePagination = table.getState().pagination;
|
|
356
350
|
|
|
357
|
-
const
|
|
351
|
+
const { t } = useLocale('Table');
|
|
358
352
|
const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
|
|
359
353
|
|
|
360
354
|
const cssPageSize = useMemo(() => {
|
|
@@ -379,7 +373,7 @@ export function Table<TData extends object>({
|
|
|
379
373
|
value: globalFilter,
|
|
380
374
|
onChange: onGlobalFilterChange,
|
|
381
375
|
loading: search?.loading,
|
|
382
|
-
placeholder: search?.placeholder ||
|
|
376
|
+
placeholder: search?.placeholder || t('searchPlaceholder'),
|
|
383
377
|
}}
|
|
384
378
|
checked={table.getIsAllPageRowsSelected()}
|
|
385
379
|
indeterminate={table.getIsSomePageRowsSelected()}
|
|
@@ -78,24 +78,26 @@ export function useEmptyState({
|
|
|
78
78
|
noResultsState?: EmptyStateProps;
|
|
79
79
|
errorDataState?: EmptyStateProps;
|
|
80
80
|
}) {
|
|
81
|
-
const
|
|
81
|
+
const { t } = useLocale('Table');
|
|
82
82
|
|
|
83
83
|
return useMemo(() => {
|
|
84
84
|
const noDataState: EmptyStateProps = {
|
|
85
85
|
icon: { icon: SearchSVG, appearance: 'neutral', decor: true },
|
|
86
|
-
|
|
86
|
+
title: t('noData.title'),
|
|
87
87
|
...noDataStateProp,
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
const noResultsState: EmptyStateProps = {
|
|
91
91
|
icon: { icon: SearchSVG, appearance: 'neutral', decor: true },
|
|
92
|
-
|
|
92
|
+
title: t('noResults.title'),
|
|
93
|
+
description: t('noResults.description'),
|
|
93
94
|
...noResultsStateProp,
|
|
94
95
|
};
|
|
95
96
|
|
|
96
97
|
const errorDataState: EmptyStateProps = {
|
|
97
98
|
icon: { icon: CrossSVG, appearance: 'red', decor: true },
|
|
98
|
-
|
|
99
|
+
title: t('errorData.title'),
|
|
100
|
+
description: t('errorData.description'),
|
|
99
101
|
...errorDataStateProp,
|
|
100
102
|
};
|
|
101
103
|
|
|
@@ -104,5 +106,5 @@ export function useEmptyState({
|
|
|
104
106
|
noResultsState,
|
|
105
107
|
errorDataState,
|
|
106
108
|
};
|
|
107
|
-
}, [errorDataStateProp,
|
|
109
|
+
}, [errorDataStateProp, noDataStateProp, noResultsStateProp, t]);
|
|
108
110
|
}
|
|
@@ -19,8 +19,8 @@ export function TablePagination<TData>({
|
|
|
19
19
|
options: optionsProp,
|
|
20
20
|
optionsLabel: optionsLabelProp,
|
|
21
21
|
}: TablePaginationProps<TData>) {
|
|
22
|
-
const
|
|
23
|
-
const optionsLabel = optionsLabelProp ??
|
|
22
|
+
const { t } = useLocale('Table');
|
|
23
|
+
const optionsLabel = optionsLabelProp ?? t('rowsOptionsLabel');
|
|
24
24
|
|
|
25
25
|
const handlePaginationOnChange = useCallback(
|
|
26
26
|
(pageIndex: number) => {
|
|
@@ -19,7 +19,7 @@ type ExportButtonProps<TData extends object> = {
|
|
|
19
19
|
|
|
20
20
|
export function ExportButton<TData extends object>({ fileName, data, columnDefinitions }: ExportButtonProps<TData>) {
|
|
21
21
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
22
|
-
const
|
|
22
|
+
const { t } = useLocale('Table');
|
|
23
23
|
|
|
24
24
|
return (
|
|
25
25
|
<Droplist
|
|
@@ -30,14 +30,14 @@ export function ExportButton<TData extends object>({ fileName, data, columnDefin
|
|
|
30
30
|
placement='bottom-end'
|
|
31
31
|
items={[
|
|
32
32
|
{
|
|
33
|
-
content: { option:
|
|
33
|
+
content: { option: t('export') + 'CSV' },
|
|
34
34
|
onClick: () => {
|
|
35
35
|
exportToCSV<TData>({ fileName, columnDefinitions, data });
|
|
36
36
|
setIsOpen(false);
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
content: { option:
|
|
40
|
+
content: { option: t('export') + 'XLSX' },
|
|
41
41
|
onClick: () => {
|
|
42
42
|
exportToXLSX<TData>({ fileName, columnDefinitions, data });
|
|
43
43
|
setIsOpen(false);
|