@addev-be/ui 0.14.1 → 0.14.2
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/icons/floppy-disk.svg +1 -0
- package/package.json +2 -1
- package/src/Icons.tsx +2 -0
- package/src/components/data/DataGrid/DataGridCell.tsx +3 -3
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +7 -12
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +2 -2
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +31 -30
- package/src/components/data/DataGrid/DataGridEditableCell/CheckboxEditableCell.tsx +38 -0
- package/src/components/data/DataGrid/DataGridEditableCell/DateEditableCell.tsx +39 -0
- package/src/components/data/DataGrid/DataGridEditableCell/NumberEditableCell.tsx +68 -0
- package/src/components/data/DataGrid/DataGridEditableCell/TextEditableCell.tsx +38 -0
- package/src/components/data/DataGrid/DataGridEditableCell/index.tsx +60 -0
- package/src/components/data/DataGrid/DataGridEditableCell/types.ts +14 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +13 -10
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +27 -29
- package/src/components/data/DataGrid/DataGridFooter.tsx +3 -3
- package/src/components/data/DataGrid/DataGridHeader.tsx +52 -7
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +16 -2
- package/src/components/data/DataGrid/DataGridRowTemplate.tsx +23 -16
- package/src/components/data/DataGrid/helpers/columns.tsx +238 -236
- package/src/components/data/DataGrid/hooks/index.ts +6 -7
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +89 -16
- package/src/components/data/DataGrid/hooks/useDataGridChangedRows.ts +56 -0
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +18 -19
- package/src/components/data/DataGrid/styles.ts +56 -1
- package/src/components/data/DataGrid/types.ts +69 -17
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +240 -216
- package/src/components/data/SqlRequestDataGrid/index.tsx +58 -43
- package/src/components/data/SqlRequestDataGrid/types.ts +21 -6
- package/src/components/data/SqlRequestForeignList/index.tsx +157 -0
- package/src/components/data/SqlRequestForeignList/styles.ts +38 -0
- package/src/components/data/SqlRequestGrid/filters/FiltersSidebar.tsx +8 -4
- package/src/components/data/SqlRequestGrid/index.tsx +24 -18
- package/src/components/data/SqlRequestGrid/types.ts +25 -3
- package/src/components/data/index.ts +2 -0
- package/src/helpers/numbers.ts +37 -0
- package/src/services/index.ts +1 -0
- package/src/services/updateSqlRequests.ts +34 -0
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +0 -43
- package/src/components/data/SqlRequestDataGrid/index.ts +0 -1
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DataGridCheckboxColumn,
|
|
5
|
+
DataGridColorColumn,
|
|
6
|
+
DataGridColumn,
|
|
7
|
+
DataGridDateColumn,
|
|
8
|
+
DataGridNumberColumn,
|
|
9
|
+
DataGridSettings,
|
|
10
|
+
DataGridTextColumn,
|
|
11
|
+
} from '../types';
|
|
4
12
|
import { dateFilter, numberFilter, textFilter } from './filters';
|
|
5
13
|
import {
|
|
6
14
|
formatMoney,
|
|
@@ -22,298 +30,292 @@ export const buildExcelFormat = (decimals = 2, suffix = '') =>
|
|
|
22
30
|
export const textColumn = <R extends Record<string, any>>(
|
|
23
31
|
key: string,
|
|
24
32
|
title: string,
|
|
25
|
-
options?: Partial<
|
|
26
|
-
):
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
options?: Partial<DataGridTextColumn<R>>
|
|
34
|
+
): DataGridTextColumn<R> => ({
|
|
35
|
+
key,
|
|
36
|
+
type: 'text',
|
|
37
|
+
name: title,
|
|
38
|
+
render: (row) => row[key] ?? '',
|
|
39
|
+
getter: (row) => row[key] ?? '',
|
|
40
|
+
sortGetter: (row) => row[key] ?? '',
|
|
41
|
+
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
42
|
+
filter: textFilter(key),
|
|
43
|
+
...options,
|
|
36
44
|
});
|
|
37
45
|
|
|
38
46
|
export const mailColumn = <R extends Record<string, any>>(
|
|
39
47
|
key: string,
|
|
40
48
|
title: string,
|
|
41
|
-
options?: Partial<
|
|
42
|
-
):
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
),
|
|
53
|
-
getter: (row) => row[key] ?? '',
|
|
54
|
-
sortGetter: (row) => row[key] ?? '',
|
|
55
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
56
|
-
filter: textFilter(key),
|
|
57
|
-
...options,
|
|
58
|
-
},
|
|
49
|
+
options?: Partial<DataGridTextColumn<R>>
|
|
50
|
+
): DataGridTextColumn<R> => ({
|
|
51
|
+
key,
|
|
52
|
+
type: 'text',
|
|
53
|
+
name: title,
|
|
54
|
+
render: (row) => <a href={`mailto:${row[key]}`}>{row[key] ?? ''}</a>,
|
|
55
|
+
getter: (row) => row[key] ?? '',
|
|
56
|
+
sortGetter: (row) => row[key] ?? '',
|
|
57
|
+
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
58
|
+
filter: textFilter(key),
|
|
59
|
+
...options,
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
export const phoneColumn = <R extends Record<string, any>>(
|
|
62
63
|
key: string,
|
|
63
64
|
title: string,
|
|
64
|
-
options?: Partial<
|
|
65
|
-
):
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
),
|
|
76
|
-
getter: (row) => row[key] ?? '',
|
|
77
|
-
sortGetter: (row) => row[key] ?? '',
|
|
78
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
79
|
-
filter: textFilter(key),
|
|
80
|
-
...options,
|
|
81
|
-
},
|
|
65
|
+
options?: Partial<DataGridTextColumn<R>>
|
|
66
|
+
): DataGridTextColumn<R> => ({
|
|
67
|
+
key,
|
|
68
|
+
type: 'text',
|
|
69
|
+
name: title,
|
|
70
|
+
render: (row) => <a href={`tel:${row[key]}`}>{row[key] ?? ''}</a>,
|
|
71
|
+
getter: (row) => row[key] ?? '',
|
|
72
|
+
sortGetter: (row) => row[key] ?? '',
|
|
73
|
+
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
74
|
+
filter: textFilter(key),
|
|
75
|
+
...options,
|
|
82
76
|
});
|
|
83
77
|
|
|
84
78
|
export const dateColumn = <R extends Record<string, any>>(
|
|
85
79
|
key: string,
|
|
86
80
|
title: string,
|
|
87
|
-
options?: Partial<
|
|
88
|
-
):
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
sortGetter: (row) => row[key] ?? '',
|
|
97
|
-
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
98
|
-
filter: {
|
|
99
|
-
...dateFilter(key),
|
|
100
|
-
renderer: (value) => moment(value).format('DD/MM/YYYY') ?? '',
|
|
101
|
-
},
|
|
102
|
-
...options,
|
|
81
|
+
options?: Partial<DataGridDateColumn<R>>
|
|
82
|
+
): DataGridDateColumn<R> => ({
|
|
83
|
+
key,
|
|
84
|
+
type: 'date',
|
|
85
|
+
name: title,
|
|
86
|
+
render: (row) => moment(row[key]).format('DD/MM/YYYY') ?? '',
|
|
87
|
+
excelOptions: {
|
|
88
|
+
formatter: () => 'dd/mm/yyyy',
|
|
89
|
+
valueGetter: (value) => moment(value).format('DD/MM/YYYY') ?? '',
|
|
103
90
|
},
|
|
91
|
+
getter: (row) => row[key] ?? '',
|
|
92
|
+
sortGetter: (row) => row[key] ?? '',
|
|
93
|
+
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
94
|
+
filter: {
|
|
95
|
+
...dateFilter(key),
|
|
96
|
+
renderer: (value) => moment(value).format('DD/MM/YYYY') ?? '',
|
|
97
|
+
},
|
|
98
|
+
...options,
|
|
104
99
|
});
|
|
105
100
|
|
|
106
101
|
export const dateTimeColumn = <R extends Record<string, any>>(
|
|
107
102
|
key: string,
|
|
108
103
|
title: string,
|
|
109
|
-
options?: Partial<
|
|
110
|
-
):
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
options?: Partial<DataGridDateColumn<R>>
|
|
105
|
+
): DataGridDateColumn<R> => ({
|
|
106
|
+
key,
|
|
107
|
+
type: 'date',
|
|
108
|
+
name: title,
|
|
109
|
+
render: (row) => moment(row[key]).format('DD/MM/YYYY HH:mm:ss') ?? '',
|
|
110
|
+
excelOptions: {
|
|
111
|
+
formatter: () => 'dd/mm/yyyy hh:mm:ss',
|
|
112
|
+
valueGetter: (value) => moment(value).format('DD/MM/YYYY HH:mm:ss') ?? '',
|
|
113
|
+
},
|
|
114
|
+
getter: (row) => row[key] ?? '',
|
|
115
|
+
sortGetter: (row) => row[key] ?? '',
|
|
116
|
+
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
117
|
+
filter: {
|
|
118
|
+
...dateFilter(key),
|
|
119
|
+
renderer: (value) => moment(value).format('DD/MM/YYYY HH:mm:ss') ?? '',
|
|
125
120
|
},
|
|
121
|
+
...options,
|
|
126
122
|
});
|
|
127
123
|
|
|
128
124
|
export const monthColumn = <R extends Record<string, any>>(
|
|
129
125
|
key: string,
|
|
130
126
|
title: string,
|
|
131
|
-
options?: Partial<
|
|
132
|
-
):
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
options?: Partial<DataGridTextColumn<R>>
|
|
128
|
+
): DataGridTextColumn<R> => ({
|
|
129
|
+
key,
|
|
130
|
+
type: 'text',
|
|
131
|
+
name: title,
|
|
132
|
+
render: (row) => (row[key] ? `${row[key]} mois ` : ''),
|
|
133
|
+
getter: (row) => row[key] ?? '',
|
|
134
|
+
sortGetter: (row) => row[key] ?? '',
|
|
135
|
+
footer: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
136
|
+
filter: textFilter(key),
|
|
137
|
+
...options,
|
|
142
138
|
});
|
|
143
139
|
|
|
144
140
|
export const numberColumn = <R extends Record<string, any>>(
|
|
145
141
|
key: string,
|
|
146
142
|
title: string,
|
|
147
143
|
decimals = 2,
|
|
148
|
-
options?: Partial<
|
|
149
|
-
):
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
footer: {
|
|
158
|
-
sum: (_, filteredRows) =>
|
|
159
|
-
formatNumber(
|
|
160
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
161
|
-
decimals
|
|
162
|
-
),
|
|
163
|
-
average: (_, filteredRows) =>
|
|
164
|
-
formatNumber(
|
|
165
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
166
|
-
(filteredRows.length || 1),
|
|
167
|
-
decimals
|
|
168
|
-
),
|
|
169
|
-
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
170
|
-
max: (_, filteredRows) =>
|
|
171
|
-
formatNumber(
|
|
172
|
-
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
173
|
-
decimals
|
|
174
|
-
),
|
|
175
|
-
min: (_, filteredRows) =>
|
|
176
|
-
formatNumber(
|
|
177
|
-
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
178
|
-
decimals
|
|
179
|
-
),
|
|
180
|
-
},
|
|
181
|
-
filter: {
|
|
182
|
-
...numberFilter(key),
|
|
183
|
-
renderer: (value) => formatNumber(value, decimals) ?? '',
|
|
184
|
-
},
|
|
185
|
-
...options,
|
|
144
|
+
options?: Partial<DataGridNumberColumn<R>>
|
|
145
|
+
): DataGridNumberColumn<R> => ({
|
|
146
|
+
key,
|
|
147
|
+
type: 'number',
|
|
148
|
+
name: title,
|
|
149
|
+
render: (row) => formatNumber(row[key], decimals) ?? '',
|
|
150
|
+
excelOptions: {
|
|
151
|
+
formatter: () => buildExcelFormat(decimals),
|
|
152
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
186
153
|
},
|
|
154
|
+
getter: (row) => row[key] ?? '',
|
|
155
|
+
sortGetter: (row) => row[key] ?? '',
|
|
156
|
+
footer: {
|
|
157
|
+
sum: (_, filteredRows) =>
|
|
158
|
+
formatNumber(
|
|
159
|
+
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
160
|
+
decimals
|
|
161
|
+
),
|
|
162
|
+
average: (_, filteredRows) =>
|
|
163
|
+
formatNumber(
|
|
164
|
+
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
165
|
+
(filteredRows.length || 1),
|
|
166
|
+
decimals
|
|
167
|
+
),
|
|
168
|
+
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
169
|
+
max: (_, filteredRows) =>
|
|
170
|
+
formatNumber(
|
|
171
|
+
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
172
|
+
decimals
|
|
173
|
+
),
|
|
174
|
+
min: (_, filteredRows) =>
|
|
175
|
+
formatNumber(
|
|
176
|
+
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
177
|
+
decimals
|
|
178
|
+
),
|
|
179
|
+
},
|
|
180
|
+
filter: {
|
|
181
|
+
...numberFilter(key),
|
|
182
|
+
renderer: (value) => formatNumber(value, decimals) ?? '',
|
|
183
|
+
},
|
|
184
|
+
...options,
|
|
187
185
|
});
|
|
188
186
|
|
|
189
187
|
export const moneyColumn = <R extends Record<string, any>>(
|
|
190
188
|
key: string,
|
|
191
189
|
title: string,
|
|
192
190
|
decimals = 2,
|
|
193
|
-
options?: Partial<
|
|
194
|
-
):
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
formatMoney(
|
|
209
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
210
|
-
decimals
|
|
211
|
-
),
|
|
212
|
-
average: (_, filteredRows) =>
|
|
213
|
-
formatMoney(
|
|
214
|
-
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
215
|
-
(filteredRows.length || 1),
|
|
216
|
-
decimals
|
|
217
|
-
),
|
|
218
|
-
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
219
|
-
max: (_, filteredRows) =>
|
|
220
|
-
formatMoney(
|
|
221
|
-
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
222
|
-
decimals
|
|
223
|
-
),
|
|
224
|
-
min: (_, filteredRows) =>
|
|
225
|
-
formatMoney(
|
|
226
|
-
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
227
|
-
decimals
|
|
228
|
-
),
|
|
229
|
-
},
|
|
230
|
-
...options,
|
|
191
|
+
options?: Partial<DataGridNumberColumn<R>>
|
|
192
|
+
): DataGridNumberColumn<R> => ({
|
|
193
|
+
key,
|
|
194
|
+
type: 'number',
|
|
195
|
+
name: title,
|
|
196
|
+
render: (row) => formatMoney(row[key], decimals) ?? '',
|
|
197
|
+
excelOptions: {
|
|
198
|
+
formatter: () => buildExcelFormat(decimals, ' €'),
|
|
199
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
200
|
+
},
|
|
201
|
+
getter: (row) => row[key] ?? '',
|
|
202
|
+
sortGetter: (row) => row[key] ?? '',
|
|
203
|
+
filter: {
|
|
204
|
+
...numberFilter(key),
|
|
205
|
+
renderer: (value) => formatMoney(value, decimals) ?? '',
|
|
231
206
|
},
|
|
207
|
+
footer: {
|
|
208
|
+
sum: (_, filteredRows) =>
|
|
209
|
+
formatMoney(
|
|
210
|
+
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
211
|
+
decimals
|
|
212
|
+
),
|
|
213
|
+
average: (_, filteredRows) =>
|
|
214
|
+
formatMoney(
|
|
215
|
+
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
216
|
+
(filteredRows.length || 1),
|
|
217
|
+
decimals
|
|
218
|
+
),
|
|
219
|
+
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
220
|
+
max: (_, filteredRows) =>
|
|
221
|
+
formatMoney(
|
|
222
|
+
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
223
|
+
decimals
|
|
224
|
+
),
|
|
225
|
+
min: (_, filteredRows) =>
|
|
226
|
+
formatMoney(
|
|
227
|
+
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
228
|
+
decimals
|
|
229
|
+
),
|
|
230
|
+
},
|
|
231
|
+
...options,
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
export const percentageColumn = <R extends Record<string, any>>(
|
|
235
235
|
key: string,
|
|
236
236
|
title: string,
|
|
237
237
|
decimals = 2,
|
|
238
|
-
options?: Partial<
|
|
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
|
-
|
|
238
|
+
options?: Partial<DataGridNumberColumn<R>>
|
|
239
|
+
): DataGridNumberColumn<R> => ({
|
|
240
|
+
key,
|
|
241
|
+
type: 'number',
|
|
242
|
+
name: title,
|
|
243
|
+
render: (row) => formatPercentage(row[key]) ?? '',
|
|
244
|
+
excelOptions: {
|
|
245
|
+
formatter: () => buildExcelFormat(decimals, '%'),
|
|
246
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
247
|
+
},
|
|
248
|
+
getter: (row) => row[key] ?? '',
|
|
249
|
+
sortGetter: (row) => row[key] ?? '',
|
|
250
|
+
filter: numberFilter(key),
|
|
251
|
+
footer: {
|
|
252
|
+
average: (_, filteredRows) =>
|
|
253
|
+
formatNumber(
|
|
254
|
+
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
|
|
255
|
+
(filteredRows.length || 1),
|
|
256
|
+
decimals
|
|
257
|
+
),
|
|
258
|
+
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
259
|
+
max: (_, filteredRows) =>
|
|
260
|
+
formatNumber(
|
|
261
|
+
Math.max(...filteredRows.map((row) => row[key] ?? 0)),
|
|
262
|
+
decimals
|
|
263
|
+
),
|
|
264
|
+
min: (_, filteredRows) =>
|
|
265
|
+
formatNumber(
|
|
266
|
+
Math.min(...filteredRows.map((row) => row[key] ?? 0)),
|
|
267
|
+
decimals
|
|
268
|
+
),
|
|
269
|
+
sum: (_, filteredRows) =>
|
|
270
|
+
formatNumber(
|
|
271
|
+
filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
|
|
272
|
+
decimals
|
|
273
|
+
),
|
|
273
274
|
},
|
|
275
|
+
...options,
|
|
274
276
|
});
|
|
275
277
|
|
|
276
278
|
export const checkboxColumn = <R extends Record<string, any>>(
|
|
277
279
|
key: string,
|
|
278
280
|
title: string,
|
|
279
|
-
options?: Partial<
|
|
280
|
-
):
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
...options,
|
|
281
|
+
options?: Partial<DataGridCheckboxColumn<R>>
|
|
282
|
+
): DataGridCheckboxColumn<R> => ({
|
|
283
|
+
key,
|
|
284
|
+
type: 'checkbox',
|
|
285
|
+
name: title,
|
|
286
|
+
render: (row) => (
|
|
287
|
+
<>
|
|
288
|
+
<input type="checkbox" checked={row[key]} readOnly />
|
|
289
|
+
<span>{row[key] ? ' Oui' : ' Non'}</span>
|
|
290
|
+
</>
|
|
291
|
+
),
|
|
292
|
+
getter: (row) => row[key] ?? '',
|
|
293
|
+
sortGetter: (row) => row[key] ?? '',
|
|
294
|
+
filter: numberFilter(key),
|
|
295
|
+
footer: {
|
|
296
|
+
count: (_, filteredRows) => `${filteredRows.length} éléments`,
|
|
297
|
+
checked: (_, filteredRows) =>
|
|
298
|
+
`${filteredRows.filter((row) => !!row[key]).length} cochés`,
|
|
299
|
+
unchecked: (_, filteredRows) =>
|
|
300
|
+
`${filteredRows.filter((row) => !row[key]).length} décochés`,
|
|
300
301
|
},
|
|
302
|
+
...options,
|
|
301
303
|
});
|
|
302
304
|
|
|
303
305
|
export const colorColumn = <R extends Record<string, any>>(
|
|
304
306
|
key: string,
|
|
305
307
|
title: string,
|
|
306
|
-
options?: Partial<
|
|
307
|
-
):
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
308
|
+
options?: Partial<DataGridColorColumn<R>>
|
|
309
|
+
): DataGridColorColumn<R> => ({
|
|
310
|
+
key,
|
|
311
|
+
type: 'color',
|
|
312
|
+
name: title,
|
|
313
|
+
render: (row) => (
|
|
314
|
+
<div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
|
|
315
|
+
),
|
|
316
|
+
getter: (row) => row[key] ?? '',
|
|
317
|
+
sortGetter: (row) => row[key] ?? '',
|
|
318
|
+
filter: textFilter(key),
|
|
319
|
+
footer: (rows) => `${rows.length} éléments`,
|
|
320
|
+
...options,
|
|
319
321
|
});
|
|
@@ -2,11 +2,10 @@ import { DataGridColumns, DataGridContext } from '../types';
|
|
|
2
2
|
import { useContext, useMemo } from 'react';
|
|
3
3
|
|
|
4
4
|
import { isColumnVisible } from '../helpers/columns';
|
|
5
|
-
import { pickBy } from 'lodash';
|
|
6
5
|
|
|
6
|
+
export { useDataGrid } from './useDataGrid';
|
|
7
7
|
export { useDataGridCopy } from './useDataGridCopy';
|
|
8
8
|
export { useDataGridSettings } from './useDataGridSettings';
|
|
9
|
-
export { useDataGrid } from './useDataGrid';
|
|
10
9
|
|
|
11
10
|
export const useDataGridContext = <R>(context: DataGridContext<R>) =>
|
|
12
11
|
useContext(context);
|
|
@@ -14,8 +13,8 @@ export const useDataGridContext = <R>(context: DataGridContext<R>) =>
|
|
|
14
13
|
export const useVisibleAndHiddenColumns = <R>(columns: DataGridColumns<R>) =>
|
|
15
14
|
useMemo(
|
|
16
15
|
() => [
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
columns.filter(isColumnVisible),
|
|
17
|
+
columns.filter((col) => !isColumnVisible(col)),
|
|
19
18
|
],
|
|
20
19
|
[columns]
|
|
21
20
|
);
|
|
@@ -23,8 +22,8 @@ export const useVisibleAndHiddenColumns = <R>(columns: DataGridColumns<R>) =>
|
|
|
23
22
|
export const useSortedColumns = <R>(columns: DataGridColumns<R>) =>
|
|
24
23
|
useMemo(
|
|
25
24
|
() =>
|
|
26
|
-
|
|
27
|
-
.filter(
|
|
28
|
-
.sort((a, b) => (a
|
|
25
|
+
columns
|
|
26
|
+
.filter(isColumnVisible)
|
|
27
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)),
|
|
29
28
|
[columns]
|
|
30
29
|
);
|