@addev-be/ui 0.2.2 → 0.2.6

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 (168) hide show
  1. package/assets/icons/arrow-down-a-z.svg +1 -1
  2. package/assets/icons/arrow-up-z-a.svg +1 -1
  3. package/assets/icons/check.svg +1 -1
  4. package/assets/icons/down.svg +1 -1
  5. package/assets/icons/filter-full.svg +1 -1
  6. package/assets/icons/filter.svg +1 -1
  7. package/assets/icons/hashtag.svg +1 -1
  8. package/assets/icons/image-slash.svg +1 -1
  9. package/assets/icons/left.svg +1 -1
  10. package/assets/icons/magnifier.svg +1 -1
  11. package/assets/icons/phone.svg +1 -1
  12. package/assets/icons/right.svg +1 -1
  13. package/assets/icons/spinner-third.svg +1 -1
  14. package/assets/icons/table-columns.svg +1 -1
  15. package/assets/icons/up.svg +1 -1
  16. package/assets/icons/user-tie.svg +1 -1
  17. package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.d.ts +14 -0
  18. package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.js +76 -0
  19. package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.d.ts +22 -0
  20. package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.js +156 -0
  21. package/dist/components/data/AdvancedRequestDataGrid/helpers/index.d.ts +2 -0
  22. package/dist/components/data/AdvancedRequestDataGrid/helpers/index.js +18 -0
  23. package/dist/components/data/AdvancedRequestDataGrid/index.d.ts +2 -0
  24. package/dist/components/data/AdvancedRequestDataGrid/index.js +215 -0
  25. package/dist/components/data/AdvancedRequestDataGrid/types.d.ts +21 -0
  26. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.d.ts +1 -2
  27. package/dist/components/data/DataGrid/AdvancedRequestDataGrid.js +3 -5
  28. package/dist/components/data/DataGrid/DataGridCell.d.ts +1 -1
  29. package/dist/components/data/DataGrid/DataGridCell.js +6 -6
  30. package/dist/components/data/DataGrid/DataGridEditableCell.js +2 -7
  31. package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +10 -8
  32. package/dist/components/data/DataGrid/DataGridFooter.js +4 -14
  33. package/dist/components/data/DataGrid/DataGridHeader.js +60 -12
  34. package/dist/components/data/DataGrid/DataGridHeaderCell.js +6 -5
  35. package/dist/components/data/DataGrid/FilterModalContent/index.d.ts +5 -5
  36. package/dist/components/data/DataGrid/FilterModalContent/index.js +11 -9
  37. package/dist/components/data/DataGrid/FilterValuesScroller.d.ts +8 -7
  38. package/dist/components/data/DataGrid/FilterValuesScroller.js +5 -6
  39. package/dist/components/data/DataGrid/VirtualScroller.js +1 -6
  40. package/dist/components/data/DataGrid/helpers/columns.d.ts +12 -13
  41. package/dist/components/data/DataGrid/helpers/columns.js +17 -71
  42. package/dist/components/data/DataGrid/helpers/filters.d.ts +8 -7
  43. package/dist/components/data/DataGrid/helpers/filters.js +26 -21
  44. package/dist/components/data/DataGrid/helpers/index.d.ts +1 -2
  45. package/dist/components/data/DataGrid/helpers/index.js +1 -2
  46. package/dist/components/data/DataGrid/hooks/index.d.ts +2 -2
  47. package/dist/components/data/DataGrid/hooks/index.js +4 -4
  48. package/dist/components/data/DataGrid/hooks/useDataGrid.js +27 -5
  49. package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +0 -1
  50. package/dist/components/data/DataGrid/hooks/useDataGridSettings.js +0 -1
  51. package/dist/components/data/DataGrid/index.js +27 -20
  52. package/dist/components/data/DataGrid/styles.d.ts +7 -2
  53. package/dist/components/data/DataGrid/styles.js +13 -10
  54. package/dist/components/data/DataGrid/types.d.ts +47 -54
  55. package/dist/components/data/SqlRequestDataGrid/helpers/columns.d.ts +16 -0
  56. package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +112 -0
  57. package/dist/components/data/SqlRequestDataGrid/helpers/index.d.ts +2 -0
  58. package/dist/components/data/SqlRequestDataGrid/helpers/index.js +18 -0
  59. package/dist/components/data/SqlRequestDataGrid/helpers/sqlRequests.d.ts +3 -0
  60. package/dist/components/data/SqlRequestDataGrid/helpers/sqlRequests.js +18 -0
  61. package/dist/components/data/SqlRequestDataGrid/index.d.ts +2 -0
  62. package/dist/components/data/SqlRequestDataGrid/index.js +224 -0
  63. package/dist/components/data/SqlRequestDataGrid/types.d.ts +21 -0
  64. package/dist/components/data/SqlRequestDataGrid/types.js +2 -0
  65. package/dist/components/data/index.d.ts +7 -2
  66. package/dist/components/data/index.js +7 -2
  67. package/dist/components/forms/IconButton.js +1 -1
  68. package/dist/components/forms/IndeterminateCheckbox.js +1 -1
  69. package/dist/components/layout/Modal/index.js +1 -1
  70. package/dist/helpers/dates.d.ts +2 -0
  71. package/dist/helpers/dates.js +13 -0
  72. package/dist/providers/PortalsProvider/index.d.ts +1 -1
  73. package/dist/providers/PortalsProvider/index.js +1 -1
  74. package/dist/services/HttpService.d.ts +10 -0
  75. package/dist/services/HttpService.js +117 -0
  76. package/dist/services/advancedRequests.d.ts +3 -3
  77. package/dist/services/advancedRequests.js +2 -2
  78. package/dist/services/hooks.d.ts +2 -1
  79. package/dist/services/hooks.js +10 -3
  80. package/dist/services/sqlRequests.d.ts +40 -0
  81. package/dist/services/sqlRequests.js +10 -0
  82. package/package.json +1 -1
  83. package/src/Icons.tsx +80 -80
  84. package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -93
  85. package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -262
  86. package/src/components/data/AdvancedRequestDataGrid/helpers/index.ts +2 -2
  87. package/src/components/data/AdvancedRequestDataGrid/index.tsx +269 -269
  88. package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -47
  89. package/src/components/data/DataGrid/DataGridCell.tsx +73 -75
  90. package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -14
  91. package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +58 -58
  92. package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -181
  93. package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -104
  94. package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -54
  95. package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -75
  96. package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +200 -190
  97. package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +100 -100
  98. package/src/components/data/DataGrid/DataGridFooter.tsx +44 -64
  99. package/src/components/data/DataGrid/DataGridHeader.tsx +126 -128
  100. package/src/components/data/DataGrid/DataGridHeaderCell.tsx +167 -166
  101. package/src/components/data/DataGrid/FilterModalContent/index.tsx +124 -125
  102. package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -22
  103. package/src/components/data/DataGrid/FilterValuesScroller.tsx +133 -131
  104. package/src/components/data/DataGrid/VirtualScroller.tsx +46 -46
  105. package/src/components/data/DataGrid/helpers/columns.tsx +196 -199
  106. package/src/components/data/DataGrid/helpers/filters.ts +220 -207
  107. package/src/components/data/DataGrid/helpers/index.ts +2 -2
  108. package/src/components/data/DataGrid/hooks/index.ts +30 -30
  109. package/src/components/data/DataGrid/hooks/useDataGrid.tsx +264 -261
  110. package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +165 -166
  111. package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -49
  112. package/src/components/data/DataGrid/index.tsx +132 -133
  113. package/src/components/data/DataGrid/styles.ts +326 -299
  114. package/src/components/data/DataGrid/types.ts +241 -233
  115. package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +224 -206
  116. package/src/components/data/SqlRequestDataGrid/helpers/index.ts +2 -2
  117. package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -16
  118. package/src/components/data/SqlRequestDataGrid/index.tsx +252 -221
  119. package/src/components/data/SqlRequestDataGrid/types.ts +47 -46
  120. package/src/components/data/index.ts +8 -6
  121. package/src/components/forms/Button.tsx +99 -99
  122. package/src/components/forms/IconButton.tsx +56 -56
  123. package/src/components/forms/IndeterminateCheckbox.tsx +46 -46
  124. package/src/components/forms/Select.tsx +40 -40
  125. package/src/components/forms/index.ts +5 -5
  126. package/src/components/forms/styles.ts +20 -20
  127. package/src/components/index.ts +3 -3
  128. package/src/components/layout/Dropdown/index.tsx +79 -79
  129. package/src/components/layout/Dropdown/styles.ts +44 -44
  130. package/src/components/layout/Loading/index.tsx +29 -29
  131. package/src/components/layout/Loading/styles.ts +29 -29
  132. package/src/components/layout/Modal/index.tsx +51 -51
  133. package/src/components/layout/Modal/styles.ts +110 -110
  134. package/src/components/layout/index.ts +3 -3
  135. package/src/config/index.ts +14 -14
  136. package/src/helpers/dates.ts +9 -0
  137. package/src/helpers/getScrollbarSize.ts +14 -14
  138. package/src/helpers/numbers.ts +20 -20
  139. package/src/hooks/index.ts +2 -2
  140. package/src/hooks/useElementSize.ts +24 -24
  141. package/src/hooks/useWindowSize.ts +20 -20
  142. package/src/index.ts +7 -7
  143. package/src/providers/PortalsProvider/index.tsx +54 -54
  144. package/src/providers/PortalsProvider/styles.ts +27 -27
  145. package/src/providers/SettingsProvider/index.tsx +70 -70
  146. package/src/providers/ThemeProvider/ThemeProvider.ts +55 -55
  147. package/src/providers/ThemeProvider/defaultTheme.ts +444 -444
  148. package/src/providers/ThemeProvider/index.ts +3 -3
  149. package/src/providers/ThemeProvider/types.ts +123 -123
  150. package/src/providers/UiProviders/index.tsx +65 -65
  151. package/src/providers/UiProviders/styles.ts +10 -10
  152. package/src/providers/hooks.ts +8 -8
  153. package/src/providers/index.ts +5 -5
  154. package/src/services/HttpService.ts +80 -80
  155. package/src/services/WebSocketService.ts +147 -147
  156. package/src/services/advancedRequests.ts +101 -101
  157. package/src/services/base.ts +31 -31
  158. package/src/services/hooks.ts +23 -23
  159. package/src/services/index.ts +2 -2
  160. package/src/services/sqlRequests.ts +99 -98
  161. package/src/styles/animations.scss +30 -30
  162. package/src/styles/index.scss +42 -42
  163. package/src/typings.d.ts +6 -6
  164. package/tsconfig.tsbuildinfo +1 -1
  165. package/dist/components/data/DataGrid/helpers.d.ts +0 -28
  166. package/dist/components/data/DataGrid/helpers.js +0 -436
  167. package/dist/config/types.d.ts +0 -11
  168. /package/dist/{config → components/data/AdvancedRequestDataGrid}/types.js +0 -0
@@ -1,166 +1,167 @@
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
- ArrowDownAZIcon,
8
- ArrowUpZAIcon,
9
- ArrowsUpDownIcon,
10
- FilterFullIcon,
11
- FilterIcon,
12
- } from '../../../Icons';
13
- import { MouseEvent, useCallback, useMemo, useRef, useState } from 'react';
14
-
15
- import { DataGridFilterMenu } from './DataGridFilterMenu';
16
- import { DataGridHeaderCellProps } from './types';
17
- import { Dropdown } from '../../layout';
18
- import { IconButton } from '../../forms/IconButton';
19
- import { useDataGridContext } from './hooks';
20
- import { useUi } from '../../../providers';
21
-
22
- export const DataGridHeaderCell = <R,>({
23
- columnKey,
24
- columnIndex,
25
- column,
26
- context,
27
- }: DataGridHeaderCellProps<R>) => {
28
- const { getElementScreenRect } = useUi();
29
- const contextValue = useDataGridContext(context);
30
- const {
31
- filters = {},
32
- sorts = {},
33
- setSorts,
34
- setColumnWidth,
35
- saveSettings,
36
- headerColor,
37
- } = contextValue;
38
- const filterButtonRef = useRef<HTMLButtonElement | null>(null);
39
-
40
- /** SORTING */
41
- const SortIcon = sorts[columnKey]
42
- ? sorts[columnKey] === 'desc'
43
- ? ArrowUpZAIcon
44
- : ArrowDownAZIcon
45
- : ArrowsUpDownIcon;
46
-
47
- const onSortButtonClicked = useCallback(
48
- (columnKey: string) => {
49
- const sort = sorts[columnKey];
50
- if (!sort || sort === 'desc') {
51
- setSorts({ [columnKey]: 'asc' });
52
- } else {
53
- setSorts({ [columnKey]: 'desc' });
54
- }
55
- },
56
- [setSorts, sorts]
57
- );
58
-
59
- /** RESIZING */
60
-
61
- const [isResizing, setIsResizing] = useState(false);
62
- const resizingOffset = useRef(0);
63
-
64
- const onResizeStart = useCallback(
65
- (e: MouseEvent) => {
66
- resizingOffset.current = e.screenX - (column.width || 150);
67
- setIsResizing(true);
68
- },
69
- [column.width]
70
- );
71
-
72
- const onResizeMove = useCallback(
73
- (e: MouseEvent) => {
74
- if (isResizing) {
75
- const newWidth = Math.max(86, e.screenX - resizingOffset.current);
76
- setColumnWidth(columnKey, newWidth);
77
- }
78
- },
79
- [columnKey, isResizing, setColumnWidth]
80
- );
81
-
82
- const onResizeEnd = useCallback(() => {
83
- setIsResizing(false);
84
- saveSettings();
85
- }, [saveSettings]);
86
-
87
- const [isFilterDropdownVisible, setIsFilterDropdownVisible] = useState(false);
88
- const filterDropdown = useMemo(() => {
89
- if (!isFilterDropdownVisible || !filterButtonRef.current || !columnKey) {
90
- return null;
91
- }
92
- const filterButtonRect = getElementScreenRect(filterButtonRef.current);
93
- filterButtonRect.x += window.scrollX;
94
- filterButtonRect.y += window.scrollY;
95
- return (
96
- <Dropdown
97
- $sourceRect={filterButtonRect}
98
- onClose={() => setIsFilterDropdownVisible(false)}
99
- $width={320}
100
- $height={[200, 320]}
101
- $autoPositionX
102
- >
103
- <DataGridFilterMenu
104
- columnKey={columnKey}
105
- columnIndex={columnIndex}
106
- context={context}
107
- onClose={() => setIsFilterDropdownVisible(false)}
108
- />
109
- </Dropdown>
110
- );
111
- }, [
112
- columnIndex,
113
- columnKey,
114
- context,
115
- getElementScreenRect,
116
- isFilterDropdownVisible,
117
- ]);
118
-
119
- const onFilterButtonClicked = useCallback(() => {
120
- setIsFilterDropdownVisible(true);
121
- }, []);
122
-
123
- return (
124
- <styles.DataGridHeaderCellContainer
125
- $headerColor={headerColor}
126
- $isResizing={isResizing}
127
- >
128
- {filterDropdown}
129
- <span>{column.name}</span>
130
- {!!column.sortGetter && (
131
- <IconButton
132
- color={headerColor}
133
- size="small"
134
- icon={SortIcon}
135
- onClick={() => onSortButtonClicked?.(columnKey)}
136
- />
137
- )}
138
- {!!column.filter && (
139
- <IconButton
140
- size="small"
141
- ref={filterButtonRef}
142
- icon={
143
- filters[columnKey]?.values.length > 0 ? FilterFullIcon : FilterIcon
144
- }
145
- color={filters[columnKey]?.values.length > 0 ? 'danger' : headerColor}
146
- onClick={onFilterButtonClicked}
147
- />
148
- )}
149
- {column.resizable !== false && (
150
- <>
151
- <styles.DataGridResizeGrip
152
- className={isResizing ? 'active' : ''}
153
- $headerColor={headerColor}
154
- onMouseDown={onResizeStart}
155
- />
156
- {isResizing && (
157
- <styles.ResizeBackdrop
158
- onMouseMove={onResizeMove}
159
- onMouseUp={onResizeEnd}
160
- />
161
- )}
162
- </>
163
- )}
164
- </styles.DataGridHeaderCellContainer>
165
- );
166
- };
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
+ ArrowDownAZIcon,
8
+ ArrowUpZAIcon,
9
+ ArrowsUpDownIcon,
10
+ FilterFullIcon,
11
+ FilterIcon,
12
+ } from '../../../Icons';
13
+ import { MouseEvent, useCallback, useMemo, useRef, useState } from 'react';
14
+
15
+ import { DataGridFilterMenu } from './DataGridFilterMenu';
16
+ import { DataGridHeaderCellProps } from './types';
17
+ import { Dropdown } from '../../layout';
18
+ import { IconButton } from '../../forms/IconButton';
19
+ import { useDataGridContext } from './hooks';
20
+ import { useUi } from '../../../providers';
21
+
22
+ export const DataGridHeaderCell = <R,>({
23
+ columnKey,
24
+ columnIndex,
25
+ column,
26
+ context,
27
+ }: DataGridHeaderCellProps<R>) => {
28
+ const { getElementScreenRect } = useUi();
29
+ const contextValue = useDataGridContext(context);
30
+ const {
31
+ filters = {},
32
+ sorts = {},
33
+ setSorts,
34
+ setColumnWidth,
35
+ saveSettings,
36
+ headerColor,
37
+ } = contextValue;
38
+ const filterButtonRef = useRef<HTMLButtonElement | null>(null);
39
+
40
+ /** SORTING */
41
+ const SortIcon = sorts[columnKey]
42
+ ? sorts[columnKey] === 'desc'
43
+ ? ArrowUpZAIcon
44
+ : ArrowDownAZIcon
45
+ : ArrowsUpDownIcon;
46
+
47
+ const onSortButtonClicked = useCallback(
48
+ (columnKey: string) => {
49
+ const sort = sorts[columnKey];
50
+ if (!sort || sort === 'desc') {
51
+ setSorts({ [columnKey]: 'asc' });
52
+ } else {
53
+ setSorts({ [columnKey]: 'desc' });
54
+ }
55
+ },
56
+ [setSorts, sorts]
57
+ );
58
+
59
+ /** RESIZING */
60
+
61
+ const [isResizing, setIsResizing] = useState(false);
62
+ const resizingOffset = useRef(0);
63
+
64
+ const onResizeStart = useCallback(
65
+ (e: MouseEvent) => {
66
+ resizingOffset.current = e.screenX - (column.width || 150);
67
+ setIsResizing(true);
68
+ },
69
+ [column.width]
70
+ );
71
+
72
+ const onResizeMove = useCallback(
73
+ (e: MouseEvent) => {
74
+ if (isResizing) {
75
+ const newWidth = Math.max(86, e.screenX - resizingOffset.current);
76
+ setColumnWidth(columnKey, newWidth);
77
+ }
78
+ },
79
+ [columnKey, isResizing, setColumnWidth]
80
+ );
81
+
82
+ const onResizeEnd = useCallback(() => {
83
+ setIsResizing(false);
84
+ saveSettings();
85
+ }, [saveSettings]);
86
+
87
+ const [isFilterDropdownVisible, setIsFilterDropdownVisible] = useState(false);
88
+ const filterDropdown = useMemo(() => {
89
+ if (!isFilterDropdownVisible || !filterButtonRef.current || !columnKey) {
90
+ return null;
91
+ }
92
+ const filterButtonRect = getElementScreenRect(filterButtonRef.current);
93
+ filterButtonRect.x += window.scrollX;
94
+ filterButtonRect.y += window.scrollY;
95
+ return (
96
+ <Dropdown
97
+ $sourceRect={filterButtonRect}
98
+ onClose={() => setIsFilterDropdownVisible(false)}
99
+ $width={320}
100
+ $height={[200, 320]}
101
+ $autoPositionX
102
+ >
103
+ <DataGridFilterMenu
104
+ columnKey={columnKey}
105
+ columnIndex={columnIndex}
106
+ context={context}
107
+ onClose={() => setIsFilterDropdownVisible(false)}
108
+ />
109
+ </Dropdown>
110
+ );
111
+ }, [
112
+ columnIndex,
113
+ columnKey,
114
+ context,
115
+ getElementScreenRect,
116
+ isFilterDropdownVisible,
117
+ ]);
118
+
119
+ const onFilterButtonClicked = useCallback(() => {
120
+ setIsFilterDropdownVisible(true);
121
+ }, []);
122
+
123
+ const hasFilters = filters[columnKey]?.values.length > 0;
124
+
125
+ return (
126
+ <styles.DataGridHeaderCellContainer
127
+ $headerColor={headerColor}
128
+ $isResizing={isResizing}
129
+ >
130
+ {filterDropdown}
131
+ <span>{column.name}</span>
132
+ {!!column.sortGetter && (
133
+ <IconButton
134
+ color={headerColor}
135
+ size="small"
136
+ icon={SortIcon}
137
+ onClick={() => onSortButtonClicked?.(columnKey)}
138
+ />
139
+ )}
140
+ {!!column.filter && (
141
+ <IconButton
142
+ size="small"
143
+ className={hasFilters ? 'danger' : ''}
144
+ ref={filterButtonRef}
145
+ icon={hasFilters ? FilterFullIcon : FilterIcon}
146
+ color={hasFilters ? 'danger' : headerColor}
147
+ onClick={onFilterButtonClicked}
148
+ />
149
+ )}
150
+ {column.resizable !== false && (
151
+ <>
152
+ <styles.DataGridResizeGrip
153
+ className={isResizing ? 'active' : ''}
154
+ $headerColor={headerColor}
155
+ onMouseDown={onResizeStart}
156
+ />
157
+ {isResizing && (
158
+ <styles.ResizeBackdrop
159
+ onMouseMove={onResizeMove}
160
+ onMouseUp={onResizeEnd}
161
+ />
162
+ )}
163
+ </>
164
+ )}
165
+ </styles.DataGridHeaderCellContainer>
166
+ );
167
+ };
@@ -1,125 +1,124 @@
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
- DataGridFilter,
8
- DataGridFilterOperator,
9
- DataGridFilterType,
10
- } from '../types';
11
- import { Input, Select } from '../../../forms';
12
- import { useEffect, useRef } from 'react';
13
-
14
- // import { Select } from '../../Select';
15
- // import clx from 'classnames';
16
-
17
- const filterOperators: {
18
- [K in DataGridFilterType]: Partial<{
19
- [K2 in DataGridFilterOperator<K>]: string;
20
- }>;
21
- } = {
22
- number: {
23
- equals: 'Égal à',
24
- notEquals: 'Différent de',
25
- greaterThan: 'Supérieur à',
26
- greaterThanOrEqual: 'Supérieur ou égal à',
27
- lessThan: 'Inférieur à',
28
- lessThanOrEqual: 'Inférieur ou égal à',
29
- inRange: "Dans l'intervalle",
30
- },
31
- text: {
32
- equals: 'Égal à',
33
- notEquals: 'Différent de',
34
- contains: 'Contient',
35
- notContains: 'Ne contient pas',
36
- startsWith: 'Commence par',
37
- endsWith: 'Finit par',
38
- },
39
- };
40
-
41
- type FilterModalContentProps<
42
- R,
43
- T extends DataGridFilterType = DataGridFilterType
44
- > = {
45
- filter: DataGridFilter<R, T>;
46
- onFilterChanged: (filter: DataGridFilter<R, T>) => void;
47
- };
48
-
49
- export const FilterModalContent = <
50
- R,
51
- T extends DataGridFilterType = DataGridFilterType
52
- >({
53
- filter,
54
- onFilterChanged,
55
- }: FilterModalContentProps<R, T>) => {
56
- const value1Ref = useRef<HTMLInputElement>(null);
57
- useEffect(() => {
58
- setTimeout(() => value1Ref.current?.focus(), 100);
59
- }, []);
60
-
61
- if (!filter) return null;
62
-
63
- const { operator, type, values } = filter;
64
- return (
65
- <styles.FilterModalContentContainer>
66
- <label htmlFor="filterOperator">
67
- <span>Opérateur :</span>
68
- <Select
69
- name="filterOperator"
70
- items={Object.entries(filterOperators[filter.type])}
71
- itemKey={0}
72
- itemLabel={1}
73
- value={String(operator)}
74
- className="text-sm"
75
- onChange={(e) =>
76
- onFilterChanged({ ...filter, operator: e.target.value as any })
77
- }
78
- />
79
- </label>
80
- <label htmlFor="filterValue1">
81
- <span>{operator === 'inRange' ? 'Entre' : 'Valeur'} :</span>
82
- <Input
83
- ref={value1Ref}
84
- name="filterValue1"
85
- type={filter.type}
86
- value={values[0] ?? ''}
87
- // className={(type === 'number' ? 'w-24 ' : '') + 'text-sm'}
88
- onChange={(e) => {
89
- const newValues = [...values];
90
- newValues[0] =
91
- type === 'number'
92
- ? Number(e.target.value)
93
- : (String(e.target.value) as any);
94
- onFilterChanged({
95
- ...filter,
96
- values: newValues,
97
- });
98
- }}
99
- />
100
- </label>
101
- {operator === 'inRange' && (
102
- <label htmlFor="filterValue2">
103
- <span>et</span>
104
- <input
105
- name="filterValue2"
106
- type={filter.type}
107
- value={values[1] ?? ''}
108
- // className="text-sm w-24"
109
- onChange={(e) => {
110
- const newValues = [...values];
111
- newValues[0] =
112
- type === 'number'
113
- ? Number(e.target.value)
114
- : (String(e.target.value) as any);
115
- onFilterChanged({
116
- ...filter,
117
- values: newValues,
118
- });
119
- }}
120
- />
121
- </label>
122
- )}
123
- </styles.FilterModalContentContainer>
124
- );
125
- };
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
+ DataGridFilter,
8
+ DataGridFilterOperator,
9
+ DataGridFilterType,
10
+ } from '../types';
11
+ import { Input, Select } from '../../../forms';
12
+ import { useEffect, useRef } from 'react';
13
+
14
+ // import { Select } from '../../Select';
15
+ // import clx from 'classnames';
16
+
17
+ const filterOperators: {
18
+ [K in DataGridFilterType]: Partial<{
19
+ [K2 in DataGridFilterOperator<K>]: string;
20
+ }>;
21
+ } = {
22
+ number: {
23
+ equals: 'Égal à',
24
+ notEquals: 'Différent de',
25
+ greaterThan: 'Supérieur à',
26
+ greaterThanOrEqual: 'Supérieur ou égal à',
27
+ lessThan: 'Inférieur à',
28
+ lessThanOrEqual: 'Inférieur ou égal à',
29
+ inRange: "Dans l'intervalle",
30
+ },
31
+ text: {
32
+ equals: 'Égal à',
33
+ notEquals: 'Différent de',
34
+ contains: 'Contient',
35
+ notContains: 'Ne contient pas',
36
+ startsWith: 'Commence par',
37
+ endsWith: 'Finit par',
38
+ },
39
+ };
40
+
41
+ type FilterModalContentProps = {
42
+ filter: DataGridFilter;
43
+ onFilterChanged: (filter: DataGridFilter) => void;
44
+ };
45
+
46
+ export const FilterModalContent = ({
47
+ filter,
48
+ onFilterChanged,
49
+ }: FilterModalContentProps) => {
50
+ const value1Ref = useRef<HTMLInputElement>(null);
51
+ useEffect(() => {
52
+ setTimeout(() => value1Ref.current?.focus(), 100);
53
+ }, []);
54
+
55
+ if (!filter) return null;
56
+
57
+ const { operator, type, values } = filter;
58
+ return (
59
+ <styles.FilterModalContentContainer>
60
+ <label htmlFor="filterOperator">
61
+ <span>Opérateur :</span>
62
+ <Select
63
+ name="filterOperator"
64
+ items={Object.entries(filterOperators[filter.type])}
65
+ itemKey={0}
66
+ itemLabel={1}
67
+ value={String(operator)}
68
+ className="text-sm"
69
+ onChange={(e) =>
70
+ onFilterChanged({ ...filter, operator: e.target.value as any })
71
+ }
72
+ />
73
+ </label>
74
+ <label htmlFor="filterValue1">
75
+ <span>{operator === 'inRange' ? 'Entre' : 'Valeur'} :</span>
76
+ <Input
77
+ ref={value1Ref}
78
+ name="filterValue1"
79
+ type={filter.type}
80
+ value={values[0] ?? ''}
81
+ onChange={(e) => {
82
+ if (type === 'number') {
83
+ const newValues = [...values];
84
+ newValues[0] = Number(e.target.value);
85
+ onFilterChanged({
86
+ ...filter,
87
+ values: newValues,
88
+ });
89
+ } else {
90
+ const newValues = [...values];
91
+ newValues[0] = String(e.target.value) as any;
92
+ onFilterChanged({
93
+ ...filter,
94
+ values: newValues,
95
+ });
96
+ }
97
+ }}
98
+ />
99
+ </label>
100
+ {operator === 'inRange' && (
101
+ <label htmlFor="filterValue2">
102
+ <span>et</span>
103
+ <input
104
+ name="filterValue2"
105
+ type={filter.type}
106
+ value={values[1] ?? ''}
107
+ // className="text-sm w-24"
108
+ onChange={(e) => {
109
+ const newValues = [...values];
110
+ newValues[0] =
111
+ type === 'number'
112
+ ? Number(e.target.value)
113
+ : (String(e.target.value) as any);
114
+ onFilterChanged({
115
+ ...filter,
116
+ values: newValues,
117
+ });
118
+ }}
119
+ />
120
+ </label>
121
+ )}
122
+ </styles.FilterModalContentContainer>
123
+ );
124
+ };
@@ -1,22 +1,22 @@
1
- import styled from 'styled-components';
2
-
3
- export const FilterModalContentContainer = styled.div.attrs({
4
- className: 'FilterModalContentContainer',
5
- })`
6
- display: flex;
7
- flex-direction: column;
8
- font-size: var(--text-base);
9
- gap: var(--space-1);
10
-
11
- & > label {
12
- display: flex;
13
- flex-direction: row;
14
- gap: var(--space-1);
15
- align-items: center;
16
-
17
- & > span {
18
- font-weight: bold;
19
- width: var(--space-32);
20
- }
21
- }
22
- `;
1
+ import styled from 'styled-components';
2
+
3
+ export const FilterModalContentContainer = styled.div.attrs({
4
+ className: 'FilterModalContentContainer',
5
+ })`
6
+ display: flex;
7
+ flex-direction: column;
8
+ font-size: var(--text-base);
9
+ gap: var(--space-1);
10
+
11
+ & > label {
12
+ display: flex;
13
+ flex-direction: row;
14
+ gap: var(--space-1);
15
+ align-items: center;
16
+
17
+ & > span {
18
+ font-weight: bold;
19
+ width: var(--space-32);
20
+ }
21
+ }
22
+ `;