@qoretechnologies/reqore 0.35.1 → 0.35.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/helpers/table.test.tsx +20 -0
- package/dist/components/Collection/index.d.ts +11 -2
- package/dist/components/Collection/index.d.ts.map +1 -1
- package/dist/components/Collection/index.js +33 -7
- 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 +1 -1
- package/dist/components/ControlGroup/index.js.map +1 -1
- package/dist/components/Dropdown/list.d.ts +1 -0
- package/dist/components/Dropdown/list.d.ts.map +1 -1
- package/dist/components/Dropdown/list.js.map +1 -1
- package/dist/components/Menu/divider.d.ts +1 -0
- package/dist/components/Menu/divider.d.ts.map +1 -1
- package/dist/components/Menu/divider.js +3 -2
- package/dist/components/Menu/divider.js.map +1 -1
- package/dist/components/Spacer/index.d.ts.map +1 -1
- package/dist/components/Spacer/index.js +1 -1
- package/dist/components/Spacer/index.js.map +1 -1
- package/dist/components/Table/body.d.ts +10 -4
- package/dist/components/Table/body.d.ts.map +1 -1
- package/dist/components/Table/body.js +44 -9
- package/dist/components/Table/body.js.map +1 -1
- package/dist/components/Table/cell.d.ts.map +1 -1
- package/dist/components/Table/cell.js +2 -2
- package/dist/components/Table/cell.js.map +1 -1
- package/dist/components/Table/header.d.ts +8 -7
- package/dist/components/Table/header.d.ts.map +1 -1
- package/dist/components/Table/header.js +34 -37
- package/dist/components/Table/header.js.map +1 -1
- package/dist/components/Table/headerCell.d.ts +2 -2
- package/dist/components/Table/headerCell.d.ts.map +1 -1
- package/dist/components/Table/headerCell.js +25 -7
- package/dist/components/Table/headerCell.js.map +1 -1
- package/dist/components/Table/helpers.d.ts +2 -0
- package/dist/components/Table/helpers.d.ts.map +1 -1
- package/dist/components/Table/helpers.js +28 -2
- package/dist/components/Table/helpers.js.map +1 -1
- package/dist/components/Table/index.d.ts +9 -2
- package/dist/components/Table/index.d.ts.map +1 -1
- package/dist/components/Table/index.js +175 -15
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Table/row.d.ts.map +1 -1
- package/dist/components/Table/row.js +17 -28
- package/dist/components/Table/row.js.map +1 -1
- package/dist/components/Tree/index.d.ts +3 -1
- package/dist/components/Tree/index.d.ts.map +1 -1
- package/dist/components/Tree/index.js +9 -2
- package/dist/components/Tree/index.js.map +1 -1
- package/dist/constants/paging.d.ts +1 -0
- package/dist/constants/paging.d.ts.map +1 -1
- package/dist/constants/paging.js +20 -1
- package/dist/constants/paging.js.map +1 -1
- package/dist/constants/sizes.d.ts +15 -0
- package/dist/constants/sizes.d.ts.map +1 -1
- package/dist/constants/sizes.js +16 -1
- package/dist/constants/sizes.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Collection/index.tsx +41 -6
- package/src/components/ControlGroup/index.tsx +1 -0
- package/src/components/Dropdown/list.tsx +1 -0
- package/src/components/Menu/divider.tsx +31 -21
- package/src/components/Spacer/index.tsx +2 -2
- package/src/components/Table/body.tsx +87 -36
- package/src/components/Table/cell.tsx +4 -1
- package/src/components/Table/header.tsx +133 -124
- package/src/components/Table/headerCell.tsx +34 -8
- package/src/components/Table/helpers.ts +42 -2
- package/src/components/Table/index.tsx +251 -53
- package/src/components/Table/row.tsx +34 -53
- package/src/components/Tree/index.tsx +13 -2
- package/src/constants/paging.ts +22 -0
- package/src/constants/sizes.ts +17 -0
- package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +0 -3
- package/src/stories/Collection/Collection.stories.tsx +16 -0
- package/src/stories/Table/Table.stories.tsx +96 -1
- package/src/stories/Tree/Tree.stories.tsx +13 -0
- package/tests.json +1 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { omit } from 'lodash';
|
|
2
|
+
import { forwardRef, useCallback } from 'react';
|
|
3
|
+
import { useMount } from 'react-use';
|
|
2
4
|
import styled, { css } from 'styled-components';
|
|
3
5
|
import { IReqoreTableColumn, IReqoreTableSort } from '.';
|
|
6
|
+
import { SIZE_TO_PX, TSizes } from '../../constants/sizes';
|
|
4
7
|
import { IReqoreTheme } from '../../constants/theme';
|
|
5
8
|
import { changeLightness } from '../../helpers/colors';
|
|
6
9
|
import { alignToFlexAlign } from '../../helpers/utils';
|
|
10
|
+
import { useCombinedRefs } from '../../hooks/useCombinedRefs';
|
|
7
11
|
import { IWithReqoreSize } from '../../types/global';
|
|
8
|
-
import { IReqoreIconName } from '../../types/icons';
|
|
9
12
|
import { IReqoreButtonProps } from '../Button';
|
|
10
13
|
import { IReqoreTableHeaderCellProps, ReqoreTableHeaderCell } from './headerCell';
|
|
11
|
-
import {
|
|
14
|
+
import { getOnlyShownColumns } from './helpers';
|
|
12
15
|
|
|
13
16
|
export type TColumnsUpdater = <T extends keyof IReqoreTableColumn>(
|
|
14
17
|
id: string,
|
|
@@ -22,37 +25,45 @@ export interface IReqoreCustomHeaderCellProps
|
|
|
22
25
|
'sortData' | 'onSortChange' | 'onColumnsUpdate' | 'onFilterChange'
|
|
23
26
|
>,
|
|
24
27
|
Omit<IReqoreTableColumn, 'cell' | 'header'>,
|
|
25
|
-
IReqoreButtonProps {
|
|
28
|
+
Omit<IReqoreButtonProps, 'maxWidth'> {
|
|
26
29
|
hasColumns?: boolean;
|
|
27
30
|
}
|
|
28
31
|
export interface IReqoreCustomHeaderCellComponent extends React.FC<IReqoreCustomHeaderCellProps> {}
|
|
29
32
|
|
|
30
33
|
export interface IReqoreTableSectionProps extends IWithReqoreSize {
|
|
31
34
|
columns: IReqoreTableColumn[];
|
|
32
|
-
leftScroll: number;
|
|
33
35
|
onSortChange?: (sort: string) => void;
|
|
34
36
|
sortData: IReqoreTableSort;
|
|
35
|
-
selectable?: boolean;
|
|
36
|
-
selectedQuant: 'none' | 'all' | 'some';
|
|
37
|
-
onToggleSelectClick: () => void;
|
|
38
37
|
hasVerticalScroll: boolean;
|
|
39
|
-
selectToggleTooltip?: string;
|
|
40
38
|
onColumnsUpdate: TColumnsUpdater;
|
|
41
39
|
onFilterChange?: (dataId: string, value: any) => void;
|
|
42
40
|
component?: IReqoreCustomHeaderCellComponent;
|
|
41
|
+
heightAsGroup?: boolean;
|
|
42
|
+
scrollable?: boolean;
|
|
43
|
+
bodyRef: React.RefObject<HTMLDivElement>;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface IReqoreTableSectionStyle {
|
|
46
47
|
leftScroll: number;
|
|
47
48
|
hasVerticalScroll: boolean;
|
|
48
49
|
theme: IReqoreTheme;
|
|
50
|
+
heightAsGroup?: boolean;
|
|
51
|
+
size?: TSizes;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
const StyledTableHeaderWrapper = styled.div<IReqoreTableSectionStyle>`
|
|
52
|
-
${({
|
|
55
|
+
${({ heightAsGroup, size }) => css`
|
|
53
56
|
display: flex;
|
|
57
|
+
|
|
58
|
+
overflow-x: auto;
|
|
59
|
+
overflow-y: hidden;
|
|
60
|
+
::-webkit-scrollbar {
|
|
61
|
+
display: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
flex-shrink: 0;
|
|
54
65
|
flex-flow: column;
|
|
55
|
-
|
|
66
|
+
height: ${heightAsGroup ? `${SIZE_TO_PX[size] * 2}px` : undefined};
|
|
56
67
|
|
|
57
68
|
${({ theme }) => css`
|
|
58
69
|
background-color: ${theme.main};
|
|
@@ -77,7 +88,10 @@ export const StyledColumnGroupHeader = styled.div<IReqoreTableHeaderStyle>`
|
|
|
77
88
|
const StyledColumnGroup = styled.div<IReqoreTableHeaderStyle>`
|
|
78
89
|
display: flex;
|
|
79
90
|
flex-flow: column;
|
|
91
|
+
flex-shrink: 0;
|
|
80
92
|
width: ${({ width }) => width}px;
|
|
93
|
+
max-width: ${({ maxWidth = 9999 }) => maxWidth}px;
|
|
94
|
+
min-width: ${({ minWidth, width }) => minWidth || width}px;
|
|
81
95
|
|
|
82
96
|
${({ grow }) =>
|
|
83
97
|
grow &&
|
|
@@ -105,126 +119,121 @@ const StyledTableHeaderRow = styled.div<{ theme: IReqoreTheme }>`
|
|
|
105
119
|
}
|
|
106
120
|
`;
|
|
107
121
|
|
|
108
|
-
const ReqoreTableHeader = (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}: IReqoreTableSectionProps
|
|
123
|
-
|
|
124
|
-
headerCellComponent: IReqoreCustomHeaderCellComponent,
|
|
125
|
-
props: IReqoreCustomHeaderCellProps
|
|
122
|
+
const ReqoreTableHeader = forwardRef<HTMLDivElement, IReqoreTableSectionProps>(
|
|
123
|
+
(
|
|
124
|
+
{
|
|
125
|
+
columns,
|
|
126
|
+
onSortChange,
|
|
127
|
+
sortData,
|
|
128
|
+
hasVerticalScroll,
|
|
129
|
+
onColumnsUpdate,
|
|
130
|
+
onFilterChange,
|
|
131
|
+
size,
|
|
132
|
+
component,
|
|
133
|
+
heightAsGroup,
|
|
134
|
+
scrollable,
|
|
135
|
+
bodyRef,
|
|
136
|
+
}: IReqoreTableSectionProps,
|
|
137
|
+
ref
|
|
126
138
|
) => {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
const { targetRef } = useCombinedRefs(ref);
|
|
140
|
+
|
|
141
|
+
useMount(() => {
|
|
142
|
+
if (scrollable) {
|
|
143
|
+
targetRef.current?.addEventListener('wheel', (e) => {
|
|
144
|
+
if (e.deltaX) {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
|
|
147
|
+
targetRef.current?.scrollTo({ left: targetRef.current?.scrollLeft + e.deltaX });
|
|
148
|
+
bodyRef.current?.scrollTo({ left: bodyRef.current?.scrollLeft + e.deltaX });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const renderHeaderCell = useCallback(
|
|
134
155
|
(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
headerCellComponent: IReqoreCustomHeaderCellComponent,
|
|
157
|
+
props: IReqoreCustomHeaderCellProps
|
|
158
|
+
) => {
|
|
159
|
+
const HeaderCell = headerCellComponent || component || ReqoreTableHeaderCell;
|
|
160
|
+
|
|
161
|
+
return <HeaderCell key={props.dataId} {...props} />;
|
|
162
|
+
},
|
|
163
|
+
[component]
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const renderColumns = (columns: IReqoreTableColumn[]) =>
|
|
167
|
+
getOnlyShownColumns(columns).map(
|
|
168
|
+
(
|
|
169
|
+
{
|
|
170
|
+
grow,
|
|
171
|
+
align,
|
|
172
|
+
dataId,
|
|
173
|
+
header: { columns, onClick, component: headerComponent, ...rest },
|
|
174
|
+
...colRest
|
|
175
|
+
},
|
|
176
|
+
index
|
|
177
|
+
) =>
|
|
178
|
+
columns ? (
|
|
179
|
+
<StyledColumnGroup
|
|
180
|
+
grow={getOnlyShownColumns(columns).reduce((gr, col) => gr + col.grow, 0)}
|
|
181
|
+
key={index}
|
|
182
|
+
className='reqore-table-column-group'
|
|
183
|
+
width={getOnlyShownColumns(columns).reduce(
|
|
184
|
+
(wid, col) => wid + (col.resizedWidth || col.width || 80),
|
|
185
|
+
0
|
|
186
|
+
)}
|
|
187
|
+
maxWidth={getOnlyShownColumns(columns).reduce((wid, col) => wid + col.maxWidth, 0)}
|
|
188
|
+
minWidth={getOnlyShownColumns(columns).reduce((wid, col) => wid + col.minWidth, 0)}
|
|
189
|
+
>
|
|
190
|
+
{renderHeaderCell(headerComponent, {
|
|
191
|
+
...rest,
|
|
192
|
+
...omit(colRest, ['cell']),
|
|
193
|
+
dataId,
|
|
194
|
+
size,
|
|
195
|
+
readOnly: !onClick,
|
|
196
|
+
onClick,
|
|
197
|
+
rounded: false,
|
|
198
|
+
textAlign: align,
|
|
199
|
+
className: 'reqore-table-column-group-header',
|
|
200
|
+
resizable: false,
|
|
201
|
+
hideable: false,
|
|
202
|
+
hasColumns: true,
|
|
203
|
+
})}
|
|
204
|
+
<StyledColumnGroupHeaders className='reqore-table-headers'>
|
|
205
|
+
{renderColumns(columns)}
|
|
206
|
+
</StyledColumnGroupHeaders>
|
|
207
|
+
</StyledColumnGroup>
|
|
208
|
+
) : (
|
|
209
|
+
renderHeaderCell(headerComponent, {
|
|
155
210
|
...rest,
|
|
156
211
|
...omit(colRest, ['cell']),
|
|
212
|
+
onClick,
|
|
157
213
|
dataId,
|
|
158
214
|
size,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
size,
|
|
177
|
-
sortData,
|
|
178
|
-
grow,
|
|
179
|
-
align,
|
|
180
|
-
onSortChange,
|
|
181
|
-
onColumnsUpdate,
|
|
182
|
-
onFilterChange,
|
|
183
|
-
})
|
|
184
|
-
)
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
const getSelectedIcon = (): IReqoreIconName => {
|
|
188
|
-
switch (selectedQuant) {
|
|
189
|
-
case 'all':
|
|
190
|
-
return 'CheckboxCircleLine';
|
|
191
|
-
case 'some':
|
|
192
|
-
return 'IndeterminateCircleLine';
|
|
193
|
-
default:
|
|
194
|
-
return 'CheckboxBlankCircleLine';
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<StyledTableHeaderWrapper
|
|
200
|
-
className='reqore-table-header-wrapper'
|
|
201
|
-
hasVerticalScroll={hasVerticalScroll}
|
|
202
|
-
>
|
|
203
|
-
<StyledTableHeaderRow
|
|
204
|
-
style={{
|
|
205
|
-
transform: `translate3d(${leftScroll ? -leftScroll : 0}px, 0, 0)`,
|
|
206
|
-
}}
|
|
215
|
+
sortData,
|
|
216
|
+
grow,
|
|
217
|
+
align,
|
|
218
|
+
onSortChange,
|
|
219
|
+
onColumnsUpdate,
|
|
220
|
+
onFilterChange,
|
|
221
|
+
})
|
|
222
|
+
)
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<StyledTableHeaderWrapper
|
|
227
|
+
className='reqore-table-header-wrapper'
|
|
228
|
+
hasVerticalScroll={hasVerticalScroll}
|
|
229
|
+
heightAsGroup={heightAsGroup}
|
|
230
|
+
size={size}
|
|
231
|
+
ref={targetRef}
|
|
207
232
|
>
|
|
208
|
-
{
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
size,
|
|
214
|
-
onSortChange,
|
|
215
|
-
icon: getSelectedIcon(),
|
|
216
|
-
width: calculateMinimumCellWidth(50, size),
|
|
217
|
-
resizable: false,
|
|
218
|
-
hideable: false,
|
|
219
|
-
tooltip: selectToggleTooltip || 'Toggle selection on all data',
|
|
220
|
-
onClick: () => {
|
|
221
|
-
onToggleSelectClick();
|
|
222
|
-
},
|
|
223
|
-
})}
|
|
224
|
-
{renderColumns(columns)}
|
|
225
|
-
</StyledTableHeaderRow>
|
|
226
|
-
</StyledTableHeaderWrapper>
|
|
227
|
-
);
|
|
228
|
-
};
|
|
233
|
+
<StyledTableHeaderRow>{renderColumns(columns)}</StyledTableHeaderRow>
|
|
234
|
+
</StyledTableHeaderWrapper>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
);
|
|
229
238
|
|
|
230
239
|
export default ReqoreTableHeader;
|
|
@@ -13,7 +13,7 @@ import { TColumnsUpdater } from './header';
|
|
|
13
13
|
|
|
14
14
|
export interface IReqoreTableHeaderCellProps
|
|
15
15
|
extends Omit<IReqoreTableColumn, 'cell'>,
|
|
16
|
-
IReqoreButtonProps {
|
|
16
|
+
Omit<IReqoreButtonProps, 'maxWidth'> {
|
|
17
17
|
onSortChange?: (sort: string) => void;
|
|
18
18
|
sortData?: IReqoreTableSort;
|
|
19
19
|
onColumnsUpdate?: TColumnsUpdater;
|
|
@@ -44,9 +44,12 @@ export const StyledTableHeaderResize = styled.div`
|
|
|
44
44
|
|
|
45
45
|
export const ReqoreTableHeaderCell = ({
|
|
46
46
|
width,
|
|
47
|
+
maxWidth,
|
|
48
|
+
minWidth,
|
|
47
49
|
resizedWidth,
|
|
48
50
|
grow,
|
|
49
51
|
align,
|
|
52
|
+
pin,
|
|
50
53
|
onSortChange,
|
|
51
54
|
dataId,
|
|
52
55
|
sortable,
|
|
@@ -58,6 +61,7 @@ export const ReqoreTableHeaderCell = ({
|
|
|
58
61
|
filterPlaceholder,
|
|
59
62
|
filterable,
|
|
60
63
|
hideable = true,
|
|
64
|
+
pinnable = true,
|
|
61
65
|
filter,
|
|
62
66
|
size,
|
|
63
67
|
onFilterChange,
|
|
@@ -68,11 +72,6 @@ export const ReqoreTableHeaderCell = ({
|
|
|
68
72
|
let _items: IReqoreDropdownItem[] = [];
|
|
69
73
|
|
|
70
74
|
if (resizable || hideable) {
|
|
71
|
-
_items.push({
|
|
72
|
-
divider: true,
|
|
73
|
-
label: 'Options',
|
|
74
|
-
});
|
|
75
|
-
|
|
76
75
|
if (resizable) {
|
|
77
76
|
_items.push({
|
|
78
77
|
label: 'Reset size',
|
|
@@ -84,7 +83,33 @@ export const ReqoreTableHeaderCell = ({
|
|
|
84
83
|
});
|
|
85
84
|
}
|
|
86
85
|
|
|
86
|
+
if (pinnable) {
|
|
87
|
+
_items.push({ divider: true, size: 'small', line: true });
|
|
88
|
+
|
|
89
|
+
_items.push({
|
|
90
|
+
label: 'Pin left',
|
|
91
|
+
icon: 'SkipBackLine',
|
|
92
|
+
active: pin === 'left',
|
|
93
|
+
intent: pin === 'left' ? 'info' : undefined,
|
|
94
|
+
onClick: () => {
|
|
95
|
+
onColumnsUpdate?.(dataId, 'pin', pin !== 'left' ? 'left' : undefined);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
_items.push({
|
|
100
|
+
label: 'Pin Right',
|
|
101
|
+
icon: 'SkipForwardLine',
|
|
102
|
+
active: pin === 'right',
|
|
103
|
+
intent: pin === 'right' ? 'info' : undefined,
|
|
104
|
+
onClick: () => {
|
|
105
|
+
onColumnsUpdate?.(dataId, 'pin', pin !== 'right' ? 'right' : undefined);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
87
110
|
if (hideable) {
|
|
111
|
+
_items.push({ divider: true, size: 'small', line: true });
|
|
112
|
+
|
|
88
113
|
_items.push({
|
|
89
114
|
label: 'Hide column',
|
|
90
115
|
icon: 'EyeCloseLine',
|
|
@@ -105,7 +130,8 @@ export const ReqoreTableHeaderCell = ({
|
|
|
105
130
|
|
|
106
131
|
return (
|
|
107
132
|
<Resizable
|
|
108
|
-
minWidth={width}
|
|
133
|
+
minWidth={minWidth || width}
|
|
134
|
+
maxWidth={maxWidth}
|
|
109
135
|
onResize={(_event, _direction, _component) => {
|
|
110
136
|
onColumnsUpdate?.(dataId, 'resizedWidth', parseInt(_component.style.width));
|
|
111
137
|
}}
|
|
@@ -154,7 +180,7 @@ export const ReqoreTableHeaderCell = ({
|
|
|
154
180
|
fixed
|
|
155
181
|
size={size}
|
|
156
182
|
rounded={false}
|
|
157
|
-
intent={filter ? 'info' :
|
|
183
|
+
intent={filter ? 'info' : rest.intent}
|
|
158
184
|
filterable={filterable}
|
|
159
185
|
filterPlaceholder={filterPlaceholder || 'Filter by this column...'}
|
|
160
186
|
filter={filter}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { size } from 'lodash';
|
|
2
2
|
import { firstBy } from 'thenby';
|
|
3
3
|
import { IReqoreTableColumn, IReqoreTableSort } from '.';
|
|
4
|
-
import { ICON_FROM_SIZE, SIZE_TO_PX, TSizes } from '../../constants/sizes';
|
|
4
|
+
import { ICON_FROM_SIZE, SIZE_TO_MODIFIER, SIZE_TO_PX, TSizes } from '../../constants/sizes';
|
|
5
5
|
import { IReqoreIconName } from '../../types/icons';
|
|
6
6
|
import { IReqorePanelAction } from '../Panel';
|
|
7
7
|
|
|
@@ -137,6 +137,12 @@ export const getColumnsCount = (columns: IReqoreTableColumn[]): number => {
|
|
|
137
137
|
return count;
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
export const hasGroupedColumns = (columns: IReqoreTableColumn[]): boolean => {
|
|
141
|
+
return columns.some((column) => {
|
|
142
|
+
return !!column.header?.columns;
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
140
146
|
export const hasHiddenColumns = (columns: IReqoreTableColumn[]): boolean => {
|
|
141
147
|
return columns.some((column) => {
|
|
142
148
|
if (column.header.columns) {
|
|
@@ -147,6 +153,40 @@ export const hasHiddenColumns = (columns: IReqoreTableColumn[]): boolean => {
|
|
|
147
153
|
});
|
|
148
154
|
};
|
|
149
155
|
|
|
156
|
+
export const getColumnsByPinType = (
|
|
157
|
+
columns: IReqoreTableColumn[],
|
|
158
|
+
type: 'left' | 'right' | 'main'
|
|
159
|
+
): IReqoreTableColumn[] => {
|
|
160
|
+
return columns.reduce((newColumns, column) => {
|
|
161
|
+
if (column.header.columns) {
|
|
162
|
+
const subColumns: IReqoreTableColumn[] = getColumnsByPinType(column.header.columns, type);
|
|
163
|
+
|
|
164
|
+
if (!size(subColumns)) {
|
|
165
|
+
return newColumns;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const columnsResult = [
|
|
169
|
+
...newColumns,
|
|
170
|
+
{
|
|
171
|
+
...column,
|
|
172
|
+
header: {
|
|
173
|
+
...column.header,
|
|
174
|
+
columns: subColumns,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
return columnsResult;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if ((type === 'main' && !column.pin) || column.pin === type) {
|
|
183
|
+
return [...newColumns, column];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return newColumns;
|
|
187
|
+
}, []);
|
|
188
|
+
};
|
|
189
|
+
|
|
150
190
|
export const getOnlyShownColumns = (columns: IReqoreTableColumn[]): IReqoreTableColumn[] => {
|
|
151
191
|
return columns.reduce((newColumns, column) => {
|
|
152
192
|
if (column.header.columns) {
|
|
@@ -202,7 +242,7 @@ export const prepareColumns = (
|
|
|
202
242
|
|
|
203
243
|
return {
|
|
204
244
|
...column,
|
|
205
|
-
width: newWidth,
|
|
245
|
+
width: newWidth * SIZE_TO_MODIFIER[size],
|
|
206
246
|
...(columnModifiers?.[column.dataId] || {}),
|
|
207
247
|
};
|
|
208
248
|
});
|