@omniumretail/component-library 1.0.74 → 1.0.75
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/.storybook/main.js +16 -16
- package/.storybook/preview-head.html +20 -20
- package/.storybook/preview.js +27 -27
- package/NPMPUBLISH.md +29 -29
- package/README.md +54 -54
- package/bitbucket-pipelines.yml +94 -94
- package/dist/bundle.js +247 -291
- package/dist/types/components/AnalyticsBar/AnalyticsBar.stories.d.ts +5 -5
- package/dist/types/components/AnalyticsBar/helpers/codeMutation.d.ts +4 -4
- package/dist/types/components/AnalyticsBar/index.d.ts +2 -2
- package/dist/types/components/AnalyticsBar/interfaces/analyticsBar.d.ts +12 -12
- package/dist/types/components/Button/Button.stories.d.ts +6 -6
- package/dist/types/components/Button/index.d.ts +7 -7
- package/dist/types/components/Category/Category.stories.d.ts +4 -4
- package/dist/types/components/Category/CategoryContent/index.d.ts +7 -7
- package/dist/types/components/Category/CategorySidebar/index.d.ts +26 -26
- package/dist/types/components/Category/index.d.ts +7 -7
- package/dist/types/components/CategoryReadOnly/CategoryReadOnly.stories.d.ts +4 -4
- package/dist/types/components/CategoryReadOnly/evaluationOptions.d.ts +10 -10
- package/dist/types/components/CategoryReadOnly/index.d.ts +9 -9
- package/dist/types/components/CategoryResponse/CategoryResponse.stories.d.ts +4 -4
- package/dist/types/components/CategoryResponse/evaluationOptions.d.ts +10 -10
- package/dist/types/components/CategoryResponse/index.d.ts +9 -9
- package/dist/types/components/DatePicker/DatePicker.stories.d.ts +5 -5
- package/dist/types/components/DatePicker/index.d.ts +8 -8
- package/dist/types/components/DatePickerTag/DatePickerTag.stories.d.ts +5 -5
- package/dist/types/components/DatePickerTag/index.d.ts +6 -6
- package/dist/types/components/Footer/Footer.stories.d.ts +5 -5
- package/dist/types/components/Footer/index.d.ts +4 -4
- package/dist/types/components/Input/Input.stories.d.ts +5 -5
- package/dist/types/components/Input/index.d.ts +10 -10
- package/dist/types/components/InputCountryCode/index.d.ts +10 -10
- package/dist/types/components/InputCountryCode/inputCountryCode.stories.d.ts +5 -5
- package/dist/types/components/Label/Label.stories.d.ts +6 -6
- package/dist/types/components/Label/index.d.ts +7 -7
- package/dist/types/components/Link/Link.stories.d.ts +7 -7
- package/dist/types/components/Link/index.d.ts +7 -7
- package/dist/types/components/Menu/Menu.stories.d.ts +5 -5
- package/dist/types/components/Menu/helpers/codeMutation.d.ts +4 -4
- package/dist/types/components/Menu/index.d.ts +3 -2
- package/dist/types/components/ModalConfirmation/ModalConfirmation.stories.d.ts +5 -5
- package/dist/types/components/ModalConfirmation/ModalStatusList.d.ts +5 -5
- package/dist/types/components/ModalConfirmation/index.d.ts +9 -9
- package/dist/types/components/ModalWithTable/ModalWithTable.stories.d.ts +5 -5
- package/dist/types/components/ModalWithTable/index.d.ts +13 -13
- package/dist/types/components/Navigation/Navigation.stories.d.ts +5 -5
- package/dist/types/components/Navigation/index.d.ts +10 -10
- package/dist/types/components/Notification/Notification.stories.d.ts +5 -5
- package/dist/types/components/Notification/index.d.ts +9 -9
- package/dist/types/components/Questions/Questions.stories.d.ts +4 -4
- package/dist/types/components/Questions/SingleQuestion/index.d.ts +1 -1
- package/dist/types/components/Questions/index.d.ts +5 -5
- package/dist/types/components/Radio/Radio.stories.d.ts +5 -5
- package/dist/types/components/Radio/index.d.ts +10 -10
- package/dist/types/components/Select/Select.stories.d.ts +6 -6
- package/dist/types/components/Select/index.d.ts +5 -5
- package/dist/types/components/Separator/Separator.stories.d.ts +6 -6
- package/dist/types/components/Separator/index.d.ts +11 -11
- package/dist/types/components/Sidebar/Sidebar.stories.d.ts +6 -6
- package/dist/types/components/Sidebar/index.d.ts +15 -15
- package/dist/types/components/Switch/Switch.stories.d.ts +5 -5
- package/dist/types/components/Switch/index.d.ts +2 -2
- package/dist/types/components/Table/Table.stories.d.ts +9 -9
- package/dist/types/components/Table/index.d.ts +37 -37
- package/dist/types/components/Tag/Tag.stories.d.ts +5 -5
- package/dist/types/components/Tag/index.d.ts +8 -8
- package/dist/types/components/Upload/Upload.stories.d.ts +4 -4
- package/dist/types/components/Upload/index.d.ts +8 -8
- package/dist/types/components/UserInfo/UserInfo.stories.d.ts +4 -4
- package/dist/types/components/UserInfo/index.d.ts +8 -8
- package/dist/types/components/index.d.ts +25 -25
- package/dist/types/constants/i18n.d.ts +1 -1
- package/dist/types/constants/translationHelper.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +198 -198
- package/src/assets/scss/_global.scss +89 -89
- package/src/assets/scss/index.scss +2 -2
- package/src/components/AnalyticsBar/AnalyticsBar.stories.tsx +236 -236
- package/src/components/AnalyticsBar/helpers/codeMutation.tsx +19 -19
- package/src/components/AnalyticsBar/index.tsx +76 -76
- package/src/components/AnalyticsBar/interfaces/analyticsBar.tsx +13 -13
- package/src/components/AnalyticsBar/styles.module.scss +108 -108
- package/src/components/Button/Button.stories.tsx +26 -26
- package/src/components/Button/index.tsx +24 -24
- package/src/components/Button/styles.module.scss +65 -65
- package/src/components/Category/Category.stories.tsx +88 -88
- package/src/components/Category/CategoryContent/index.tsx +188 -188
- package/src/components/Category/CategoryContent/styles.module.scss +51 -51
- package/src/components/Category/CategorySidebar/index.tsx +268 -268
- package/src/components/Category/CategorySidebar/styles.module.scss +28 -28
- package/src/components/Category/index.tsx +76 -76
- package/src/components/Category/styles.module.scss +13 -13
- package/src/components/CategoryReadOnly/CategoryReadOnly.stories.tsx +270 -270
- package/src/components/CategoryReadOnly/evaluationOptions.tsx +81 -81
- package/src/components/CategoryReadOnly/index.tsx +254 -254
- package/src/components/CategoryReadOnly/styles.module.scss +184 -184
- package/src/components/CategoryResponse/CategoryResponse.stories.tsx +251 -251
- package/src/components/CategoryResponse/evaluationOptions.tsx +81 -81
- package/src/components/CategoryResponse/index.tsx +277 -277
- package/src/components/CategoryResponse/styles.module.scss +180 -180
- package/src/components/DatePicker/DatePicker.stories.tsx +16 -16
- package/src/components/DatePicker/index.tsx +38 -38
- package/src/components/DatePicker/styles.module.scss +3 -3
- package/src/components/DatePickerTag/DatePickerTag.stories.tsx +19 -19
- package/src/components/DatePickerTag/index.tsx +89 -89
- package/src/components/DatePickerTag/styles.module.scss +31 -31
- package/src/components/Footer/Footer.stories.tsx +14 -14
- package/src/components/Footer/index.tsx +38 -38
- package/src/components/Footer/styles.module.scss +38 -38
- package/src/components/Input/Input.stories.tsx +13 -13
- package/src/components/Input/index.tsx +31 -31
- package/src/components/Input/styles.module.scss +8 -8
- package/src/components/InputCountryCode/index.tsx +75 -75
- package/src/components/InputCountryCode/inputCountryCode.stories.tsx +55 -55
- package/src/components/InputCountryCode/styles.module.scss +3 -3
- package/src/components/Label/Label.stories.tsx +21 -21
- package/src/components/Label/index.tsx +19 -19
- package/src/components/Label/styles.module.scss +16 -16
- package/src/components/Link/Link.stories.tsx +30 -30
- package/src/components/Link/index.tsx +21 -21
- package/src/components/Link/styles.module.scss +24 -24
- package/src/components/Menu/Menu.stories.tsx +178 -178
- package/src/components/Menu/helpers/codeMutation.tsx +19 -19
- package/src/components/Menu/index.tsx +23 -23
- package/src/components/ModalConfirmation/ModalConfirmation.stories.tsx +40 -40
- package/src/components/ModalConfirmation/ModalStatusList.tsx +5 -5
- package/src/components/ModalConfirmation/index.tsx +70 -70
- package/src/components/ModalConfirmation/styles.module.scss +62 -62
- package/src/components/ModalWithTable/ModalWithTable.stories.tsx +96 -96
- package/src/components/ModalWithTable/index.tsx +232 -232
- package/src/components/ModalWithTable/styles.module.scss +77 -77
- package/src/components/Navigation/Navigation.stories.tsx +17 -17
- package/src/components/Navigation/index.tsx +33 -33
- package/src/components/Navigation/styles.module.scss +59 -59
- package/src/components/Notification/Notification.stories.tsx +29 -29
- package/src/components/Notification/index.tsx +21 -21
- package/src/components/Questions/Questions.stories.tsx +37 -37
- package/src/components/Questions/SingleQuestion/index.tsx +84 -84
- package/src/components/Questions/SingleQuestion/styles.module.scss +81 -81
- package/src/components/Questions/index.tsx +78 -78
- package/src/components/Radio/Radio.stories.tsx +43 -43
- package/src/components/Radio/index.tsx +26 -26
- package/src/components/Radio/styles.module.scss +23 -23
- package/src/components/Select/Select.stories.tsx +39 -39
- package/src/components/Select/index.tsx +27 -27
- package/src/components/Select/styles.module.scss +13 -13
- package/src/components/Separator/Separator.stories.tsx +22 -22
- package/src/components/Separator/index.tsx +27 -27
- package/src/components/Separator/styles.module.scss +25 -25
- package/src/components/Sidebar/Sidebar.stories.tsx +85 -85
- package/src/components/Sidebar/index.tsx +103 -103
- package/src/components/Sidebar/styles.module.scss +85 -85
- package/src/components/Switch/Switch.stories.tsx +14 -14
- package/src/components/Switch/index.tsx +8 -8
- package/src/components/Switch/styles.module.scss +7 -7
- package/src/components/Table/Table.stories.tsx +222 -222
- package/src/components/Table/index.tsx +279 -275
- package/src/components/Table/styles.module.scss +75 -75
- package/src/components/Tag/Tag.stories.tsx +22 -22
- package/src/components/Tag/index.tsx +189 -189
- package/src/components/Tag/styles.module.scss +60 -60
- package/src/components/Upload/Upload.stories.tsx +45 -45
- package/src/components/Upload/index.tsx +91 -91
- package/src/components/UserInfo/UserInfo.stories.tsx +37 -37
- package/src/components/UserInfo/index.tsx +62 -62
- package/src/components/UserInfo/styles.module.scss +29 -29
- package/src/components/index.tsx +25 -25
- package/src/constants/i18n.ts +25 -25
- package/src/constants/translationHelper.ts +7 -7
- package/src/index.ts +2 -2
- package/src/locales/en.json +86 -86
- package/src/locales/es.json +86 -86
- package/src/locales/pt.json +86 -86
- package/src/types/Global.d.ts +4 -4
- package/tsconfig.json +29 -29
- package/webpack.config.js +51 -51
|
@@ -1,275 +1,279 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
import { Space, TableProps, Select, Dropdown, MenuProps } from 'antd';
|
|
3
|
-
import { Table as AntdTable } from 'antd';
|
|
4
|
-
import type { ColumnsType } from 'antd/es/table/interface';
|
|
5
|
-
import styles from './styles.module.scss';
|
|
6
|
-
import { useTranslation } from 'react-i18next';
|
|
7
|
-
import { MoreOutlined } from '@ant-design/icons';
|
|
8
|
-
import classnames from 'classnames';
|
|
9
|
-
import { Button } from '../Button';
|
|
10
|
-
|
|
11
|
-
export interface FilterOptions {
|
|
12
|
-
value: string;
|
|
13
|
-
label: string;
|
|
14
|
-
direction: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Actions {
|
|
18
|
-
key: string;
|
|
19
|
-
label: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export enum sortBy {
|
|
23
|
-
asc = 'asc',
|
|
24
|
-
desc = 'desc',
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TableCustomProps extends TableProps<any> {
|
|
28
|
-
fieldsToSort?: any[],
|
|
29
|
-
selectPlaceholder?: string,
|
|
30
|
-
onSort?: (field: any, sortBy: any) => void;
|
|
31
|
-
sortInfo?: any;
|
|
32
|
-
paginationInfo?: any;
|
|
33
|
-
headingTranslationsKey?: string;
|
|
34
|
-
actionsArray?: any;
|
|
35
|
-
rowSelectionInfo?: any;
|
|
36
|
-
rowKeyValue?: string;
|
|
37
|
-
hiddenColumns?: string[];
|
|
38
|
-
rowSelection?: any;
|
|
39
|
-
onSelectAllButtonClick?: () => void;
|
|
40
|
-
AllItemsShowing?: boolean;
|
|
41
|
-
selectAllStatus?: any;
|
|
42
|
-
isTableDataRefreshed?: any;
|
|
43
|
-
tableLoading?: any;
|
|
44
|
-
tableMaxHeight?: any;
|
|
45
|
-
columnsSortChange?: any;
|
|
46
|
-
sortByColumns?: boolean;
|
|
47
|
-
columnsToSort?: string[];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const Table = (props: TableCustomProps) => {
|
|
51
|
-
const { t } = useTranslation();
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
dataSource = undefined,
|
|
55
|
-
fieldsToSort,
|
|
56
|
-
selectPlaceholder = 'Sort By',
|
|
57
|
-
onSort,
|
|
58
|
-
headingTranslationsKey,
|
|
59
|
-
actionsArray: items,
|
|
60
|
-
rowKeyValue,
|
|
61
|
-
hiddenColumns,
|
|
62
|
-
rowSelection,
|
|
63
|
-
onSelectAllButtonClick,
|
|
64
|
-
AllItemsShowing,
|
|
65
|
-
selectAllStatus,
|
|
66
|
-
isTableDataRefreshed,
|
|
67
|
-
tableLoading,
|
|
68
|
-
tableMaxHeight,
|
|
69
|
-
sortByColumns,
|
|
70
|
-
columnsToSort
|
|
71
|
-
} = props;
|
|
72
|
-
|
|
73
|
-
const [customFilters, setCustomFilters] = useState<any>([]);
|
|
74
|
-
const [customColumns, setCustomColumns] = useState<ColumnsType<any>>([]);
|
|
75
|
-
const [sortInfo, setSortInfo] = useState<any>([]);
|
|
76
|
-
const [selectedRowKeys, setselectedRowKeys] = useState<any>(rowSelection?.selectedRowKeys || []);
|
|
77
|
-
const [selectedAllRowKeys, setSelectedAllRowKeys] = useState(false);
|
|
78
|
-
const [deselectAll, setDeselectAll] = useState(false);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
|
|
82
|
-
if (rowSelection.type === 'radio') {
|
|
83
|
-
setselectedRowKeys(newSelectedRowKeys);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
setselectedRowKeys((prevKeys: any) => {
|
|
88
|
-
const dataSourceIds = dataSource?.map((data) => data[rowKeyValue as any])
|
|
89
|
-
|
|
90
|
-
const oldKeys = prevKeys.filter((key: any) => {
|
|
91
|
-
return !dataSourceIds?.includes(key)
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return [...oldKeys, ...newSelectedRowKeys];
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
setSelectedAllRowKeys(false);
|
|
98
|
-
setDeselectAll(false);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const handleChange: TableProps<any>['onChange'] = (pagination, filters, sorter: any, extra) => {
|
|
102
|
-
const getPagination = {
|
|
103
|
-
currentPage: pagination.current,
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const getSortAndPaginationInfo = { ...sortInfo, ...getPagination }
|
|
107
|
-
props.paginationInfo(getSortAndPaginationInfo);
|
|
108
|
-
|
|
109
|
-
// SORT
|
|
110
|
-
if(sortByColumns) {
|
|
111
|
-
const { field, order } = sorter;
|
|
112
|
-
let mappedOrder = null;
|
|
113
|
-
if(order === "ascend") {
|
|
114
|
-
mappedOrder = "asc";
|
|
115
|
-
} else if(order === "descend") {
|
|
116
|
-
mappedOrder = "desc";
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if(field && mappedOrder) {
|
|
120
|
-
props.columnsSortChange({ field, order: mappedOrder });
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const setSorter = (option: any) => {
|
|
126
|
-
onSort?.(option.value.split('-')[0], option.direction);
|
|
127
|
-
const sortData = {
|
|
128
|
-
sortDirection: option.direction,
|
|
129
|
-
sortValue: option.value.split('-')[0],
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
setSortInfo(sortData)
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const selectAllRows = () => {
|
|
136
|
-
if (selectedAllRowKeys) {
|
|
137
|
-
setDeselectAll(true);
|
|
138
|
-
} else {
|
|
139
|
-
onSelectAllButtonClick?.(); // Call the onSelectAllButtonClick callback
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
if (isTableDataRefreshed && !tableLoading || AllItemsShowing) {
|
|
145
|
-
if (selectAllStatus && AllItemsShowing) {
|
|
146
|
-
const allRowKeys = dataSource?.map((record) => record[rowKeyValue as any]);
|
|
147
|
-
setselectedRowKeys(allRowKeys);
|
|
148
|
-
setSelectedAllRowKeys(true);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}, [isTableDataRefreshed, tableLoading, selectAllStatus, AllItemsShowing]);
|
|
152
|
-
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
if (deselectAll) {
|
|
155
|
-
setselectedRowKeys([]);
|
|
156
|
-
setDeselectAll(false);
|
|
157
|
-
setSelectedAllRowKeys(false);
|
|
158
|
-
}
|
|
159
|
-
}, [deselectAll]);
|
|
160
|
-
|
|
161
|
-
useEffect(() => {
|
|
162
|
-
props.rowSelectionInfo(selectedRowKeys);
|
|
163
|
-
}, [selectedRowKeys]);
|
|
164
|
-
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
if (dataSource && (dataSource as any)?.length > 0) {
|
|
167
|
-
// Columns
|
|
168
|
-
let columns = Object.keys(dataSource?.[0]).map(key => {
|
|
169
|
-
if (hiddenColumns?.includes(key)) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const isColumnSortable = columnsToSort?.includes(key) ? sortByColumns : false;
|
|
174
|
-
|
|
175
|
-
return ({
|
|
176
|
-
title: headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key,
|
|
177
|
-
dataIndex: key,
|
|
178
|
-
key: key,
|
|
179
|
-
ellipsis: false,
|
|
180
|
-
sorter: isColumnSortable,
|
|
181
|
-
})
|
|
182
|
-
}).filter(el => el !== undefined) as any;
|
|
183
|
-
|
|
184
|
-
let columnActions = {
|
|
185
|
-
key: 'action',
|
|
186
|
-
title: headingTranslationsKey ? t(`${headingTranslationsKey}.${'action'}`) : 'action',
|
|
187
|
-
dataIndex: 6,
|
|
188
|
-
ellipsis: false,
|
|
189
|
-
render: () =>
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { Space, TableProps, Select, Dropdown, MenuProps } from 'antd';
|
|
3
|
+
import { Table as AntdTable } from 'antd';
|
|
4
|
+
import type { ColumnsType } from 'antd/es/table/interface';
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { MoreOutlined } from '@ant-design/icons';
|
|
8
|
+
import classnames from 'classnames';
|
|
9
|
+
import { Button } from '../Button';
|
|
10
|
+
|
|
11
|
+
export interface FilterOptions {
|
|
12
|
+
value: string;
|
|
13
|
+
label: string;
|
|
14
|
+
direction: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Actions {
|
|
18
|
+
key: string;
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export enum sortBy {
|
|
23
|
+
asc = 'asc',
|
|
24
|
+
desc = 'desc',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TableCustomProps extends TableProps<any> {
|
|
28
|
+
fieldsToSort?: any[],
|
|
29
|
+
selectPlaceholder?: string,
|
|
30
|
+
onSort?: (field: any, sortBy: any) => void;
|
|
31
|
+
sortInfo?: any;
|
|
32
|
+
paginationInfo?: any;
|
|
33
|
+
headingTranslationsKey?: string;
|
|
34
|
+
actionsArray?: any;
|
|
35
|
+
rowSelectionInfo?: any;
|
|
36
|
+
rowKeyValue?: string;
|
|
37
|
+
hiddenColumns?: string[];
|
|
38
|
+
rowSelection?: any;
|
|
39
|
+
onSelectAllButtonClick?: () => void;
|
|
40
|
+
AllItemsShowing?: boolean;
|
|
41
|
+
selectAllStatus?: any;
|
|
42
|
+
isTableDataRefreshed?: any;
|
|
43
|
+
tableLoading?: any;
|
|
44
|
+
tableMaxHeight?: any;
|
|
45
|
+
columnsSortChange?: any;
|
|
46
|
+
sortByColumns?: boolean;
|
|
47
|
+
columnsToSort?: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const Table = (props: TableCustomProps) => {
|
|
51
|
+
const { t } = useTranslation();
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
dataSource = undefined,
|
|
55
|
+
fieldsToSort,
|
|
56
|
+
selectPlaceholder = 'Sort By',
|
|
57
|
+
onSort,
|
|
58
|
+
headingTranslationsKey,
|
|
59
|
+
actionsArray: items,
|
|
60
|
+
rowKeyValue,
|
|
61
|
+
hiddenColumns,
|
|
62
|
+
rowSelection,
|
|
63
|
+
onSelectAllButtonClick,
|
|
64
|
+
AllItemsShowing,
|
|
65
|
+
selectAllStatus,
|
|
66
|
+
isTableDataRefreshed,
|
|
67
|
+
tableLoading,
|
|
68
|
+
tableMaxHeight,
|
|
69
|
+
sortByColumns,
|
|
70
|
+
columnsToSort
|
|
71
|
+
} = props;
|
|
72
|
+
|
|
73
|
+
const [customFilters, setCustomFilters] = useState<any>([]);
|
|
74
|
+
const [customColumns, setCustomColumns] = useState<ColumnsType<any>>([]);
|
|
75
|
+
const [sortInfo, setSortInfo] = useState<any>([]);
|
|
76
|
+
const [selectedRowKeys, setselectedRowKeys] = useState<any>(rowSelection?.selectedRowKeys || []);
|
|
77
|
+
const [selectedAllRowKeys, setSelectedAllRowKeys] = useState(false);
|
|
78
|
+
const [deselectAll, setDeselectAll] = useState(false);
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
|
|
82
|
+
if (rowSelection.type === 'radio') {
|
|
83
|
+
setselectedRowKeys(newSelectedRowKeys);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setselectedRowKeys((prevKeys: any) => {
|
|
88
|
+
const dataSourceIds = dataSource?.map((data) => data[rowKeyValue as any])
|
|
89
|
+
|
|
90
|
+
const oldKeys = prevKeys.filter((key: any) => {
|
|
91
|
+
return !dataSourceIds?.includes(key)
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return [...oldKeys, ...newSelectedRowKeys];
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
setSelectedAllRowKeys(false);
|
|
98
|
+
setDeselectAll(false);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const handleChange: TableProps<any>['onChange'] = (pagination, filters, sorter: any, extra) => {
|
|
102
|
+
const getPagination = {
|
|
103
|
+
currentPage: pagination.current,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const getSortAndPaginationInfo = { ...sortInfo, ...getPagination }
|
|
107
|
+
props.paginationInfo(getSortAndPaginationInfo);
|
|
108
|
+
|
|
109
|
+
// SORT
|
|
110
|
+
if(sortByColumns) {
|
|
111
|
+
const { field, order } = sorter;
|
|
112
|
+
let mappedOrder = null;
|
|
113
|
+
if(order === "ascend") {
|
|
114
|
+
mappedOrder = "asc";
|
|
115
|
+
} else if(order === "descend") {
|
|
116
|
+
mappedOrder = "desc";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if(field && mappedOrder) {
|
|
120
|
+
props.columnsSortChange({ field, order: mappedOrder });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const setSorter = (option: any) => {
|
|
126
|
+
onSort?.(option.value.split('-')[0], option.direction);
|
|
127
|
+
const sortData = {
|
|
128
|
+
sortDirection: option.direction,
|
|
129
|
+
sortValue: option.value.split('-')[0],
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
setSortInfo(sortData)
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const selectAllRows = () => {
|
|
136
|
+
if (selectedAllRowKeys) {
|
|
137
|
+
setDeselectAll(true);
|
|
138
|
+
} else {
|
|
139
|
+
onSelectAllButtonClick?.(); // Call the onSelectAllButtonClick callback
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (isTableDataRefreshed && !tableLoading || AllItemsShowing) {
|
|
145
|
+
if (selectAllStatus && AllItemsShowing) {
|
|
146
|
+
const allRowKeys = dataSource?.map((record) => record[rowKeyValue as any]);
|
|
147
|
+
setselectedRowKeys(allRowKeys);
|
|
148
|
+
setSelectedAllRowKeys(true);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, [isTableDataRefreshed, tableLoading, selectAllStatus, AllItemsShowing]);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (deselectAll) {
|
|
155
|
+
setselectedRowKeys([]);
|
|
156
|
+
setDeselectAll(false);
|
|
157
|
+
setSelectedAllRowKeys(false);
|
|
158
|
+
}
|
|
159
|
+
}, [deselectAll]);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
props.rowSelectionInfo(selectedRowKeys);
|
|
163
|
+
}, [selectedRowKeys]);
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (dataSource && (dataSource as any)?.length > 0) {
|
|
167
|
+
// Columns
|
|
168
|
+
let columns = Object.keys(dataSource?.[0]).map(key => {
|
|
169
|
+
if (hiddenColumns?.includes(key)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const isColumnSortable = columnsToSort?.includes(key) ? sortByColumns : false;
|
|
174
|
+
|
|
175
|
+
return ({
|
|
176
|
+
title: headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key,
|
|
177
|
+
dataIndex: key,
|
|
178
|
+
key: key,
|
|
179
|
+
ellipsis: false,
|
|
180
|
+
sorter: isColumnSortable,
|
|
181
|
+
})
|
|
182
|
+
}).filter(el => el !== undefined) as any;
|
|
183
|
+
|
|
184
|
+
let columnActions = {
|
|
185
|
+
key: 'action',
|
|
186
|
+
title: headingTranslationsKey ? t(`${headingTranslationsKey}.${'action'}`) : 'action',
|
|
187
|
+
dataIndex: 6,
|
|
188
|
+
ellipsis: false,
|
|
189
|
+
render: () => {
|
|
190
|
+
if (!items?.[0]) return null; // Verifica se o array items é nulo
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<Space size="middle">
|
|
194
|
+
<Dropdown menu={{ items }}>
|
|
195
|
+
<a>
|
|
196
|
+
<MoreOutlined style={{ color: 'var(--color-blue)', transform: 'scale(1.6)' }} />
|
|
197
|
+
</a>
|
|
198
|
+
</Dropdown>
|
|
199
|
+
</Space>
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
items && columns.push(columnActions as any);
|
|
205
|
+
|
|
206
|
+
setCustomColumns(columns);
|
|
207
|
+
|
|
208
|
+
// Filters
|
|
209
|
+
const dataKeysToFilter = Object.keys(dataSource?.[0]).filter((el) => fieldsToSort?.includes(el));
|
|
210
|
+
|
|
211
|
+
const filters = ([] as FilterOptions[]).concat(
|
|
212
|
+
...dataKeysToFilter.map(key => ({
|
|
213
|
+
value: `${key}-${sortBy.desc}`,
|
|
214
|
+
label: `${headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key} (${sortBy.desc})`,
|
|
215
|
+
direction: `${sortBy.desc}`,
|
|
216
|
+
})),
|
|
217
|
+
...dataKeysToFilter.map(key => ({
|
|
218
|
+
value: `${key}-${sortBy.asc}`,
|
|
219
|
+
label: `${headingTranslationsKey ? t(`${headingTranslationsKey}.${key}`) : key} (${sortBy.asc})`,
|
|
220
|
+
direction: `${sortBy.asc}`,
|
|
221
|
+
}))
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
setCustomFilters(filters);
|
|
225
|
+
}
|
|
226
|
+
}, [dataSource]);
|
|
227
|
+
|
|
228
|
+
const shouldRenderSortDropdown = customFilters.length > 0;
|
|
229
|
+
|
|
230
|
+
const tableWrapperClasses = classnames({
|
|
231
|
+
[styles.tableWrapperNoSelection]: !rowSelection
|
|
232
|
+
}, [styles.tableWrapper]);
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<div className={tableWrapperClasses}>
|
|
236
|
+
{shouldRenderSortDropdown &&
|
|
237
|
+
<Space style={{ marginBottom: 16 }}>
|
|
238
|
+
<Select
|
|
239
|
+
style={{ width: 'auto', minWidth: 200 }}
|
|
240
|
+
placeholder={selectPlaceholder}
|
|
241
|
+
onSelect={(_, option: any) => {
|
|
242
|
+
setSorter(option);
|
|
243
|
+
}}
|
|
244
|
+
optionFilterProp="children"
|
|
245
|
+
filterOption={(input, option) => (option?.label ?? '').includes(input)}
|
|
246
|
+
filterSort={(optionA, optionB) =>
|
|
247
|
+
(optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase())
|
|
248
|
+
}
|
|
249
|
+
options={customFilters}
|
|
250
|
+
/>
|
|
251
|
+
</Space>
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
<AntdTable
|
|
255
|
+
dataSource={dataSource}
|
|
256
|
+
onChange={handleChange}
|
|
257
|
+
{...props}
|
|
258
|
+
columns={customColumns}
|
|
259
|
+
{...props.rowSelection ? (
|
|
260
|
+
{
|
|
261
|
+
rowSelection: {
|
|
262
|
+
selectedRowKeys: selectedRowKeys,
|
|
263
|
+
onChange: onSelectChange,
|
|
264
|
+
type: props.rowSelection?.type,
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
) : null}
|
|
268
|
+
rowKey={rowKeyValue}
|
|
269
|
+
{...(tableMaxHeight ? { scroll: { y: tableMaxHeight } } : {})}
|
|
270
|
+
/>
|
|
271
|
+
{
|
|
272
|
+
onSelectAllButtonClick &&
|
|
273
|
+
<Button onClick={selectAllRows} className={styles.selectAllRows}>
|
|
274
|
+
{selectedAllRowKeys ? t('components.table.deselectAll') : t('components.table.selectAll')}
|
|
275
|
+
</Button>
|
|
276
|
+
}
|
|
277
|
+
</div>
|
|
278
|
+
);
|
|
279
|
+
};
|