@cloud-ru/uikit-product-mobile-table 0.14.0 → 0.16.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/CHANGELOG.md +22 -0
- package/dist/cjs/components/MobileTable.d.ts +2 -2
- package/dist/cjs/components/MobileTable.js +82 -6
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/helperComponents/ColumnsSettings/ColumnsSettings.d.ts +7 -0
- package/dist/cjs/helperComponents/ColumnsSettings/ColumnsSettings.js +18 -0
- package/dist/cjs/helperComponents/ColumnsSettings/index.d.ts +1 -0
- package/dist/cjs/helperComponents/ColumnsSettings/index.js +17 -0
- package/dist/cjs/helperComponents/ColumnsSettings/styles.module.css +3 -0
- package/dist/cjs/helperComponents/TableCard/TableCard.d.ts +3 -1
- package/dist/cjs/helperComponents/TableCard/TableCard.js +10 -3
- package/dist/cjs/helperComponents/TableSorting/TableSorting.d.ts +10 -0
- package/dist/cjs/helperComponents/TableSorting/TableSorting.js +29 -0
- package/dist/cjs/helperComponents/TableSorting/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TableSorting/index.js +17 -0
- package/dist/cjs/helperComponents/TableSorting/styles.module.css +3 -0
- package/dist/cjs/helperComponents/TableSorting/useTableSorting.d.ts +23 -0
- package/dist/cjs/helperComponents/TableSorting/useTableSorting.js +189 -0
- package/dist/cjs/helperComponents/TableSorting/utils.d.ts +9 -0
- package/dist/cjs/helperComponents/TableSorting/utils.js +75 -0
- package/dist/cjs/helperComponents/index.d.ts +3 -1
- package/dist/cjs/helperComponents/index.js +3 -1
- package/dist/esm/components/MobileTable.d.ts +2 -2
- package/dist/esm/components/MobileTable.js +84 -8
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/helperComponents/ColumnsSettings/ColumnsSettings.d.ts +7 -0
- package/dist/esm/helperComponents/ColumnsSettings/ColumnsSettings.js +12 -0
- package/dist/esm/helperComponents/ColumnsSettings/index.d.ts +1 -0
- package/dist/esm/helperComponents/ColumnsSettings/index.js +1 -0
- package/dist/esm/helperComponents/ColumnsSettings/styles.module.css +3 -0
- package/dist/esm/helperComponents/TableCard/TableCard.d.ts +3 -1
- package/dist/esm/helperComponents/TableCard/TableCard.js +10 -3
- package/dist/esm/helperComponents/TableSorting/TableSorting.d.ts +10 -0
- package/dist/esm/helperComponents/TableSorting/TableSorting.js +26 -0
- package/dist/esm/helperComponents/TableSorting/index.d.ts +1 -0
- package/dist/esm/helperComponents/TableSorting/index.js +1 -0
- package/dist/esm/helperComponents/TableSorting/styles.module.css +3 -0
- package/dist/esm/helperComponents/TableSorting/useTableSorting.d.ts +23 -0
- package/dist/esm/helperComponents/TableSorting/useTableSorting.js +183 -0
- package/dist/esm/helperComponents/TableSorting/utils.d.ts +9 -0
- package/dist/esm/helperComponents/TableSorting/utils.js +70 -0
- package/dist/esm/helperComponents/index.d.ts +3 -1
- package/dist/esm/helperComponents/index.js +3 -1
- package/package.json +6 -3
- package/src/components/MobileTable.tsx +144 -9
- package/src/components/index.ts +1 -0
- package/src/helperComponents/ColumnsSettings/ColumnsSettings.tsx +28 -0
- package/src/helperComponents/ColumnsSettings/index.ts +1 -0
- package/src/helperComponents/ColumnsSettings/styles.module.scss +5 -0
- package/src/helperComponents/TableCard/TableCard.tsx +21 -4
- package/src/helperComponents/TableSorting/TableSorting.tsx +60 -0
- package/src/helperComponents/TableSorting/index.ts +1 -0
- package/src/helperComponents/TableSorting/styles.module.scss +9 -0
- package/src/helperComponents/TableSorting/useTableSorting.tsx +248 -0
- package/src/helperComponents/TableSorting/utils.ts +89 -0
- package/src/helperComponents/index.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.16.0 (2025-12-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **FF-7473:** add disabled state and HideToggler support for row selection in mobile table ([f0f7517](https://gitverse.ru/cloud-ru-tech/uikit-product/commits/f0f7517d45ef8f5580865951790238426b96fc16))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# 0.15.0 (2025-12-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **FF-7560:** add table sorting and column settings support to mobile table ([f6c47c0](https://gitverse.ru/cloud-ru-tech/uikit-product/commits/f6c47c0bce3f47ad2098b21d9520d244f32f31a2))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
# 0.14.0 (2025-12-03)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { FiltersState, MobileChipChoiceRowProps } from '@cloud-ru/uikit-product-mobile-chips';
|
|
2
2
|
import { WithSupportProps } from '@cloud-ru/uikit-product-utils';
|
|
3
3
|
import { TableProps } from '@snack-uikit/table';
|
|
4
|
-
export type MobileTableProps<TData extends object, TFilters extends FiltersState = Record<string, unknown>> = Pick<TableProps<TData, TFilters>, 'data' | 'columnDefinitions' | 'suppressPagination' | 'suppressToolbar' | 'suppressSearch' | 'search' | 'onRefresh' | '
|
|
4
|
+
export type MobileTableProps<TData extends object, TFilters extends FiltersState = Record<string, unknown>> = Pick<TableProps<TData, TFilters>, 'data' | 'columnDefinitions' | 'suppressPagination' | 'suppressToolbar' | 'suppressSearch' | 'search' | 'onRefresh' | 'moreActions' | 'className' | 'enableFuzzySearch' | 'loading' | 'dataError' | 'dataFiltered' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'sorting' | 'pagination' | 'pageCount' | 'manualFiltering' | 'manualPagination' | 'manualSorting' | 'getRowId' | 'rowSelection' | 'bulkActions' | 'columnsSettings' | 'savedState' | 'autoResetPageIndex' | 'toolbarAfter'> & WithSupportProps<{
|
|
5
5
|
headlineId?: string;
|
|
6
6
|
headerBackground?: 'default' | '1-level' | '2-level';
|
|
7
7
|
columnFilters?: MobileChipChoiceRowProps<FiltersState>;
|
|
8
8
|
}>;
|
|
9
|
-
export declare function MobileTable<TData extends object, TFilters extends FiltersState = Record<string, unknown>>({ data, columnDefinitions, headlineId, suppressPagination, suppressToolbar, suppressSearch, enableFuzzySearch, search, onRefresh, toolbarAfter, moreActions, columnFilters, className, headerBackground, noDataState, noResultsState, errorDataState, loading, dataError, dataFiltered, pagination: paginationProp, pageCount, sorting: sortingProp, manualSorting, manualPagination, manualFiltering, getRowId, rowSelection: rowSelectionProp, bulkActions: bulkActionsProp, ...rest }: MobileTableProps<TData, TFilters>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function MobileTable<TData extends object, TFilters extends FiltersState = Record<string, unknown>>({ data, columnDefinitions, headlineId, suppressPagination, suppressToolbar, suppressSearch, enableFuzzySearch, search, onRefresh, toolbarAfter, moreActions, columnFilters, className, headerBackground, noDataState, noResultsState, errorDataState, loading, dataError, dataFiltered, pagination: paginationProp, pageCount, sorting: sortingProp, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, getRowId, rowSelection: rowSelectionProp, bulkActions: bulkActionsProp, columnsSettings: columnsSettingsProp, savedState, ...rest }: MobileTableProps<TData, TFilters>): import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export declare namespace MobileTable {
|
|
11
11
|
var getRowActionsColumnDef: typeof import("../helperComponents").getRowActionsColumnDef;
|
|
12
12
|
var getStatusColumnDef: typeof import("../helperComponents").getStatusColumnDef;
|
|
@@ -23,13 +23,15 @@ const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
|
23
23
|
const uikit_product_mobile_toolbar_1 = require("@cloud-ru/uikit-product-mobile-toolbar");
|
|
24
24
|
const uikit_product_utils_1 = require("@cloud-ru/uikit-product-utils");
|
|
25
25
|
const skeleton_1 = require("@snack-uikit/skeleton");
|
|
26
|
+
const table_1 = require("@snack-uikit/table");
|
|
26
27
|
const helperComponents_1 = require("../helperComponents");
|
|
28
|
+
const ColumnsSettings_1 = require("../helperComponents/ColumnsSettings");
|
|
27
29
|
const constants_1 = require("./constants");
|
|
28
30
|
const hooks_1 = require("./hooks");
|
|
29
31
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
30
32
|
const utils_1 = require("./utils");
|
|
31
33
|
function MobileTable(_a) {
|
|
32
|
-
var { data, columnDefinitions, headlineId, suppressPagination = false, suppressToolbar = false, suppressSearch = false, enableFuzzySearch = false, search, onRefresh, toolbarAfter, moreActions, columnFilters, className, headerBackground = 'default', noDataState, noResultsState, errorDataState, loading, dataError, dataFiltered, pagination: paginationProp, pageCount, sorting: sortingProp, manualSorting = false, manualPagination = false, manualFiltering = false, getRowId, rowSelection: rowSelectionProp, bulkActions: bulkActionsProp } = _a, rest = __rest(_a, ["data", "columnDefinitions", "headlineId", "suppressPagination", "suppressToolbar", "suppressSearch", "enableFuzzySearch", "search", "onRefresh", "toolbarAfter", "moreActions", "columnFilters", "className", "headerBackground", "noDataState", "noResultsState", "errorDataState", "loading", "dataError", "dataFiltered", "pagination", "pageCount", "sorting", "manualSorting", "manualPagination", "manualFiltering", "getRowId", "rowSelection", "bulkActions"]);
|
|
34
|
+
var { data, columnDefinitions, headlineId, suppressPagination = false, suppressToolbar = false, suppressSearch = false, enableFuzzySearch = false, search, onRefresh, toolbarAfter, moreActions, columnFilters, className, headerBackground = 'default', noDataState, noResultsState, errorDataState, loading, dataError, dataFiltered, pagination: paginationProp, pageCount, sorting: sortingProp, manualSorting = false, manualPagination = false, manualFiltering = false, autoResetPageIndex = false, getRowId, rowSelection: rowSelectionProp, bulkActions: bulkActionsProp, columnsSettings: columnsSettingsProp, savedState } = _a, rest = __rest(_a, ["data", "columnDefinitions", "headlineId", "suppressPagination", "suppressToolbar", "suppressSearch", "enableFuzzySearch", "search", "onRefresh", "toolbarAfter", "moreActions", "columnFilters", "className", "headerBackground", "noDataState", "noResultsState", "errorDataState", "loading", "dataError", "dataFiltered", "pagination", "pageCount", "sorting", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "getRowId", "rowSelection", "bulkActions", "columnsSettings", "savedState"]);
|
|
33
35
|
const defaultPaginationState = (0, react_1.useMemo)(() => ({ pageIndex: 0, pageSize: constants_1.DEFAULT_PAGE_SIZE }), []);
|
|
34
36
|
const { state: sorting, onStateChange: onSortingChange } = (0, hooks_1.useStateControl)(sortingProp, []);
|
|
35
37
|
const { state: globalFilter, onStateChange: onGlobalFilterChange } = (0, hooks_1.useStateControl)(search, '');
|
|
@@ -45,23 +47,88 @@ function MobileTable(_a) {
|
|
|
45
47
|
}
|
|
46
48
|
return isParentSelected && isCurrentRowSelected;
|
|
47
49
|
}, [rowSelectionProp]);
|
|
50
|
+
const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
|
|
51
|
+
const pinnedGroups = (0, react_1.useMemo)(() => (0, table_1.getPinnedGroups)(columnDefinitions), [columnDefinitions]);
|
|
52
|
+
const { enabledColumns, setEnabledColumns, getColumnsSettings, enabledTableColumns, enabledColumnsDefinitions, areColumnsSettingsEnabled, } = (0, table_1.useColumnSettings)({
|
|
53
|
+
columnDefinitions,
|
|
54
|
+
pinnedGroups,
|
|
55
|
+
savedState,
|
|
56
|
+
columnsSettings: columnsSettingsProp,
|
|
57
|
+
rowSelection: undefined,
|
|
58
|
+
enableSelectPinned: false,
|
|
59
|
+
expanding: undefined,
|
|
60
|
+
});
|
|
61
|
+
const { columnOrder, setColumnOrder, enableColumnsOrderSortByDrag } = (0, table_1.useColumnOrderByDrag)({
|
|
62
|
+
tableColumns: columnDefinitions,
|
|
63
|
+
savedState,
|
|
64
|
+
columnSettings: columnsSettingsProp,
|
|
65
|
+
});
|
|
66
|
+
const columnsSettings = (0, react_1.useMemo)(() => getColumnsSettings(columnOrder), [columnOrder, getColumnsSettings]);
|
|
67
|
+
// Получаем список колонок с mode: 'hidden', которые всегда доступны для сортировки
|
|
68
|
+
const hiddenColumnsBySettings = (0, react_1.useMemo)(() => {
|
|
69
|
+
if (!areColumnsSettingsEnabled)
|
|
70
|
+
return new Set();
|
|
71
|
+
const hidden = new Set();
|
|
72
|
+
columnDefinitions.forEach(colDef => {
|
|
73
|
+
var _a;
|
|
74
|
+
let columnId;
|
|
75
|
+
if ('id' in colDef && colDef.id) {
|
|
76
|
+
columnId = colDef.id;
|
|
77
|
+
}
|
|
78
|
+
else if ('accessorKey' in colDef && colDef.accessorKey) {
|
|
79
|
+
columnId = String(colDef.accessorKey);
|
|
80
|
+
}
|
|
81
|
+
if (columnId) {
|
|
82
|
+
const colDefWithSettings = colDef;
|
|
83
|
+
if (((_a = colDefWithSettings.columnSettings) === null || _a === void 0 ? void 0 : _a.mode) === 'hidden') {
|
|
84
|
+
hidden.add(columnId);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return hidden;
|
|
89
|
+
}, [areColumnsSettingsEnabled, columnDefinitions]);
|
|
90
|
+
// Сбрасываем сортировку, если колонка с активной сортировкой была скрыта
|
|
91
|
+
// Колонки с mode: 'hidden' всегда доступны для сортировки
|
|
92
|
+
(0, react_1.useEffect)(() => {
|
|
93
|
+
var _a;
|
|
94
|
+
if (areColumnsSettingsEnabled && enabledColumns && sorting.length > 0) {
|
|
95
|
+
const activeSortColumnId = (_a = sorting[0]) === null || _a === void 0 ? void 0 : _a.id;
|
|
96
|
+
if (activeSortColumnId) {
|
|
97
|
+
const isHiddenColumn = hiddenColumnsBySettings.has(activeSortColumnId);
|
|
98
|
+
const isEnabledColumn = enabledColumns.includes(activeSortColumnId);
|
|
99
|
+
// Сбрасываем сортировку только если колонка не скрыта через mode: 'hidden' и не включена
|
|
100
|
+
if (!isHiddenColumn && !isEnabledColumn) {
|
|
101
|
+
// Колонка с активной сортировкой скрыта - сбрасываем сортировку
|
|
102
|
+
onSortingChange([]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}, [areColumnsSettingsEnabled, enabledColumns, sorting, onSortingChange, hiddenColumnsBySettings]);
|
|
48
107
|
const table = (0, react_table_1.useReactTable)({
|
|
49
108
|
data,
|
|
50
|
-
columns:
|
|
109
|
+
columns: enabledTableColumns,
|
|
51
110
|
getCoreRowModel: (0, react_table_1.getCoreRowModel)(),
|
|
52
111
|
getPaginationRowModel: (0, react_table_1.getPaginationRowModel)(),
|
|
53
112
|
getFilteredRowModel: (0, react_table_1.getFilteredRowModel)(),
|
|
54
113
|
getSortedRowModel: (0, react_table_1.getSortedRowModel)(),
|
|
55
|
-
state: {
|
|
114
|
+
state: {
|
|
115
|
+
pagination,
|
|
116
|
+
globalFilter,
|
|
117
|
+
sorting,
|
|
118
|
+
rowSelection,
|
|
119
|
+
columnOrder: enableColumnsOrderSortByDrag ? columnOrder : undefined,
|
|
120
|
+
},
|
|
56
121
|
pageCount,
|
|
57
122
|
onPaginationChange,
|
|
58
123
|
onSortingChange,
|
|
124
|
+
onColumnOrderChange: enableColumnsOrderSortByDrag ? setColumnOrder : undefined,
|
|
59
125
|
globalFilterFn: enableFuzzySearch ? utils_1.fuzzyFilter : 'includesString',
|
|
60
126
|
enableFilters: true,
|
|
61
127
|
manualSorting,
|
|
62
128
|
manualPagination,
|
|
63
129
|
manualFiltering,
|
|
64
130
|
getRowId,
|
|
131
|
+
autoResetPageIndex,
|
|
65
132
|
onRowSelectionChange,
|
|
66
133
|
enableGrouping: true,
|
|
67
134
|
enableRowSelection,
|
|
@@ -70,7 +137,7 @@ function MobileTable(_a) {
|
|
|
70
137
|
});
|
|
71
138
|
const { loadingTable } = (0, hooks_1.useLoadingTable)({
|
|
72
139
|
pageSize: constants_1.DEFAULT_PAGE_SIZE,
|
|
73
|
-
columnDefinitions,
|
|
140
|
+
columnDefinitions: enabledColumnsDefinitions,
|
|
74
141
|
});
|
|
75
142
|
const tableRows = table.getRowModel().rows;
|
|
76
143
|
const loadingTableRows = loadingTable.getRowModel().rows;
|
|
@@ -80,7 +147,6 @@ function MobileTable(_a) {
|
|
|
80
147
|
table.resetRowSelection();
|
|
81
148
|
onRefresh === null || onRefresh === void 0 ? void 0 : onRefresh();
|
|
82
149
|
}, [onRefresh, table]);
|
|
83
|
-
const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
|
|
84
150
|
const bulkActions = (0, react_1.useMemo)(() => enableSelection
|
|
85
151
|
? bulkActionsProp === null || bulkActionsProp === void 0 ? void 0 : bulkActionsProp.map(action => (Object.assign(Object.assign({}, action), { onClick: () => { var _a; return (_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action, table.getState().rowSelection, table.resetRowSelection); } })))
|
|
86
152
|
: undefined, [bulkActionsProp, enableSelection, table]);
|
|
@@ -104,6 +170,16 @@ function MobileTable(_a) {
|
|
|
104
170
|
const selectionMode = (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow)
|
|
105
171
|
? 'multiple'
|
|
106
172
|
: 'single';
|
|
173
|
+
const hasSortableColumns = (0, react_1.useMemo)(() => columnDefinitions.some(column => column.enableSorting !== false), [columnDefinitions]);
|
|
174
|
+
const shouldShowSorting = (0, react_1.useMemo)(() => Boolean(sortingProp) || hasSortableColumns, [sortingProp, hasSortableColumns]);
|
|
175
|
+
const tableFilteredRows = table.getFilteredRowModel().rows;
|
|
176
|
+
(0, table_1.usePageReset)({
|
|
177
|
+
manualPagination,
|
|
178
|
+
maximumAvailablePage: pageCount || tableFilteredRows.length / pagination.pageSize,
|
|
179
|
+
pagination,
|
|
180
|
+
onPaginationChange,
|
|
181
|
+
autoResetPageIndex,
|
|
182
|
+
});
|
|
107
183
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)(styles_module_scss_1.default.tableWrapper, className) }, (0, uikit_product_utils_1.extractSupportProps)(rest), { children: [(!suppressToolbar || columnFilters) && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.header, "data-background": headerBackground, children: (0, jsx_runtime_1.jsx)(uikit_product_mobile_toolbar_1.MobileToolbar, { search: suppressSearch
|
|
108
184
|
? undefined
|
|
109
185
|
: {
|
|
@@ -111,7 +187,7 @@ function MobileTable(_a) {
|
|
|
111
187
|
onChange: onGlobalFilterChange,
|
|
112
188
|
loading: search === null || search === void 0 ? void 0 : search.loading,
|
|
113
189
|
placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || t('searchPlaceholder'),
|
|
114
|
-
}, onRefresh: onRefresh ? handleOnRefresh : undefined, outline: true, filterRow: columnFilters, after: toolbarAfter, moreActions: moreActions, bulkActions: bulkActions, selectedCount: table.getSelectedRowModel().rows.length, selectionMode: selectionMode, onCheck: enableSelection ? handleOnToolbarCheck : undefined, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected() }) })), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.table, children: loading ? ((0, jsx_runtime_1.jsx)(skeleton_1.SkeletonContextProvider, { loading: true, children: loadingTableRows.map((row, index) => ((0, jsx_runtime_1.jsx)(helperComponents_1.TableCard, { headlineId: headlineId, row: row, table: loadingTable, selection: 'none' }, index))) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [tableRows.map((row, index) => ((0, jsx_runtime_1.jsx)(helperComponents_1.TableCard, { headlineId: headlineId, row: row, table: table, selection: enableSelection ? selectionMode : 'none' }, index))), (0, jsx_runtime_1.jsx)(helperComponents_1.TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length })] })) }), !suppressPagination && (0, jsx_runtime_1.jsx)(helperComponents_1.TablePagination, { table: table })] })));
|
|
190
|
+
}, onRefresh: onRefresh ? handleOnRefresh : undefined, outline: true, filterRow: columnFilters, after: toolbarAfter || shouldShowSorting || (areColumnsSettingsEnabled && columnsSettings) ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [toolbarAfter, shouldShowSorting && ((0, jsx_runtime_1.jsx)(helperComponents_1.TableSorting, { table: table, columnDefinitions: columnDefinitions, enabledColumns: areColumnsSettingsEnabled ? enabledColumns : undefined, areColumnsSettingsEnabled: areColumnsSettingsEnabled })), areColumnsSettingsEnabled && columnsSettings && ((0, jsx_runtime_1.jsx)(ColumnsSettings_1.ColumnsSettings, { columnsSettings: columnsSettings, enabledColumns: enabledColumns, setEnabledColumns: setEnabledColumns }))] })) : undefined, moreActions: moreActions, bulkActions: bulkActions, selectedCount: table.getSelectedRowModel().rows.length, selectionMode: selectionMode, onCheck: enableSelection ? handleOnToolbarCheck : undefined, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected() }) })), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.table, children: loading ? ((0, jsx_runtime_1.jsx)(skeleton_1.SkeletonContextProvider, { loading: true, children: loadingTableRows.map((row, index) => ((0, jsx_runtime_1.jsx)(helperComponents_1.TableCard, { headlineId: headlineId, row: row, table: loadingTable, selection: 'none' }, index))) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [tableRows.map((row, index) => ((0, jsx_runtime_1.jsx)(helperComponents_1.TableCard, { headlineId: headlineId, row: row, table: table, selectionAppearance: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.appearance, selection: enableSelection ? selectionMode : 'none' }, index))), (0, jsx_runtime_1.jsx)(helperComponents_1.TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length })] })) }), !suppressPagination && (0, jsx_runtime_1.jsx)(helperComponents_1.TablePagination, { table: table })] })));
|
|
115
191
|
}
|
|
116
192
|
MobileTable.getRowActionsColumnDef = helperComponents_1.getRowActionsColumnDef;
|
|
117
193
|
MobileTable.getStatusColumnDef = helperComponents_1.getStatusColumnDef;
|
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./AdaptiveTable"), exports);
|
|
18
18
|
__exportStar(require("./AdaptiveServerTable"), exports);
|
|
19
19
|
__exportStar(require("./MobileTable"), exports);
|
|
20
|
+
__exportStar(require("../helperComponents"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GroupSelectItemProps } from '@snack-uikit/list';
|
|
2
|
+
export type ColumnsSettingsProps = {
|
|
3
|
+
enabledColumns: string[];
|
|
4
|
+
setEnabledColumns(enabledColumns: string[]): void;
|
|
5
|
+
columnsSettings: [GroupSelectItemProps];
|
|
6
|
+
};
|
|
7
|
+
export declare function ColumnsSettings({ columnsSettings, enabledColumns, setEnabledColumns }: ColumnsSettingsProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ColumnsSettings = ColumnsSettings;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const uikit_product_mobile_dropdown_1 = require("@cloud-ru/uikit-product-mobile-dropdown");
|
|
9
|
+
const button_1 = require("@snack-uikit/button");
|
|
10
|
+
const icons_1 = require("@snack-uikit/icons");
|
|
11
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
12
|
+
function ColumnsSettings({ columnsSettings, enabledColumns, setEnabledColumns }) {
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(uikit_product_mobile_dropdown_1.MobileDroplist, { className: styles_module_scss_1.default.columnsSettings, items: columnsSettings, selection: {
|
|
14
|
+
value: enabledColumns,
|
|
15
|
+
onChange: setEnabledColumns,
|
|
16
|
+
mode: 'multiple',
|
|
17
|
+
}, "data-test-id": 'table__column-settings-droplist', children: (0, jsx_runtime_1.jsx)(button_1.ButtonFunction, { size: 'm', "data-test-id": 'table__column-settings', icon: (0, jsx_runtime_1.jsx)(icons_1.FunctionSettingsSVG, {}) }) }));
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ColumnsSettings';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ColumnsSettings"), exports);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Row, Table } from '@tanstack/react-table';
|
|
2
|
+
import { RowAppearance } from '@snack-uikit/table';
|
|
2
3
|
type TableCardProps<TData extends object> = {
|
|
3
4
|
headlineId?: string;
|
|
4
5
|
row: Row<TData>;
|
|
5
6
|
table: Table<TData>;
|
|
6
7
|
selection: 'multiple' | 'single' | 'none';
|
|
8
|
+
selectionAppearance?: RowAppearance;
|
|
7
9
|
};
|
|
8
|
-
export declare function TableCard<TData extends object>({ headlineId, table, row, selection }: TableCardProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function TableCard<TData extends object>({ headlineId, table, row, selection, selectionAppearance, }: TableCardProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
9
11
|
export {};
|
|
@@ -7,22 +7,27 @@ exports.TableCard = TableCard;
|
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const react_table_1 = require("@tanstack/react-table");
|
|
9
9
|
const react_1 = require("react");
|
|
10
|
+
const table_1 = require("@snack-uikit/table");
|
|
10
11
|
const toggles_1 = require("@snack-uikit/toggles");
|
|
11
12
|
const constants_1 = require("../../constants");
|
|
12
13
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
13
|
-
function TableCard({ headlineId, table, row, selection }) {
|
|
14
|
+
function TableCard({ headlineId, table, row, selection, selectionAppearance = table_1.RowAppearance.Disabled, }) {
|
|
14
15
|
const headerGroups = table.getHeaderGroups();
|
|
15
16
|
const headerCell = row._getAllCellsByColumnId()[headlineId !== null && headlineId !== void 0 ? headlineId : ''];
|
|
16
17
|
const headerColumn = table.getFlatHeaders().find(header => header.id === headlineId);
|
|
17
18
|
const actionsCell = row._getAllCellsByColumnId()[constants_1.ROW_ACTIONS_COLUMN_ID];
|
|
18
19
|
const actionsColumn = table.getFlatHeaders().find(header => header.id === constants_1.ROW_ACTIONS_COLUMN_ID);
|
|
19
20
|
const isSelected = row.getIsSelected();
|
|
21
|
+
const canSelect = row.getCanSelect();
|
|
22
|
+
const isDisabled = !canSelect;
|
|
20
23
|
const handleSelection = (0, react_1.useCallback)(() => {
|
|
24
|
+
if (isDisabled)
|
|
25
|
+
return;
|
|
21
26
|
if (selection === 'single')
|
|
22
27
|
row.toggleSelected(true);
|
|
23
28
|
if (selection === 'multiple')
|
|
24
29
|
row.toggleSelected(!isSelected);
|
|
25
|
-
}, [isSelected, row, selection]);
|
|
30
|
+
}, [isDisabled, isSelected, row, selection]);
|
|
26
31
|
return (
|
|
27
32
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
28
33
|
(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.card, "data-is-selected": isSelected !== null && isSelected !== void 0 ? isSelected : undefined, "data-selection-mode": selection, onClick: handleSelection, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.content, children: [headerCell && headerColumn && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.headline, children: (0, react_table_1.flexRender)(headerColumn.column.columnDef.cell, headerCell.getContext()) })), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.body, children: headerGroups.map(group => group.headers.map((header, index) => {
|
|
@@ -32,5 +37,7 @@ function TableCard({ headlineId, table, row, selection }) {
|
|
|
32
37
|
const column = header.column.columnDef;
|
|
33
38
|
const cell = row._getAllCellsByColumnId()[header.column.id];
|
|
34
39
|
return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.cardRow, children: [(0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.cardRowHeader, children: (0, react_table_1.flexRender)(column.header, header.getContext()) }), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.cardRowContent, children: (0, react_table_1.flexRender)(column.cell, cell.getContext()) })] }, header.id || index));
|
|
35
|
-
})) })] }), selection === 'single' &&
|
|
40
|
+
})) })] }), selection === 'single' &&
|
|
41
|
+
(isDisabled && selectionAppearance === table_1.RowAppearance.HideToggler ? null : ((0, jsx_runtime_1.jsx)(toggles_1.Radio, { size: 'm', className: styles_module_scss_1.default.selectionController, checked: isSelected, disabled: isDisabled }))), selection === 'multiple' &&
|
|
42
|
+
(isDisabled && selectionAppearance === table_1.RowAppearance.HideToggler ? null : ((0, jsx_runtime_1.jsx)(toggles_1.Checkbox, { size: 'm', className: styles_module_scss_1.default.selectionController, checked: isSelected, disabled: isDisabled }))), actionsCell && actionsColumn && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.button, children: (0, react_table_1.flexRender)(actionsColumn.column.columnDef.cell, actionsCell.getContext()) }))] }));
|
|
36
43
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SortingState, Table } from '@tanstack/react-table';
|
|
2
|
+
import { ColumnDefinition } from '@snack-uikit/table';
|
|
3
|
+
export type TableSortingProps<TData extends object> = {
|
|
4
|
+
table: Table<TData>;
|
|
5
|
+
sorting?: SortingState;
|
|
6
|
+
columnDefinitions: ColumnDefinition<TData>[];
|
|
7
|
+
enabledColumns?: string[];
|
|
8
|
+
areColumnsSettingsEnabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function TableSorting<TData extends object>({ table, sorting, columnDefinitions, enabledColumns, areColumnsSettingsEnabled, }: TableSortingProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableSorting = TableSorting;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const uikit_product_icons_1 = require("@cloud-ru/uikit-product-icons");
|
|
7
|
+
const uikit_product_mobile_dropdown_1 = require("@cloud-ru/uikit-product-mobile-dropdown");
|
|
8
|
+
const button_1 = require("@snack-uikit/button");
|
|
9
|
+
const useTableSorting_1 = require("./useTableSorting");
|
|
10
|
+
function TableSorting({ table, sorting, columnDefinitions, enabledColumns, areColumnsSettingsEnabled = false, }) {
|
|
11
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
12
|
+
const { items, pinBottom, selection, currentSort, selectedSortId, handleClearSort } = (0, useTableSorting_1.useTableSorting)({
|
|
13
|
+
table,
|
|
14
|
+
sorting,
|
|
15
|
+
columnDefinitions,
|
|
16
|
+
enabledColumns,
|
|
17
|
+
areColumnsSettingsEnabled,
|
|
18
|
+
});
|
|
19
|
+
const handleClear = () => {
|
|
20
|
+
handleClearSort();
|
|
21
|
+
setOpen(false);
|
|
22
|
+
};
|
|
23
|
+
const clearItem = (pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom[0]) ? [Object.assign(Object.assign({}, pinBottom[0]), { onClick: handleClear })] : undefined;
|
|
24
|
+
let SortIcon = uikit_product_icons_1.SortSVG;
|
|
25
|
+
if (currentSort) {
|
|
26
|
+
SortIcon = currentSort.desc ? uikit_product_icons_1.ArrowDownSVG : uikit_product_icons_1.ArrowUpSVG;
|
|
27
|
+
}
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)(uikit_product_mobile_dropdown_1.MobileDroplist, { items: items, selection: selection, virtualized: items.length > 10, pinBottom: clearItem, open: open, onOpenChange: setOpen, children: (0, jsx_runtime_1.jsx)(button_1.ButtonFunction, { size: 'm', icon: (0, jsx_runtime_1.jsx)(SortIcon, {}), appearance: selectedSortId ? 'primary' : 'neutral' }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableSorting';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TableSorting"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SortingState, Table } from '@tanstack/react-table';
|
|
2
|
+
import { MobileDroplistProps, SelectionSingleState } from '@cloud-ru/uikit-product-mobile-dropdown';
|
|
3
|
+
import { ColumnDefinition } from '@snack-uikit/table';
|
|
4
|
+
type UseTableSortingReturn = {
|
|
5
|
+
items: MobileDroplistProps['items'];
|
|
6
|
+
pinBottom: MobileDroplistProps['items'];
|
|
7
|
+
selection?: SelectionSingleState;
|
|
8
|
+
currentSort: {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
desc: boolean;
|
|
12
|
+
} | null;
|
|
13
|
+
selectedSortId?: string;
|
|
14
|
+
handleClearSort(): void;
|
|
15
|
+
};
|
|
16
|
+
export declare function useTableSorting<TData extends object>({ table, sorting: sortingProp, columnDefinitions, enabledColumns, areColumnsSettingsEnabled, }: {
|
|
17
|
+
table: Table<TData>;
|
|
18
|
+
sorting?: SortingState;
|
|
19
|
+
columnDefinitions: ColumnDefinition<TData>[];
|
|
20
|
+
enabledColumns?: string[];
|
|
21
|
+
areColumnsSettingsEnabled?: boolean;
|
|
22
|
+
}): UseTableSortingReturn;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useTableSorting = useTableSorting;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const uikit_product_icons_1 = require("@cloud-ru/uikit-product-icons");
|
|
10
|
+
const uikit_product_locale_1 = require("@cloud-ru/uikit-product-locale");
|
|
11
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
function useTableSorting({ table, sorting: sortingProp, columnDefinitions, enabledColumns, areColumnsSettingsEnabled = false, }) {
|
|
14
|
+
const { t } = (0, uikit_product_locale_1.useLocale)('Table');
|
|
15
|
+
const sorting = sortingProp !== null && sortingProp !== void 0 ? sortingProp : table.getState().sorting;
|
|
16
|
+
const columnDefMap = (0, react_1.useMemo)(() => (0, utils_1.createColumnDefMap)(columnDefinitions), [columnDefinitions]);
|
|
17
|
+
const hiddenColumnsBySettings = (0, react_1.useMemo)(() => {
|
|
18
|
+
if (!areColumnsSettingsEnabled)
|
|
19
|
+
return new Set();
|
|
20
|
+
const hidden = new Set();
|
|
21
|
+
columnDefMap.forEach((colDef, columnId) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const colDefWithSettings = colDef;
|
|
24
|
+
if (((_a = colDefWithSettings.columnSettings) === null || _a === void 0 ? void 0 : _a.mode) === 'hidden') {
|
|
25
|
+
hidden.add(columnId);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return hidden;
|
|
29
|
+
}, [areColumnsSettingsEnabled, columnDefMap]);
|
|
30
|
+
const sortableHeaders = (0, react_1.useMemo)(() => {
|
|
31
|
+
let headers = table
|
|
32
|
+
.getFlatHeaders()
|
|
33
|
+
.filter(header => header.column.getCanSort() && header.id !== 'select' && header.id !== 'actions');
|
|
34
|
+
if (areColumnsSettingsEnabled && enabledColumns) {
|
|
35
|
+
headers = headers.filter(header => hiddenColumnsBySettings.has(header.id) || enabledColumns.includes(header.id));
|
|
36
|
+
}
|
|
37
|
+
return headers;
|
|
38
|
+
}, [table, areColumnsSettingsEnabled, enabledColumns, hiddenColumnsBySettings]);
|
|
39
|
+
const currentSort = (0, react_1.useMemo)(() => {
|
|
40
|
+
if (sorting.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
const firstSort = sorting[0];
|
|
43
|
+
if (areColumnsSettingsEnabled && enabledColumns) {
|
|
44
|
+
const isHiddenColumn = hiddenColumnsBySettings.has(firstSort.id);
|
|
45
|
+
const isEnabledColumn = enabledColumns.includes(firstSort.id);
|
|
46
|
+
if (!isHiddenColumn && !isEnabledColumn) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const header = table.getFlatHeaders().find(h => h.id === firstSort.id);
|
|
51
|
+
if (!header)
|
|
52
|
+
return null;
|
|
53
|
+
const headerLabel = (0, utils_1.getHeaderLabel)(header);
|
|
54
|
+
return {
|
|
55
|
+
id: firstSort.id,
|
|
56
|
+
label: headerLabel || firstSort.id,
|
|
57
|
+
desc: firstSort.desc,
|
|
58
|
+
};
|
|
59
|
+
}, [sorting, table, areColumnsSettingsEnabled, enabledColumns, hiddenColumnsBySettings]);
|
|
60
|
+
const handleColumnSortToggle = (0, react_1.useCallback)((columnId) => {
|
|
61
|
+
const currentSorting = table.getState().sorting;
|
|
62
|
+
const currentColumnSort = currentSorting.find(s => s.id === columnId);
|
|
63
|
+
let newSorting;
|
|
64
|
+
if (!currentColumnSort) {
|
|
65
|
+
newSorting = [{ id: columnId, desc: false }];
|
|
66
|
+
}
|
|
67
|
+
else if (!currentColumnSort.desc) {
|
|
68
|
+
newSorting = [{ id: columnId, desc: true }];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
newSorting = [];
|
|
72
|
+
}
|
|
73
|
+
table.setSorting(newSorting);
|
|
74
|
+
}, [table]);
|
|
75
|
+
const handleClearSort = (0, react_1.useCallback)(() => {
|
|
76
|
+
table.setSorting([]);
|
|
77
|
+
}, [table]);
|
|
78
|
+
const selectedSortId = (0, react_1.useMemo)(() => {
|
|
79
|
+
if (sorting.length === 0)
|
|
80
|
+
return undefined;
|
|
81
|
+
const firstSort = sorting[0];
|
|
82
|
+
if (areColumnsSettingsEnabled && enabledColumns) {
|
|
83
|
+
const isHiddenColumn = hiddenColumnsBySettings.has(firstSort.id);
|
|
84
|
+
const isEnabledColumn = enabledColumns.includes(firstSort.id);
|
|
85
|
+
if (!isHiddenColumn && !isEnabledColumn) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return `sort-${firstSort.id}`;
|
|
90
|
+
}, [sorting, areColumnsSettingsEnabled, enabledColumns, hiddenColumnsBySettings]);
|
|
91
|
+
const createSortItem = (0, react_1.useCallback)((header) => {
|
|
92
|
+
const columnId = header.id;
|
|
93
|
+
const currentColumnSort = sorting.find(s => s.id === columnId);
|
|
94
|
+
const isAsc = currentColumnSort && !currentColumnSort.desc;
|
|
95
|
+
const isDesc = currentColumnSort && currentColumnSort.desc;
|
|
96
|
+
const headerLabel = (0, utils_1.getHeaderLabel)(header) || columnId;
|
|
97
|
+
let SortIcon = undefined;
|
|
98
|
+
if (isAsc) {
|
|
99
|
+
SortIcon = (0, jsx_runtime_1.jsx)(uikit_product_icons_1.ArrowUpSVG, {});
|
|
100
|
+
}
|
|
101
|
+
else if (isDesc) {
|
|
102
|
+
SortIcon = (0, jsx_runtime_1.jsx)(uikit_product_icons_1.ArrowDownSVG, {});
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
id: `sort-${columnId}`,
|
|
106
|
+
content: {
|
|
107
|
+
option: headerLabel,
|
|
108
|
+
},
|
|
109
|
+
afterContent: SortIcon,
|
|
110
|
+
onClick: () => handleColumnSortToggle(columnId),
|
|
111
|
+
};
|
|
112
|
+
}, [sorting, handleColumnSortToggle]);
|
|
113
|
+
const groupSortableHeadersByPinned = (0, react_1.useCallback)(() => (0, utils_1.groupHeadersByPinned)(sortableHeaders, columnDefMap), [sortableHeaders, columnDefMap]);
|
|
114
|
+
const { items, pinBottom } = (0, react_1.useMemo)(() => {
|
|
115
|
+
const { leftHeaders, unpinnedHeaders, rightHeaders } = groupSortableHeadersByPinned();
|
|
116
|
+
const groups = [];
|
|
117
|
+
if (leftHeaders.length > 0) {
|
|
118
|
+
groups.push({
|
|
119
|
+
type: 'group',
|
|
120
|
+
divider: false,
|
|
121
|
+
items: leftHeaders.map(createSortItem),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (unpinnedHeaders.length > 0) {
|
|
125
|
+
groups.push({
|
|
126
|
+
type: 'group',
|
|
127
|
+
divider: leftHeaders.length > 0 || rightHeaders.length > 0,
|
|
128
|
+
items: unpinnedHeaders.map(createSortItem),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (rightHeaders.length > 0) {
|
|
132
|
+
groups.push({
|
|
133
|
+
type: 'group',
|
|
134
|
+
divider: leftHeaders.length > 0 || unpinnedHeaders.length > 0,
|
|
135
|
+
items: rightHeaders.map(createSortItem),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const clearItem = [
|
|
139
|
+
{
|
|
140
|
+
id: 'snack-internal-clear-id',
|
|
141
|
+
content: {
|
|
142
|
+
option: t('clearSort'),
|
|
143
|
+
},
|
|
144
|
+
afterContent: (0, jsx_runtime_1.jsx)(uikit_product_icons_1.UpdateSVG, {}),
|
|
145
|
+
onClick: handleClearSort,
|
|
146
|
+
disabled: sorting.length === 0,
|
|
147
|
+
className: styles_module_scss_1.default.clearSortItem,
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
const mainGroup = {
|
|
151
|
+
type: 'group',
|
|
152
|
+
label: t('sort'),
|
|
153
|
+
items: groups,
|
|
154
|
+
mode: 'primary',
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
items: [mainGroup],
|
|
158
|
+
pinBottom: clearItem,
|
|
159
|
+
};
|
|
160
|
+
}, [groupSortableHeadersByPinned, createSortItem, sorting, handleClearSort, t]);
|
|
161
|
+
const handleSelectionChange = (0, react_1.useCallback)((selectedId) => {
|
|
162
|
+
const id = String(selectedId);
|
|
163
|
+
if (id === 'sort-clear') {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const match = id.match(/^sort-(.+)$/);
|
|
167
|
+
if (match) {
|
|
168
|
+
const [, columnId] = match;
|
|
169
|
+
handleColumnSortToggle(columnId);
|
|
170
|
+
}
|
|
171
|
+
}, [handleColumnSortToggle]);
|
|
172
|
+
const selection = (0, react_1.useMemo)(() => {
|
|
173
|
+
if (!selectedSortId)
|
|
174
|
+
return undefined;
|
|
175
|
+
return {
|
|
176
|
+
mode: 'single',
|
|
177
|
+
value: selectedSortId,
|
|
178
|
+
onChange: handleSelectionChange,
|
|
179
|
+
};
|
|
180
|
+
}, [selectedSortId, handleSelectionChange]);
|
|
181
|
+
return {
|
|
182
|
+
items,
|
|
183
|
+
pinBottom,
|
|
184
|
+
selection,
|
|
185
|
+
currentSort,
|
|
186
|
+
selectedSortId,
|
|
187
|
+
handleClearSort,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Header } from '@tanstack/react-table';
|
|
2
|
+
import { ColumnDefinition } from '@snack-uikit/table';
|
|
3
|
+
export declare function getHeaderLabel<TData extends object>(header: Header<TData, unknown>): string;
|
|
4
|
+
export declare function createColumnDefMap<TData extends object>(columnDefinitions: ColumnDefinition<TData>[]): Map<string, ColumnDefinition<TData>>;
|
|
5
|
+
export declare function groupHeadersByPinned<TData extends object>(headers: Header<TData, unknown>[], columnDefMap: Map<string, ColumnDefinition<TData>>): {
|
|
6
|
+
leftHeaders: Header<TData, unknown>[];
|
|
7
|
+
unpinnedHeaders: Header<TData, unknown>[];
|
|
8
|
+
rightHeaders: Header<TData, unknown>[];
|
|
9
|
+
};
|