@addev-be/ui 0.2.13 → 0.2.15

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