@addev-be/ui 0.1.18
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/assets/fonts/montserrat-200.woff2 +0 -0
- package/assets/fonts/montserrat-400.woff2 +0 -0
- package/assets/fonts/montserrat-500.woff2 +0 -0
- package/assets/fonts/montserrat-700.woff2 +0 -0
- package/assets/icons/arrow-down-a-z.svg +1 -0
- package/assets/icons/arrow-up-z-a.svg +1 -0
- package/assets/icons/arrows-rotate.svg +1 -0
- package/assets/icons/arrows-up-down.svg +1 -0
- package/assets/icons/check.svg +1 -0
- package/assets/icons/copy.svg +1 -0
- package/assets/icons/down.svg +1 -0
- package/assets/icons/filter-full.svg +1 -0
- package/assets/icons/filter-slash.svg +1 -0
- package/assets/icons/filter.svg +1 -0
- package/assets/icons/hashtag.svg +1 -0
- package/assets/icons/image-slash.svg +1 -0
- package/assets/icons/left.svg +1 -0
- package/assets/icons/magnifier.svg +1 -0
- package/assets/icons/phone.svg +1 -0
- package/assets/icons/plus.svg +1 -0
- package/assets/icons/right.svg +1 -0
- package/assets/icons/spinner-third.svg +1 -0
- package/assets/icons/table-columns.svg +1 -0
- package/assets/icons/up.svg +1 -0
- package/assets/icons/user-tie.svg +1 -0
- package/eslint.config.js +28 -0
- package/package.json +49 -0
- package/src/Icons.tsx +80 -0
- package/src/components/data/DataGrid/AdvancedRequestDataGrid.tsx +236 -0
- package/src/components/data/DataGrid/DataGridCell.tsx +78 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +58 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -0
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +54 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +190 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +100 -0
- package/src/components/data/DataGrid/DataGridFooter.tsx +64 -0
- package/src/components/data/DataGrid/DataGridHeader.tsx +129 -0
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +166 -0
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +125 -0
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -0
- package/src/components/data/DataGrid/FilterValuesScroller.tsx +131 -0
- package/src/components/data/DataGrid/VirtualScroller.tsx +51 -0
- package/src/components/data/DataGrid/helpers/advancedRequests.tsx +61 -0
- package/src/components/data/DataGrid/helpers/columns.tsx +259 -0
- package/src/components/data/DataGrid/helpers/filters.ts +219 -0
- package/src/components/data/DataGrid/helpers/index.ts +3 -0
- package/src/components/data/DataGrid/hooks/index.ts +30 -0
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +225 -0
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +166 -0
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +49 -0
- package/src/components/data/DataGrid/index.tsx +145 -0
- package/src/components/data/DataGrid/styles.ts +284 -0
- package/src/components/data/DataGrid/types.ts +232 -0
- package/src/components/data/index.ts +3 -0
- package/src/components/forms/Button.tsx +99 -0
- package/src/components/forms/IconButton.tsx +57 -0
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -0
- package/src/components/forms/Select.tsx +40 -0
- package/src/components/forms/index.ts +5 -0
- package/src/components/forms/styles.ts +20 -0
- package/src/components/index.ts +3 -0
- package/src/components/layout/Dropdown/index.tsx +79 -0
- package/src/components/layout/Dropdown/styles.ts +44 -0
- package/src/components/layout/Loading/index.tsx +28 -0
- package/src/components/layout/Loading/styles.ts +29 -0
- package/src/components/layout/Modal/index.tsx +51 -0
- package/src/components/layout/Modal/styles.ts +110 -0
- package/src/components/layout/index.ts +3 -0
- package/src/config/index.ts +14 -0
- package/src/helpers/getScrollbarSize.ts +14 -0
- package/src/helpers/numbers.ts +20 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useElementSize.ts +24 -0
- package/src/hooks/useWindowSize.ts +20 -0
- package/src/index.ts +7 -0
- package/src/providers/PortalsProvider/index.tsx +54 -0
- package/src/providers/PortalsProvider/styles.ts +27 -0
- package/src/providers/SettingsProvider/index.tsx +70 -0
- package/src/providers/ThemeProvider/ThemeProvider.ts +55 -0
- package/src/providers/ThemeProvider/defaultTheme.ts +444 -0
- package/src/providers/ThemeProvider/index.ts +3 -0
- package/src/providers/ThemeProvider/types.ts +123 -0
- package/src/providers/UiProviders/index.tsx +65 -0
- package/src/providers/UiProviders/styles.ts +10 -0
- package/src/providers/hooks.ts +8 -0
- package/src/providers/index.ts +5 -0
- package/src/services/WebSocketService.ts +147 -0
- package/src/services/advancedRequests.ts +100 -0
- package/src/services/base.ts +31 -0
- package/src/services/hooks.ts +13 -0
- package/src/services/index.ts +2 -0
- package/src/styles/animations.scss +30 -0
- package/src/styles/index.scss +42 -0
- package/src/typings.d.ts +6 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AdvancedRequestDTO,
|
|
5
|
+
ConditionDTO,
|
|
6
|
+
OrderByDTO,
|
|
7
|
+
} from '../../../../services/advancedRequests';
|
|
8
|
+
|
|
9
|
+
import { DataGridColumns } from '../types';
|
|
10
|
+
|
|
11
|
+
export const getAdvancedRequestDto = <R,>({
|
|
12
|
+
type,
|
|
13
|
+
columns,
|
|
14
|
+
conditions = [],
|
|
15
|
+
orderBy = [],
|
|
16
|
+
start = 0,
|
|
17
|
+
length = 100,
|
|
18
|
+
getTotal = false,
|
|
19
|
+
addIdColumn = true,
|
|
20
|
+
}: {
|
|
21
|
+
type: string;
|
|
22
|
+
columns: DataGridColumns<R>;
|
|
23
|
+
conditions?: ConditionDTO[];
|
|
24
|
+
orderBy?: OrderByDTO[];
|
|
25
|
+
start?: number;
|
|
26
|
+
length?: number;
|
|
27
|
+
getTotal?: boolean;
|
|
28
|
+
addIdColumn?: boolean;
|
|
29
|
+
}): AdvancedRequestDTO => ({
|
|
30
|
+
fields: [
|
|
31
|
+
...(Object.keys(columns).includes('Id') || addIdColumn === false
|
|
32
|
+
? []
|
|
33
|
+
: [{ fieldName: 'Id' }]),
|
|
34
|
+
...Object.keys(columns).map((key) =>
|
|
35
|
+
columns[key].field
|
|
36
|
+
? {
|
|
37
|
+
...columns[key].field,
|
|
38
|
+
fieldName: columns[key].field?.fieldName ?? key,
|
|
39
|
+
fieldAlias: key,
|
|
40
|
+
}
|
|
41
|
+
: {
|
|
42
|
+
fieldName: key,
|
|
43
|
+
fieldAlias: key,
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
],
|
|
47
|
+
conditions: [
|
|
48
|
+
...conditions,
|
|
49
|
+
{
|
|
50
|
+
field: {
|
|
51
|
+
fieldName: 'DeletedAt',
|
|
52
|
+
},
|
|
53
|
+
operator: 'isNull' as const,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
orderBy,
|
|
57
|
+
type,
|
|
58
|
+
start,
|
|
59
|
+
length,
|
|
60
|
+
getTotal,
|
|
61
|
+
});
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DataGridColumn,
|
|
5
|
+
DataGridColumns,
|
|
6
|
+
DataGridFilterType,
|
|
7
|
+
DataGridSettings,
|
|
8
|
+
} from '../types';
|
|
9
|
+
import {
|
|
10
|
+
formatMoney,
|
|
11
|
+
formatNumber,
|
|
12
|
+
formatPercentage,
|
|
13
|
+
} from '../../../../helpers/numbers';
|
|
14
|
+
|
|
15
|
+
import _ from 'lodash';
|
|
16
|
+
import moment from 'moment';
|
|
17
|
+
|
|
18
|
+
export const isColumnVisible = <R,>(
|
|
19
|
+
obj: DataGridColumn<R, any> | DataGridSettings
|
|
20
|
+
): boolean => {
|
|
21
|
+
return obj?.order !== -1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const textColumn = <R extends Record<string, any>>(
|
|
25
|
+
key: string,
|
|
26
|
+
title: string,
|
|
27
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
28
|
+
): DataGridColumns<R> => ({
|
|
29
|
+
[key]: {
|
|
30
|
+
name: title,
|
|
31
|
+
render: (col, row) => row[key] ?? '',
|
|
32
|
+
getter: (row) => row[key] ?? '',
|
|
33
|
+
sortGetter: (row) => row[key] ?? '',
|
|
34
|
+
filter: {
|
|
35
|
+
type: 'text',
|
|
36
|
+
operator: 'contains',
|
|
37
|
+
values: [''],
|
|
38
|
+
getter: (row) => row[key] ?? '',
|
|
39
|
+
},
|
|
40
|
+
...options,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const mailColumn = <R extends Record<string, any>>(
|
|
45
|
+
key: string,
|
|
46
|
+
title: string,
|
|
47
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
48
|
+
): DataGridColumns<R> => ({
|
|
49
|
+
[key]: {
|
|
50
|
+
name: title,
|
|
51
|
+
render: (col, row) => (
|
|
52
|
+
<a
|
|
53
|
+
// className="text-blue-500 hover:text-blue-700"
|
|
54
|
+
href={`mailto:${row[key]}`}
|
|
55
|
+
>
|
|
56
|
+
{row[key] ?? ''}
|
|
57
|
+
</a>
|
|
58
|
+
),
|
|
59
|
+
getter: (row) => row[key] ?? '',
|
|
60
|
+
sortGetter: (row) => row[key] ?? '',
|
|
61
|
+
filter: {
|
|
62
|
+
type: 'text',
|
|
63
|
+
operator: 'contains',
|
|
64
|
+
values: [''],
|
|
65
|
+
getter: (row) => row[key] ?? '',
|
|
66
|
+
},
|
|
67
|
+
...options,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const phoneColumn = <R extends Record<string, any>>(
|
|
72
|
+
key: string,
|
|
73
|
+
title: string,
|
|
74
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
75
|
+
): DataGridColumns<R> => ({
|
|
76
|
+
[key]: {
|
|
77
|
+
name: title,
|
|
78
|
+
render: (col, row) => (
|
|
79
|
+
<a
|
|
80
|
+
// className="text-blue-500 hover:text-blue-700"
|
|
81
|
+
href={`tel:${row[key]}`}
|
|
82
|
+
>
|
|
83
|
+
{row[key] ?? ''}
|
|
84
|
+
</a>
|
|
85
|
+
),
|
|
86
|
+
getter: (row) => row[key] ?? '',
|
|
87
|
+
sortGetter: (row) => row[key] ?? '',
|
|
88
|
+
filter: {
|
|
89
|
+
type: 'text',
|
|
90
|
+
operator: 'contains',
|
|
91
|
+
values: [''],
|
|
92
|
+
getter: (row) => row[key] ?? '',
|
|
93
|
+
},
|
|
94
|
+
...options,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const dateColumn = <R extends Record<string, any>>(
|
|
99
|
+
key: string,
|
|
100
|
+
title: string,
|
|
101
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
102
|
+
): DataGridColumns<R> => ({
|
|
103
|
+
[key]: {
|
|
104
|
+
name: title,
|
|
105
|
+
render: (col, row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
|
|
106
|
+
getter: (row) => row[key] ?? '',
|
|
107
|
+
sortGetter: (row) => row[key] ?? '',
|
|
108
|
+
filter: {
|
|
109
|
+
type: 'text',
|
|
110
|
+
operator: 'contains',
|
|
111
|
+
values: [''],
|
|
112
|
+
getter: (row) => row[key] ?? '',
|
|
113
|
+
},
|
|
114
|
+
...options,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const monthColumn = <R extends Record<string, any>>(
|
|
119
|
+
key: string,
|
|
120
|
+
title: string,
|
|
121
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
122
|
+
): DataGridColumns<R> => ({
|
|
123
|
+
[key]: {
|
|
124
|
+
name: title,
|
|
125
|
+
render: (col, row) => (row[key] ? `${row[key]} mois ` : ''),
|
|
126
|
+
getter: (row) => row[key] ?? '',
|
|
127
|
+
sortGetter: (row) => row[key] ?? '',
|
|
128
|
+
filter: {
|
|
129
|
+
type: 'text',
|
|
130
|
+
operator: 'contains',
|
|
131
|
+
values: [''],
|
|
132
|
+
getter: (row) => row[key] ?? '',
|
|
133
|
+
},
|
|
134
|
+
...options,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const numberColumn = <R extends Record<string, any>>(
|
|
139
|
+
key: string,
|
|
140
|
+
title: string,
|
|
141
|
+
decimals = 2,
|
|
142
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
143
|
+
): DataGridColumns<R> => ({
|
|
144
|
+
[key]: {
|
|
145
|
+
name: title,
|
|
146
|
+
render: (col, row) => formatNumber(row[key], decimals) ?? '',
|
|
147
|
+
excelFormatter: () => '#',
|
|
148
|
+
getter: (row) => row[key] ?? '',
|
|
149
|
+
sortGetter: (row) => row[key] ?? '',
|
|
150
|
+
filter: {
|
|
151
|
+
type: 'number',
|
|
152
|
+
operator: 'equals',
|
|
153
|
+
values: [0],
|
|
154
|
+
getter: (row) => row[key] ?? 0,
|
|
155
|
+
},
|
|
156
|
+
...options,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
export const moneyColumn = <R extends Record<string, any>>(
|
|
161
|
+
key: string,
|
|
162
|
+
title: string,
|
|
163
|
+
decimals = 2,
|
|
164
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
165
|
+
): DataGridColumns<R> => ({
|
|
166
|
+
[key]: {
|
|
167
|
+
name: title,
|
|
168
|
+
render: (col, row) => formatMoney(row[key], decimals) ?? '',
|
|
169
|
+
excelFormatter: () => '#0.00',
|
|
170
|
+
getter: (row) => row[key] ?? '',
|
|
171
|
+
sortGetter: (row) => row[key] ?? '',
|
|
172
|
+
filter: {
|
|
173
|
+
type: 'number',
|
|
174
|
+
operator: 'equals',
|
|
175
|
+
values: [0],
|
|
176
|
+
getter: (row) => row[key] ?? 0,
|
|
177
|
+
},
|
|
178
|
+
...options,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const percentageColumn = <R extends Record<string, any>>(
|
|
183
|
+
key: string,
|
|
184
|
+
title: string,
|
|
185
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
186
|
+
): DataGridColumns<R> => ({
|
|
187
|
+
[key]: {
|
|
188
|
+
name: title,
|
|
189
|
+
render: (col, row) => formatPercentage(row[key]) ?? '',
|
|
190
|
+
excelFormatter: () => '#0.00',
|
|
191
|
+
getter: (row) => row[key] ?? '',
|
|
192
|
+
sortGetter: (row) => row[key] ?? '',
|
|
193
|
+
filter: {
|
|
194
|
+
type: 'number',
|
|
195
|
+
operator: 'equals',
|
|
196
|
+
values: [0],
|
|
197
|
+
getter: (row) => row[key] ?? 0,
|
|
198
|
+
},
|
|
199
|
+
...options,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
export const checkboxColumn = <R extends Record<string, any>>(
|
|
204
|
+
key: string,
|
|
205
|
+
title: string,
|
|
206
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
207
|
+
): DataGridColumns<R> => ({
|
|
208
|
+
[key]: {
|
|
209
|
+
name: title,
|
|
210
|
+
render: (col, row) => (
|
|
211
|
+
<>
|
|
212
|
+
<input type="checkbox" checked={row[key]} />
|
|
213
|
+
<span>{row[key] ? ' Oui' : ' Non'}</span>
|
|
214
|
+
</>
|
|
215
|
+
),
|
|
216
|
+
getter: (row) => row[key] ?? '',
|
|
217
|
+
sortGetter: (row) => row[key] ?? '',
|
|
218
|
+
filter: {
|
|
219
|
+
type: 'number',
|
|
220
|
+
operator: 'equals',
|
|
221
|
+
values: [0],
|
|
222
|
+
getter: (row) => row[key] ?? 0,
|
|
223
|
+
},
|
|
224
|
+
...options,
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
export const colorColumn = <R extends Record<string, any>>(
|
|
229
|
+
key: string,
|
|
230
|
+
title: string,
|
|
231
|
+
options?: Partial<DataGridColumn<R, DataGridFilterType>>
|
|
232
|
+
): DataGridColumns<R> => ({
|
|
233
|
+
[key]: {
|
|
234
|
+
name: title,
|
|
235
|
+
render: (col, row) => (
|
|
236
|
+
<div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
|
|
237
|
+
),
|
|
238
|
+
getter: (row) => row[key] ?? '',
|
|
239
|
+
sortGetter: (row) => row[key] ?? '',
|
|
240
|
+
filter: {
|
|
241
|
+
type: 'text',
|
|
242
|
+
operator: 'contains',
|
|
243
|
+
values: [''],
|
|
244
|
+
getter: (row) => row[key] ?? '',
|
|
245
|
+
},
|
|
246
|
+
...options,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
export const withGroupBy = <R extends Record<string, any>>(
|
|
251
|
+
columns: DataGridColumns<R>
|
|
252
|
+
): DataGridColumns<R> =>
|
|
253
|
+
_.mapValues(columns, (column, key) => ({
|
|
254
|
+
...column,
|
|
255
|
+
field: {
|
|
256
|
+
...(column.field ?? { fieldName: key }),
|
|
257
|
+
groupBy: true,
|
|
258
|
+
},
|
|
259
|
+
}));
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DataGridFilter,
|
|
5
|
+
DataGridFilterCheckbox,
|
|
6
|
+
DataGridFilterDataType,
|
|
7
|
+
DataGridFilterFormatter,
|
|
8
|
+
DataGridFilterGroup,
|
|
9
|
+
DataGridFilterPredicateBuilder,
|
|
10
|
+
DataGridFilterPredicates,
|
|
11
|
+
DataGridFilterType,
|
|
12
|
+
DataGridFilters,
|
|
13
|
+
} from '../types';
|
|
14
|
+
|
|
15
|
+
import { ConditionDTO } from '../../../../services/advancedRequests';
|
|
16
|
+
import _ from 'lodash';
|
|
17
|
+
import moment from 'moment';
|
|
18
|
+
|
|
19
|
+
const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
20
|
+
|
|
21
|
+
const textContainsPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
22
|
+
...filterValues
|
|
23
|
+
) => {
|
|
24
|
+
const regex = new RegExp(`${escapeRegExp(filterValues[0])}`, 'i');
|
|
25
|
+
return (valueToVerify: string) => regex.test(valueToVerify);
|
|
26
|
+
};
|
|
27
|
+
const textNotContainsPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
28
|
+
...filterValues
|
|
29
|
+
) => {
|
|
30
|
+
const regex = new RegExp(`${escapeRegExp(filterValues[0])}`, 'i');
|
|
31
|
+
return (valueToVerify: string) => !regex.test(valueToVerify);
|
|
32
|
+
};
|
|
33
|
+
const textEqualsPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
34
|
+
...filterValues
|
|
35
|
+
) => {
|
|
36
|
+
const regex = new RegExp(`^${escapeRegExp(filterValues[0])}$`, 'i');
|
|
37
|
+
return (valueToVerify: string) => regex.test(valueToVerify);
|
|
38
|
+
};
|
|
39
|
+
const textNotEqualsPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
40
|
+
...filterValues
|
|
41
|
+
) => {
|
|
42
|
+
const regex = new RegExp(`^${escapeRegExp(filterValues[0])}$`, 'i');
|
|
43
|
+
return (valueToVerify: string) => !regex.test(valueToVerify);
|
|
44
|
+
};
|
|
45
|
+
const textStartsWithPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
46
|
+
...filterValues
|
|
47
|
+
) => {
|
|
48
|
+
const regex = new RegExp(`^${escapeRegExp(filterValues[0])}`, 'i');
|
|
49
|
+
return (valueToVerify: string) => regex.test(valueToVerify);
|
|
50
|
+
};
|
|
51
|
+
const textEndsWithPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
52
|
+
...filterValues
|
|
53
|
+
) => {
|
|
54
|
+
const regex = new RegExp(`${escapeRegExp(filterValues[0])}$`, 'i');
|
|
55
|
+
return (valueToVerify: string) => regex.test(valueToVerify);
|
|
56
|
+
};
|
|
57
|
+
const textInArrayPredicate: DataGridFilterPredicateBuilder<string> = (
|
|
58
|
+
...filterValues
|
|
59
|
+
) => {
|
|
60
|
+
return (valueToVerify: string) => filterValues.includes(valueToVerify);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const numberEqualsPredicate: DataGridFilterPredicateBuilder<number> =
|
|
64
|
+
(...filterValues) =>
|
|
65
|
+
(valueToVerify: number) =>
|
|
66
|
+
valueToVerify === filterValues[0];
|
|
67
|
+
const numberNotEqualsPredicate: DataGridFilterPredicateBuilder<number> =
|
|
68
|
+
(...filterValues) =>
|
|
69
|
+
(valueToVerify: number) =>
|
|
70
|
+
valueToVerify !== filterValues[0];
|
|
71
|
+
const numberLessThanPredicate: DataGridFilterPredicateBuilder<number> =
|
|
72
|
+
(...filterValues) =>
|
|
73
|
+
(valueToVerify: number) =>
|
|
74
|
+
valueToVerify < filterValues[0];
|
|
75
|
+
const numberLessThanOrEqualPredicate: DataGridFilterPredicateBuilder<number> =
|
|
76
|
+
(...filterValues) =>
|
|
77
|
+
(valueToVerify: number) =>
|
|
78
|
+
valueToVerify <= filterValues[0];
|
|
79
|
+
const numberGreaterThanPredicate: DataGridFilterPredicateBuilder<number> =
|
|
80
|
+
(...filterValues) =>
|
|
81
|
+
(valueToVerify: number) =>
|
|
82
|
+
valueToVerify > filterValues[0];
|
|
83
|
+
const numberGreaterThanOrEqualPredicate: DataGridFilterPredicateBuilder<
|
|
84
|
+
number
|
|
85
|
+
> =
|
|
86
|
+
(...filterValues) =>
|
|
87
|
+
(valueToVerify: number) =>
|
|
88
|
+
valueToVerify >= filterValues[0];
|
|
89
|
+
const numberInRangePredicate: DataGridFilterPredicateBuilder<number> =
|
|
90
|
+
(...filterValues) =>
|
|
91
|
+
(valueToVerify: number) =>
|
|
92
|
+
valueToVerify >= filterValues[0] && valueToVerify <= filterValues[1];
|
|
93
|
+
const numberInArrayPredicate: DataGridFilterPredicateBuilder<number> = (
|
|
94
|
+
...filterValues
|
|
95
|
+
) => {
|
|
96
|
+
return (valueToVerify: number) => filterValues.includes(valueToVerify);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const filtersPredicates: DataGridFilterPredicates = {
|
|
100
|
+
text: {
|
|
101
|
+
contains: textContainsPredicate,
|
|
102
|
+
notContains: textNotContainsPredicate,
|
|
103
|
+
equals: textEqualsPredicate,
|
|
104
|
+
notEquals: textNotEqualsPredicate,
|
|
105
|
+
startsWith: textStartsWithPredicate,
|
|
106
|
+
endsWith: textEndsWithPredicate,
|
|
107
|
+
inArray: textInArrayPredicate,
|
|
108
|
+
},
|
|
109
|
+
number: {
|
|
110
|
+
equals: numberEqualsPredicate,
|
|
111
|
+
notEquals: numberNotEqualsPredicate,
|
|
112
|
+
lessThan: numberLessThanPredicate,
|
|
113
|
+
lessThanOrEqual: numberLessThanOrEqualPredicate,
|
|
114
|
+
greaterThan: numberGreaterThanPredicate,
|
|
115
|
+
greaterThanOrEqual: numberGreaterThanOrEqualPredicate,
|
|
116
|
+
inRange: numberInRangePredicate,
|
|
117
|
+
inArray: numberInArrayPredicate,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const applyFilters = <R>(
|
|
122
|
+
rows: R[],
|
|
123
|
+
filters: DataGridFilter<R, DataGridFilterType>[]
|
|
124
|
+
): R[] => {
|
|
125
|
+
return filters.reduce(
|
|
126
|
+
(tempRows, filter) => applyFilter(tempRows, filter),
|
|
127
|
+
rows
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const applyFilter = <R, T extends DataGridFilterType>(
|
|
132
|
+
rows: R[],
|
|
133
|
+
filter: DataGridFilter<R, T>
|
|
134
|
+
): R[] => {
|
|
135
|
+
const predicateBuilder = filtersPredicates[filter.type][filter.operator];
|
|
136
|
+
if (typeof predicateBuilder !== 'function') return rows;
|
|
137
|
+
const predicate = predicateBuilder(...filter.values);
|
|
138
|
+
return rows.filter((row) => predicate(filter.getter(row)));
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const defaultFilterGetter = (row: any, columnKey: string) =>
|
|
142
|
+
row[columnKey];
|
|
143
|
+
|
|
144
|
+
export const defaultFilterValues: {
|
|
145
|
+
[K in DataGridFilterType]: DataGridFilterDataType<K>;
|
|
146
|
+
} = {
|
|
147
|
+
text: '',
|
|
148
|
+
number: 0,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const defaultValueParsers: {
|
|
152
|
+
[K in DataGridFilterType]: (value: string) => DataGridFilterDataType<K>;
|
|
153
|
+
} = {
|
|
154
|
+
text: (value) => value,
|
|
155
|
+
number: (value) => parseFloat(value),
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const groupDatesByYearAndMonth = (dates: any[]) =>
|
|
159
|
+
dates.reduce((acc: Record<string, Record<string, any[]>>, date) => {
|
|
160
|
+
const year = moment(date).format('YYYY');
|
|
161
|
+
if (!acc[year]) {
|
|
162
|
+
acc[year] = {};
|
|
163
|
+
}
|
|
164
|
+
const yearAndMonth = moment(date).format(`YYYY-MM`);
|
|
165
|
+
if (!acc[year][yearAndMonth]) {
|
|
166
|
+
acc[year][yearAndMonth] = [];
|
|
167
|
+
}
|
|
168
|
+
acc[year][yearAndMonth].push(date);
|
|
169
|
+
return acc;
|
|
170
|
+
}, {} as Record<string, Record<string, any[]>>);
|
|
171
|
+
|
|
172
|
+
export const getDateGroups = <R extends string | number | null>(
|
|
173
|
+
dates: any[]
|
|
174
|
+
): DataGridFilterGroup<R>[] => {
|
|
175
|
+
const grouperDates = groupDatesByYearAndMonth(dates);
|
|
176
|
+
return Object.entries(grouperDates).map(([year, months]) => ({
|
|
177
|
+
name: year,
|
|
178
|
+
values: Object.values(months).flat(),
|
|
179
|
+
groups: Object.entries(months).map(([month, dates]) => ({
|
|
180
|
+
name: month,
|
|
181
|
+
values: dates,
|
|
182
|
+
})),
|
|
183
|
+
}));
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const convertFiltersToConditions = <R>(
|
|
187
|
+
filters: DataGridFilters<R>
|
|
188
|
+
): ConditionDTO[] => {
|
|
189
|
+
return Object.entries(filters).map(([columnKey, filter]) => {
|
|
190
|
+
const condition: ConditionDTO = {
|
|
191
|
+
field: {
|
|
192
|
+
fieldName: columnKey,
|
|
193
|
+
},
|
|
194
|
+
operator: filter.operator,
|
|
195
|
+
value: ['inArray', 'inRange'].includes(filter.operator)
|
|
196
|
+
? filter.values
|
|
197
|
+
: _.castArray(filter.values)[0],
|
|
198
|
+
};
|
|
199
|
+
return condition;
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export const getCheckboxes = <R extends string | number | null>(
|
|
204
|
+
values: R[],
|
|
205
|
+
formatter: DataGridFilterFormatter,
|
|
206
|
+
groups?: DataGridFilterGroup<R>[],
|
|
207
|
+
level = 0
|
|
208
|
+
): DataGridFilterCheckbox<R>[] => [
|
|
209
|
+
...(groups ?? [])
|
|
210
|
+
.map((group) =>
|
|
211
|
+
getCheckboxes(group.values ?? [], formatter, group.groups, level + 1)
|
|
212
|
+
)
|
|
213
|
+
.flat(),
|
|
214
|
+
...values.map((value) => ({
|
|
215
|
+
displayValue: formatter(value),
|
|
216
|
+
values: [value],
|
|
217
|
+
level,
|
|
218
|
+
})),
|
|
219
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DataGridColumns, DataGridContext } from '../types';
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
import { isColumnVisible } from '../helpers';
|
|
5
|
+
import { pickBy } from 'lodash';
|
|
6
|
+
|
|
7
|
+
export { useDataGridCopy } from './useDataGridCopy';
|
|
8
|
+
export { useDataGridSettings } from './useDataGridSettings';
|
|
9
|
+
export { useDataGrid } from './useDataGrid';
|
|
10
|
+
|
|
11
|
+
export const useDataGridContext = <R>(context: DataGridContext<R>) =>
|
|
12
|
+
useContext(context);
|
|
13
|
+
|
|
14
|
+
export const useVisibleAndHiddenColumns = <R>(columns: DataGridColumns<R>) =>
|
|
15
|
+
useMemo(
|
|
16
|
+
() => [
|
|
17
|
+
pickBy(columns, (col) => isColumnVisible(col)),
|
|
18
|
+
pickBy(columns, (col) => !isColumnVisible(col)),
|
|
19
|
+
],
|
|
20
|
+
[columns]
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const useSortedColumns = <R>(columns: DataGridColumns<R>) =>
|
|
24
|
+
useMemo(
|
|
25
|
+
() =>
|
|
26
|
+
Object.entries(columns)
|
|
27
|
+
.filter(([, col]) => isColumnVisible(col))
|
|
28
|
+
.sort((a, b) => (a[1].order ?? 0) - (b[1].order ?? 0)),
|
|
29
|
+
[columns]
|
|
30
|
+
);
|