@qoretechnologies/reqore 0.34.13 → 0.35.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/__tests__/helpers/table.test.tsx +47 -0
- package/__tests__/table.test.tsx +356 -124
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Button/index.js +7 -4
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Collection/index.d.ts +2 -1
- package/dist/components/Collection/index.d.ts.map +1 -1
- package/dist/components/Collection/index.js +5 -11
- package/dist/components/Collection/index.js.map +1 -1
- package/dist/components/ControlGroup/index.d.ts.map +1 -1
- package/dist/components/ControlGroup/index.js +4 -3
- package/dist/components/ControlGroup/index.js.map +1 -1
- package/dist/components/Dropdown/index.d.ts +4 -1
- package/dist/components/Dropdown/index.d.ts.map +1 -1
- package/dist/components/Dropdown/index.js +2 -2
- package/dist/components/Dropdown/index.js.map +1 -1
- package/dist/components/Dropdown/list.d.ts +4 -1
- package/dist/components/Dropdown/list.d.ts.map +1 -1
- package/dist/components/Dropdown/list.js +10 -5
- package/dist/components/Dropdown/list.js.map +1 -1
- package/dist/components/Input/index.js +4 -4
- package/dist/components/Input/index.js.map +1 -1
- package/dist/components/Panel/index.d.ts +4 -1
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/Table/cell.d.ts +13 -0
- package/dist/components/Table/cell.d.ts.map +1 -0
- package/dist/components/Table/cell.js +89 -0
- package/dist/components/Table/cell.js.map +1 -0
- package/dist/components/Table/header.d.ts +15 -2
- package/dist/components/Table/header.d.ts.map +1 -1
- package/dist/components/Table/header.js +31 -14
- package/dist/components/Table/header.js.map +1 -1
- package/dist/components/Table/headerCell.d.ts +9 -6
- package/dist/components/Table/headerCell.d.ts.map +1 -1
- package/dist/components/Table/headerCell.js +73 -51
- package/dist/components/Table/headerCell.js.map +1 -1
- package/dist/components/Table/helpers.d.ts +43 -1
- package/dist/components/Table/helpers.d.ts.map +1 -1
- package/dist/components/Table/helpers.js +145 -1
- package/dist/components/Table/helpers.js.map +1 -1
- package/dist/components/Table/index.d.ts +45 -25
- package/dist/components/Table/index.d.ts.map +1 -1
- package/dist/components/Table/index.js +167 -52
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Table/row.d.ts +11 -5
- package/dist/components/Table/row.d.ts.map +1 -1
- package/dist/components/Table/row.js +32 -55
- package/dist/components/Table/row.js.map +1 -1
- package/dist/hooks/useQueryWithDelay.d.ts +8 -0
- package/dist/hooks/useQueryWithDelay.d.ts.map +1 -0
- package/dist/hooks/useQueryWithDelay.js +25 -0
- package/dist/hooks/useQueryWithDelay.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Button/index.tsx +6 -1
- package/src/components/Collection/index.tsx +9 -15
- package/src/components/ControlGroup/index.tsx +10 -5
- package/src/components/Dropdown/index.tsx +9 -0
- package/src/components/Dropdown/list.tsx +18 -6
- package/src/components/Input/index.tsx +3 -3
- package/src/components/Panel/index.tsx +3 -1
- package/src/components/Table/cell.tsx +120 -0
- package/src/components/Table/header.tsx +102 -45
- package/src/components/Table/headerCell.tsx +133 -80
- package/src/components/Table/helpers.ts +211 -1
- package/src/components/Table/index.tsx +334 -91
- package/src/components/Table/row.tsx +51 -127
- package/src/hooks/useQueryWithDelay.ts +30 -0
- package/src/index.tsx +3 -0
- package/src/mock/tableData.ts +40 -20
- package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +1 -1
- package/src/stories/Button/Button.stories.tsx +1 -1
- package/src/stories/Checkbox/Checkbox.stories.tsx +1 -1
- package/src/stories/Collection/Collection.stories.tsx +19 -1
- package/src/stories/Columns/Columns.stories.tsx +1 -1
- package/src/stories/Comment/Comment.stories.tsx +1 -1
- package/src/stories/ControlGroup/ControlGroup.stories.tsx +1 -1
- package/src/stories/Drawer/Drawer.stories.tsx +5 -5
- package/src/stories/Dropdown/Dropdown.stories.tsx +11 -1
- package/src/stories/Header/Header.stories.tsx +1 -1
- package/src/stories/Icon/Icon.stories.tsx +1 -1
- package/src/stories/Input/Input.stories.tsx +1 -1
- package/src/stories/Menu/Menu.stories.tsx +1 -1
- package/src/stories/Message/Message.stories.tsx +1 -1
- package/src/stories/Modal/Modal.stories.tsx +1 -1
- package/src/stories/MultiSelect/MultiSelect.stories.tsx +1 -1
- package/src/stories/Navbar/Navbar.stories.tsx +1 -1
- package/src/stories/Notifications/Interactive.stories.tsx +1 -1
- package/src/stories/Notifications/Notification.stories.tsx +1 -1
- package/src/stories/Notifications/Notifications.stories.tsx +1 -1
- package/src/stories/Paging/Paging.stories.tsx +1 -1
- package/src/stories/Panel/Panel.stories.tsx +5 -5
- package/src/stories/Paragraph/Paragraph.stories.tsx +1 -1
- package/src/stories/Popover/Popover.stories.tsx +2 -2
- package/src/stories/RadioGroup/RadioGroup.stories.tsx +1 -1
- package/src/stories/Sidebar/Sidebar.stories.tsx +2 -2
- package/src/stories/Spacer/Spacer.stories.tsx +1 -1
- package/src/stories/Spinner/Spinner.stories.tsx +1 -1
- package/src/stories/Table/Table.stories.tsx +297 -78
- package/src/stories/Tabs/Tabs.stories.tsx +1 -1
- package/src/stories/Tag/Tag.stories.tsx +1 -1
- package/src/stories/TextArea/TextArea.stories.tsx +2 -2
- package/src/stories/Tree/Tree.stories.tsx +2 -2
- package/src/stories/utils/args.ts +1 -1
- package/tests.json +1 -1
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
import { size as count } from 'lodash';
|
|
3
|
-
import React, { useState } from 'react';
|
|
2
|
+
import { size as count, isArray } from 'lodash';
|
|
3
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
4
4
|
import { useMeasure, useUpdateEffect } from 'react-use';
|
|
5
|
-
import
|
|
5
|
+
import { ReqoreMessage, ReqorePanel, ReqoreVerticalSpacer } from '../..';
|
|
6
6
|
import { TABLE_SIZE_TO_PX, TSizes } from '../../constants/sizes';
|
|
7
7
|
import { IReqoreTheme, TReqoreIntent } from '../../constants/theme';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { useQueryWithDelay } from '../../hooks/useQueryWithDelay';
|
|
9
|
+
import { IReqoreIntent, IReqoreTooltip } from '../../types/global';
|
|
10
|
+
import { IReqoreButtonProps, TReqoreBadge } from '../Button';
|
|
11
|
+
import { IReqoreDropdownItem } from '../Dropdown/list';
|
|
12
|
+
import ReqoreInput, { IReqoreInputProps } from '../Input';
|
|
13
|
+
import { IReqorePanelAction, IReqorePanelProps, IReqorePanelSubAction } from '../Panel';
|
|
13
14
|
import ReqoreTableBody from './body';
|
|
14
|
-
import ReqoreTableHeader, {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import ReqoreTableHeader, { IReqoreCustomHeaderCellComponent } from './header';
|
|
16
|
+
import { IReqoreTableHeaderCellProps } from './headerCell';
|
|
17
|
+
import {
|
|
18
|
+
fixSort,
|
|
19
|
+
flipSortDirection,
|
|
20
|
+
getColumnsCount,
|
|
21
|
+
getOnlyShownColumns,
|
|
22
|
+
getZoomActions,
|
|
23
|
+
hasHiddenColumns,
|
|
24
|
+
prepareColumns,
|
|
25
|
+
sizeToZoom,
|
|
26
|
+
sortTableData,
|
|
27
|
+
zoomToSize,
|
|
28
|
+
} from './helpers';
|
|
29
|
+
import { IReqoreTableRowOptions } from './row';
|
|
17
30
|
|
|
18
31
|
export type TReqoreTableColumnContent =
|
|
19
|
-
| React.FC<{ [key: string]: any; _selectId?: string | number }>
|
|
32
|
+
| React.FC<{ [key: string]: any; _selectId?: string | number; _size: TSizes; _dataId: string }>
|
|
20
33
|
| 'time-ago'
|
|
21
34
|
| 'tag'
|
|
22
35
|
| `tag:${TReqoreIntent}`
|
|
@@ -28,19 +41,33 @@ export type TReqoreTableColumnContent =
|
|
|
28
41
|
|
|
29
42
|
export interface IReqoreTableColumn extends IReqoreIntent {
|
|
30
43
|
dataId: string;
|
|
31
|
-
|
|
44
|
+
show?: boolean;
|
|
32
45
|
grow?: 1 | 2 | 3 | 4;
|
|
33
46
|
width?: number;
|
|
34
|
-
|
|
35
|
-
props?: React.HTMLAttributes<HTMLDivElement>;
|
|
47
|
+
resizedWidth?: number;
|
|
36
48
|
align?: 'center' | 'left' | 'right';
|
|
37
|
-
|
|
49
|
+
|
|
50
|
+
resizable?: boolean;
|
|
38
51
|
sortable?: boolean;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
hideable?: boolean;
|
|
53
|
+
|
|
54
|
+
filterable?: boolean;
|
|
55
|
+
filterPlaceholder?: string;
|
|
56
|
+
filter?: string | number;
|
|
57
|
+
|
|
58
|
+
header?: {
|
|
59
|
+
columns?: IReqoreTableColumn[];
|
|
60
|
+
component?: React.FC<IReqoreTableHeaderCellProps>;
|
|
61
|
+
actions?: IReqoreDropdownItem[];
|
|
62
|
+
} & IReqoreButtonProps;
|
|
63
|
+
|
|
64
|
+
cell?: {
|
|
65
|
+
onClick?: (cellValue: any) => void;
|
|
66
|
+
tooltip?: (cellValue: any) => string | IReqoreTooltip;
|
|
67
|
+
content?: TReqoreTableColumnContent;
|
|
68
|
+
intent?: TReqoreIntent;
|
|
69
|
+
padded?: 'both' | 'horizontal' | 'vertical' | 'none';
|
|
70
|
+
};
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
export interface IReqoreTableRowData {
|
|
@@ -53,28 +80,39 @@ export interface IReqoreTableRowData {
|
|
|
53
80
|
export type IReqoreTableRowClick = (data: IReqoreTableRowData) => void;
|
|
54
81
|
export type IReqoreTableData = IReqoreTableRowData[];
|
|
55
82
|
|
|
56
|
-
export interface IReqoreTableProps
|
|
57
|
-
extends React.HTMLAttributes<HTMLDivElement>,
|
|
58
|
-
IReqoreIntent,
|
|
59
|
-
IWithReqoreFlat,
|
|
60
|
-
IWithReqoreCustomTheme {
|
|
83
|
+
export interface IReqoreTableProps extends IReqorePanelProps {
|
|
61
84
|
columns: IReqoreTableColumn[];
|
|
62
85
|
data?: IReqoreTableData;
|
|
63
|
-
|
|
86
|
+
|
|
64
87
|
width?: number;
|
|
65
88
|
height?: number;
|
|
89
|
+
wrapperSize?: TSizes;
|
|
90
|
+
|
|
66
91
|
sort?: IReqoreTableSort;
|
|
67
|
-
|
|
92
|
+
onSortChange?: (sort?: IReqoreTableSort) => void;
|
|
93
|
+
|
|
94
|
+
filterable?: boolean;
|
|
95
|
+
filterProps?: (data: IReqoreTableData) => IReqoreInputProps;
|
|
96
|
+
filter?: string;
|
|
97
|
+
onFilterChange?: (query: string) => void;
|
|
98
|
+
|
|
99
|
+
zoomable?: boolean;
|
|
100
|
+
defaultZoom?: number;
|
|
101
|
+
|
|
68
102
|
selectable?: boolean;
|
|
69
103
|
selected?: string[];
|
|
70
104
|
selectedRowIntent?: TReqoreIntent;
|
|
71
|
-
onSortChange?: (sort?: IReqoreTableSort) => void;
|
|
72
105
|
onSelectedChange?: (selected?: any[]) => void;
|
|
106
|
+
onSelectClick?: (dataId: string | number) => void;
|
|
73
107
|
selectToggleTooltip?: string;
|
|
108
|
+
|
|
109
|
+
striped?: boolean;
|
|
110
|
+
emptyMessage?: string;
|
|
111
|
+
|
|
74
112
|
onRowClick?: IReqoreTableRowClick;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
113
|
+
headerCellComponent?: IReqoreCustomHeaderCellComponent;
|
|
114
|
+
rowComponent?: IReqoreTableRowOptions['rowComponent'];
|
|
115
|
+
bodyCellComponent?: IReqoreTableRowOptions['cellComponent'];
|
|
78
116
|
}
|
|
79
117
|
|
|
80
118
|
export interface IReqoreTableStyle {
|
|
@@ -93,35 +131,6 @@ export interface IReqoreTableSort {
|
|
|
93
131
|
direction?: 'asc' | 'desc';
|
|
94
132
|
}
|
|
95
133
|
|
|
96
|
-
const StyledTableWrapper = styled.div<IReqoreTableStyle>`
|
|
97
|
-
${({ theme, width, rounded, flat, fill }: IReqoreTableStyle) => css`
|
|
98
|
-
width: ${width ? `${width}px` : '100%'};
|
|
99
|
-
height: ${fill ? '100%' : 'auto'};
|
|
100
|
-
|
|
101
|
-
position: relative;
|
|
102
|
-
clear: both;
|
|
103
|
-
overflow: hidden;
|
|
104
|
-
z-index: 1;
|
|
105
|
-
|
|
106
|
-
display: flex;
|
|
107
|
-
flex-flow: column;
|
|
108
|
-
|
|
109
|
-
border-radius: ${rounded ? '10px' : undefined};
|
|
110
|
-
|
|
111
|
-
background-color: ${theme.main};
|
|
112
|
-
color: ${getReadableColor(theme, undefined, undefined, true)};
|
|
113
|
-
|
|
114
|
-
${!flat &&
|
|
115
|
-
css`
|
|
116
|
-
${StyledTableHeader}, ${StyledColumnGroupHeader} {
|
|
117
|
-
${({ theme }: IReqoreTableHeaderStyle) => css`
|
|
118
|
-
border-bottom: 1px solid ${changeLightness(theme.main, 0.07)};
|
|
119
|
-
`}
|
|
120
|
-
}
|
|
121
|
-
`}
|
|
122
|
-
`}
|
|
123
|
-
`;
|
|
124
|
-
|
|
125
134
|
const ReqoreTable = ({
|
|
126
135
|
className,
|
|
127
136
|
height = 300,
|
|
@@ -135,13 +144,24 @@ const ReqoreTable = ({
|
|
|
135
144
|
onSelectedChange,
|
|
136
145
|
selectToggleTooltip,
|
|
137
146
|
customTheme,
|
|
138
|
-
rounded,
|
|
139
147
|
onRowClick,
|
|
140
148
|
striped,
|
|
141
149
|
selectedRowIntent,
|
|
142
|
-
size,
|
|
150
|
+
size = 'normal',
|
|
151
|
+
wrapperSize = 'normal',
|
|
143
152
|
intent,
|
|
144
153
|
fill,
|
|
154
|
+
filterable,
|
|
155
|
+
zoomable,
|
|
156
|
+
filter,
|
|
157
|
+
actions = [],
|
|
158
|
+
onFilterChange,
|
|
159
|
+
filterProps,
|
|
160
|
+
emptyMessage = 'No data in this table, try changing your search query or filters',
|
|
161
|
+
headerCellComponent,
|
|
162
|
+
rowComponent,
|
|
163
|
+
bodyCellComponent,
|
|
164
|
+
onSelectClick,
|
|
145
165
|
...rest
|
|
146
166
|
}: IReqoreTableProps) => {
|
|
147
167
|
const [leftScroll, setLeftScroll] = useState<number>(0);
|
|
@@ -149,8 +169,61 @@ const ReqoreTable = ({
|
|
|
149
169
|
const [_sort, setSort] = useState<IReqoreTableSort>(fixSort(sort));
|
|
150
170
|
const [_selected, setSelected] = useState<(string | number)[]>([]);
|
|
151
171
|
const [_selectedQuant, setSelectedQuant] = useState<'all' | 'none' | 'some'>('none');
|
|
172
|
+
const [columnModifiers, setColumnModifiers] = useState<{
|
|
173
|
+
[key: string]: { [dataId: string]: any };
|
|
174
|
+
}>({});
|
|
175
|
+
const [_internalColumns, setColumns] = useState<IReqoreTableColumn[]>(columns);
|
|
176
|
+
const [zoom, setZoom] = useState<number>(sizeToZoom[size]);
|
|
177
|
+
|
|
152
178
|
const [wrapperRef, sizes] = useMeasure();
|
|
153
|
-
const
|
|
179
|
+
const { query, preQuery, setQuery, setPreQuery } = useQueryWithDelay(filter, 300, onFilterChange);
|
|
180
|
+
|
|
181
|
+
const finalColumns = useMemo(
|
|
182
|
+
() => prepareColumns(_internalColumns, columnModifiers, size),
|
|
183
|
+
[_internalColumns, columnModifiers]
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const filters: { [key: string]: string } = useMemo(() => {
|
|
187
|
+
const getFilters = (columnsToTransform: IReqoreTableColumn[]) =>
|
|
188
|
+
columnsToTransform.reduce((filterObject, column) => {
|
|
189
|
+
if (column.header?.columns) {
|
|
190
|
+
return {
|
|
191
|
+
...filterObject,
|
|
192
|
+
...getFilters(column.header.columns),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (column.filter) {
|
|
197
|
+
return {
|
|
198
|
+
...filterObject,
|
|
199
|
+
[column.dataId]: column.filter,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return filterObject;
|
|
204
|
+
}, {});
|
|
205
|
+
|
|
206
|
+
return getFilters(finalColumns);
|
|
207
|
+
}, [finalColumns]);
|
|
208
|
+
|
|
209
|
+
const transformedData = useMemo(() => {
|
|
210
|
+
// Filter by global query
|
|
211
|
+
let filteredData = _data.filter((datum) =>
|
|
212
|
+
JSON.stringify(datum).toLowerCase().includes(query.toLowerCase())
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// Filter by column filters
|
|
216
|
+
filteredData = filteredData.filter((datum) => {
|
|
217
|
+
return Object.keys(filters).every((filterKey) => {
|
|
218
|
+
const filterValue = filters[filterKey];
|
|
219
|
+
const datumValue = datum[filterKey];
|
|
220
|
+
|
|
221
|
+
return datumValue?.toString().toLowerCase().includes(filterValue.toString().toLowerCase());
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
return _sort ? sortTableData(filteredData, _sort) : filteredData;
|
|
226
|
+
}, [_data, _sort, query, filters]);
|
|
154
227
|
|
|
155
228
|
useUpdateEffect(() => {
|
|
156
229
|
if (onSortChange) {
|
|
@@ -158,6 +231,10 @@ const ReqoreTable = ({
|
|
|
158
231
|
}
|
|
159
232
|
}, [_sort]);
|
|
160
233
|
|
|
234
|
+
useUpdateEffect(() => {
|
|
235
|
+
setColumns(columns);
|
|
236
|
+
}, [columns]);
|
|
237
|
+
|
|
161
238
|
useUpdateEffect(() => {
|
|
162
239
|
setData(data);
|
|
163
240
|
}, [data]);
|
|
@@ -173,7 +250,9 @@ const ReqoreTable = ({
|
|
|
173
250
|
onSelectedChange(_selected);
|
|
174
251
|
}
|
|
175
252
|
|
|
176
|
-
const selectableData: IReqoreTableData =
|
|
253
|
+
const selectableData: IReqoreTableData = transformedData.filter(
|
|
254
|
+
(datum) => datum._selectId ?? false
|
|
255
|
+
);
|
|
177
256
|
|
|
178
257
|
if (count(_selected)) {
|
|
179
258
|
if (count(_selected) === count(selectableData)) {
|
|
@@ -199,6 +278,11 @@ const ReqoreTable = ({
|
|
|
199
278
|
};
|
|
200
279
|
|
|
201
280
|
const handleSelectClick = (selectId: string | number) => {
|
|
281
|
+
if (onSelectClick) {
|
|
282
|
+
onSelectClick(selectId);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
202
286
|
setSelected((current) => {
|
|
203
287
|
let newSelected = [...current];
|
|
204
288
|
const isSelected = newSelected.find((selected) => selectId === selected);
|
|
@@ -217,7 +301,7 @@ const ReqoreTable = ({
|
|
|
217
301
|
switch (_selectedQuant) {
|
|
218
302
|
case 'none':
|
|
219
303
|
case 'some': {
|
|
220
|
-
const selectableData: (string | number)[] =
|
|
304
|
+
const selectableData: (string | number)[] = transformedData
|
|
221
305
|
.filter((datum) => datum._selectId ?? false)
|
|
222
306
|
.map((datum) => datum._selectId);
|
|
223
307
|
|
|
@@ -231,30 +315,187 @@ const ReqoreTable = ({
|
|
|
231
315
|
}
|
|
232
316
|
};
|
|
233
317
|
|
|
318
|
+
const handleColumnsUpdate = useCallback(
|
|
319
|
+
<T extends keyof IReqoreTableColumn>(id: string, key: T, value: IReqoreTableColumn[T]) => {
|
|
320
|
+
setColumnModifiers((current) => {
|
|
321
|
+
return {
|
|
322
|
+
...current,
|
|
323
|
+
[id]: {
|
|
324
|
+
...current[id],
|
|
325
|
+
[key]: value,
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
},
|
|
330
|
+
[columnModifiers]
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const handlePreQueryChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
|
334
|
+
setPreQuery(event.target.value);
|
|
335
|
+
}, []);
|
|
336
|
+
|
|
337
|
+
const columnsList = useMemo(() => {
|
|
338
|
+
const _columnsList: IReqorePanelSubAction[] = [
|
|
339
|
+
{
|
|
340
|
+
divider: true,
|
|
341
|
+
label: 'Show / hide columns',
|
|
342
|
+
},
|
|
343
|
+
];
|
|
344
|
+
|
|
345
|
+
const addColumn = (column: IReqoreTableColumn) => {
|
|
346
|
+
_columnsList.push({
|
|
347
|
+
label: typeof column.header.label === 'string' ? column.header.label : column.dataId,
|
|
348
|
+
selected: column.show !== false,
|
|
349
|
+
onClick: () =>
|
|
350
|
+
handleColumnsUpdate(column.dataId, 'show', column.show !== false ? false : true),
|
|
351
|
+
intent: column.show !== false ? 'info' : undefined,
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
finalColumns.forEach((column) => {
|
|
356
|
+
if (column.header?.columns) {
|
|
357
|
+
column.header?.columns.forEach((subColumn) => {
|
|
358
|
+
addColumn(subColumn);
|
|
359
|
+
});
|
|
360
|
+
} else {
|
|
361
|
+
addColumn(column);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
return _columnsList;
|
|
366
|
+
}, [finalColumns]);
|
|
367
|
+
|
|
368
|
+
const tableActions = useMemo<IReqorePanelAction[]>(() => {
|
|
369
|
+
const finalActions: IReqorePanelAction[] = [...actions];
|
|
370
|
+
|
|
371
|
+
finalActions.push({
|
|
372
|
+
label: 'Columns',
|
|
373
|
+
icon: 'LayoutColumnLine',
|
|
374
|
+
className: 'reqore-table-columns-options',
|
|
375
|
+
badge: getColumnsCount(getOnlyShownColumns(finalColumns)),
|
|
376
|
+
intent: hasHiddenColumns(finalColumns) ? 'info' : undefined,
|
|
377
|
+
multiSelect: true,
|
|
378
|
+
actions: columnsList,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
if (filterable) {
|
|
382
|
+
finalActions.push({
|
|
383
|
+
as: ReqoreInput,
|
|
384
|
+
props: {
|
|
385
|
+
key: 'search',
|
|
386
|
+
fixed: false,
|
|
387
|
+
placeholder: `Search in ${count(transformedData)} items...`,
|
|
388
|
+
onClearClick: () => {
|
|
389
|
+
setQuery('');
|
|
390
|
+
setPreQuery('');
|
|
391
|
+
},
|
|
392
|
+
onChange: handlePreQueryChange,
|
|
393
|
+
value: preQuery,
|
|
394
|
+
icon: 'Search2Line',
|
|
395
|
+
disabled: !query && !count(transformedData),
|
|
396
|
+
minimal: false,
|
|
397
|
+
...filterProps?.(transformedData),
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (zoomable) {
|
|
403
|
+
finalActions.push({
|
|
404
|
+
fluid: false,
|
|
405
|
+
group: getZoomActions('reqore-table', zoom, setZoom),
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (count(columnModifiers) || zoomable || filterable) {
|
|
410
|
+
finalActions.push({
|
|
411
|
+
icon: 'MoreLine',
|
|
412
|
+
className: 'reqore-table-more',
|
|
413
|
+
actions: [
|
|
414
|
+
{
|
|
415
|
+
label: 'Reset table',
|
|
416
|
+
icon: 'RestartLine',
|
|
417
|
+
className: 'reqore-table-reset',
|
|
418
|
+
onClick: () => {
|
|
419
|
+
setZoom(1);
|
|
420
|
+
setPreQuery('');
|
|
421
|
+
setQuery('');
|
|
422
|
+
setColumnModifiers({});
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
],
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return finalActions;
|
|
430
|
+
}, [
|
|
431
|
+
preQuery,
|
|
432
|
+
transformedData,
|
|
433
|
+
actions,
|
|
434
|
+
filterable,
|
|
435
|
+
filterProps,
|
|
436
|
+
finalColumns,
|
|
437
|
+
zoomable,
|
|
438
|
+
zoom,
|
|
439
|
+
columnsList,
|
|
440
|
+
]);
|
|
441
|
+
|
|
442
|
+
const badge = useMemo(() => {
|
|
443
|
+
const badgeList: TReqoreBadge[] = rest.label ? [count(transformedData)] : undefined;
|
|
444
|
+
|
|
445
|
+
if (rest.badge) {
|
|
446
|
+
if (isArray(rest.badge)) {
|
|
447
|
+
badgeList.push(...rest.badge);
|
|
448
|
+
} else {
|
|
449
|
+
badgeList.push(rest.badge);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return badgeList;
|
|
454
|
+
}, [transformedData, rest.badge]);
|
|
455
|
+
|
|
234
456
|
return (
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
457
|
+
<ReqorePanel
|
|
458
|
+
transparent
|
|
459
|
+
flat
|
|
460
|
+
padded={false}
|
|
461
|
+
contentStyle={{ display: 'flex', flexFlow: 'column', overflow: 'hidden' }}
|
|
462
|
+
{...rest}
|
|
463
|
+
size={wrapperSize}
|
|
464
|
+
actions={tableActions}
|
|
465
|
+
fill={fill}
|
|
466
|
+
className={`${className || ''} reqore-table`}
|
|
467
|
+
style={{ width, ...(rest.style || {}) }}
|
|
468
|
+
getContentRef={wrapperRef}
|
|
469
|
+
badge={badge}
|
|
470
|
+
>
|
|
471
|
+
<ReqoreTableHeader
|
|
472
|
+
size={zoomToSize[zoom]}
|
|
473
|
+
columns={finalColumns}
|
|
474
|
+
leftScroll={leftScroll}
|
|
475
|
+
onSortChange={handleSortChange}
|
|
476
|
+
sortData={_sort}
|
|
477
|
+
selectable={selectable}
|
|
478
|
+
selectedQuant={_selectedQuant}
|
|
479
|
+
onToggleSelectClick={handleToggleSelectClick}
|
|
480
|
+
hasVerticalScroll={count(transformedData) * TABLE_SIZE_TO_PX[size] > height}
|
|
481
|
+
selectToggleTooltip={selectToggleTooltip}
|
|
482
|
+
onColumnsUpdate={handleColumnsUpdate}
|
|
483
|
+
onFilterChange={(dataId: string, value: any) => {
|
|
484
|
+
handleColumnsUpdate(dataId, 'filter', value);
|
|
485
|
+
}}
|
|
486
|
+
component={headerCellComponent}
|
|
487
|
+
/>
|
|
488
|
+
{count(transformedData) === 0 ? (
|
|
489
|
+
<>
|
|
490
|
+
<ReqoreVerticalSpacer height={10} />
|
|
491
|
+
<ReqoreMessage flat size={size} icon='Search2Line'>
|
|
492
|
+
{emptyMessage}
|
|
493
|
+
</ReqoreMessage>
|
|
494
|
+
</>
|
|
495
|
+
) : (
|
|
255
496
|
<ReqoreTableBody
|
|
256
|
-
data={
|
|
257
|
-
columns={
|
|
497
|
+
data={transformedData}
|
|
498
|
+
columns={finalColumns}
|
|
258
499
|
setLeftScroll={setLeftScroll}
|
|
259
500
|
height={fill ? sizes.height : height}
|
|
260
501
|
selectable={selectable}
|
|
@@ -262,12 +503,14 @@ const ReqoreTable = ({
|
|
|
262
503
|
onRowClick={onRowClick}
|
|
263
504
|
selected={_selected}
|
|
264
505
|
selectedRowIntent={selectedRowIntent}
|
|
265
|
-
size={
|
|
506
|
+
size={zoomToSize[zoom]}
|
|
266
507
|
striped={striped}
|
|
267
508
|
flat={rest.flat}
|
|
509
|
+
rowComponent={rowComponent}
|
|
510
|
+
cellComponent={bodyCellComponent}
|
|
268
511
|
/>
|
|
269
|
-
|
|
270
|
-
</
|
|
512
|
+
)}
|
|
513
|
+
</ReqorePanel>
|
|
271
514
|
);
|
|
272
515
|
};
|
|
273
516
|
|