@addev-be/ui 0.14.1 → 0.14.4
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,179 +1,168 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { SqlImage, SqlImageWrapper } from '../styles';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '
|
|
5
|
+
SqlRequestDataGridCheckboxColumn,
|
|
6
|
+
SqlRequestDataGridDateColumn,
|
|
7
|
+
SqlRequestDataGridNumberColumn,
|
|
8
|
+
SqlRequestDataGridTextColumn,
|
|
9
|
+
} from '../types';
|
|
10
10
|
import {
|
|
11
11
|
buildExcelFormat,
|
|
12
12
|
dateFilter,
|
|
13
13
|
numberFilter,
|
|
14
14
|
textFilter,
|
|
15
15
|
} from '../../DataGrid/helpers';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { formatDate, formatDateTime } from '../../../../helpers/dates';
|
|
17
|
+
import {
|
|
18
|
+
formatMoney,
|
|
19
|
+
formatNumber,
|
|
20
|
+
formatNumberInvariant,
|
|
21
|
+
formatPercentage,
|
|
22
|
+
} from '../../../../helpers/numbers';
|
|
23
|
+
|
|
24
|
+
import { CheckboxEditableCell } from '../../DataGrid/DataGridEditableCell/CheckboxEditableCell';
|
|
25
|
+
import { DateEditableCell } from '../../DataGrid/DataGridEditableCell/DateEditableCell';
|
|
26
|
+
import { NumberEditableCell } from '../../DataGrid/DataGridEditableCell/NumberEditableCell';
|
|
27
|
+
import { TextEditableCell } from '../../DataGrid/DataGridEditableCell/TextEditableCell';
|
|
28
|
+
import { forwardRef } from 'react';
|
|
18
29
|
|
|
19
30
|
export const sqlTextColumn = <R extends Record<string, any>>(
|
|
20
31
|
key: string,
|
|
21
|
-
title:
|
|
22
|
-
options?: Partial<
|
|
23
|
-
):
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a column with a composed value from multiple fields,
|
|
37
|
-
* and filtered by a text filter on the first field
|
|
38
|
-
*/
|
|
39
|
-
export const sqlComposedColumn = <R extends Record<string, any>>(
|
|
40
|
-
key: string,
|
|
41
|
-
title: string,
|
|
42
|
-
fields: string[],
|
|
43
|
-
options?: Partial<SqlRequestDataGridColumn<R>>
|
|
44
|
-
): SqlRequestDataGridColumns<R> => ({
|
|
45
|
-
[key]: {
|
|
46
|
-
field: {
|
|
47
|
-
fieldAlias: key,
|
|
48
|
-
operator: 'jsonObject',
|
|
49
|
-
operands: fields.flatMap((field) => [
|
|
50
|
-
{ constantValue: field },
|
|
51
|
-
{ fieldName: field },
|
|
52
|
-
]),
|
|
53
|
-
},
|
|
54
|
-
name: title,
|
|
55
|
-
render: (row) => row[key] ?? '',
|
|
56
|
-
getter: (row) => row[key] ?? '',
|
|
57
|
-
sortGetter: (row) => row[key] ?? '',
|
|
58
|
-
filter: {
|
|
59
|
-
...textFilter(fields[0]),
|
|
60
|
-
getter: (value) => value[fields[0]] ?? 0,
|
|
61
|
-
},
|
|
62
|
-
filterField: fields[0],
|
|
63
|
-
sortField: fields[0],
|
|
64
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
65
|
-
...options,
|
|
66
|
-
},
|
|
32
|
+
title: React.ReactNode,
|
|
33
|
+
options?: Partial<SqlRequestDataGridTextColumn<R>>
|
|
34
|
+
): SqlRequestDataGridTextColumn<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
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
42
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
43
|
+
editComponent: TextEditableCell,
|
|
44
|
+
...options,
|
|
67
45
|
});
|
|
68
46
|
|
|
69
47
|
export const sqlMailColumn = <R extends Record<string, any>>(
|
|
70
48
|
key: string,
|
|
71
49
|
title: string,
|
|
72
|
-
options?: Partial<
|
|
73
|
-
):
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
options?: Partial<SqlRequestDataGridTextColumn<R>>
|
|
51
|
+
): SqlRequestDataGridTextColumn<R> => ({
|
|
52
|
+
key,
|
|
53
|
+
type: 'text',
|
|
54
|
+
name: title,
|
|
55
|
+
render: (row) => <a href={`mailto:${row[key]}`}>{row[key] ?? ''}</a>,
|
|
56
|
+
getter: (row) => row[key] ?? '',
|
|
57
|
+
sortGetter: (row) => row[key] ?? '',
|
|
58
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
59
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
60
|
+
editComponent: TextEditableCell,
|
|
61
|
+
...options,
|
|
83
62
|
});
|
|
84
63
|
|
|
85
64
|
export const sqlPhoneColumn = <R extends Record<string, any>>(
|
|
86
65
|
key: string,
|
|
87
66
|
title: string,
|
|
88
|
-
options?: Partial<
|
|
89
|
-
):
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
options?: Partial<SqlRequestDataGridTextColumn<R>>
|
|
68
|
+
): SqlRequestDataGridTextColumn<R> => ({
|
|
69
|
+
key,
|
|
70
|
+
type: 'text',
|
|
71
|
+
name: title,
|
|
72
|
+
render: (row) => <a href={`tel:${row[key]}`}>{row[key] ?? ''}</a>,
|
|
73
|
+
getter: (row) => row[key] ?? '',
|
|
74
|
+
sortGetter: (row) => row[key] ?? '',
|
|
75
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
76
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
77
|
+
editComponent: TextEditableCell,
|
|
78
|
+
...options,
|
|
99
79
|
});
|
|
100
80
|
|
|
101
81
|
export const sqlDateColumn = <R extends Record<string, any>>(
|
|
102
82
|
key: string,
|
|
103
83
|
title: string,
|
|
104
|
-
options?: Partial<
|
|
105
|
-
):
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
...dateFilter(key),
|
|
116
|
-
getter: (value) => value[key] ?? '',
|
|
117
|
-
formatter: (value) => formatDate(value),
|
|
118
|
-
renderer: (value) => formatDate(value),
|
|
119
|
-
},
|
|
120
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
121
|
-
...options,
|
|
84
|
+
options?: Partial<SqlRequestDataGridDateColumn<R>>
|
|
85
|
+
): SqlRequestDataGridDateColumn<R> => ({
|
|
86
|
+
key,
|
|
87
|
+
name: title,
|
|
88
|
+
type: 'date',
|
|
89
|
+
render: (row) => formatDate(row[key]),
|
|
90
|
+
getter: (row) => row[key] ?? '',
|
|
91
|
+
sortGetter: (row) => row[key] ?? '',
|
|
92
|
+
excelOptions: {
|
|
93
|
+
formatter: () => 'dd/mm/yyyy',
|
|
94
|
+
valueGetter: (value) => formatDate(value, 'YYYY-MM-DD'),
|
|
122
95
|
},
|
|
96
|
+
filter: {
|
|
97
|
+
...dateFilter(key),
|
|
98
|
+
getter: (value) => value[key] ?? '',
|
|
99
|
+
formatter: (value) => formatDate(value),
|
|
100
|
+
renderer: (value) => formatDate(value),
|
|
101
|
+
},
|
|
102
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
103
|
+
editComponent: DateEditableCell,
|
|
104
|
+
...options,
|
|
123
105
|
});
|
|
124
106
|
|
|
125
107
|
export const sqlDateTimeColumn = <R extends Record<string, any>>(
|
|
126
108
|
key: string,
|
|
127
109
|
title: string,
|
|
128
|
-
options?: Partial<
|
|
129
|
-
):
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
...options,
|
|
110
|
+
options?: Partial<SqlRequestDataGridDateColumn<R>>
|
|
111
|
+
): SqlRequestDataGridDateColumn<R> => ({
|
|
112
|
+
key,
|
|
113
|
+
name: title,
|
|
114
|
+
type: 'date',
|
|
115
|
+
render: (row) => formatDateTime(row[key]),
|
|
116
|
+
getter: (row) => row[key] ?? '',
|
|
117
|
+
sortGetter: (row) => row[key] ?? '',
|
|
118
|
+
excelOptions: {
|
|
119
|
+
formatter: () => 'dd/mm/yyyy hh:mm:ss',
|
|
120
|
+
valueGetter: (value) => formatDateTime(value, 'YYYY-MM-DD HH:mm:ss'),
|
|
121
|
+
},
|
|
122
|
+
filter: {
|
|
123
|
+
...dateFilter(key),
|
|
124
|
+
getter: (value) => value[key] ?? '',
|
|
125
|
+
formatter: (value) => formatDateTime(value),
|
|
126
|
+
renderer: (value) => formatDateTime(value),
|
|
146
127
|
},
|
|
128
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
129
|
+
editComponent: DateEditableCell,
|
|
130
|
+
...options,
|
|
147
131
|
});
|
|
148
132
|
|
|
149
133
|
export const sqlMonthColumn = <R extends Record<string, any>>(
|
|
150
134
|
key: string,
|
|
151
135
|
title: string,
|
|
152
|
-
options?: Partial<
|
|
153
|
-
):
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
136
|
+
options?: Partial<SqlRequestDataGridTextColumn<R>>
|
|
137
|
+
): SqlRequestDataGridTextColumn<R> => ({
|
|
138
|
+
key,
|
|
139
|
+
type: 'text',
|
|
140
|
+
name: title,
|
|
141
|
+
render: (row) => (row[key] ? `${row[key]} mois ` : ''),
|
|
142
|
+
getter: (row) => row[key] ?? '',
|
|
143
|
+
sortGetter: (row) => row[key] ?? '',
|
|
144
|
+
filter: { ...textFilter(key), getter: (value) => value[key] ?? '' },
|
|
145
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
146
|
+
...options,
|
|
163
147
|
});
|
|
164
148
|
|
|
165
149
|
export const sqlNumberColumn = <R extends Record<string, any>>(
|
|
166
150
|
key: string,
|
|
167
151
|
title: string,
|
|
168
152
|
decimals = 2,
|
|
169
|
-
options?: Partial<
|
|
170
|
-
):
|
|
171
|
-
|
|
153
|
+
options?: Partial<SqlRequestDataGridNumberColumn<R>>
|
|
154
|
+
): SqlRequestDataGridNumberColumn<R> => {
|
|
155
|
+
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
156
|
+
key,
|
|
172
157
|
name: title,
|
|
173
158
|
type: 'number',
|
|
159
|
+
decimals,
|
|
160
|
+
textAlign: 'right',
|
|
174
161
|
render: (row) => formatNumber(row[key], decimals) ?? '',
|
|
175
|
-
|
|
176
|
-
|
|
162
|
+
excelOptions: {
|
|
163
|
+
formatter: () => buildExcelFormat(decimals),
|
|
164
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
165
|
+
},
|
|
177
166
|
getter: (row) => row[key] ?? '',
|
|
178
167
|
sortGetter: (row) => row[key] ?? 0,
|
|
179
168
|
filter: {
|
|
@@ -188,29 +177,44 @@ export const sqlNumberColumn = <R extends Record<string, any>>(
|
|
|
188
177
|
max: null,
|
|
189
178
|
min: null,
|
|
190
179
|
},
|
|
180
|
+
editComponent: forwardRef((props, ref) => (
|
|
181
|
+
<NumberEditableCell<R>
|
|
182
|
+
ref={ref}
|
|
183
|
+
decimals={column.decimals}
|
|
184
|
+
currency={column.currency}
|
|
185
|
+
{...props}
|
|
186
|
+
/>
|
|
187
|
+
)),
|
|
191
188
|
...options,
|
|
192
|
-
}
|
|
193
|
-
|
|
189
|
+
};
|
|
190
|
+
return column;
|
|
191
|
+
};
|
|
194
192
|
|
|
195
193
|
export const sqlMoneyColumn = <R extends Record<string, any>>(
|
|
196
194
|
key: string,
|
|
197
195
|
title: string,
|
|
198
196
|
decimals = 2,
|
|
199
197
|
currency: string | ((row: R) => string) = 'EUR',
|
|
200
|
-
options?: Partial<
|
|
201
|
-
):
|
|
202
|
-
|
|
198
|
+
options?: Partial<SqlRequestDataGridNumberColumn<R>>
|
|
199
|
+
): SqlRequestDataGridNumberColumn<R> => {
|
|
200
|
+
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
201
|
+
key,
|
|
203
202
|
name: title,
|
|
204
203
|
type: 'number',
|
|
204
|
+
decimals,
|
|
205
|
+
currency,
|
|
206
|
+
textAlign: 'right',
|
|
205
207
|
render:
|
|
206
208
|
typeof currency === 'function'
|
|
207
209
|
? (row) => formatMoney(row[key], decimals, currency(row)) ?? ''
|
|
208
210
|
: (row) => formatMoney(row[key], decimals, currency) ?? '',
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
excelOptions: {
|
|
212
|
+
formatter:
|
|
213
|
+
typeof currency === 'function'
|
|
214
|
+
? (row) => buildExcelFormat(decimals, currency(row))
|
|
215
|
+
: () => buildExcelFormat(decimals, currency),
|
|
216
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
217
|
+
},
|
|
214
218
|
getter: (row) => row[key] ?? '',
|
|
215
219
|
sortGetter: (row) => row[key] ?? 0,
|
|
216
220
|
filter: {
|
|
@@ -228,47 +232,34 @@ export const sqlMoneyColumn = <R extends Record<string, any>>(
|
|
|
228
232
|
max: null,
|
|
229
233
|
min: null,
|
|
230
234
|
},
|
|
235
|
+
editComponent: forwardRef((props, ref) => (
|
|
236
|
+
<NumberEditableCell<R>
|
|
237
|
+
ref={ref}
|
|
238
|
+
decimals={column.decimals}
|
|
239
|
+
currency={column.currency}
|
|
240
|
+
{...props}
|
|
241
|
+
/>
|
|
242
|
+
)),
|
|
231
243
|
...options,
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
export const sqlImageColumn = <R extends Record<string, any>>(
|
|
236
|
-
key: string,
|
|
237
|
-
title: string,
|
|
238
|
-
urlPrefix: string,
|
|
239
|
-
options?: Partial<SqlRequestDataGridColumn<R>>
|
|
240
|
-
): SqlRequestDataGridColumns<R> => ({
|
|
241
|
-
[key]: {
|
|
242
|
-
name: title,
|
|
243
|
-
render: (row) => (
|
|
244
|
-
<SqlImageWrapper>
|
|
245
|
-
<SqlImage
|
|
246
|
-
src={
|
|
247
|
-
row[key] ? `${urlPrefix}${row[key]}` : `${urlPrefix}no-image.png`
|
|
248
|
-
}
|
|
249
|
-
alt={title}
|
|
250
|
-
/>
|
|
251
|
-
</SqlImageWrapper>
|
|
252
|
-
),
|
|
253
|
-
getter: (row) => row[key] ?? '',
|
|
254
|
-
sortGetter: (row) => row[key] ?? '',
|
|
255
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
256
|
-
...options,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
244
|
+
};
|
|
245
|
+
return column;
|
|
246
|
+
};
|
|
259
247
|
|
|
260
248
|
export const sqlPercentageColumn = <R extends Record<string, any>>(
|
|
261
249
|
key: string,
|
|
262
250
|
title: string,
|
|
263
251
|
decimals = 2,
|
|
264
|
-
options?: Partial<
|
|
265
|
-
):
|
|
266
|
-
|
|
252
|
+
options?: Partial<SqlRequestDataGridNumberColumn<R>>
|
|
253
|
+
): SqlRequestDataGridNumberColumn<R> => {
|
|
254
|
+
const column: SqlRequestDataGridNumberColumn<R> = {
|
|
255
|
+
key,
|
|
267
256
|
name: title,
|
|
268
257
|
type: 'number',
|
|
269
258
|
render: (row) => formatPercentage(row[key]) ?? '',
|
|
270
|
-
|
|
271
|
-
|
|
259
|
+
excelOptions: {
|
|
260
|
+
formatter: () => buildExcelFormat(decimals, '%'),
|
|
261
|
+
valueGetter: (value) => formatNumberInvariant(value, decimals),
|
|
262
|
+
},
|
|
272
263
|
getter: (row) => row[key] ?? '',
|
|
273
264
|
sortGetter: (row) => row[key] ?? 0,
|
|
274
265
|
filter: {
|
|
@@ -276,67 +267,100 @@ export const sqlPercentageColumn = <R extends Record<string, any>>(
|
|
|
276
267
|
getter: (value) => value[key] ?? 0,
|
|
277
268
|
renderer: (value) => formatPercentage(value, decimals) ?? '',
|
|
278
269
|
},
|
|
270
|
+
editComponent: forwardRef((props, ref) => (
|
|
271
|
+
<NumberEditableCell<R>
|
|
272
|
+
ref={ref}
|
|
273
|
+
decimals={column.decimals}
|
|
274
|
+
currency={column.currency}
|
|
275
|
+
{...props}
|
|
276
|
+
/>
|
|
277
|
+
)),
|
|
279
278
|
...options,
|
|
280
|
-
}
|
|
281
|
-
|
|
279
|
+
};
|
|
280
|
+
return column;
|
|
281
|
+
};
|
|
282
282
|
|
|
283
283
|
export const sqlCheckboxColumn = <R extends Record<string, any>>(
|
|
284
284
|
key: string,
|
|
285
285
|
title: string,
|
|
286
|
-
options?: Partial<
|
|
287
|
-
):
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
getter: (row) => row[key] ?? '',
|
|
300
|
-
sortGetter: (row) => row[key] ?? '',
|
|
301
|
-
filter: { ...numberFilter(key), getter: (value) => +(value[key] ?? 0) },
|
|
302
|
-
footer: (rows) => `${rows[0][key]} éléments`,
|
|
303
|
-
...options,
|
|
286
|
+
options?: Partial<SqlRequestDataGridCheckboxColumn<R>>
|
|
287
|
+
): SqlRequestDataGridCheckboxColumn<R> => ({
|
|
288
|
+
key,
|
|
289
|
+
name: title,
|
|
290
|
+
type: 'checkbox',
|
|
291
|
+
render: (row) => {
|
|
292
|
+
const value = !!+(row[key] ?? 0);
|
|
293
|
+
return (
|
|
294
|
+
<>
|
|
295
|
+
<input type="checkbox" checked={value} readOnly />
|
|
296
|
+
<span>{value ? ' Oui' : ' Non'}</span>
|
|
297
|
+
</>
|
|
298
|
+
);
|
|
304
299
|
},
|
|
300
|
+
getter: (row) => row[key] ?? '',
|
|
301
|
+
sortGetter: (row) => row[key] ?? '',
|
|
302
|
+
filter: { ...numberFilter(key), getter: (value) => +(value[key] ?? 0) },
|
|
303
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
304
|
+
editComponent: CheckboxEditableCell,
|
|
305
|
+
...options,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
export const sqlImageColumn = <R extends Record<string, any>>(
|
|
309
|
+
key: string,
|
|
310
|
+
title: string,
|
|
311
|
+
urlPrefix: string,
|
|
312
|
+
options?: Partial<SqlRequestDataGridTextColumn<R>>
|
|
313
|
+
): SqlRequestDataGridTextColumn<R> => ({
|
|
314
|
+
key,
|
|
315
|
+
type: 'text',
|
|
316
|
+
name: title,
|
|
317
|
+
render: (row) => (
|
|
318
|
+
<SqlImageWrapper>
|
|
319
|
+
<SqlImage
|
|
320
|
+
src={row[key] ? `${urlPrefix}${row[key]}` : `${urlPrefix}no-image.png`}
|
|
321
|
+
alt={title}
|
|
322
|
+
/>
|
|
323
|
+
</SqlImageWrapper>
|
|
324
|
+
),
|
|
325
|
+
getter: (row) => row[key] ?? '',
|
|
326
|
+
sortGetter: (row) => row[key] ?? '',
|
|
327
|
+
footer: (rows) => `${rows[0][key]} éléments`,
|
|
328
|
+
...options,
|
|
305
329
|
});
|
|
306
330
|
|
|
307
331
|
export const sqlColorColumn = <R extends Record<string, any>>(
|
|
308
332
|
key: string,
|
|
309
333
|
title: string,
|
|
310
|
-
options?: Partial<
|
|
311
|
-
):
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
334
|
+
options?: Partial<SqlRequestDataGridTextColumn<R>>
|
|
335
|
+
): SqlRequestDataGridTextColumn<R> => ({
|
|
336
|
+
key,
|
|
337
|
+
type: 'text',
|
|
338
|
+
name: title,
|
|
339
|
+
render: (row) => (
|
|
340
|
+
<div style={{ position: 'absolute', inset: 0, backgroundColor: row[key] }}>
|
|
341
|
+
|
|
342
|
+
</div>
|
|
343
|
+
),
|
|
344
|
+
excelOptions: {
|
|
345
|
+
valueGetter: () => '',
|
|
346
|
+
colorGetter: (value) => value,
|
|
347
|
+
},
|
|
348
|
+
getter: (row) => row[key] ?? '',
|
|
349
|
+
sortGetter: (row) => row[key] ?? '',
|
|
350
|
+
filter: {
|
|
351
|
+
...textFilter(key),
|
|
352
|
+
getter: (value) => value[key] ?? '',
|
|
353
|
+
renderer: (value) => (
|
|
315
354
|
<div
|
|
316
|
-
style={{
|
|
355
|
+
style={{
|
|
356
|
+
backgroundColor: value,
|
|
357
|
+
width: 'var(--space-16)',
|
|
358
|
+
height: '1em',
|
|
359
|
+
}}
|
|
317
360
|
>
|
|
318
361
|
|
|
319
362
|
</div>
|
|
320
363
|
),
|
|
321
|
-
excelValue: () => '',
|
|
322
|
-
excelBackgroundColor: (value) => value,
|
|
323
|
-
getter: (row) => row[key] ?? '',
|
|
324
|
-
sortGetter: (row) => row[key] ?? '',
|
|
325
|
-
filter: {
|
|
326
|
-
...textFilter(key),
|
|
327
|
-
getter: (value) => value[key] ?? '',
|
|
328
|
-
renderer: (value) => (
|
|
329
|
-
<div
|
|
330
|
-
style={{
|
|
331
|
-
backgroundColor: value,
|
|
332
|
-
width: 'var(--space-16)',
|
|
333
|
-
height: '1em',
|
|
334
|
-
}}
|
|
335
|
-
>
|
|
336
|
-
|
|
337
|
-
</div>
|
|
338
|
-
),
|
|
339
|
-
},
|
|
340
|
-
...options,
|
|
341
364
|
},
|
|
365
|
+
...options,
|
|
342
366
|
});
|