@bit.rhplus/ui.grid-layout 0.0.3 → 0.0.4
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.
- package/ColumnEditorModal.jsx +426 -369
- package/dist/ColumnEditorModal.js +134 -88
- package/dist/ColumnEditorModal.js.map +1 -1
- package/dist/useGridLayout.d.ts +1 -1
- package/dist/useGridLayout.js +1115 -221
- package/dist/useGridLayout.js.map +1 -1
- package/dist/useGridLayoutApi.d.ts +1 -1
- package/dist/useGridLayoutApi.js +102 -65
- package/dist/useGridLayoutApi.js.map +1 -1
- package/gridLayout.js +106 -106
- package/package.json +2 -2
- package/useGridLayout.js +1714 -625
- package/useGridLayoutApi.js +382 -296
- /package/dist/{preview-1755033542068.js → preview-1755777309104.js} +0 -0
package/useGridLayoutApi.js
CHANGED
|
@@ -1,296 +1,382 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/**
|
|
3
|
-
* Hook pro komunikaci s Grid Layout API službou
|
|
4
|
-
* Poskytuje funkcionalitu pro načítání a ukládání personalizovaných nastavení gridů
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { useCallback, useMemo } from 'react';
|
|
8
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
9
|
-
import { useApiQuery, useApiQuerySilence } from '@bit.rhplus/data';
|
|
10
|
-
import {
|
|
11
|
-
userFieldsApi,
|
|
12
|
-
getSingleGridApi,
|
|
13
|
-
getUserGridsApi,
|
|
14
|
-
saveGridLayoutApi
|
|
15
|
-
} from './gridLayout';
|
|
16
|
-
import useData from '@bit.rhplus/data';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Hook pro práci s Grid Layout API
|
|
20
|
-
* @param {Object} config - Konfigurace gridu
|
|
21
|
-
* @param {string} config.userKey - Klíč uživatele
|
|
22
|
-
* @param {string} config.applicationName - Název aplikace
|
|
23
|
-
* @param {string} config.gridName - Název gridu
|
|
24
|
-
* @param {string} [config.filterName] - Název filtru (volitelné)
|
|
25
|
-
* @param {string} [config.accessToken] - Přístupový token
|
|
26
|
-
* @returns {Object} API methods pro grid layout
|
|
27
|
-
*/
|
|
28
|
-
export const useGridLayoutApi = ({
|
|
29
|
-
userKey,
|
|
30
|
-
applicationName,
|
|
31
|
-
gridName,
|
|
32
|
-
filterName = null,
|
|
33
|
-
accessToken = null
|
|
34
|
-
}) => {
|
|
35
|
-
const { fetchDataUIAsync } = useData();
|
|
36
|
-
const queryClient = useQueryClient();
|
|
37
|
-
|
|
38
|
-
// Základní identifikace pro API volání
|
|
39
|
-
const baseParams = useMemo(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Hook pro komunikaci s Grid Layout API službou
|
|
4
|
+
* Poskytuje funkcionalitu pro načítání a ukládání personalizovaných nastavení gridů
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useCallback, useMemo } from 'react';
|
|
8
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
9
|
+
import { useApiQuery, useApiQuerySilence } from '@bit.rhplus/data';
|
|
10
|
+
import {
|
|
11
|
+
userFieldsApi,
|
|
12
|
+
getSingleGridApi,
|
|
13
|
+
getUserGridsApi,
|
|
14
|
+
saveGridLayoutApi,
|
|
15
|
+
} from './gridLayout';
|
|
16
|
+
import useData from '@bit.rhplus/data';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hook pro práci s Grid Layout API
|
|
20
|
+
* @param {Object} config - Konfigurace gridu
|
|
21
|
+
* @param {string} config.userKey - Klíč uživatele
|
|
22
|
+
* @param {string} config.applicationName - Název aplikace
|
|
23
|
+
* @param {string} config.gridName - Název gridu
|
|
24
|
+
* @param {string} [config.filterName] - Název filtru (volitelné)
|
|
25
|
+
* @param {string} [config.accessToken] - Přístupový token
|
|
26
|
+
* @returns {Object} API methods pro grid layout
|
|
27
|
+
*/
|
|
28
|
+
export const useGridLayoutApi = ({
|
|
29
|
+
userKey,
|
|
30
|
+
applicationName,
|
|
31
|
+
gridName,
|
|
32
|
+
filterName = null,
|
|
33
|
+
accessToken = null,
|
|
34
|
+
}) => {
|
|
35
|
+
const { fetchDataUIAsync } = useData();
|
|
36
|
+
const queryClient = useQueryClient();
|
|
37
|
+
|
|
38
|
+
// Základní identifikace pro API volání
|
|
39
|
+
const baseParams = useMemo(
|
|
40
|
+
() => ({
|
|
41
|
+
userKey,
|
|
42
|
+
applicationName,
|
|
43
|
+
gridName,
|
|
44
|
+
...(filterName && { filterName }),
|
|
45
|
+
}),
|
|
46
|
+
[userKey, applicationName, gridName, filterName]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// Query key pro caching
|
|
50
|
+
const gridQueryKey = useMemo(
|
|
51
|
+
() =>
|
|
52
|
+
`grid_layout_${userKey}_${applicationName}_${gridName}_${
|
|
53
|
+
filterName || 'default'
|
|
54
|
+
}`,
|
|
55
|
+
[userKey, applicationName, gridName, filterName]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Načte seznam polí pro konkrétní grid s personalizací uživatele
|
|
60
|
+
* @param {Array} fields - Definice polí gridu
|
|
61
|
+
* @param {Object} options - React Query options
|
|
62
|
+
*/
|
|
63
|
+
const useUserFields = (fields = [], options = {}) => {
|
|
64
|
+
const params = useMemo(
|
|
65
|
+
() => ({
|
|
66
|
+
...baseParams,
|
|
67
|
+
fields,
|
|
68
|
+
}),
|
|
69
|
+
[baseParams, fields]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return useApiQuery(
|
|
73
|
+
`${gridQueryKey}_fields`,
|
|
74
|
+
userFieldsApi,
|
|
75
|
+
params,
|
|
76
|
+
accessToken,
|
|
77
|
+
null,
|
|
78
|
+
options?.enabled ?? true,
|
|
79
|
+
5, // 5 minut stale time
|
|
80
|
+
options
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Načte konkrétní jeden grid pro uživatele
|
|
86
|
+
* @param {Object} options - React Query options
|
|
87
|
+
*/
|
|
88
|
+
const useSingleGrid = (options = {}) => {
|
|
89
|
+
return useApiQuery(
|
|
90
|
+
gridQueryKey,
|
|
91
|
+
getSingleGridApi,
|
|
92
|
+
baseParams,
|
|
93
|
+
accessToken,
|
|
94
|
+
null,
|
|
95
|
+
true,
|
|
96
|
+
5 // 5 minut stale time
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Načte seznam všech gridů uživatele v aplikaci
|
|
102
|
+
* @param {Object} options - React Query options
|
|
103
|
+
*/
|
|
104
|
+
const useUserGrids = (options = {}) => {
|
|
105
|
+
const params = useMemo(
|
|
106
|
+
() => ({
|
|
107
|
+
userKey,
|
|
108
|
+
applicationName,
|
|
109
|
+
}),
|
|
110
|
+
[userKey, applicationName]
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return useApiQuery(
|
|
114
|
+
`user_grids_${userKey}_${applicationName}`,
|
|
115
|
+
getUserGridsApi,
|
|
116
|
+
params,
|
|
117
|
+
accessToken,
|
|
118
|
+
null,
|
|
119
|
+
true,
|
|
120
|
+
10 // 10 minut stale time
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Uloží personalizované nastavení gridu pomocí SaveUserFields endpoint
|
|
126
|
+
* @param {Array} userFields - UserFieldModel array pro uložení
|
|
127
|
+
* @returns {Promise} Promise s výsledkem
|
|
128
|
+
*/
|
|
129
|
+
const saveGridLayout = useCallback(
|
|
130
|
+
async (userFields) => {
|
|
131
|
+
try {
|
|
132
|
+
const params = {
|
|
133
|
+
...baseParams,
|
|
134
|
+
userFields, // Nová struktura pro SaveUserFieldsCommand
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Vrátíme Promise z fetchDataUIAsync
|
|
138
|
+
return fetchDataUIAsync(saveGridLayoutApi, params, accessToken)
|
|
139
|
+
.then((result) => {
|
|
140
|
+
// Invalidujeme cache pro načtení čerstvých dat z API - všechny queries související s tímto gridem
|
|
141
|
+
queryClient
|
|
142
|
+
.invalidateQueries({
|
|
143
|
+
predicate: (query) => {
|
|
144
|
+
// Invalidujeme všechny queries které začínají našim gridQueryKey
|
|
145
|
+
const queryKey = query.queryKey?.[0];
|
|
146
|
+
return (
|
|
147
|
+
queryKey &&
|
|
148
|
+
typeof queryKey === 'string' &&
|
|
149
|
+
queryKey.startsWith(gridQueryKey)
|
|
150
|
+
);
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
.then();
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
data: result.data,
|
|
158
|
+
message: result.message,
|
|
159
|
+
};
|
|
160
|
+
})
|
|
161
|
+
.catch((error) => {
|
|
162
|
+
throw new Error(error?.message ||
|
|
163
|
+
'Chyba při ukládání grid layoutu'
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
} catch (error) {
|
|
167
|
+
// Removed console.error for production
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
[baseParams, fetchDataUIAsync, accessToken, queryClient, gridQueryKey]
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Transformuje AG-Grid column state na UserFieldModel format
|
|
176
|
+
* @param {Array} columnState - AG-Grid column state
|
|
177
|
+
* @param {Array} columnDefs - Původní column definitions
|
|
178
|
+
* @returns {Array} UserFieldModel array pro SaveUserFields API
|
|
179
|
+
*/
|
|
180
|
+
const transformColumnStateToFields = useCallback(
|
|
181
|
+
(columnState, columnDefs) => {
|
|
182
|
+
if (!columnState) return [];
|
|
183
|
+
if (!columnDefs || !Array.isArray(columnDefs)) {
|
|
184
|
+
console.error(
|
|
185
|
+
'[GridLayoutApi] transformColumnStateToFields: columnDefs is not a valid array:',
|
|
186
|
+
columnDefs
|
|
187
|
+
);
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Filtrujeme pouze validní column state položky s platným colId
|
|
192
|
+
const validColumnState = columnState.filter((columnStateItem, index) => {
|
|
193
|
+
const hasValidColId =
|
|
194
|
+
columnStateItem &&
|
|
195
|
+
typeof columnStateItem.colId === 'string' &&
|
|
196
|
+
columnStateItem.colId.trim() !== '';
|
|
197
|
+
|
|
198
|
+
if (!hasValidColId) {
|
|
199
|
+
console.warn(
|
|
200
|
+
`[GridLayoutApi] Ignoring invalid column state at index ${index}:`,
|
|
201
|
+
{
|
|
202
|
+
colId: columnStateItem?.colId,
|
|
203
|
+
typeof_colId: typeof columnStateItem?.colId,
|
|
204
|
+
fullItem: columnStateItem,
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return hasValidColId;
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
var resultColumnState = validColumnState.map((columnStateItem, index) => {
|
|
213
|
+
// Najdeme odpovídající column definition podle field
|
|
214
|
+
let colDef = columnDefs.find(
|
|
215
|
+
(cd) => cd.field === columnStateItem.colId
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// Pokud nebyl nalezen podle field, zkusíme hledat podle colId
|
|
219
|
+
if (!colDef) {
|
|
220
|
+
colDef = columnDefs.find((cd) => cd.colId === columnStateItem.colId);
|
|
221
|
+
}
|
|
222
|
+
if (!colDef) {
|
|
223
|
+
return {};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Bezpečné určení HeaderName - používáme aktuální hodnotu z columnStateItem, pokud existuje
|
|
227
|
+
const headerName =
|
|
228
|
+
(columnStateItem.headerName !== undefined
|
|
229
|
+
? columnStateItem.headerName
|
|
230
|
+
: colDef.headerName) || columnStateItem.colId;
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
// Mapování na UserFieldModel strukturu
|
|
234
|
+
Id: 0, // Nové pole má ID = 0, existující budou mít správné ID z API
|
|
235
|
+
UserKey: baseParams.userKey,
|
|
236
|
+
ApplicationName: baseParams.applicationName,
|
|
237
|
+
GridName: baseParams.gridName,
|
|
238
|
+
FilterName: baseParams.filterName || null,
|
|
239
|
+
FieldName: columnStateItem.colId,
|
|
240
|
+
HeaderName: headerName,
|
|
241
|
+
Order: index, // Pořadí podle pozice v validním column state
|
|
242
|
+
Show: columnStateItem.hide !== true,
|
|
243
|
+
Width: columnStateItem.width != null ? columnStateItem.width : (colDef.width || null),
|
|
244
|
+
System: colDef.system || false, // Systémové sloupce nejde skrývat/editovat
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return resultColumnState.filter((f) => Object.keys(f).length > 0);
|
|
249
|
+
},
|
|
250
|
+
[baseParams]
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Transformuje UserFieldModel array na AG-Grid column state
|
|
255
|
+
* Používá columnDefs jako primární zdroj a userFields jen pro úpravy
|
|
256
|
+
* @param {Array} userFields - UserFieldModel array z API (pro úpravy)
|
|
257
|
+
* @param {Array} columnDefs - Původní column definitions (primární)
|
|
258
|
+
* @returns {Array} Column state pro AG-Grid
|
|
259
|
+
*/
|
|
260
|
+
const transformFieldsToColumnState = useCallback((userFields, columnDefs) => {
|
|
261
|
+
if (!columnDefs || !Array.isArray(columnDefs)) {
|
|
262
|
+
console.warn(
|
|
263
|
+
'[GridLayoutApi] transformFieldsToColumnState: invalid columnDefs, returning empty array'
|
|
264
|
+
);
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
// Pokud nemáme userFields, vrátíme default column state z columnDefs
|
|
268
|
+
if (!userFields || !Array.isArray(userFields)) {
|
|
269
|
+
return columnDefs.map((colDef, index) => ({
|
|
270
|
+
colId: colDef.field || colDef.colId,
|
|
271
|
+
width: colDef.width || 100,
|
|
272
|
+
hide: colDef.hide || false,
|
|
273
|
+
pinned: colDef.pinned || null,
|
|
274
|
+
sort: null,
|
|
275
|
+
sortIndex: null,
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Vytvoříme mapu userFields pro rychlé vyhledávání - pouze s validními fieldName
|
|
280
|
+
const userFieldsMap = new Map();
|
|
281
|
+
const invalidUserFields = [];
|
|
282
|
+
|
|
283
|
+
userFields.forEach((userField, index) => {
|
|
284
|
+
// API používá lowercase názvy (fieldName, order, show) místo uppercase (FieldName, Order, Show)
|
|
285
|
+
const fieldName = userField.fieldName || userField.FieldName;
|
|
286
|
+
|
|
287
|
+
// Validace fieldName - musí být neprázdný string
|
|
288
|
+
if (typeof fieldName === 'string' && fieldName.trim() !== '') {
|
|
289
|
+
userFieldsMap.set(fieldName, userField);
|
|
290
|
+
} else {
|
|
291
|
+
invalidUserFields.push({ index, userField, fieldName });
|
|
292
|
+
console.warn(
|
|
293
|
+
`[GridLayoutApi] Ignoring userField with invalid fieldName at index ${index}:`,
|
|
294
|
+
{
|
|
295
|
+
fieldName,
|
|
296
|
+
typeof_fieldName: typeof fieldName,
|
|
297
|
+
userField,
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
if (invalidUserFields.length > 0) {
|
|
304
|
+
console.warn(
|
|
305
|
+
`[GridLayoutApi] Found ${invalidUserFields.length} userFields with invalid fieldNames:`,
|
|
306
|
+
invalidUserFields
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Removed console.log debug for production
|
|
311
|
+
|
|
312
|
+
// Vytvoříme column state POUZE pro sloupce, které mají záznam v userFields
|
|
313
|
+
const columnStateWithUserFields = columnDefs
|
|
314
|
+
.map((colDef, defaultIndex) => {
|
|
315
|
+
// Získat userField podle field nebo colId
|
|
316
|
+
const fieldName = colDef.field || colDef.colId;
|
|
317
|
+
const userField = userFieldsMap.get(fieldName);
|
|
318
|
+
|
|
319
|
+
// Pokud pro tento sloupec není userField, vracíme null (bude odfiltrován)
|
|
320
|
+
if (!userField) {
|
|
321
|
+
// Removed console.log for production
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Získáme hodnotu show z API - musíme kontrolovat explicitně false hodnoty
|
|
326
|
+
const showValue =
|
|
327
|
+
userField.show !== undefined
|
|
328
|
+
? userField.show
|
|
329
|
+
: userField.Show !== undefined
|
|
330
|
+
? userField.Show
|
|
331
|
+
: !colDef.hide; // Fallback na opak column def hide hodnoty
|
|
332
|
+
|
|
333
|
+
const result = {
|
|
334
|
+
colId: colDef.field || colDef.colId,
|
|
335
|
+
// API používá lowercase názvy polí - správně zachováváme i nulové hodnoty
|
|
336
|
+
width: (userField.width != null) ? userField.width :
|
|
337
|
+
(userField.Width != null) ? userField.Width :
|
|
338
|
+
(colDef.width ?? 100),
|
|
339
|
+
hide: !showValue, // Respektujeme přesně hodnotu show z API
|
|
340
|
+
pinned: colDef.pinned || null, // Pinning z columnDefs, userFields to zatím nepodporuje
|
|
341
|
+
sort: null, // Sorting není součástí layout managementu
|
|
342
|
+
sortIndex: null,
|
|
343
|
+
// Pořadí z userFields (lowercase/uppercase)
|
|
344
|
+
__order: userField.order ?? userField.Order ?? defaultIndex,
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// Removed console.log for production
|
|
348
|
+
|
|
349
|
+
return result;
|
|
350
|
+
})
|
|
351
|
+
.filter(Boolean); // Odfiltrujeme null hodnoty
|
|
352
|
+
|
|
353
|
+
// Seřadíme podle pořadí z userFields
|
|
354
|
+
const sortedColumnState = columnStateWithUserFields.sort(
|
|
355
|
+
(a, b) => (a.__order || 0) - (b.__order || 0)
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
// Removed console.log for production
|
|
359
|
+
|
|
360
|
+
const finalResult = sortedColumnState.map(
|
|
361
|
+
({ __order, ...columnState }) => columnState
|
|
362
|
+
);
|
|
363
|
+
return finalResult;
|
|
364
|
+
}, []);
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
// Query hooks
|
|
368
|
+
useUserFields,
|
|
369
|
+
useSingleGrid,
|
|
370
|
+
useUserGrids,
|
|
371
|
+
// Mutation methods
|
|
372
|
+
saveGridLayout,
|
|
373
|
+
// Transform utilities
|
|
374
|
+
transformColumnStateToFields,
|
|
375
|
+
transformFieldsToColumnState,
|
|
376
|
+
// Config
|
|
377
|
+
gridQueryKey,
|
|
378
|
+
baseParams,
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export default useGridLayoutApi;
|