@addev-be/ui 0.2.5 → 0.2.7

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 (166) hide show
  1. package/assets/icons/arrow-down-1-9.svg +1 -0
  2. package/assets/icons/arrow-down-a-z.svg +1 -1
  3. package/assets/icons/arrow-down-big-small.svg +1 -0
  4. package/assets/icons/arrow-up-9-1.svg +1 -0
  5. package/assets/icons/arrow-up-big-small.svg +1 -0
  6. package/assets/icons/arrow-up-z-a.svg +1 -1
  7. package/assets/icons/check.svg +1 -1
  8. package/assets/icons/chevron-down.svg +1 -0
  9. package/assets/icons/down.svg +1 -1
  10. package/assets/icons/ellipsis.svg +1 -0
  11. package/assets/icons/filter-full.svg +1 -1
  12. package/assets/icons/filter.svg +1 -1
  13. package/assets/icons/hashtag.svg +1 -1
  14. package/assets/icons/image-slash.svg +1 -1
  15. package/assets/icons/left.svg +1 -1
  16. package/assets/icons/magnifier.svg +1 -1
  17. package/assets/icons/phone.svg +1 -1
  18. package/assets/icons/right.svg +1 -1
  19. package/assets/icons/sigma.svg +1 -0
  20. package/assets/icons/spinner-third.svg +1 -1
  21. package/assets/icons/table-columns.svg +1 -1
  22. package/assets/icons/table-footer-slash.svg +5 -0
  23. package/assets/icons/table-footer.svg +4 -0
  24. package/assets/icons/table.svg +1 -0
  25. package/assets/icons/tally.svg +1 -0
  26. package/assets/icons/up.svg +1 -1
  27. package/assets/icons/user-tie.svg +1 -1
  28. package/assets/icons/x-bar.svg +4 -0
  29. package/dist/Icons.d.ts +13 -1
  30. package/dist/Icons.js +25 -1
  31. package/dist/components/data/AdvancedRequestDataGrid/index.js +3 -3
  32. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +1 -2
  33. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +3 -5
  34. package/dist/components/data/DataGrid/DataGridCell.d.ts +1 -1
  35. package/dist/components/data/DataGrid/DataGridCell.js +5 -5
  36. package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.js +2 -1
  37. package/dist/components/data/DataGrid/DataGridEditableCell.js +2 -7
  38. package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +90 -10
  39. package/dist/components/data/DataGrid/DataGridFilterMenu/styles.d.ts +3 -9
  40. package/dist/components/data/DataGrid/DataGridFilterMenu/styles.js +10 -37
  41. package/dist/components/data/DataGrid/DataGridFooter.d.ts +1 -1
  42. package/dist/components/data/DataGrid/DataGridFooter.js +35 -22
  43. package/dist/components/data/DataGrid/DataGridHeader.js +1 -3
  44. package/dist/components/data/DataGrid/DataGridHeaderCell.js +8 -23
  45. package/dist/components/data/DataGrid/FilterModalContent/index.d.ts +5 -5
  46. package/dist/components/data/DataGrid/FilterModalContent/index.js +11 -9
  47. package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +8 -7
  48. package/dist/components/data/DataGrid/FilterValuesScroller.js +5 -6
  49. package/dist/components/data/DataGrid/helpers/columns.d.ts +1 -1
  50. package/dist/components/data/DataGrid/helpers/columns.js +72 -20
  51. package/dist/components/data/DataGrid/helpers/filters.d.ts +4 -3
  52. package/dist/components/data/DataGrid/helpers/filters.js +13 -5
  53. package/dist/components/data/DataGrid/hooks/useDataGrid.d.ts +1 -1
  54. package/dist/components/data/DataGrid/hooks/useDataGrid.js +60 -30
  55. package/dist/components/data/DataGrid/hooks/useDataGridCopy.d.ts +2 -2
  56. package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +41 -40
  57. package/dist/components/data/DataGrid/hooks/useDataGridSettings.js +0 -1
  58. package/dist/components/data/DataGrid/index.d.ts +4 -2
  59. package/dist/components/data/DataGrid/index.js +38 -17
  60. package/dist/components/data/DataGrid/styles.d.ts +12 -5
  61. package/dist/components/data/DataGrid/styles.js +31 -18
  62. package/dist/components/data/DataGrid/types.d.ts +28 -16
  63. package/dist/components/data/SqlRequestDataGrid/helpers/columns.d.ts +1 -1
  64. package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +30 -19
  65. package/dist/components/data/SqlRequestDataGrid/index.js +125 -37
  66. package/dist/components/data/SqlRequestDataGrid/types.d.ts +1 -0
  67. package/dist/components/data/index.d.ts +2 -0
  68. package/dist/components/data/index.js +2 -0
  69. package/dist/components/ui/ContextMenu/index.d.ts +11 -0
  70. package/dist/components/ui/ContextMenu/index.js +58 -0
  71. package/dist/components/ui/ContextMenu/styles.d.ts +18 -0
  72. package/dist/components/ui/ContextMenu/styles.js +56 -0
  73. package/dist/helpers/dates.d.ts +2 -0
  74. package/dist/helpers/dates.js +13 -0
  75. package/dist/services/advancedRequests.d.ts +1 -1
  76. package/dist/services/sqlRequests.d.ts +9 -4
  77. package/dist/services/sqlRequests.js +1 -0
  78. package/package.json +1 -1
  79. package/src/Icons.tsx +104 -80
  80. package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -93
  81. package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -262
  82. package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -2
  83. package/src/components/data/AdvancedRequestDataGrid/index.tsx +267 -269
  84. package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -47
  85. package/src/components/data/DataGrid/DataGridCell.tsx +73 -73
  86. package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -14
  87. package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -58
  88. package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -181
  89. package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
  90. package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -54
  91. package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -75
  92. package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +364 -190
  93. package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +49 -100
  94. package/src/components/data/DataGrid/DataGridFooter.tsx +42 -64
  95. package/src/components/data/DataGrid/DataGridHeader.tsx +126 -126
  96. package/src/components/data/DataGrid/DataGridHeaderCell.tsx +132 -167
  97. package/src/components/data/DataGrid/FilterModalContent/index.tsx +124 -125
  98. package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
  99. package/src/components/data/DataGrid/FilterValuesScroller.tsx +133 -131
  100. package/src/components/data/DataGrid/VirtualScroller.tsx +46 -46
  101. package/src/components/data/DataGrid/helpers/columns.tsx +287 -196
  102. package/src/components/data/DataGrid/helpers/filters.ts +220 -207
  103. package/src/components/data/DataGrid/helpers/index.ts +2 -2
  104. package/src/components/data/DataGrid/hooks/index.ts +30 -30
  105. package/src/components/data/DataGrid/hooks/useDataGrid.tsx +305 -264
  106. package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +170 -165
  107. package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -48
  108. package/src/components/data/DataGrid/index.tsx +139 -132
  109. package/src/components/data/DataGrid/styles.ts +347 -326
  110. package/src/components/data/DataGrid/types.ts +260 -240
  111. package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +259 -224
  112. package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
  113. package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -16
  114. package/src/components/data/SqlRequestDataGrid/index.tsx +347 -252
  115. package/src/components/data/SqlRequestDataGrid/types.ts +47 -47
  116. package/src/components/data/index.ts +8 -8
  117. package/src/components/forms/Button.tsx +99 -99
  118. package/src/components/forms/IconButton.tsx +56 -56
  119. package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
  120. package/src/components/forms/Select.tsx +40 -40
  121. package/src/components/forms/index.ts +5 -5
  122. package/src/components/forms/styles.ts +20 -20
  123. package/src/components/index.ts +3 -3
  124. package/src/components/layout/Dropdown/index.tsx +79 -79
  125. package/src/components/layout/Dropdown/styles.ts +44 -44
  126. package/src/components/layout/Loading/index.tsx +29 -29
  127. package/src/components/layout/Loading/styles.ts +29 -29
  128. package/src/components/layout/Modal/index.tsx +51 -51
  129. package/src/components/layout/Modal/styles.ts +110 -110
  130. package/src/components/layout/index.ts +3 -3
  131. package/src/components/ui/ContextMenu/index.tsx +73 -0
  132. package/src/components/ui/ContextMenu/styles.ts +115 -0
  133. package/src/config/index.ts +14 -14
  134. package/src/helpers/dates.ts +9 -9
  135. package/src/helpers/getScrollbarSize.ts +14 -14
  136. package/src/helpers/numbers.ts +20 -20
  137. package/src/hooks/index.ts +2 -2
  138. package/src/hooks/useElementSize.ts +24 -24
  139. package/src/hooks/useWindowSize.ts +20 -20
  140. package/src/index.ts +7 -7
  141. package/src/providers/PortalsProvider/index.tsx +54 -54
  142. package/src/providers/PortalsProvider/styles.ts +27 -27
  143. package/src/providers/SettingsProvider/index.tsx +70 -70
  144. package/src/providers/ThemeProvider/ThemeProvider.ts +55 -55
  145. package/src/providers/ThemeProvider/defaultTheme.ts +444 -444
  146. package/src/providers/ThemeProvider/index.ts +3 -3
  147. package/src/providers/ThemeProvider/types.ts +123 -123
  148. package/src/providers/UiProviders/index.tsx +65 -65
  149. package/src/providers/UiProviders/styles.ts +10 -10
  150. package/src/providers/hooks.ts +8 -8
  151. package/src/providers/index.ts +5 -5
  152. package/src/services/HttpService.ts +80 -80
  153. package/src/services/WebSocketService.ts +147 -147
  154. package/src/services/advancedRequests.ts +101 -101
  155. package/src/services/base.ts +31 -31
  156. package/src/services/hooks.ts +23 -23
  157. package/src/services/index.ts +2 -2
  158. package/src/services/sqlRequests.ts +110 -99
  159. package/src/styles/animations.scss +30 -30
  160. package/src/styles/index.scss +42 -42
  161. package/src/typings.d.ts +6 -6
  162. package/tsconfig.tsbuildinfo +1 -1
  163. package/dist/components/data/DataGrid/helpers.d.ts +0 -28
  164. package/dist/components/data/DataGrid/helpers.js +0 -436
  165. package/dist/config/types.d.ts +0 -11
  166. package/dist/config/types.js +0 -2
@@ -1,190 +1,364 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
-
4
- import * as styles from './styles';
5
-
6
- import { DataGridContext, MysqlJsonObject } from '../types';
7
- import { FilterIcon, FilterSlashIcon, MagnifierIcon } from '../../../../Icons';
8
- import { applyFilters, getDateGroups } from '../helpers';
9
- import { intersection, uniq, without } from 'lodash';
10
- import {
11
- useCallback,
12
- useContext,
13
- useEffect,
14
- useMemo,
15
- useRef,
16
- useState,
17
- } from 'react';
18
-
19
- import { FilterValuesScroller } from '../FilterValuesScroller';
20
- import { Input } from '../../../forms';
21
- import { useFilterModal } from './hooks';
22
-
23
- type FilterValuesProps<R> = {
24
- columnKey: string;
25
- columnIndex: number;
26
- context: DataGridContext<R>;
27
- onClose?: () => void;
28
- };
29
-
30
- export const DataGridFilterMenu = <R,>({
31
- columnKey,
32
- context,
33
- onClose,
34
- }: FilterValuesProps<R>) => {
35
- const { openModal, modal } = useFilterModal({ columnKey, context });
36
- const {
37
- filters = {},
38
- rows,
39
- columns,
40
- setFilters,
41
- filterValuesLoader,
42
- } = useContext(context);
43
- const column = columns[columnKey] ?? {};
44
- const textFilterInputRef = useRef<HTMLInputElement>(null);
45
- const [textFilter, setTextFilter] = useState('');
46
-
47
- const [availableValues, setAvailableValues] = useState<
48
- (string | number | null | MysqlJsonObject)[]
49
- >([]);
50
-
51
- useEffect(() => {
52
- if (filterValuesLoader) {
53
- filterValuesLoader(columnKey).then((values) => {
54
- setAvailableValues(() => values);
55
- });
56
- } else {
57
- const otherFilters = Object.entries(filters)
58
- .filter(([key]) => key !== columnKey)
59
- .map(([, filter]) => filter);
60
- const availableRows = applyFilters(rows, otherFilters);
61
- const values = availableRows.map((row) => column.filter!.getter(row));
62
- setAvailableValues(() => uniq(values).sort());
63
- }
64
- }, [column.filter, columnKey, filterValuesLoader, filters, rows]);
65
-
66
- const selectedValues = useMemo(
67
- () => filters?.[columnKey]?.values ?? [],
68
- [columnKey, filters]
69
- );
70
-
71
- const clearFilter = useCallback(() => {
72
- const newFilters = { ...filters };
73
- delete newFilters[columnKey];
74
- setFilters(newFilters);
75
- onClose?.();
76
- }, [filters, columnKey, setFilters, onClose]);
77
-
78
- const setValuesChecked = useCallback(
79
- (values: any[], checked?: boolean) => {
80
- setFilters((prevFilters) => {
81
- const newValues = checked
82
- ? [...(prevFilters[columnKey]?.values ?? []), ...values]
83
- : without(prevFilters[columnKey]?.values ?? [], ...values);
84
- const newFilters = {
85
- ...prevFilters,
86
- };
87
- if (newValues.length === 0) {
88
- delete newFilters[columnKey];
89
- } else {
90
- newFilters[columnKey] = {
91
- ...(prevFilters[columnKey] ?? column.filter),
92
- operator: 'inArray',
93
- values: newValues,
94
- };
95
- }
96
- return newFilters;
97
- });
98
- },
99
- [setFilters, columnKey, column.filter]
100
- );
101
-
102
- const toggleValues = useCallback(
103
- (values: any[]) => {
104
- const checked =
105
- intersection(selectedValues, values).length === values.length;
106
- setValuesChecked(values, !checked);
107
- },
108
- [setValuesChecked, selectedValues]
109
- );
110
-
111
- const formatter = useMemo(
112
- () =>
113
- column.filter?.formatter ?? ((v: any) => (v === null ? null : String(v))),
114
- [column.filter?.formatter]
115
- );
116
-
117
- const filteredAvailableValues = useMemo(
118
- () =>
119
- !textFilter
120
- ? availableValues
121
- : availableValues.filter((value) =>
122
- formatter(value)?.toLowerCase().includes(textFilter.toLowerCase())
123
- ),
124
- [availableValues, formatter, textFilter]
125
- );
126
-
127
- useEffect(() => {
128
- if (textFilterInputRef.current) {
129
- textFilterInputRef.current.focus();
130
- }
131
- }, []);
132
-
133
- const checkboxesComponent = useMemo(() => {
134
- if (column.type === 'date') {
135
- const groups = getDateGroups(filteredAvailableValues);
136
- return (
137
- <FilterValuesScroller
138
- values={filteredAvailableValues}
139
- selectedValues={selectedValues}
140
- onToggle={toggleValues}
141
- formatter={formatter}
142
- groups={groups}
143
- />
144
- );
145
- }
146
- return (
147
- <FilterValuesScroller
148
- values={filteredAvailableValues}
149
- selectedValues={selectedValues}
150
- onToggle={toggleValues}
151
- formatter={formatter}
152
- />
153
- );
154
- }, [
155
- column.type,
156
- filteredAvailableValues,
157
- formatter,
158
- selectedValues,
159
- toggleValues,
160
- ]);
161
-
162
- return (
163
- <styles.Menu onClick={(e) => e.stopPropagation()}>
164
- {modal}
165
- <styles.MenuItem onClick={openModal}>
166
- <FilterIcon />
167
- Filtrer ...
168
- </styles.MenuItem>
169
- <styles.MenuItem $color="danger" onClick={clearFilter}>
170
- <FilterSlashIcon />
171
- Supprimer le filtre
172
- </styles.MenuItem>
173
- <styles.InputContainer>
174
- <MagnifierIcon />
175
- <Input
176
- ref={textFilterInputRef}
177
- type="text"
178
- name="search"
179
- id="search"
180
- placeholder="Rechercher ..."
181
- value={textFilter}
182
- onChange={(e) => setTextFilter(e.target.value)}
183
- />
184
- </styles.InputContainer>
185
- <styles.CheckboxesContainer>
186
- {checkboxesComponent}
187
- </styles.CheckboxesContainer>
188
- </styles.Menu>
189
- );
190
- };
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
3
+
4
+ import * as styles from './styles';
5
+
6
+ import {
7
+ ArrowDown19Icon,
8
+ ArrowDownAZIcon,
9
+ ArrowDownBigSmallIcon,
10
+ ArrowUp91Icon,
11
+ ArrowUpBigSmallIcon,
12
+ ArrowUpZAIcon,
13
+ FilterIcon,
14
+ FilterSlashIcon,
15
+ IconFC,
16
+ MagnifierIcon,
17
+ SigmaIcon,
18
+ TableFooterIcon,
19
+ TableFooterSlashIcon,
20
+ TallyIcon,
21
+ XBarIcon,
22
+ } from '../../../../Icons';
23
+ import {
24
+ DataGridContext,
25
+ DataGridFilterType,
26
+ DataGridFilterValue,
27
+ DataGridFooterPredefinedFunction,
28
+ } from '../types';
29
+ import {
30
+ applyFilters,
31
+ defaultRendererAndFormatter,
32
+ getDateGroups,
33
+ } from '../helpers';
34
+ import { intersection, uniq, without } from 'lodash';
35
+ import {
36
+ useCallback,
37
+ useContext,
38
+ useEffect,
39
+ useMemo,
40
+ useRef,
41
+ useState,
42
+ } from 'react';
43
+
44
+ import { ContextMenu } from '../../../ui/ContextMenu';
45
+ import { FilterValuesScroller } from '../FilterValuesScroller';
46
+ import { Input } from '../../../forms';
47
+ import { useFilterModal } from './hooks';
48
+
49
+ type FilterValuesProps<R> = {
50
+ columnKey: string;
51
+ columnIndex: number;
52
+ context: DataGridContext<R>;
53
+ onClose?: () => void;
54
+ };
55
+
56
+ const sortAsc: Record<DataGridFilterType, [string, IconFC]> = {
57
+ number: ['Trier du plus petit au plus grand', ArrowDown19Icon],
58
+ text: ['Trier de A à Z', ArrowDownAZIcon],
59
+ // date: 'Trier du plus ancien au plus récent',
60
+ };
61
+ const sortDesc: Record<DataGridFilterType, [string, IconFC]> = {
62
+ number: ['Trier du plus grand au plus petit', ArrowUp91Icon],
63
+ text: ['Trier de Z à A', ArrowUpZAIcon],
64
+ // date: 'Trier du plus récent au plus ancien',
65
+ };
66
+
67
+ const footerFunctionsTexts: Record<DataGridFooterPredefinedFunction, string> = {
68
+ average: 'Moyenne',
69
+ count: 'Nombre',
70
+ max: 'Maximum',
71
+ min: 'Minimum',
72
+ sum: 'Somme',
73
+ };
74
+ const footerFunctionsIcons: Record<DataGridFooterPredefinedFunction, IconFC> = {
75
+ average: XBarIcon,
76
+ count: TallyIcon,
77
+ max: ArrowUpBigSmallIcon,
78
+ min: ArrowDownBigSmallIcon,
79
+ sum: SigmaIcon,
80
+ };
81
+
82
+ export const DataGridFilterMenu = <R,>({
83
+ columnKey,
84
+ context,
85
+ onClose,
86
+ }: FilterValuesProps<R>) => {
87
+ const { openModal, modal } = useFilterModal({ columnKey, context });
88
+ const {
89
+ filters = {},
90
+ footers = {},
91
+ rows,
92
+ columns,
93
+ setFilters,
94
+ filterValuesLoader,
95
+ setSorts,
96
+ setFooters,
97
+ } = useContext(context);
98
+ const column = columns[columnKey] ?? {};
99
+ const textFilterInputRef = useRef<HTMLInputElement>(null);
100
+ const [textFilter, setTextFilter] = useState('');
101
+
102
+ const [availableValues, setAvailableValues] = useState<DataGridFilterValue[]>(
103
+ []
104
+ );
105
+
106
+ useEffect(() => {
107
+ if (filterValuesLoader) {
108
+ filterValuesLoader(columnKey).then((values) => {
109
+ setAvailableValues(() => values);
110
+ });
111
+ } else {
112
+ const otherFilters = Object.entries(filters)
113
+ .filter(([key]) => key !== columnKey)
114
+ .map(([, filter]) => filter);
115
+ const availableRows = applyFilters(rows, otherFilters);
116
+ const values = availableRows.map((row) => column.filter!.getter(row));
117
+ setAvailableValues(() =>
118
+ uniq(values).sort(
119
+ column.filter?.type === 'number'
120
+ ? (a, b) => (a as number) - (b as number)
121
+ : (a, b) => (a as string).localeCompare(b as string)
122
+ )
123
+ );
124
+ }
125
+ }, [column.filter, columnKey, filterValuesLoader, filters, rows]);
126
+
127
+ const selectedValues = useMemo(
128
+ () => filters?.[columnKey]?.values ?? [],
129
+ [columnKey, filters]
130
+ );
131
+
132
+ const clearFilter = useCallback(() => {
133
+ const newFilters = { ...filters };
134
+ delete newFilters[columnKey];
135
+ setFilters(newFilters);
136
+ onClose?.();
137
+ }, [filters, columnKey, setFilters, onClose]);
138
+
139
+ const setValuesChecked = useCallback(
140
+ (values: any[], checked?: boolean) => {
141
+ setFilters((prevFilters) => {
142
+ const newValues = checked
143
+ ? [...(prevFilters[columnKey]?.values ?? []), ...values]
144
+ : without(prevFilters[columnKey]?.values ?? [], ...values);
145
+ const newFilters = {
146
+ ...prevFilters,
147
+ };
148
+ if (newValues.length === 0) {
149
+ delete newFilters[columnKey];
150
+ } else {
151
+ newFilters[columnKey] = {
152
+ ...(prevFilters[columnKey] ?? column.filter),
153
+ operator: 'inArray',
154
+ values: newValues,
155
+ };
156
+ }
157
+ return newFilters;
158
+ });
159
+ },
160
+ [setFilters, columnKey, column.filter]
161
+ );
162
+
163
+ const toggleValues = useCallback(
164
+ (values: DataGridFilterValue[]) => {
165
+ const checked =
166
+ intersection(selectedValues, values).length === values.length;
167
+ setValuesChecked(values, !checked);
168
+ },
169
+ [setValuesChecked, selectedValues]
170
+ );
171
+
172
+ const formatter = useMemo(
173
+ () => column.filter?.formatter ?? defaultRendererAndFormatter,
174
+ [column.filter?.formatter]
175
+ );
176
+ const renderer = useMemo(
177
+ () => column.filter?.renderer ?? defaultRendererAndFormatter,
178
+ [column.filter?.renderer]
179
+ );
180
+
181
+ const filteredAvailableValues = useMemo(
182
+ () =>
183
+ !textFilter
184
+ ? availableValues
185
+ : availableValues.filter((value) =>
186
+ formatter(value)?.toLowerCase().includes(textFilter.toLowerCase())
187
+ ),
188
+ [availableValues, formatter, textFilter]
189
+ );
190
+
191
+ useEffect(() => {
192
+ if (textFilterInputRef.current) {
193
+ textFilterInputRef.current.focus();
194
+ }
195
+ }, []);
196
+
197
+ const checkboxesComponent = useMemo(() => {
198
+ if (column.type === 'date') {
199
+ const groups = getDateGroups(filteredAvailableValues);
200
+ return (
201
+ <FilterValuesScroller
202
+ values={filteredAvailableValues}
203
+ selectedValues={selectedValues}
204
+ onToggle={toggleValues}
205
+ formatter={formatter}
206
+ renderer={renderer}
207
+ groups={groups}
208
+ />
209
+ );
210
+ }
211
+ return (
212
+ <FilterValuesScroller
213
+ values={filteredAvailableValues}
214
+ selectedValues={selectedValues}
215
+ onToggle={toggleValues}
216
+ formatter={formatter}
217
+ renderer={renderer}
218
+ />
219
+ );
220
+ }, [
221
+ column.type,
222
+ filteredAvailableValues,
223
+ formatter,
224
+ renderer,
225
+ selectedValues,
226
+ toggleValues,
227
+ ]);
228
+
229
+ const onSortAscClicked = useCallback(() => {
230
+ setSorts({ [columnKey]: 'asc' });
231
+ onClose?.();
232
+ }, [columnKey, onClose, setSorts]);
233
+ const onSortDescClicked = useCallback(() => {
234
+ setSorts({ [columnKey]: 'desc' });
235
+ onClose?.();
236
+ }, [columnKey, onClose, setSorts]);
237
+
238
+ const hasFilters = filters[columnKey]?.values.length > 0;
239
+ const [[sortAscText, SortAscIcon], [sortDescText, SortDescIcon]] = [
240
+ sortAsc[column.filter?.type ?? 'text'],
241
+ sortDesc[column.filter?.type ?? 'text'],
242
+ ];
243
+
244
+ const isFooterVisible =
245
+ columnKey in footers && footers[columnKey] !== undefined;
246
+ const showFooter = useCallback(
247
+ (key: string) => {
248
+ setFooters((prevFooters) => ({
249
+ ...prevFooters,
250
+ [columnKey]: key,
251
+ }));
252
+ onClose?.();
253
+ },
254
+ [columnKey, onClose, setFooters]
255
+ );
256
+ const hideFooter = useCallback(() => {
257
+ setFooters((prevFooters) => {
258
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
259
+ const { [columnKey]: _, ...newFooters } = prevFooters;
260
+ return newFooters;
261
+ });
262
+ onClose?.();
263
+ }, [columnKey, onClose, setFooters]);
264
+
265
+ return (
266
+ <ContextMenu>
267
+ {modal}
268
+ {column.sortGetter && (
269
+ <>
270
+ <ContextMenu.Item onClick={onSortAscClicked}>
271
+ <SortAscIcon />
272
+ {sortAscText}
273
+ </ContextMenu.Item>
274
+ <ContextMenu.Item onClick={onSortDescClicked}>
275
+ <SortDescIcon />
276
+ {sortDescText}
277
+ </ContextMenu.Item>
278
+ <ContextMenu.Divider />
279
+ </>
280
+ )}
281
+ {isFooterVisible && typeof column.footer === 'function' && (
282
+ <>
283
+ <ContextMenu.Item onClick={hideFooter}>
284
+ <TableFooterSlashIcon />
285
+ Masquer le total
286
+ </ContextMenu.Item>
287
+ <ContextMenu.Divider />
288
+ </>
289
+ )}
290
+ {!isFooterVisible && typeof column.footer === 'function' && (
291
+ <>
292
+ <ContextMenu.Item onClick={() => showFooter('count')}>
293
+ <TableFooterIcon />
294
+ Afficher le total
295
+ </ContextMenu.Item>
296
+ <ContextMenu.Divider />
297
+ </>
298
+ )}
299
+ {typeof column.footer === 'object' && (
300
+ <>
301
+ <ContextMenu.ParentItem>
302
+ <TableFooterIcon />
303
+ Afficher le total
304
+ <ContextMenu.SubMenu>
305
+ {Object.keys(column.footer).map((key) => {
306
+ const TotalIcon =
307
+ footerFunctionsIcons[
308
+ key as DataGridFooterPredefinedFunction
309
+ ] ?? TableFooterIcon;
310
+ return (
311
+ <ContextMenu.Item key={key} onClick={() => showFooter(key)}>
312
+ <TotalIcon />
313
+ {key in footerFunctionsTexts
314
+ ? footerFunctionsTexts[
315
+ key as DataGridFooterPredefinedFunction
316
+ ]
317
+ : key}
318
+ </ContextMenu.Item>
319
+ );
320
+ })}
321
+ <ContextMenu.Divider />
322
+ <ContextMenu.Item
323
+ onClick={hideFooter}
324
+ disabled={!isFooterVisible}
325
+ >
326
+ <TableFooterSlashIcon />
327
+ Masquer le total
328
+ </ContextMenu.Item>
329
+ </ContextMenu.SubMenu>
330
+ </ContextMenu.ParentItem>
331
+ <ContextMenu.Divider />
332
+ </>
333
+ )}
334
+ <ContextMenu.Item onClick={openModal}>
335
+ <FilterIcon />
336
+ Filtrer ...
337
+ </ContextMenu.Item>
338
+ <ContextMenu.Item
339
+ $color="danger"
340
+ onClick={clearFilter}
341
+ disabled={!hasFilters}
342
+ >
343
+ <FilterSlashIcon />
344
+ Supprimer le filtre
345
+ </ContextMenu.Item>
346
+ <ContextMenu.Divider />
347
+ <styles.InputContainer>
348
+ <MagnifierIcon />
349
+ <Input
350
+ ref={textFilterInputRef}
351
+ type="text"
352
+ name="search"
353
+ id="search"
354
+ placeholder="Rechercher ..."
355
+ value={textFilter}
356
+ onChange={(e) => setTextFilter(e.target.value)}
357
+ />
358
+ </styles.InputContainer>
359
+ <styles.CheckboxesContainer>
360
+ {checkboxesComponent}
361
+ </styles.CheckboxesContainer>
362
+ </ContextMenu>
363
+ );
364
+ };