@addev-be/ui 1.1.6 → 1.2.0

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.
Files changed (301) hide show
  1. package/assets/icons/arrow-down-1-9.svg +1 -1
  2. package/assets/icons/arrow-down-a-z.svg +1 -1
  3. package/assets/icons/arrow-up-z-a.svg +1 -1
  4. package/assets/icons/check.svg +1 -1
  5. package/assets/icons/circle-check.svg +1 -1
  6. package/assets/icons/down.svg +1 -1
  7. package/assets/icons/filter-full.svg +1 -1
  8. package/assets/icons/filter.svg +1 -1
  9. package/assets/icons/hashtag.svg +1 -1
  10. package/assets/icons/image-slash.svg +1 -1
  11. package/assets/icons/left.svg +1 -1
  12. package/assets/icons/magnifier.svg +1 -1
  13. package/assets/icons/phone.svg +1 -1
  14. package/assets/icons/right.svg +1 -1
  15. package/assets/icons/sort-calendar-ascending.svg +5 -5
  16. package/assets/icons/spinner-third.svg +1 -1
  17. package/assets/icons/table-columns.svg +1 -1
  18. package/assets/icons/table-footer-slash.svg +4 -4
  19. package/assets/icons/table-footer.svg +3 -3
  20. package/assets/icons/table.svg +1 -1
  21. package/assets/icons/up.svg +1 -1
  22. package/assets/icons/user-tie.svg +1 -1
  23. package/assets/icons/x-bar.svg +3 -3
  24. package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.d.ts +14 -0
  25. package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.js +77 -0
  26. package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.d.ts +22 -0
  27. package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.js +105 -0
  28. package/dist/components/data/AdvancedRequestDataGrid/helpers/index.d.ts +2 -0
  29. package/dist/components/data/AdvancedRequestDataGrid/helpers/index.js +18 -0
  30. package/dist/components/data/AdvancedRequestDataGrid/index.d.ts +2 -0
  31. package/dist/components/data/AdvancedRequestDataGrid/index.js +215 -0
  32. package/dist/components/data/AdvancedRequestDataGrid/types.d.ts +21 -0
  33. package/dist/components/data/AdvancedRequestDataGrid/types.js +2 -0
  34. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +10 -0
  35. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +173 -0
  36. package/dist/components/data/DataGrid/DataGridCell.js +17 -7
  37. package/dist/components/data/DataGrid/DataGridColumnsModal/index.js +17 -7
  38. package/dist/components/data/DataGrid/DataGridColumnsModal/styles.js +17 -7
  39. package/dist/components/data/DataGrid/DataGridEditableCell.d.ts +2 -0
  40. package/dist/components/data/DataGrid/DataGridEditableCell.js +27 -0
  41. package/dist/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.js +17 -7
  42. package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +17 -7
  43. package/dist/components/data/DataGrid/DataGridFooter.js +17 -7
  44. package/dist/components/data/DataGrid/DataGridHeader.js +17 -7
  45. package/dist/components/data/DataGrid/DataGridHeaderCell.js +17 -7
  46. package/dist/components/data/DataGrid/DataGridRowTemplate.js +17 -7
  47. package/dist/components/data/DataGrid/DataGridToolbar.js +17 -7
  48. package/dist/components/data/DataGrid/FilterModalContent/index.js +17 -7
  49. package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +13 -0
  50. package/dist/components/data/DataGrid/FilterValuesScroller.js +73 -0
  51. package/dist/components/data/DataGrid/VirtualScroller.d.ts +11 -0
  52. package/dist/components/data/DataGrid/VirtualScroller.js +41 -0
  53. package/dist/components/data/DataGrid/helpers/advancedRequests.d.ts +12 -0
  54. package/dist/components/data/DataGrid/helpers/advancedRequests.js +53 -0
  55. package/dist/components/data/DataGrid/helpers.d.ts +28 -0
  56. package/dist/components/data/DataGrid/helpers.js +436 -0
  57. package/dist/components/data/DataGrid/index.js +17 -7
  58. package/dist/components/data/DataGrid/styles.js +17 -7
  59. package/dist/components/data/DataGrid/types.js +17 -7
  60. package/dist/components/data/SmartQueryDataGrid/helpers/columns.d.ts +20 -0
  61. package/dist/components/data/SmartQueryDataGrid/helpers/columns.js +160 -0
  62. package/dist/components/data/SmartQueryDataGrid/helpers/hooks.d.ts +5 -0
  63. package/dist/components/data/SmartQueryDataGrid/helpers/hooks.js +41 -0
  64. package/dist/components/data/SmartQueryDataGrid/helpers/index.d.ts +2 -0
  65. package/dist/components/data/SmartQueryDataGrid/helpers/index.js +18 -0
  66. package/dist/components/data/SmartQueryDataGrid/helpers/smartQueries.d.ts +3 -0
  67. package/dist/components/data/SmartQueryDataGrid/helpers/smartQueries.js +15 -0
  68. package/dist/components/data/SmartQueryDataGrid/hooks.d.ts +9 -0
  69. package/dist/components/data/SmartQueryDataGrid/hooks.js +63 -0
  70. package/dist/components/data/SmartQueryDataGrid/index.d.ts +12 -0
  71. package/dist/components/data/SmartQueryDataGrid/index.js +242 -0
  72. package/dist/components/data/SmartQueryDataGrid/types.d.ts +22 -0
  73. package/dist/components/data/SmartQueryDataGrid/types.js +2 -0
  74. package/dist/components/data/SqlRequestDataGrid/index.js +17 -7
  75. package/dist/components/data/SqlRequestGrid/filters/FiltersSidebar.js +17 -7
  76. package/dist/components/data/SqlRequestGrid/index.js +17 -7
  77. package/dist/components/data/VirtualScroller/index.js +17 -7
  78. package/dist/components/forms/Button.js +17 -7
  79. package/dist/components/forms/Form/InputWithLabel.d.ts +2 -0
  80. package/dist/components/forms/Form/InputWithLabel.js +10 -0
  81. package/dist/components/forms/Form/styles.js +17 -7
  82. package/dist/components/forms/Form/types.d.ts +7 -0
  83. package/dist/components/forms/Form/types.js +2 -0
  84. package/dist/components/forms/styles.js +17 -7
  85. package/dist/components/layout/Dropdown/index.js +17 -7
  86. package/dist/components/layout/Dropdown/styles.js +17 -7
  87. package/dist/components/layout/Loading/index.js +17 -7
  88. package/dist/components/layout/Modal/index.js +17 -7
  89. package/dist/components/layout/Modal/styles.js +17 -7
  90. package/dist/components/search/QuickSearchBar.js +17 -7
  91. package/dist/components/search/QuickSearchResults.js +17 -7
  92. package/dist/components/ui/Avatar/index.js +17 -7
  93. package/dist/components/ui/Avatar/styles.js +17 -7
  94. package/dist/components/ui/ContextMenu/styles.js +17 -7
  95. package/dist/components/ui/Label.js +17 -7
  96. package/dist/components/ui/Message/index.js +17 -7
  97. package/dist/components/ui/Message/styles.js +17 -7
  98. package/dist/components/ui/TabsView/styles.js +17 -7
  99. package/dist/config/types.d.ts +11 -0
  100. package/dist/config/types.js +2 -0
  101. package/dist/helpers/styled/index.d.ts +1 -0
  102. package/dist/helpers/styled/index.js +17 -0
  103. package/dist/helpers/styled/typography.js +17 -7
  104. package/dist/providers/PortalsProvider/index.js +17 -7
  105. package/dist/providers/UiProviders/index.js +17 -7
  106. package/dist/services/index.js +17 -7
  107. package/dist/services/requests/generic.d.ts +6 -94
  108. package/dist/services/requests/userPermissions.d.ts +4 -0
  109. package/dist/services/requests/userPermissions.js +20 -0
  110. package/dist/services/types/auth.js +17 -7
  111. package/dist/services/types/base.js +17 -7
  112. package/dist/services/types/generic.js +17 -7
  113. package/dist/services/types/tracking.js +17 -7
  114. package/dist/services/types/userProfiles.js +17 -7
  115. package/dist/services/types/users.js +17 -7
  116. package/eslint.config.js +3 -3
  117. package/package.json +14 -14
  118. package/src/Icons.tsx +138 -138
  119. package/src/components/auth/LoginForm.tsx +84 -84
  120. package/src/components/auth/LoginPage.tsx +32 -32
  121. package/src/components/auth/PasswordRecoveryForm.tsx +52 -52
  122. package/src/components/auth/PasswordResetForm.tsx +112 -112
  123. package/src/components/auth/index.ts +4 -4
  124. package/src/components/auth/styles.ts +14 -14
  125. package/src/components/data/DataGrid/DataGridCell.tsx +81 -81
  126. package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +9 -9
  127. package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -59
  128. package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +182 -182
  129. package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
  130. package/src/components/data/DataGrid/DataGridEditableCell/CheckboxEditableCell.tsx +38 -38
  131. package/src/components/data/DataGrid/DataGridEditableCell/DateEditableCell.tsx +39 -39
  132. package/src/components/data/DataGrid/DataGridEditableCell/NumberEditableCell.tsx +75 -75
  133. package/src/components/data/DataGrid/DataGridEditableCell/TextEditableCell.tsx +38 -38
  134. package/src/components/data/DataGrid/DataGridEditableCell/index.tsx +106 -106
  135. package/src/components/data/DataGrid/DataGridEditableCell/styles.ts +35 -35
  136. package/src/components/data/DataGrid/DataGridEditableCell/types.ts +19 -19
  137. package/src/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +129 -129
  138. package/src/components/data/DataGrid/DataGridFilterMenu/helpers.ts +23 -23
  139. package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +81 -81
  140. package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +370 -370
  141. package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +97 -97
  142. package/src/components/data/DataGrid/DataGridFooter.tsx +45 -45
  143. package/src/components/data/DataGrid/DataGridHeader.tsx +74 -74
  144. package/src/components/data/DataGrid/DataGridHeaderCell.tsx +112 -112
  145. package/src/components/data/DataGrid/DataGridRowTemplate.tsx +83 -83
  146. package/src/components/data/DataGrid/DataGridToolbar.tsx +134 -134
  147. package/src/components/data/DataGrid/FilterModalContent/index.tsx +135 -135
  148. package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
  149. package/src/components/data/DataGrid/constants.ts +6 -6
  150. package/src/components/data/DataGrid/helpers/columns.tsx +453 -453
  151. package/src/components/data/DataGrid/helpers/filters.ts +287 -287
  152. package/src/components/data/DataGrid/helpers/index.ts +2 -2
  153. package/src/components/data/DataGrid/hooks/index.ts +29 -29
  154. package/src/components/data/DataGrid/hooks/useDataGrid.tsx +380 -380
  155. package/src/components/data/DataGrid/hooks/useDataGridChangedRows.ts +97 -97
  156. package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +174 -174
  157. package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -48
  158. package/src/components/data/DataGrid/hooks/useRefreshModal.tsx +48 -48
  159. package/src/components/data/DataGrid/index.tsx +122 -122
  160. package/src/components/data/DataGrid/styles.ts +430 -430
  161. package/src/components/data/DataGrid/types.ts +380 -380
  162. package/src/components/data/SqlRequestDataGrid/SqlRequestForeignListEditableCell.tsx +16 -16
  163. package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +526 -526
  164. package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
  165. package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -16
  166. package/src/components/data/SqlRequestDataGrid/index.tsx +420 -420
  167. package/src/components/data/SqlRequestDataGrid/styles.ts +15 -15
  168. package/src/components/data/SqlRequestDataGrid/types.ts +74 -74
  169. package/src/components/data/SqlRequestForeignList/index.tsx +257 -257
  170. package/src/components/data/SqlRequestForeignList/styles.ts +43 -43
  171. package/src/components/data/SqlRequestForeignList/types.ts +32 -32
  172. package/src/components/data/SqlRequestGrid/filters/FiltersSidebar.tsx +108 -108
  173. package/src/components/data/SqlRequestGrid/filters/styles.ts +88 -88
  174. package/src/components/data/SqlRequestGrid/helpers/index.ts +1 -1
  175. package/src/components/data/SqlRequestGrid/helpers/sqlRequests.ts +16 -16
  176. package/src/components/data/SqlRequestGrid/index.tsx +315 -315
  177. package/src/components/data/SqlRequestGrid/styles.ts +20 -20
  178. package/src/components/data/SqlRequestGrid/types.ts +73 -73
  179. package/src/components/data/VirtualScroller/hooks.ts +71 -71
  180. package/src/components/data/VirtualScroller/index.tsx +89 -89
  181. package/src/components/data/VirtualScroller/styles.ts +57 -57
  182. package/src/components/data/VirtualScroller/types.ts +10 -10
  183. package/src/components/data/index.ts +16 -16
  184. package/src/components/forms/AutoTextArea.tsx +48 -48
  185. package/src/components/forms/Button.tsx +132 -132
  186. package/src/components/forms/Form/Checkbox.tsx +12 -12
  187. package/src/components/forms/Form/CustomSelect.tsx +94 -94
  188. package/src/components/forms/Form/FormGroup.tsx +31 -31
  189. package/src/components/forms/Form/Input.tsx +16 -16
  190. package/src/components/forms/Form/Row.tsx +32 -32
  191. package/src/components/forms/Form/Select.tsx +87 -87
  192. package/src/components/forms/Form/TextArea.tsx +17 -17
  193. package/src/components/forms/Form/index.tsx +48 -48
  194. package/src/components/forms/Form/styles.ts +184 -184
  195. package/src/components/forms/IconButton.tsx +67 -67
  196. package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
  197. package/src/components/forms/NumberInput.tsx +53 -53
  198. package/src/components/forms/Select.tsx +34 -34
  199. package/src/components/forms/VerticalLabel.tsx +20 -20
  200. package/src/components/forms/index.ts +9 -9
  201. package/src/components/forms/styles.ts +42 -42
  202. package/src/components/index.ts +6 -6
  203. package/src/components/layout/Columns.ts +28 -28
  204. package/src/components/layout/Dropdown/index.tsx +113 -113
  205. package/src/components/layout/Dropdown/styles.ts +53 -53
  206. package/src/components/layout/Flexbox.ts +21 -21
  207. package/src/components/layout/Grid/index.tsx +8 -8
  208. package/src/components/layout/Grid/styles.ts +34 -34
  209. package/src/components/layout/Loading/index.tsx +29 -29
  210. package/src/components/layout/Loading/styles.ts +29 -29
  211. package/src/components/layout/Masonry/index.tsx +29 -29
  212. package/src/components/layout/Masonry/styles.ts +20 -20
  213. package/src/components/layout/Modal/index.tsx +51 -51
  214. package/src/components/layout/Modal/styles.ts +125 -125
  215. package/src/components/layout/index.ts +7 -7
  216. package/src/components/search/HighlightedText.tsx +41 -41
  217. package/src/components/search/QuickSearchBar.tsx +99 -99
  218. package/src/components/search/QuickSearchResults.tsx +86 -86
  219. package/src/components/search/index.ts +9 -9
  220. package/src/components/search/styles.ts +96 -96
  221. package/src/components/search/types.ts +29 -29
  222. package/src/components/ui/Avatar/index.tsx +54 -54
  223. package/src/components/ui/Avatar/styles.ts +61 -61
  224. package/src/components/ui/Card/index.tsx +14 -14
  225. package/src/components/ui/Card/styles.ts +37 -37
  226. package/src/components/ui/ContextMenu/index.tsx +79 -79
  227. package/src/components/ui/ContextMenu/styles.ts +119 -119
  228. package/src/components/ui/Ellipsis.tsx +34 -34
  229. package/src/components/ui/Label.tsx +99 -99
  230. package/src/components/ui/Message/index.tsx +57 -57
  231. package/src/components/ui/Message/styles.ts +40 -40
  232. package/src/components/ui/TabsView/TabsList.tsx +44 -44
  233. package/src/components/ui/TabsView/TabsView.tsx +38 -38
  234. package/src/components/ui/TabsView/index.ts +3 -3
  235. package/src/components/ui/TabsView/styles.ts +73 -73
  236. package/src/components/ui/TabsView/types.ts +12 -12
  237. package/src/components/ui/index.ts +7 -7
  238. package/src/config/index.ts +14 -14
  239. package/src/helpers/components.ts +23 -23
  240. package/src/helpers/dates.ts +17 -17
  241. package/src/helpers/getScrollbarSize.ts +14 -14
  242. package/src/helpers/index.ts +5 -5
  243. package/src/helpers/numbers.ts +63 -63
  244. package/src/helpers/responsive.ts +83 -83
  245. package/src/helpers/styled/space.ts +111 -111
  246. package/src/helpers/styled/typography.ts +25 -25
  247. package/src/helpers/text.ts +13 -13
  248. package/src/helpers/types.ts +9 -9
  249. package/src/hooks/index.ts +7 -7
  250. package/src/hooks/useContainerMediaQuery.ts +7 -7
  251. package/src/hooks/useElementSize.ts +24 -24
  252. package/src/hooks/useMediaQuery.ts +9 -9
  253. package/src/hooks/useMediaQueryForWidth.ts +35 -35
  254. package/src/hooks/useMutableState.ts +17 -17
  255. package/src/hooks/useShowArchived.ts +28 -28
  256. package/src/hooks/useWindowSize.ts +20 -20
  257. package/src/index.ts +13 -13
  258. package/src/providers/AuthenticationProvider/helpers.ts +3 -3
  259. package/src/providers/AuthenticationProvider/index.tsx +303 -303
  260. package/src/providers/LoadingProvider/index.tsx +47 -47
  261. package/src/providers/PortalsProvider/index.tsx +54 -54
  262. package/src/providers/PortalsProvider/styles.ts +31 -31
  263. package/src/providers/SettingsProvider/index.tsx +70 -70
  264. package/src/providers/ThemeProvider/ThemeProvider.ts +66 -66
  265. package/src/providers/ThemeProvider/defaultTheme.ts +470 -470
  266. package/src/providers/ThemeProvider/helpers.ts +84 -84
  267. package/src/providers/ThemeProvider/index.ts +5 -5
  268. package/src/providers/ThemeProvider/types.ts +134 -134
  269. package/src/providers/ToastProvider/index.tsx +93 -93
  270. package/src/providers/TrackingProvider/hooks.ts +14 -14
  271. package/src/providers/TrackingProvider/index.tsx +71 -71
  272. package/src/providers/UiProviders/index.tsx +76 -76
  273. package/src/providers/UiProviders/styles.ts +10 -10
  274. package/src/providers/hooks.ts +14 -14
  275. package/src/providers/index.ts +9 -9
  276. package/src/services/HttpService.ts +92 -92
  277. package/src/services/WebSocketService.ts +155 -155
  278. package/src/services/advancedRequests.ts +102 -102
  279. package/src/services/base.ts +23 -23
  280. package/src/services/globalSearch.ts +32 -32
  281. package/src/services/hooks.ts +92 -92
  282. package/src/services/index.ts +21 -21
  283. package/src/services/requests/auth.ts +44 -44
  284. package/src/services/requests/generic.ts +62 -62
  285. package/src/services/requests/tracking.ts +12 -12
  286. package/src/services/requests/userProfiles.ts +35 -35
  287. package/src/services/requests/users.ts +28 -28
  288. package/src/services/smartQueries.ts +122 -122
  289. package/src/services/sqlRequests.ts +111 -111
  290. package/src/services/types/auth.ts +98 -98
  291. package/src/services/types/base.ts +10 -10
  292. package/src/services/types/generic.ts +82 -82
  293. package/src/services/types/tracking.ts +29 -29
  294. package/src/services/types/userProfiles.ts +79 -79
  295. package/src/services/types/users.ts +74 -74
  296. package/src/services/updateSqlRequests.ts +32 -32
  297. package/src/styles/animations.scss +30 -30
  298. package/src/styles/index.scss +42 -42
  299. package/src/typings.d.ts +17 -17
  300. package/tsconfig.json +18 -18
  301. package/tsconfig.tsbuildinfo +1 -1
@@ -1,453 +1,453 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import {
4
- DataGridCheckboxColumn,
5
- DataGridColorColumn,
6
- DataGridColumn,
7
- DataGridDateColumn,
8
- DataGridNumberColumn,
9
- DataGridSelectColumn,
10
- DataGridSettings,
11
- DataGridTextColumn,
12
- } from '../types';
13
- import { dateFilter, numberFilter, textFilter } from './filters';
14
- import { formatDate, formatDateTime } from '../../../../helpers';
15
- import {
16
- formatMoney,
17
- formatNumber,
18
- formatNumberInvariant,
19
- formatPercentage,
20
- } from '../../../../helpers/numbers';
21
-
22
- import { CheckboxEditableCell } from '../DataGridEditableCell/CheckboxEditableCell';
23
- import { DateEditableCell } from '../DataGridEditableCell/DateEditableCell';
24
- import { DeepPartial } from '../../../../typings';
25
- import { NumberEditableCell } from '../DataGridEditableCell/NumberEditableCell';
26
- import { Ref } from 'react';
27
- import { Select } from '../../../forms/Form/Select';
28
- import { SqlRequestDataGridTextColumn } from '../../SqlRequestDataGrid/types';
29
- import { StyledTypography } from '../../../../helpers/styled/typography';
30
- import { TextEditableCell } from '../DataGridEditableCell/TextEditableCell';
31
- import { forwardRefWithName } from '../../../../helpers/components';
32
- import moment from 'moment';
33
- import { repeat } from 'lodash';
34
-
35
- export const isColumnVisible = <R,>(
36
- obj: DataGridColumn<R> | DataGridSettings
37
- ): boolean => obj?.order !== -1;
38
-
39
- export const buildExcelFormat = (decimals = 2, suffix = '') =>
40
- `#0${decimals > 0 ? `.${repeat('0', decimals)}` : ''}${suffix}`;
41
-
42
- export const textColumn = <R extends Record<string, any>>(
43
- key: string,
44
- title: string,
45
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
46
- otherOptions?: Partial<DataGridTextColumn<R>>
47
- ): DataGridTextColumn<R> => ({
48
- key,
49
- type: 'text',
50
- name: title,
51
- render: (value) => (
52
- <StyledTypography {...options?.typography}>{value}</StyledTypography>
53
- ),
54
- getter: (row) => row[key] ?? '',
55
- sortGetter: (row) => row[key] ?? '',
56
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
57
- filter: textFilter(key),
58
- editComponent: TextEditableCell,
59
- ...otherOptions,
60
- });
61
-
62
- export const mailColumn = <R extends Record<string, any>>(
63
- key: string,
64
- title: string,
65
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
66
- otherOptions?: Partial<DataGridTextColumn<R>>
67
- ): DataGridTextColumn<R> => ({
68
- key,
69
- type: 'text',
70
- name: title,
71
- render: (value) => (
72
- <StyledTypography
73
- href={`mailto:${value}`}
74
- {...options?.typography}
75
- as={'a'}
76
- >
77
- {value}
78
- </StyledTypography>
79
- ),
80
- getter: (row) => row[key] ?? '',
81
- sortGetter: (row) => row[key] ?? '',
82
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
83
- filter: textFilter(key),
84
- editComponent: TextEditableCell,
85
- ...otherOptions,
86
- });
87
-
88
- export const phoneColumn = <R extends Record<string, any>>(
89
- key: string,
90
- title: string,
91
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
92
- otherOptions?: Partial<DataGridTextColumn<R>>
93
- ): DataGridTextColumn<R> => ({
94
- key,
95
- type: 'text',
96
- name: title,
97
- render: (value) => (
98
- <StyledTypography href={`tel:${value}`} {...options?.typography} as={'a'}>
99
- {value}
100
- </StyledTypography>
101
- ),
102
- getter: (row) => row[key] ?? '',
103
- sortGetter: (row) => row[key] ?? '',
104
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
105
- filter: textFilter(key),
106
- editComponent: TextEditableCell,
107
- ...otherOptions,
108
- });
109
-
110
- export const dateColumn = <R extends Record<string, any>>(
111
- key: string,
112
- title: string,
113
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
114
- otherOptions?: Partial<DataGridDateColumn<R>>
115
- ): DataGridDateColumn<R> => ({
116
- key,
117
- type: 'date',
118
- name: title,
119
- render: (value) => (
120
- <StyledTypography {...options?.typography}>
121
- {formatDate(value)}
122
- </StyledTypography>
123
- ),
124
- excelOptions: {
125
- formatter: () => 'dd/mm/yyyy',
126
- valueGetter: (value) => moment(value).format('DD/MM/YYYY') ?? '',
127
- },
128
- getter: (row) => row[key] ?? '',
129
- sortGetter: (row) => row[key] ?? '',
130
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
131
- filter: {
132
- ...dateFilter(key),
133
- renderer: (value) => moment(value).format('DD/MM/YYYY') ?? '',
134
- },
135
- editComponent: DateEditableCell,
136
- ...otherOptions,
137
- });
138
-
139
- export const dateTimeColumn = <R extends Record<string, any>>(
140
- key: string,
141
- title: string,
142
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
143
- otherOptions?: Partial<DataGridDateColumn<R>>
144
- ): DataGridDateColumn<R> => ({
145
- key,
146
- type: 'date',
147
- name: title,
148
- render: (value) => (
149
- <StyledTypography {...options?.typography}>
150
- {formatDateTime(value)}
151
- </StyledTypography>
152
- ),
153
- excelOptions: {
154
- formatter: () => 'dd/mm/yyyy hh:mm:ss',
155
- valueGetter: (value) => moment(value).format('DD/MM/YYYY HH:mm:ss') ?? '',
156
- },
157
- getter: (row) => row[key] ?? '',
158
- sortGetter: (row) => row[key] ?? '',
159
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
160
- filter: {
161
- ...dateFilter(key),
162
- renderer: (value) => moment(value).format('DD/MM/YYYY HH:mm:ss') ?? '',
163
- },
164
- editComponent: DateEditableCell,
165
- ...otherOptions,
166
- });
167
-
168
- export const monthColumn = <R extends Record<string, any>>(
169
- key: string,
170
- title: string,
171
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
172
- otherOptions?: Partial<DataGridTextColumn<R>>
173
- ): DataGridTextColumn<R> => ({
174
- key,
175
- type: 'text',
176
- name: title,
177
- render: (value) => (
178
- <StyledTypography {...options?.typography}>
179
- {value + 'Mois'}
180
- </StyledTypography>
181
- ),
182
- getter: (row) => row[key] ?? '',
183
- sortGetter: (row) => row[key] ?? '',
184
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
185
- filter: textFilter(key),
186
- ...otherOptions,
187
- });
188
-
189
- export const numberColumn = <R extends Record<string, any>>(
190
- key: string,
191
- title: string,
192
- decimals = 2,
193
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
194
- otherOptions?: Partial<DataGridNumberColumn<R>>
195
- ): DataGridNumberColumn<R> => {
196
- const column: DataGridNumberColumn<R> = {
197
- key,
198
- type: 'number',
199
- name: title,
200
- render: (value) => (
201
- <StyledTypography {...options?.typography}>
202
- {formatNumber(value, decimals)}
203
- </StyledTypography>
204
- ),
205
- excelOptions: {
206
- formatter: () => buildExcelFormat(decimals),
207
- valueGetter: (value) => formatNumberInvariant(value, decimals),
208
- },
209
- getter: (row) => row[key] ?? '',
210
- sortGetter: (row) => row[key] ?? '',
211
- footer: {
212
- sum: (_, filteredRows) =>
213
- formatNumber(
214
- filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
215
- decimals
216
- ),
217
- average: (_, filteredRows) =>
218
- formatNumber(
219
- filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
220
- (filteredRows.length || 1),
221
- decimals
222
- ),
223
- count: (_, filteredRows) => `${filteredRows.length} éléments`,
224
- max: (_, filteredRows) =>
225
- formatNumber(
226
- Math.max(...filteredRows.map((row) => row[key] ?? 0)),
227
- decimals
228
- ),
229
- min: (_, filteredRows) =>
230
- formatNumber(
231
- Math.min(...filteredRows.map((row) => row[key] ?? 0)),
232
- decimals
233
- ),
234
- },
235
- filter: {
236
- ...numberFilter(key),
237
- renderer: (value) => formatNumber(value, decimals) ?? '',
238
- },
239
- editComponent: forwardRefWithName(
240
- (props, ref: Ref<HTMLInputElement>) => (
241
- <NumberEditableCell<R>
242
- ref={ref}
243
- decimals={column.decimals}
244
- currency={column.currency}
245
- {...props}
246
- />
247
- ),
248
- 'NumberColumnEditComponent'
249
- ),
250
- ...otherOptions,
251
- };
252
- return column;
253
- };
254
-
255
- export const moneyColumn = <R extends Record<string, any>>(
256
- key: string,
257
- title: string,
258
- decimals = 2,
259
- currency: string | ((row: R) => string) = '€',
260
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
261
- otherOptions?: Partial<DataGridNumberColumn<R>>
262
- ): DataGridNumberColumn<R> => {
263
- const column: DataGridNumberColumn<R> = {
264
- key,
265
- type: 'number',
266
- name: title,
267
- render:
268
- typeof currency === 'function'
269
- ? (value, row) => (
270
- <StyledTypography {...options?.typography}>
271
- {formatMoney(value, decimals, currency(row))}
272
- </StyledTypography>
273
- )
274
- : (value) => (
275
- <StyledTypography {...options?.typography}>
276
- {formatMoney(value, decimals, currency)}
277
- </StyledTypography>
278
- ),
279
- excelOptions: {
280
- formatter: () => buildExcelFormat(decimals, ' €'),
281
- valueGetter: (value) => formatNumberInvariant(value, decimals),
282
- },
283
- getter: (row) => row[key] ?? '',
284
- sortGetter: (row) => row[key] ?? '',
285
- filter: {
286
- ...numberFilter(key),
287
- renderer: (value) => formatMoney(value, decimals) ?? '',
288
- },
289
- footer: {
290
- sum: (_, filteredRows) =>
291
- formatMoney(
292
- filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
293
- decimals
294
- ),
295
- average: (_, filteredRows) =>
296
- formatMoney(
297
- filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
298
- (filteredRows.length || 1),
299
- decimals
300
- ),
301
- count: (_, filteredRows) => `${filteredRows.length} éléments`,
302
- max: (_, filteredRows) =>
303
- formatMoney(
304
- Math.max(...filteredRows.map((row) => row[key] ?? 0)),
305
- decimals
306
- ),
307
- min: (_, filteredRows) =>
308
- formatMoney(
309
- Math.min(...filteredRows.map((row) => row[key] ?? 0)),
310
- decimals
311
- ),
312
- },
313
- ...otherOptions,
314
- };
315
- return column;
316
- };
317
-
318
- export const percentageColumn = <R extends Record<string, any>>(
319
- key: string,
320
- title: string,
321
- decimals = 2,
322
- options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
323
- otherOptions?: Partial<DataGridNumberColumn<R>>
324
- ): DataGridNumberColumn<R> => {
325
- const column: DataGridNumberColumn<R> = {
326
- key,
327
- type: 'number',
328
- name: title,
329
- render: (value) => (
330
- <StyledTypography {...options?.typography}>
331
- {formatPercentage(value)}
332
- </StyledTypography>
333
- ),
334
- excelOptions: {
335
- formatter: () => buildExcelFormat(decimals, '%'),
336
- valueGetter: (value) => formatNumberInvariant(value, decimals),
337
- },
338
- getter: (row) => row[key] ?? '',
339
- sortGetter: (row) => row[key] ?? '',
340
- filter: numberFilter(key),
341
- footer: {
342
- average: (_, filteredRows) =>
343
- formatNumber(
344
- filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
345
- (filteredRows.length || 1),
346
- decimals
347
- ),
348
- count: (_, filteredRows) => `${filteredRows.length} éléments`,
349
- max: (_, filteredRows) =>
350
- formatNumber(
351
- Math.max(...filteredRows.map((row) => row[key] ?? 0)),
352
- decimals
353
- ),
354
- min: (_, filteredRows) =>
355
- formatNumber(
356
- Math.min(...filteredRows.map((row) => row[key] ?? 0)),
357
- decimals
358
- ),
359
- sum: (_, filteredRows) =>
360
- formatNumber(
361
- filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
362
- decimals
363
- ),
364
- },
365
- ...otherOptions,
366
- };
367
- return column;
368
- };
369
-
370
- export const checkboxColumn = <R extends Record<string, any>>(
371
- key: string,
372
- title: string,
373
- otherOptions?: Partial<DataGridCheckboxColumn<R>>
374
- ): DataGridCheckboxColumn<R> => ({
375
- key,
376
- type: 'checkbox',
377
- name: title,
378
- render: (value, row) => (
379
- <>
380
- <input type="checkbox" checked={row[key]} readOnly />
381
- <span>{row[key] ? ' Oui' : ' Non'}</span>
382
- </>
383
- ),
384
- getter: (row) => row[key] ?? '',
385
- sortGetter: (row) => row[key] ?? '',
386
- filter: numberFilter(key),
387
- footer: {
388
- count: (_, filteredRows) => `${filteredRows.length} éléments`,
389
- checked: (_, filteredRows) =>
390
- `${filteredRows.filter((row) => !!row[key]).length} cochés`,
391
- unchecked: (_, filteredRows) =>
392
- `${filteredRows.filter((row) => !row[key]).length} décochés`,
393
- },
394
- editComponent: CheckboxEditableCell,
395
- ...otherOptions,
396
- });
397
-
398
- export const selectColumn = <R extends Record<string, any>, T>(
399
- key: string,
400
- title: string,
401
- items: T[],
402
- itemKey: (item: T | null) => string,
403
- itemLabel: (item: T | null) => string,
404
- otherOptions?: Partial<DataGridSelectColumn<R, T>>
405
- ): DataGridSelectColumn<R, T> => ({
406
- key,
407
- type: 'select',
408
- name: title,
409
- render: (value, row) => itemLabel(row[key]) ?? '',
410
- getter: (row) => row[key] ?? null,
411
- sortGetter: (row) => itemLabel(row[key]) ?? '',
412
- footer: (_, filteredRows) => `${filteredRows.length} éléments`,
413
- filter: {
414
- ...textFilter(key),
415
- renderer: (value) => itemLabel(value) ?? '',
416
- },
417
- items,
418
- itemKey,
419
- itemLabel,
420
- editComponent: forwardRefWithName(
421
- ({ value, onChange, onClose }, ref: Ref<HTMLSelectElement>) => (
422
- <Select<T>
423
- ref={ref}
424
- items={items}
425
- itemKey={itemKey}
426
- itemLabel={itemLabel}
427
- value={value}
428
- onChange={onChange}
429
- onBlur={() => onClose(true)}
430
- />
431
- ),
432
- 'SelectColumnEditComponent'
433
- ),
434
- ...otherOptions,
435
- });
436
-
437
- export const colorColumn = <R extends Record<string, any>>(
438
- key: string,
439
- title: string,
440
- otherOptions?: Partial<DataGridColorColumn<R>>
441
- ): DataGridColorColumn<R> => ({
442
- key,
443
- type: 'color',
444
- name: title,
445
- render: (value, row) => (
446
- <div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
447
- ),
448
- getter: (row) => row[key] ?? '',
449
- sortGetter: (row) => row[key] ?? '',
450
- filter: textFilter(key),
451
- footer: (rows) => `${rows.length} éléments`,
452
- ...otherOptions,
453
- });
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import {
4
+ DataGridCheckboxColumn,
5
+ DataGridColorColumn,
6
+ DataGridColumn,
7
+ DataGridDateColumn,
8
+ DataGridNumberColumn,
9
+ DataGridSelectColumn,
10
+ DataGridSettings,
11
+ DataGridTextColumn,
12
+ } from '../types';
13
+ import { dateFilter, numberFilter, textFilter } from './filters';
14
+ import { formatDate, formatDateTime } from '../../../../helpers';
15
+ import {
16
+ formatMoney,
17
+ formatNumber,
18
+ formatNumberInvariant,
19
+ formatPercentage,
20
+ } from '../../../../helpers/numbers';
21
+
22
+ import { CheckboxEditableCell } from '../DataGridEditableCell/CheckboxEditableCell';
23
+ import { DateEditableCell } from '../DataGridEditableCell/DateEditableCell';
24
+ import { DeepPartial } from '../../../../typings';
25
+ import { NumberEditableCell } from '../DataGridEditableCell/NumberEditableCell';
26
+ import { Ref } from 'react';
27
+ import { Select } from '../../../forms/Form/Select';
28
+ import { SqlRequestDataGridTextColumn } from '../../SqlRequestDataGrid/types';
29
+ import { StyledTypography } from '../../../../helpers/styled/typography';
30
+ import { TextEditableCell } from '../DataGridEditableCell/TextEditableCell';
31
+ import { forwardRefWithName } from '../../../../helpers/components';
32
+ import moment from 'moment';
33
+ import { repeat } from 'lodash';
34
+
35
+ export const isColumnVisible = <R,>(
36
+ obj: DataGridColumn<R> | DataGridSettings
37
+ ): boolean => obj?.order !== -1;
38
+
39
+ export const buildExcelFormat = (decimals = 2, suffix = '') =>
40
+ `#0${decimals > 0 ? `.${repeat('0', decimals)}` : ''}${suffix}`;
41
+
42
+ export const textColumn = <R extends Record<string, any>>(
43
+ key: string,
44
+ title: string,
45
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
46
+ otherOptions?: Partial<DataGridTextColumn<R>>
47
+ ): DataGridTextColumn<R> => ({
48
+ key,
49
+ type: 'text',
50
+ name: title,
51
+ render: (value) => (
52
+ <StyledTypography {...options?.typography}>{value}</StyledTypography>
53
+ ),
54
+ getter: (row) => row[key] ?? '',
55
+ sortGetter: (row) => row[key] ?? '',
56
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
57
+ filter: textFilter(key),
58
+ editComponent: TextEditableCell,
59
+ ...otherOptions,
60
+ });
61
+
62
+ export const mailColumn = <R extends Record<string, any>>(
63
+ key: string,
64
+ title: string,
65
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
66
+ otherOptions?: Partial<DataGridTextColumn<R>>
67
+ ): DataGridTextColumn<R> => ({
68
+ key,
69
+ type: 'text',
70
+ name: title,
71
+ render: (value) => (
72
+ <StyledTypography
73
+ href={`mailto:${value}`}
74
+ {...options?.typography}
75
+ as={'a'}
76
+ >
77
+ {value}
78
+ </StyledTypography>
79
+ ),
80
+ getter: (row) => row[key] ?? '',
81
+ sortGetter: (row) => row[key] ?? '',
82
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
83
+ filter: textFilter(key),
84
+ editComponent: TextEditableCell,
85
+ ...otherOptions,
86
+ });
87
+
88
+ export const phoneColumn = <R extends Record<string, any>>(
89
+ key: string,
90
+ title: string,
91
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
92
+ otherOptions?: Partial<DataGridTextColumn<R>>
93
+ ): DataGridTextColumn<R> => ({
94
+ key,
95
+ type: 'text',
96
+ name: title,
97
+ render: (value) => (
98
+ <StyledTypography href={`tel:${value}`} {...options?.typography} as={'a'}>
99
+ {value}
100
+ </StyledTypography>
101
+ ),
102
+ getter: (row) => row[key] ?? '',
103
+ sortGetter: (row) => row[key] ?? '',
104
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
105
+ filter: textFilter(key),
106
+ editComponent: TextEditableCell,
107
+ ...otherOptions,
108
+ });
109
+
110
+ export const dateColumn = <R extends Record<string, any>>(
111
+ key: string,
112
+ title: string,
113
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
114
+ otherOptions?: Partial<DataGridDateColumn<R>>
115
+ ): DataGridDateColumn<R> => ({
116
+ key,
117
+ type: 'date',
118
+ name: title,
119
+ render: (value) => (
120
+ <StyledTypography {...options?.typography}>
121
+ {formatDate(value)}
122
+ </StyledTypography>
123
+ ),
124
+ excelOptions: {
125
+ formatter: () => 'dd/mm/yyyy',
126
+ valueGetter: (value) => moment(value).format('DD/MM/YYYY') ?? '',
127
+ },
128
+ getter: (row) => row[key] ?? '',
129
+ sortGetter: (row) => row[key] ?? '',
130
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
131
+ filter: {
132
+ ...dateFilter(key),
133
+ renderer: (value) => moment(value).format('DD/MM/YYYY') ?? '',
134
+ },
135
+ editComponent: DateEditableCell,
136
+ ...otherOptions,
137
+ });
138
+
139
+ export const dateTimeColumn = <R extends Record<string, any>>(
140
+ key: string,
141
+ title: string,
142
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
143
+ otherOptions?: Partial<DataGridDateColumn<R>>
144
+ ): DataGridDateColumn<R> => ({
145
+ key,
146
+ type: 'date',
147
+ name: title,
148
+ render: (value) => (
149
+ <StyledTypography {...options?.typography}>
150
+ {formatDateTime(value)}
151
+ </StyledTypography>
152
+ ),
153
+ excelOptions: {
154
+ formatter: () => 'dd/mm/yyyy hh:mm:ss',
155
+ valueGetter: (value) => moment(value).format('DD/MM/YYYY HH:mm:ss') ?? '',
156
+ },
157
+ getter: (row) => row[key] ?? '',
158
+ sortGetter: (row) => row[key] ?? '',
159
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
160
+ filter: {
161
+ ...dateFilter(key),
162
+ renderer: (value) => moment(value).format('DD/MM/YYYY HH:mm:ss') ?? '',
163
+ },
164
+ editComponent: DateEditableCell,
165
+ ...otherOptions,
166
+ });
167
+
168
+ export const monthColumn = <R extends Record<string, any>>(
169
+ key: string,
170
+ title: string,
171
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
172
+ otherOptions?: Partial<DataGridTextColumn<R>>
173
+ ): DataGridTextColumn<R> => ({
174
+ key,
175
+ type: 'text',
176
+ name: title,
177
+ render: (value) => (
178
+ <StyledTypography {...options?.typography}>
179
+ {value + 'Mois'}
180
+ </StyledTypography>
181
+ ),
182
+ getter: (row) => row[key] ?? '',
183
+ sortGetter: (row) => row[key] ?? '',
184
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
185
+ filter: textFilter(key),
186
+ ...otherOptions,
187
+ });
188
+
189
+ export const numberColumn = <R extends Record<string, any>>(
190
+ key: string,
191
+ title: string,
192
+ decimals = 2,
193
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
194
+ otherOptions?: Partial<DataGridNumberColumn<R>>
195
+ ): DataGridNumberColumn<R> => {
196
+ const column: DataGridNumberColumn<R> = {
197
+ key,
198
+ type: 'number',
199
+ name: title,
200
+ render: (value) => (
201
+ <StyledTypography {...options?.typography}>
202
+ {formatNumber(value, decimals)}
203
+ </StyledTypography>
204
+ ),
205
+ excelOptions: {
206
+ formatter: () => buildExcelFormat(decimals),
207
+ valueGetter: (value) => formatNumberInvariant(value, decimals),
208
+ },
209
+ getter: (row) => row[key] ?? '',
210
+ sortGetter: (row) => row[key] ?? '',
211
+ footer: {
212
+ sum: (_, filteredRows) =>
213
+ formatNumber(
214
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
215
+ decimals
216
+ ),
217
+ average: (_, filteredRows) =>
218
+ formatNumber(
219
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
220
+ (filteredRows.length || 1),
221
+ decimals
222
+ ),
223
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
224
+ max: (_, filteredRows) =>
225
+ formatNumber(
226
+ Math.max(...filteredRows.map((row) => row[key] ?? 0)),
227
+ decimals
228
+ ),
229
+ min: (_, filteredRows) =>
230
+ formatNumber(
231
+ Math.min(...filteredRows.map((row) => row[key] ?? 0)),
232
+ decimals
233
+ ),
234
+ },
235
+ filter: {
236
+ ...numberFilter(key),
237
+ renderer: (value) => formatNumber(value, decimals) ?? '',
238
+ },
239
+ editComponent: forwardRefWithName(
240
+ (props, ref: Ref<HTMLInputElement>) => (
241
+ <NumberEditableCell<R>
242
+ ref={ref}
243
+ decimals={column.decimals}
244
+ currency={column.currency}
245
+ {...props}
246
+ />
247
+ ),
248
+ 'NumberColumnEditComponent'
249
+ ),
250
+ ...otherOptions,
251
+ };
252
+ return column;
253
+ };
254
+
255
+ export const moneyColumn = <R extends Record<string, any>>(
256
+ key: string,
257
+ title: string,
258
+ decimals = 2,
259
+ currency: string | ((row: R) => string) = '€',
260
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
261
+ otherOptions?: Partial<DataGridNumberColumn<R>>
262
+ ): DataGridNumberColumn<R> => {
263
+ const column: DataGridNumberColumn<R> = {
264
+ key,
265
+ type: 'number',
266
+ name: title,
267
+ render:
268
+ typeof currency === 'function'
269
+ ? (value, row) => (
270
+ <StyledTypography {...options?.typography}>
271
+ {formatMoney(value, decimals, currency(row))}
272
+ </StyledTypography>
273
+ )
274
+ : (value) => (
275
+ <StyledTypography {...options?.typography}>
276
+ {formatMoney(value, decimals, currency)}
277
+ </StyledTypography>
278
+ ),
279
+ excelOptions: {
280
+ formatter: () => buildExcelFormat(decimals, ' €'),
281
+ valueGetter: (value) => formatNumberInvariant(value, decimals),
282
+ },
283
+ getter: (row) => row[key] ?? '',
284
+ sortGetter: (row) => row[key] ?? '',
285
+ filter: {
286
+ ...numberFilter(key),
287
+ renderer: (value) => formatMoney(value, decimals) ?? '',
288
+ },
289
+ footer: {
290
+ sum: (_, filteredRows) =>
291
+ formatMoney(
292
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
293
+ decimals
294
+ ),
295
+ average: (_, filteredRows) =>
296
+ formatMoney(
297
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
298
+ (filteredRows.length || 1),
299
+ decimals
300
+ ),
301
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
302
+ max: (_, filteredRows) =>
303
+ formatMoney(
304
+ Math.max(...filteredRows.map((row) => row[key] ?? 0)),
305
+ decimals
306
+ ),
307
+ min: (_, filteredRows) =>
308
+ formatMoney(
309
+ Math.min(...filteredRows.map((row) => row[key] ?? 0)),
310
+ decimals
311
+ ),
312
+ },
313
+ ...otherOptions,
314
+ };
315
+ return column;
316
+ };
317
+
318
+ export const percentageColumn = <R extends Record<string, any>>(
319
+ key: string,
320
+ title: string,
321
+ decimals = 2,
322
+ options?: DeepPartial<SqlRequestDataGridTextColumn<R>>,
323
+ otherOptions?: Partial<DataGridNumberColumn<R>>
324
+ ): DataGridNumberColumn<R> => {
325
+ const column: DataGridNumberColumn<R> = {
326
+ key,
327
+ type: 'number',
328
+ name: title,
329
+ render: (value) => (
330
+ <StyledTypography {...options?.typography}>
331
+ {formatPercentage(value)}
332
+ </StyledTypography>
333
+ ),
334
+ excelOptions: {
335
+ formatter: () => buildExcelFormat(decimals, '%'),
336
+ valueGetter: (value) => formatNumberInvariant(value, decimals),
337
+ },
338
+ getter: (row) => row[key] ?? '',
339
+ sortGetter: (row) => row[key] ?? '',
340
+ filter: numberFilter(key),
341
+ footer: {
342
+ average: (_, filteredRows) =>
343
+ formatNumber(
344
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0) /
345
+ (filteredRows.length || 1),
346
+ decimals
347
+ ),
348
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
349
+ max: (_, filteredRows) =>
350
+ formatNumber(
351
+ Math.max(...filteredRows.map((row) => row[key] ?? 0)),
352
+ decimals
353
+ ),
354
+ min: (_, filteredRows) =>
355
+ formatNumber(
356
+ Math.min(...filteredRows.map((row) => row[key] ?? 0)),
357
+ decimals
358
+ ),
359
+ sum: (_, filteredRows) =>
360
+ formatNumber(
361
+ filteredRows.reduce((acc, row) => acc + (row[key] ?? 0), 0),
362
+ decimals
363
+ ),
364
+ },
365
+ ...otherOptions,
366
+ };
367
+ return column;
368
+ };
369
+
370
+ export const checkboxColumn = <R extends Record<string, any>>(
371
+ key: string,
372
+ title: string,
373
+ otherOptions?: Partial<DataGridCheckboxColumn<R>>
374
+ ): DataGridCheckboxColumn<R> => ({
375
+ key,
376
+ type: 'checkbox',
377
+ name: title,
378
+ render: (value, row) => (
379
+ <>
380
+ <input type="checkbox" checked={row[key]} readOnly />
381
+ <span>{row[key] ? ' Oui' : ' Non'}</span>
382
+ </>
383
+ ),
384
+ getter: (row) => row[key] ?? '',
385
+ sortGetter: (row) => row[key] ?? '',
386
+ filter: numberFilter(key),
387
+ footer: {
388
+ count: (_, filteredRows) => `${filteredRows.length} éléments`,
389
+ checked: (_, filteredRows) =>
390
+ `${filteredRows.filter((row) => !!row[key]).length} cochés`,
391
+ unchecked: (_, filteredRows) =>
392
+ `${filteredRows.filter((row) => !row[key]).length} décochés`,
393
+ },
394
+ editComponent: CheckboxEditableCell,
395
+ ...otherOptions,
396
+ });
397
+
398
+ export const selectColumn = <R extends Record<string, any>, T>(
399
+ key: string,
400
+ title: string,
401
+ items: T[],
402
+ itemKey: (item: T | null) => string,
403
+ itemLabel: (item: T | null) => string,
404
+ otherOptions?: Partial<DataGridSelectColumn<R, T>>
405
+ ): DataGridSelectColumn<R, T> => ({
406
+ key,
407
+ type: 'select',
408
+ name: title,
409
+ render: (value, row) => itemLabel(row[key]) ?? '',
410
+ getter: (row) => row[key] ?? null,
411
+ sortGetter: (row) => itemLabel(row[key]) ?? '',
412
+ footer: (_, filteredRows) => `${filteredRows.length} éléments`,
413
+ filter: {
414
+ ...textFilter(key),
415
+ renderer: (value) => itemLabel(value) ?? '',
416
+ },
417
+ items,
418
+ itemKey,
419
+ itemLabel,
420
+ editComponent: forwardRefWithName(
421
+ ({ value, onChange, onClose }, ref: Ref<HTMLSelectElement>) => (
422
+ <Select<T>
423
+ ref={ref}
424
+ items={items}
425
+ itemKey={itemKey}
426
+ itemLabel={itemLabel}
427
+ value={value}
428
+ onChange={onChange}
429
+ onBlur={() => onClose(true)}
430
+ />
431
+ ),
432
+ 'SelectColumnEditComponent'
433
+ ),
434
+ ...otherOptions,
435
+ });
436
+
437
+ export const colorColumn = <R extends Record<string, any>>(
438
+ key: string,
439
+ title: string,
440
+ otherOptions?: Partial<DataGridColorColumn<R>>
441
+ ): DataGridColorColumn<R> => ({
442
+ key,
443
+ type: 'color',
444
+ name: title,
445
+ render: (value, row) => (
446
+ <div style={{ backgroundColor: row[key] }}>{row[key] ?? ''}</div>
447
+ ),
448
+ getter: (row) => row[key] ?? '',
449
+ sortGetter: (row) => row[key] ?? '',
450
+ filter: textFilter(key),
451
+ footer: (rows) => `${rows.length} éléments`,
452
+ ...otherOptions,
453
+ });