@bit.rhplus/ag-grid 0.0.81 → 0.0.82

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.
@@ -1,310 +1,310 @@
1
- /* eslint-disable */
2
- import React, { useCallback, useEffect, useRef } from 'react';
3
- import { Input, InputNumber, Button, Alert, Space } from 'antd';
4
- import { validateValue, getInputType } from './utils';
5
- import { createMemoComparison } from '@bit.rhplus/react-memo';
6
-
7
- /**
8
- * Popover komponenta s inputem pro bulk edit
9
- * @param {Object} props
10
- * @param {boolean} props.visible - Viditelnost popoveru
11
- * @param {string} props.value - Aktuální hodnota
12
- * @param {boolean} props.loading - Loading state
13
- * @param {string} props.error - Chybová hláška
14
- * @param {Object} props.column - AG Grid column objekt
15
- * @param {Object} props.range - AG Grid cell range objekt
16
- * @param {number} props.cellCount - Počet buněk k editaci
17
- * @param {Function} props.onValueChange - Handler pro změnu hodnoty
18
- * @param {Function} props.onSubmit - Handler pro submit
19
- * @param {Function} props.onCancel - Handler pro cancel
20
- */
21
- const BulkEditPopover = ({
22
- visible,
23
- value,
24
- loading,
25
- error,
26
- column,
27
- range,
28
- cellCount,
29
- onValueChange,
30
- onSubmit,
31
- onCancel,
32
- }) => {
33
- const inputRef = useRef(null);
34
-
35
- // Focus input při otevření
36
- useEffect(() => {
37
- if (visible && inputRef.current) {
38
- setTimeout(() => {
39
- inputRef.current?.focus();
40
- }, 100);
41
- }
42
- }, [visible]);
43
-
44
- if (!visible) return null;
45
-
46
- const colDef = column?.getColDef();
47
- const inputType = getInputType(colDef);
48
- const fieldName = colDef?.headerName || colDef?.field || 'Sloupec';
49
-
50
- /**
51
- * Handler pro submit
52
- */
53
- const handleSubmit = useCallback(() => {
54
- // Validace hodnoty
55
- const validation = validateValue(value, colDef);
56
-
57
- if (!validation.valid) {
58
- // Zobrazit error (parent komponenta zobrazí)
59
- return;
60
- }
61
-
62
- onSubmit(validation.parsedValue);
63
- }, [value, colDef, onSubmit]);
64
-
65
- /**
66
- * Handler pro Enter key
67
- */
68
- const handleKeyPress = useCallback(
69
- (e) => {
70
- if (e.key === 'Enter' && !loading) {
71
- e.preventDefault();
72
- handleSubmit();
73
- } else if (e.key === 'Escape') {
74
- e.preventDefault();
75
- onCancel();
76
- }
77
- },
78
- [handleSubmit, loading, onCancel]
79
- );
80
-
81
- /**
82
- * Render input podle typu
83
- */
84
- const renderInput = () => {
85
- // Check pro custom bulkEditPopover komponentu
86
- const CustomComponent = colDef?.bulkEditPopover;
87
-
88
- if (CustomComponent && typeof CustomComponent === 'function') {
89
- // Renderovat custom komponentu s props
90
- return (
91
- <CustomComponent
92
- value={value}
93
- onChange={onValueChange}
94
- onSubmit={onSubmit}
95
- onCancel={onCancel}
96
- loading={loading}
97
- error={error}
98
- column={column}
99
- range={range}
100
- cellCount={cellCount}
101
- colDef={colDef}
102
- />
103
- );
104
- }
105
-
106
- // Default input podle typu
107
- switch (inputType) {
108
- case 'number':
109
- return (
110
- <InputNumber
111
- ref={inputRef}
112
- style={{ width: '100%' }}
113
- value={value}
114
- onChange={onValueChange}
115
- onPressEnter={handleKeyPress}
116
- placeholder="Zadejte číslo..."
117
- disabled={loading}
118
- />
119
- );
120
-
121
- case 'date':
122
- return (
123
- <Input
124
- ref={inputRef}
125
- type="date"
126
- value={value}
127
- onChange={(e) => onValueChange(e.target.value)}
128
- onKeyDown={handleKeyPress}
129
- placeholder="Vyberte datum..."
130
- disabled={loading}
131
- />
132
- );
133
-
134
- case 'text':
135
- default:
136
- return (
137
- <Input
138
- ref={inputRef}
139
- value={value}
140
- onChange={(e) => onValueChange(e.target.value)}
141
- onKeyDown={handleKeyPress}
142
- placeholder="Zadejte hodnotu..."
143
- disabled={loading}
144
- />
145
- );
146
- }
147
- };
148
-
149
- // Check zda je custom komponenta
150
- const CustomComponent = colDef?.bulkEditPopover;
151
- const isCustomComponent = CustomComponent && typeof CustomComponent === 'function';
152
-
153
- // Check zda má custom komponenta automatická tlačítka (default: true)
154
- const autoButtons = colDef?.bulkEditPopoverAutoButtons !== false;
155
-
156
- // Pokud je custom komponenta s automatickými tlačítky
157
- if (isCustomComponent && autoButtons) {
158
- return (
159
- <div
160
- style={{
161
- background: '#fff',
162
- border: '1px solid #d9d9d9',
163
- borderRadius: '4px',
164
- padding: '12px',
165
- boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
166
- minWidth: '280px',
167
- maxWidth: '1050px',
168
- }}
169
- >
170
- <div style={{ marginBottom: '8px' }}>
171
- <div style={{ fontSize: '14px', fontWeight: 500, marginBottom: '4px' }}>
172
- Hromadná změna
173
- </div>
174
- <div style={{ fontSize: '12px', color: '#8c8c8c' }}>
175
- {fieldName} · {cellCount} {cellCount === 1 ? 'buňka' : cellCount < 5 ? 'buňky' : 'buněk'}
176
- </div>
177
- </div>
178
-
179
- {error && (
180
- <Alert
181
- message={error}
182
- type="error"
183
- showIcon
184
- closable
185
- style={{ marginBottom: '12px' }}
186
- />
187
- )}
188
-
189
- <div style={{ marginBottom: '12px' }}>
190
- {renderInput()}
191
- </div>
192
-
193
- {/* Automatická tlačítka */}
194
- <Space style={{ width: '100%', justifyContent: 'flex-end' }}>
195
- <Button size="small" onClick={onCancel} disabled={loading}>
196
- Zrušit
197
- </Button>
198
- <Button
199
- type="primary"
200
- size="small"
201
- onClick={handleSubmit}
202
- loading={loading}
203
- >
204
- Použít
205
- </Button>
206
- </Space>
207
- </div>
208
- );
209
- }
210
-
211
- // Pokud je custom komponenta BEZ automatických tlačítek (plná kontrola)
212
- if (isCustomComponent && !autoButtons) {
213
- return (
214
- <div
215
- style={{
216
- background: '#fff',
217
- border: '1px solid #d9d9d9',
218
- borderRadius: '4px',
219
- padding: '12px',
220
- boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
221
- minWidth: '280px',
222
- maxWidth: '1050px',
223
- }}
224
- >
225
- <div style={{ marginBottom: '8px' }}>
226
- <div style={{ fontSize: '14px', fontWeight: 500, marginBottom: '4px' }}>
227
- Hromadná změna
228
- </div>
229
- <div style={{ fontSize: '12px', color: '#8c8c8c' }}>
230
- {fieldName} · {cellCount} {cellCount === 1 ? 'buňka' : cellCount < 5 ? 'buňky' : 'buněk'}
231
- </div>
232
- </div>
233
-
234
- {error && (
235
- <Alert
236
- message={error}
237
- type="error"
238
- showIcon
239
- closable
240
- style={{ marginBottom: '12px' }}
241
- />
242
- )}
243
-
244
- {renderInput()}
245
- </div>
246
- );
247
- }
248
-
249
- // Default popover s vlastními tlačítky
250
- return (
251
- <div
252
- style={{
253
- background: '#fff',
254
- border: '1px solid #d9d9d9',
255
- borderRadius: '4px',
256
- padding: '12px',
257
- boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
258
- minWidth: '280px',
259
- maxWidth: '320px',
260
- }}
261
- >
262
- <div style={{ marginBottom: '8px' }}>
263
- <div style={{ fontSize: '14px', fontWeight: 500, marginBottom: '4px' }}>
264
- Hromadná změna
265
- </div>
266
- <div style={{ fontSize: '12px', color: '#8c8c8c' }}>
267
- {fieldName} · {cellCount} {cellCount === 1 ? 'buňka' : cellCount < 5 ? 'buňky' : 'buněk'}
268
- </div>
269
- </div>
270
-
271
- {error && (
272
- <Alert
273
- message={error}
274
- type="error"
275
- showIcon
276
- closable
277
- style={{ marginBottom: '12px' }}
278
- />
279
- )}
280
-
281
- <div style={{ marginBottom: '12px' }}>
282
- {renderInput()}
283
- </div>
284
-
285
- <Space style={{ width: '100%', justifyContent: 'flex-end' }}>
286
- <Button size="small" onClick={onCancel} disabled={loading}>
287
- Zrušit
288
- </Button>
289
- <Button
290
- type="primary"
291
- size="small"
292
- onClick={handleSubmit}
293
- loading={loading}
294
- >
295
- Použít
296
- </Button>
297
- </Space>
298
- </div>
299
- );
300
- };
301
-
302
- // React.memo optimalizace - rerender pouze při změně kritických props
303
- const arePropsEqual = createMemoComparison(
304
- ['visible', 'value', 'loading', 'error', 'column', 'range', 'cellCount'],
305
- ['onValueChange', 'onSubmit', 'onCancel'],
306
- false,
307
- 'BulkEditPopover'
308
- );
309
-
310
- export default React.memo(BulkEditPopover, arePropsEqual);
1
+ /* eslint-disable */
2
+ import React, { useCallback, useEffect, useRef } from 'react';
3
+ import { Input, InputNumber, Button, Alert, Space } from 'antd';
4
+ import { validateValue, getInputType } from './utils';
5
+ import { createMemoComparison } from '@bit.rhplus/react-memo';
6
+
7
+ /**
8
+ * Popover komponenta s inputem pro bulk edit
9
+ * @param {Object} props
10
+ * @param {boolean} props.visible - Viditelnost popoveru
11
+ * @param {string} props.value - Aktuální hodnota
12
+ * @param {boolean} props.loading - Loading state
13
+ * @param {string} props.error - Chybová hláška
14
+ * @param {Object} props.column - AG Grid column objekt
15
+ * @param {Object} props.range - AG Grid cell range objekt
16
+ * @param {number} props.cellCount - Počet buněk k editaci
17
+ * @param {Function} props.onValueChange - Handler pro změnu hodnoty
18
+ * @param {Function} props.onSubmit - Handler pro submit
19
+ * @param {Function} props.onCancel - Handler pro cancel
20
+ */
21
+ const BulkEditPopover = ({
22
+ visible,
23
+ value,
24
+ loading,
25
+ error,
26
+ column,
27
+ range,
28
+ cellCount,
29
+ onValueChange,
30
+ onSubmit,
31
+ onCancel,
32
+ }) => {
33
+ const inputRef = useRef(null);
34
+
35
+ // Focus input při otevření
36
+ useEffect(() => {
37
+ if (visible && inputRef.current) {
38
+ setTimeout(() => {
39
+ inputRef.current?.focus();
40
+ }, 100);
41
+ }
42
+ }, [visible]);
43
+
44
+ if (!visible) return null;
45
+
46
+ const colDef = column?.getColDef();
47
+ const inputType = getInputType(colDef);
48
+ const fieldName = colDef?.headerName || colDef?.field || 'Sloupec';
49
+
50
+ /**
51
+ * Handler pro submit
52
+ */
53
+ const handleSubmit = useCallback(() => {
54
+ // Validace hodnoty
55
+ const validation = validateValue(value, colDef);
56
+
57
+ if (!validation.valid) {
58
+ // Zobrazit error (parent komponenta zobrazí)
59
+ return;
60
+ }
61
+
62
+ onSubmit(validation.parsedValue);
63
+ }, [value, colDef, onSubmit]);
64
+
65
+ /**
66
+ * Handler pro Enter key
67
+ */
68
+ const handleKeyPress = useCallback(
69
+ (e) => {
70
+ if (e.key === 'Enter' && !loading) {
71
+ e.preventDefault();
72
+ handleSubmit();
73
+ } else if (e.key === 'Escape') {
74
+ e.preventDefault();
75
+ onCancel();
76
+ }
77
+ },
78
+ [handleSubmit, loading, onCancel]
79
+ );
80
+
81
+ /**
82
+ * Render input podle typu
83
+ */
84
+ const renderInput = () => {
85
+ // Check pro custom bulkEditPopover komponentu
86
+ const CustomComponent = colDef?.bulkEditPopover;
87
+
88
+ if (CustomComponent && typeof CustomComponent === 'function') {
89
+ // Renderovat custom komponentu s props
90
+ return (
91
+ <CustomComponent
92
+ value={value}
93
+ onChange={onValueChange}
94
+ onSubmit={onSubmit}
95
+ onCancel={onCancel}
96
+ loading={loading}
97
+ error={error}
98
+ column={column}
99
+ range={range}
100
+ cellCount={cellCount}
101
+ colDef={colDef}
102
+ />
103
+ );
104
+ }
105
+
106
+ // Default input podle typu
107
+ switch (inputType) {
108
+ case 'number':
109
+ return (
110
+ <InputNumber
111
+ ref={inputRef}
112
+ style={{ width: '100%' }}
113
+ value={value}
114
+ onChange={onValueChange}
115
+ onPressEnter={handleKeyPress}
116
+ placeholder="Zadejte číslo..."
117
+ disabled={loading}
118
+ />
119
+ );
120
+
121
+ case 'date':
122
+ return (
123
+ <Input
124
+ ref={inputRef}
125
+ type="date"
126
+ value={value}
127
+ onChange={(e) => onValueChange(e.target.value)}
128
+ onKeyDown={handleKeyPress}
129
+ placeholder="Vyberte datum..."
130
+ disabled={loading}
131
+ />
132
+ );
133
+
134
+ case 'text':
135
+ default:
136
+ return (
137
+ <Input
138
+ ref={inputRef}
139
+ value={value}
140
+ onChange={(e) => onValueChange(e.target.value)}
141
+ onKeyDown={handleKeyPress}
142
+ placeholder="Zadejte hodnotu..."
143
+ disabled={loading}
144
+ />
145
+ );
146
+ }
147
+ };
148
+
149
+ // Check zda je custom komponenta
150
+ const CustomComponent = colDef?.bulkEditPopover;
151
+ const isCustomComponent = CustomComponent && typeof CustomComponent === 'function';
152
+
153
+ // Check zda má custom komponenta automatická tlačítka (default: true)
154
+ const autoButtons = colDef?.bulkEditPopoverAutoButtons !== false;
155
+
156
+ // Pokud je custom komponenta s automatickými tlačítky
157
+ if (isCustomComponent && autoButtons) {
158
+ return (
159
+ <div
160
+ style={{
161
+ background: '#fff',
162
+ border: '1px solid #d9d9d9',
163
+ borderRadius: '4px',
164
+ padding: '12px',
165
+ boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
166
+ minWidth: '280px',
167
+ maxWidth: '1050px',
168
+ }}
169
+ >
170
+ <div style={{ marginBottom: '8px' }}>
171
+ <div style={{ fontSize: '14px', fontWeight: 500, marginBottom: '4px' }}>
172
+ Hromadná změna
173
+ </div>
174
+ <div style={{ fontSize: '12px', color: '#8c8c8c' }}>
175
+ {fieldName} · {cellCount} {cellCount === 1 ? 'buňka' : cellCount < 5 ? 'buňky' : 'buněk'}
176
+ </div>
177
+ </div>
178
+
179
+ {error && (
180
+ <Alert
181
+ message={error}
182
+ type="error"
183
+ showIcon
184
+ closable
185
+ style={{ marginBottom: '12px' }}
186
+ />
187
+ )}
188
+
189
+ <div style={{ marginBottom: '12px' }}>
190
+ {renderInput()}
191
+ </div>
192
+
193
+ {/* Automatická tlačítka */}
194
+ <Space style={{ width: '100%', justifyContent: 'flex-end' }}>
195
+ <Button size="small" onClick={onCancel} disabled={loading}>
196
+ Zrušit
197
+ </Button>
198
+ <Button
199
+ type="primary"
200
+ size="small"
201
+ onClick={handleSubmit}
202
+ loading={loading}
203
+ >
204
+ Použít
205
+ </Button>
206
+ </Space>
207
+ </div>
208
+ );
209
+ }
210
+
211
+ // Pokud je custom komponenta BEZ automatických tlačítek (plná kontrola)
212
+ if (isCustomComponent && !autoButtons) {
213
+ return (
214
+ <div
215
+ style={{
216
+ background: '#fff',
217
+ border: '1px solid #d9d9d9',
218
+ borderRadius: '4px',
219
+ padding: '12px',
220
+ boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
221
+ minWidth: '280px',
222
+ maxWidth: '1050px',
223
+ }}
224
+ >
225
+ <div style={{ marginBottom: '8px' }}>
226
+ <div style={{ fontSize: '14px', fontWeight: 500, marginBottom: '4px' }}>
227
+ Hromadná změna
228
+ </div>
229
+ <div style={{ fontSize: '12px', color: '#8c8c8c' }}>
230
+ {fieldName} · {cellCount} {cellCount === 1 ? 'buňka' : cellCount < 5 ? 'buňky' : 'buněk'}
231
+ </div>
232
+ </div>
233
+
234
+ {error && (
235
+ <Alert
236
+ message={error}
237
+ type="error"
238
+ showIcon
239
+ closable
240
+ style={{ marginBottom: '12px' }}
241
+ />
242
+ )}
243
+
244
+ {renderInput()}
245
+ </div>
246
+ );
247
+ }
248
+
249
+ // Default popover s vlastními tlačítky
250
+ return (
251
+ <div
252
+ style={{
253
+ background: '#fff',
254
+ border: '1px solid #d9d9d9',
255
+ borderRadius: '4px',
256
+ padding: '12px',
257
+ boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
258
+ minWidth: '280px',
259
+ maxWidth: '320px',
260
+ }}
261
+ >
262
+ <div style={{ marginBottom: '8px' }}>
263
+ <div style={{ fontSize: '14px', fontWeight: 500, marginBottom: '4px' }}>
264
+ Hromadná změna
265
+ </div>
266
+ <div style={{ fontSize: '12px', color: '#8c8c8c' }}>
267
+ {fieldName} · {cellCount} {cellCount === 1 ? 'buňka' : cellCount < 5 ? 'buňky' : 'buněk'}
268
+ </div>
269
+ </div>
270
+
271
+ {error && (
272
+ <Alert
273
+ message={error}
274
+ type="error"
275
+ showIcon
276
+ closable
277
+ style={{ marginBottom: '12px' }}
278
+ />
279
+ )}
280
+
281
+ <div style={{ marginBottom: '12px' }}>
282
+ {renderInput()}
283
+ </div>
284
+
285
+ <Space style={{ width: '100%', justifyContent: 'flex-end' }}>
286
+ <Button size="small" onClick={onCancel} disabled={loading}>
287
+ Zrušit
288
+ </Button>
289
+ <Button
290
+ type="primary"
291
+ size="small"
292
+ onClick={handleSubmit}
293
+ loading={loading}
294
+ >
295
+ Použít
296
+ </Button>
297
+ </Space>
298
+ </div>
299
+ );
300
+ };
301
+
302
+ // React.memo optimalizace - rerender pouze při změně kritických props
303
+ const arePropsEqual = createMemoComparison(
304
+ ['visible', 'value', 'loading', 'error', 'column', 'range', 'cellCount'],
305
+ ['onValueChange', 'onSubmit', 'onCancel'],
306
+ false,
307
+ 'BulkEditPopover'
308
+ );
309
+
310
+ export default React.memo(BulkEditPopover, arePropsEqual);