data-primals-engine 1.5.2 → 1.6.1
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/README.md +938 -915
- package/client/README.md +136 -136
- package/client/index.js +0 -1
- package/client/public/doc/API.postman_collection.json +213 -213
- package/client/public/react.svg +9 -9
- package/client/src/AddWidgetTypeModal.jsx +47 -47
- package/client/src/App.css +42 -42
- package/client/src/App.jsx +92 -150
- package/client/src/App.scss +6 -0
- package/client/src/AssistantChat.jsx +362 -363
- package/client/src/Button.jsx +12 -12
- package/client/src/Dashboard.jsx +480 -480
- package/client/src/DashboardHtmlViewItem.jsx +146 -146
- package/client/src/DashboardView.jsx +654 -654
- package/client/src/DataEditor.jsx +383 -383
- package/client/src/DataLayout.jsx +779 -808
- package/client/src/DataTable.jsx +782 -822
- package/client/src/DataTable.scss +186 -186
- package/client/src/GeolocationField.jsx +93 -93
- package/client/src/HistoryDialog.jsx +307 -307
- package/client/src/HistoryDialog.scss +319 -319
- package/client/src/HtmlViewBuilderModal.jsx +90 -90
- package/client/src/HtmlViewBuilderModal.scss +17 -17
- package/client/src/HtmlViewCard.jsx +43 -43
- package/client/src/ModelCreator.jsx +683 -686
- package/client/src/ModelCreator.scss +1 -1
- package/client/src/ModelCreatorField.jsx +950 -950
- package/client/src/ModelImporter.jsx +3 -0
- package/client/src/ModelList.jsx +280 -280
- package/client/src/Notification.jsx +136 -136
- package/client/src/PackGallery.jsx +391 -391
- package/client/src/PackGallery.scss +231 -231
- package/client/src/Pagination.jsx +143 -143
- package/client/src/RelationField.jsx +354 -354
- package/client/src/RelationSelectorWidget.jsx +172 -172
- package/client/src/RelationValue.jsx +2 -1
- package/client/src/contexts/CommandContext.jsx +260 -0
- package/client/src/contexts/ModelContext.jsx +4 -1
- package/client/src/contexts/UIContext.jsx +72 -72
- package/client/src/filter.js +263 -263
- package/client/src/index.css +90 -90
- package/package.json +6 -5
- package/perf/artillery-hooks.js +37 -37
- package/perf/setup.yml +25 -25
- package/src/constants.js +4 -0
- package/src/defaultModels.js +7 -0
- package/src/engine.js +335 -335
- package/src/events.js +232 -137
- package/src/filter.js +274 -274
- package/src/index.js +1 -0
- package/src/modules/assistant/assistant.js +225 -83
- package/src/modules/auth-google/index.js +50 -50
- package/src/modules/auth-microsoft/index.js +81 -81
- package/src/modules/data/data.core.js +118 -118
- package/src/modules/data/data.history.js +555 -555
- package/src/modules/data/data.operations.js +112 -9
- package/src/modules/data/data.relations.js +686 -686
- package/src/modules/data/data.routes.js +1879 -1879
- package/src/modules/data/data.validation.js +2 -2
- package/src/modules/file.js +247 -247
- package/src/modules/user.js +14 -9
- package/src/packs.js +2 -2
- package/src/providers.js +2 -2
- package/src/services/stripe.js +196 -196
- package/src/sso.js +193 -193
- package/test/data.history.integration.test.js +264 -264
- package/test/data.integration.test.js +1281 -1206
- package/test/events.test.js +108 -10
- package/test/model.integration.test.js +377 -377
- package/test/user.test.js +106 -1
|
@@ -1,687 +1,684 @@
|
|
|
1
|
-
|
|
2
|
-
import React, {forwardRef, useEffect, useRef, useState} from 'react';
|
|
3
|
-
import {useMutation, useQuery, useQueryClient} from 'react-query';
|
|
4
|
-
import {useModelContext} from "./contexts/ModelContext.jsx";
|
|
5
|
-
import {FaArrowDown, FaArrowUp, FaEdit, FaInfo, FaMinus, FaPlus, FaSave, FaTrash} from "react-icons/fa";
|
|
6
|
-
|
|
7
|
-
import "./ModelCreator.scss"
|
|
8
|
-
import {CheckboxField, CodeField, ColorField, IconField, NumberField, SelectField, TextField} from "./Field.jsx";
|
|
9
|
-
import Button from "./Button.jsx";
|
|
10
|
-
import {Trans, useTranslation} from "react-i18next";
|
|
11
|
-
import {
|
|
12
|
-
allowedFields,
|
|
13
|
-
defaultMaxRequestData,
|
|
14
|
-
mainFieldsTypes, maxFileSize,
|
|
15
|
-
maxModelNameLength,
|
|
16
|
-
maxRequestData
|
|
17
|
-
} from "../../src/constants.js";
|
|
18
|
-
import {useAuthContext} from "./contexts/AuthContext.jsx";
|
|
19
|
-
import {getUserHash, getUserId, isLocalUser} from "../../src/data.js";
|
|
20
|
-
import {useNotificationContext} from "./NotificationProvider.jsx";
|
|
21
|
-
import ConditionBuilder from './ConditionBuilder.jsx';
|
|
22
|
-
import './ConditionBuilder.scss';
|
|
23
|
-
import {Tooltip} from "react-tooltip";
|
|
24
|
-
import {FaCircleInfo} from "react-icons/fa6";
|
|
25
|
-
import i18n from "../../src/i18n.js";
|
|
26
|
-
import Draggable from "./Draggable.jsx";
|
|
27
|
-
import FlexBuilder from "./FlexBuilder.jsx";
|
|
28
|
-
import {NavLink} from "react-router";
|
|
29
|
-
import CalculationBuilder from "./CalculationBuilder.jsx";
|
|
30
|
-
import CronBuilder from "./CronBuilder.jsx";
|
|
31
|
-
import ModelCreatorField from "./ModelCreatorField.jsx";
|
|
32
|
-
import useLocalStorage from "./hooks/useLocalStorage.js";
|
|
33
|
-
|
|
34
|
-
const ModelCreator = forwardRef(({ initialPrompt = '', onModelGenerated, autoGenerate = false, initialModel, onModelSaved }, ref) => {
|
|
35
|
-
|
|
36
|
-
const queryClient = useQueryClient();
|
|
37
|
-
const {t, i18n} = useTranslation();
|
|
38
|
-
const lang = (i18n.resolvedLanguage || i18n.language).split(/[-_]/)?.[0];
|
|
39
|
-
|
|
40
|
-
const {models, elementsPerPage, page, setDatasToLoad, selectedModel, setSelectedModel, pagedFilters, relationIds, pagedSort, setGeneratedModels, generatedModels } = useModelContext();
|
|
41
|
-
const [modelName, setModelName] = useState(initialModel?.name || ''); // Utilisation de initialModel
|
|
42
|
-
const [modelMaxRequestData, setModelMaxRequestData] = useState(initialModel?.maxRequestData || ''); // Utilisation de initialModel
|
|
43
|
-
const [modelDescription, setModelDescription] = useState(initialModel?.name ? t(`model_description_${initialModel?.name}`, initialModel?.description) : '');
|
|
44
|
-
const [modelHistory, setModelHistory] = useState(!!initialModel?.history || undefined);
|
|
45
|
-
const [modelIcon, setModelIcon] = useState(!!initialModel?.icon || undefined);
|
|
46
|
-
const [fields, setFields] = useState([]);
|
|
47
|
-
const [changed, setChanged] = useState(false);
|
|
48
|
-
|
|
49
|
-
const [selectedGeneratedModelIndex, setSelectedGeneratedModelIndex] = useState(0); // Pour l'index du modèle choisi
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
if (initialModel) {
|
|
53
|
-
// Mode édition : on charge les données du modèle existant
|
|
54
|
-
setModelName(initialModel.name || '');
|
|
55
|
-
setModelMaxRequestData(initialModel.maxRequestData || defaultMaxRequestData);
|
|
56
|
-
setModelDescription(initialModel.name ? t(`model_description_${initialModel.name}`, initialModel.description) : '');
|
|
57
|
-
setFields([...(initialModel.fields || []).map(m => ({...m}))]);
|
|
58
|
-
setModelHistory(initialModel.history);
|
|
59
|
-
setModelIcon(initialModel.icon);
|
|
60
|
-
} else {
|
|
61
|
-
// Mode création : on réinitialise tout pour une nouvelle génération
|
|
62
|
-
setModelName('');
|
|
63
|
-
setModelDescription('');
|
|
64
|
-
setFields([]);
|
|
65
|
-
setUseAI(true); // On active l'IA par défaut
|
|
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
|
-
queryClient.invalidateQueries('api/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
queryClient.invalidateQueries(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
newFields
|
|
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
|
-
case '
|
|
241
|
-
case '
|
|
242
|
-
case '
|
|
243
|
-
case '
|
|
244
|
-
case '
|
|
245
|
-
case '
|
|
246
|
-
case '
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
case '
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
case '
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
array[
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
newFields
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
newFields[index].items[i
|
|
351
|
-
newFields
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
newFields[index].items[i
|
|
361
|
-
newFields
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const [
|
|
366
|
-
const [
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const [
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
{
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
{
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
{
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
/>
|
|
502
|
-
<
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
{
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
{
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
<
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
disabled={modelLocked
|
|
563
|
-
checked={
|
|
564
|
-
onChange={(e) => {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
<
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
<
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
<
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
)
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
<
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
});
|
|
685
|
-
ModelCreator.displayName = "ModelCreator";
|
|
686
|
-
|
|
1
|
+
|
|
2
|
+
import React, {forwardRef, useEffect, useRef, useState} from 'react';
|
|
3
|
+
import {useMutation, useQuery, useQueryClient} from 'react-query';
|
|
4
|
+
import {useModelContext} from "./contexts/ModelContext.jsx";
|
|
5
|
+
import {FaArrowDown, FaArrowUp, FaEdit, FaInfo, FaMinus, FaPlus, FaSave, FaTrash} from "react-icons/fa";
|
|
6
|
+
|
|
7
|
+
import "./ModelCreator.scss"
|
|
8
|
+
import {CheckboxField, CodeField, ColorField, IconField, NumberField, SelectField, TextField} from "./Field.jsx";
|
|
9
|
+
import Button from "./Button.jsx";
|
|
10
|
+
import {Trans, useTranslation} from "react-i18next";
|
|
11
|
+
import {
|
|
12
|
+
allowedFields,
|
|
13
|
+
defaultMaxRequestData,
|
|
14
|
+
mainFieldsTypes, maxFileSize,
|
|
15
|
+
maxModelNameLength,
|
|
16
|
+
maxRequestData
|
|
17
|
+
} from "../../src/constants.js";
|
|
18
|
+
import {useAuthContext} from "./contexts/AuthContext.jsx";
|
|
19
|
+
import {getUserHash, getUserId, isLocalUser} from "../../src/data.js";
|
|
20
|
+
import {useNotificationContext} from "./NotificationProvider.jsx";
|
|
21
|
+
import ConditionBuilder from './ConditionBuilder.jsx';
|
|
22
|
+
import './ConditionBuilder.scss';
|
|
23
|
+
import {Tooltip} from "react-tooltip";
|
|
24
|
+
import {FaCircleInfo} from "react-icons/fa6";
|
|
25
|
+
import i18n from "../../src/i18n.js";
|
|
26
|
+
import Draggable from "./Draggable.jsx";
|
|
27
|
+
import FlexBuilder from "./FlexBuilder.jsx";
|
|
28
|
+
import {NavLink} from "react-router";
|
|
29
|
+
import CalculationBuilder from "./CalculationBuilder.jsx";
|
|
30
|
+
import CronBuilder from "./CronBuilder.jsx";
|
|
31
|
+
import ModelCreatorField from "./ModelCreatorField.jsx";
|
|
32
|
+
import useLocalStorage from "./hooks/useLocalStorage.js";
|
|
33
|
+
|
|
34
|
+
const ModelCreator = forwardRef(({ initialPrompt = '', onModelGenerated, autoGenerate = false, initialModel, onModelSaved }, ref) => {
|
|
35
|
+
|
|
36
|
+
const queryClient = useQueryClient();
|
|
37
|
+
const {t, i18n} = useTranslation();
|
|
38
|
+
const lang = (i18n.resolvedLanguage || i18n.language).split(/[-_]/)?.[0];
|
|
39
|
+
|
|
40
|
+
const {models, elementsPerPage, page, setDatasToLoad, selectedModel, setSelectedModel, pagedFilters, relationIds, pagedSort, setGeneratedModels, generatedModels } = useModelContext();
|
|
41
|
+
const [modelName, setModelName] = useState(initialModel?.name || ''); // Utilisation de initialModel
|
|
42
|
+
const [modelMaxRequestData, setModelMaxRequestData] = useState(initialModel?.maxRequestData || ''); // Utilisation de initialModel
|
|
43
|
+
const [modelDescription, setModelDescription] = useState(initialModel?.name ? t(`model_description_${initialModel?.name}`, initialModel?.description) : '');
|
|
44
|
+
const [modelHistory, setModelHistory] = useState(!!initialModel?.history || undefined);
|
|
45
|
+
const [modelIcon, setModelIcon] = useState(!!initialModel?.icon || undefined);
|
|
46
|
+
const [fields, setFields] = useState([]);
|
|
47
|
+
const [changed, setChanged] = useState(false);
|
|
48
|
+
|
|
49
|
+
const [selectedGeneratedModelIndex, setSelectedGeneratedModelIndex] = useState(0); // Pour l'index du modèle choisi
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (initialModel) {
|
|
53
|
+
// Mode édition : on charge les données du modèle existant
|
|
54
|
+
setModelName(initialModel.name || '');
|
|
55
|
+
setModelMaxRequestData(initialModel.maxRequestData || defaultMaxRequestData);
|
|
56
|
+
setModelDescription(initialModel.name ? t(`model_description_${initialModel.name}`, initialModel.description) : '');
|
|
57
|
+
setFields([...(initialModel.fields || []).map(m => ({...m}))]);
|
|
58
|
+
setModelHistory(initialModel.history);
|
|
59
|
+
setModelIcon(initialModel.icon);
|
|
60
|
+
} else {
|
|
61
|
+
// Mode création : on réinitialise tout pour une nouvelle génération
|
|
62
|
+
setModelName('');
|
|
63
|
+
setModelDescription('');
|
|
64
|
+
setFields([]);
|
|
65
|
+
setUseAI(true); // On active l'IA par défaut
|
|
66
|
+
setModelHistory(false);
|
|
67
|
+
setModelIcon(null);
|
|
68
|
+
}
|
|
69
|
+
}, [initialModel]);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (generatedModels.length > 0 && selectedGeneratedModelIndex >= 0) {
|
|
73
|
+
const selectedModel = generatedModels[selectedGeneratedModelIndex];
|
|
74
|
+
if (selectedModel) {
|
|
75
|
+
setModelName(selectedModel.name || '');
|
|
76
|
+
setModelDescription(selectedModel.description || '');
|
|
77
|
+
setFields(selectedModel.fields || []);
|
|
78
|
+
setModelMaxRequestData(selectedModel.maxRequestData || defaultMaxRequestData);
|
|
79
|
+
setModelIcon(selectedModel.icon || null);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, [generatedModels, selectedGeneratedModelIndex]);
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if( !changed)
|
|
86
|
+
setModelDescription(initialModel?.name ? t('model_description_'+initialModel?.name, initialModel?.description) : '');
|
|
87
|
+
}, [lang]);
|
|
88
|
+
|
|
89
|
+
const mutationRename = useMutation(
|
|
90
|
+
({oldName, newName}) => {
|
|
91
|
+
const url = `/api/model/${initialModel._id}/renameField?_user=${encodeURIComponent(getUserId(me))}`;
|
|
92
|
+
return fetch(url, {
|
|
93
|
+
method: 'PATCH',
|
|
94
|
+
headers: { 'Content-Type': 'application/json' },
|
|
95
|
+
body: JSON.stringify({ oldFieldName: oldName, newFieldName: newName }),
|
|
96
|
+
}).then((res) => res.json());
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
onSuccess: (data) => {
|
|
100
|
+
setDatasToLoad(datas=>[...datas, modelName]);
|
|
101
|
+
queryClient.invalidateQueries('api/models');
|
|
102
|
+
queryClient.invalidateQueries(['api/data', modelName, 'page', page, elementsPerPage, pagedFilters[modelName], pagedSort[modelName]]);
|
|
103
|
+
},
|
|
104
|
+
onError: (error) => {
|
|
105
|
+
console.error('Erreur:', error);
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const { me } = useAuthContext()
|
|
111
|
+
|
|
112
|
+
const {addNotification} = useNotificationContext()
|
|
113
|
+
|
|
114
|
+
const mutation = useMutation(
|
|
115
|
+
(modelData) => {
|
|
116
|
+
const url = initialModel?._id ? `/api/model/${initialModel._id}` : '/api/model'; // Utilisation de initialModel pour l'URL
|
|
117
|
+
const method = initialModel?._id ? 'PUT' : 'POST';
|
|
118
|
+
return fetch(url+'?_user='+me.username, {
|
|
119
|
+
method: method,
|
|
120
|
+
headers: { 'Content-Type': 'application/json' },
|
|
121
|
+
body: JSON.stringify(modelData),
|
|
122
|
+
}).then((res) => res.json());
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
onSuccess: (data) => {
|
|
126
|
+
|
|
127
|
+
const notificationData = {
|
|
128
|
+
title: data.success ? t('modelcreator.success', 'Modèle sauvegardé') : t(data.error, data.error),
|
|
129
|
+
icon: data.success ? <FaInfo /> : undefined,
|
|
130
|
+
status: data.success ? 'completed': 'error'
|
|
131
|
+
};
|
|
132
|
+
addNotification(notificationData);
|
|
133
|
+
|
|
134
|
+
if (!initialModel) {
|
|
135
|
+
setModelName('');
|
|
136
|
+
setModelDescription('');
|
|
137
|
+
setModelMaxRequestData(defaultMaxRequestData);
|
|
138
|
+
setFields([{ name: '', type: 'string' }]);
|
|
139
|
+
setModelHistory(undefined);
|
|
140
|
+
setModelIcon(null);
|
|
141
|
+
}
|
|
142
|
+
setDatasToLoad(datas=>[...datas, modelName]);
|
|
143
|
+
|
|
144
|
+
queryClient.invalidateQueries(['api/data', modelName, 'page', page, elementsPerPage, pagedFilters[modelName], pagedSort[modelName]]);
|
|
145
|
+
queryClient.invalidateQueries('api/models');
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
},
|
|
149
|
+
onError: (error) => {
|
|
150
|
+
const notificationData = {
|
|
151
|
+
title: t(error, error),
|
|
152
|
+
status: 'error'
|
|
153
|
+
};
|
|
154
|
+
addNotification(notificationData);
|
|
155
|
+
console.error('Erreur:', error);
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const handleAddField = () => {
|
|
161
|
+
setFields([...fields, { name: '', type: 'string', _isNewField: true }]);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const handleRemoveField = (index) => {
|
|
165
|
+
const newFields = [...fields];
|
|
166
|
+
newFields.splice(index, 1);
|
|
167
|
+
setFields(newFields);
|
|
168
|
+
};
|
|
169
|
+
const deleteMutation = useMutation(
|
|
170
|
+
(modelName) =>
|
|
171
|
+
fetch(`/api/model?name=${modelName}&_user=${encodeURIComponent(getUserId(me))}`, {
|
|
172
|
+
method: 'DELETE',
|
|
173
|
+
}).then((res) => res.json()),
|
|
174
|
+
{
|
|
175
|
+
onSuccess: () => {
|
|
176
|
+
queryClient.invalidateQueries('api/models');
|
|
177
|
+
if (onModelSaved) {
|
|
178
|
+
onModelSaved(); // Vous pouvez passer un argument ici si nécessaire
|
|
179
|
+
}
|
|
180
|
+
// Réinitialiser le formulaire ou rediriger, selon vos besoins
|
|
181
|
+
setModelName('');
|
|
182
|
+
setModelDescription('');
|
|
183
|
+
setSelectedModel(null)
|
|
184
|
+
setModelHistory(undefined)
|
|
185
|
+
setModelIcon(null);
|
|
186
|
+
setFields([{ name: '', type: 'string', _isNewField: true }]);
|
|
187
|
+
setDatasToLoad(datas => datas.filter(f => f !== modelName));
|
|
188
|
+
setGeneratedModels(mods => {
|
|
189
|
+
return mods.filter(m => m.name !== initialModel.name);
|
|
190
|
+
});
|
|
191
|
+
const notificationData = {
|
|
192
|
+
title: t('modelcreator.deleteSuccess', 'Modèle supprimé'),
|
|
193
|
+
icon: <FaInfo />,
|
|
194
|
+
status: 'completed'
|
|
195
|
+
};
|
|
196
|
+
addNotification(notificationData);
|
|
197
|
+
},
|
|
198
|
+
onError: (error) => {
|
|
199
|
+
console.error('Erreur lors de la suppression:', error);
|
|
200
|
+
|
|
201
|
+
const notificationData = {
|
|
202
|
+
title: t(error, error),
|
|
203
|
+
status: 'error'
|
|
204
|
+
};
|
|
205
|
+
addNotification(notificationData);
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const handleDelete = () => {
|
|
211
|
+
if (initialModel && window.confirm("Êtes-vous sûr de vouloir supprimer ce modèle ?")) {
|
|
212
|
+
deleteMutation.mutate(initialModel.name);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const handleSubmit = (e) => {
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
const newModel = {
|
|
218
|
+
name: modelName,
|
|
219
|
+
description: modelDescription,
|
|
220
|
+
maxRequestData: modelMaxRequestData,
|
|
221
|
+
history: modelHistory,
|
|
222
|
+
icon: modelIcon,
|
|
223
|
+
fields: (fields || []).map((field) => {
|
|
224
|
+
delete field['_isNewField'];
|
|
225
|
+
let otherFields = [];
|
|
226
|
+
// Check for specific field types
|
|
227
|
+
switch ((field.type)) {
|
|
228
|
+
case 'relation':
|
|
229
|
+
otherFields = ['relation', 'multiple', 'relationFilter'];
|
|
230
|
+
break;
|
|
231
|
+
case 'enum':
|
|
232
|
+
{
|
|
233
|
+
otherFields = ['items']
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case 'number':
|
|
237
|
+
otherFields = ['min', 'max', 'step', 'unit','delay', 'gauge', 'percent'];
|
|
238
|
+
break;
|
|
239
|
+
case 'string':
|
|
240
|
+
case 'string_t':
|
|
241
|
+
case 'richtext':
|
|
242
|
+
case 'url':
|
|
243
|
+
case 'email':
|
|
244
|
+
case 'phone':
|
|
245
|
+
case 'password':
|
|
246
|
+
case 'code':
|
|
247
|
+
const t = (field.itemsType || field.type);
|
|
248
|
+
if (t === 'code')
|
|
249
|
+
otherFields = ['maxlength', 'language', 'conditionBuilder'];
|
|
250
|
+
else if( ['string_t', 'string'].includes(t))
|
|
251
|
+
otherFields = ['maxlength', 'multiline', 'mask', 'replacement'];
|
|
252
|
+
else
|
|
253
|
+
otherFields = ['maxlength'];
|
|
254
|
+
break;
|
|
255
|
+
case 'date':
|
|
256
|
+
case 'datetime':
|
|
257
|
+
{
|
|
258
|
+
otherFields = ['min','max'];
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case 'image':
|
|
262
|
+
case 'file':
|
|
263
|
+
otherFields = ['mimeTypes', 'maxSize'];
|
|
264
|
+
break;
|
|
265
|
+
case 'calculated':
|
|
266
|
+
otherFields = ['calculation'];
|
|
267
|
+
break;
|
|
268
|
+
case 'array':
|
|
269
|
+
otherFields = ['itemsType'];
|
|
270
|
+
break;
|
|
271
|
+
default:
|
|
272
|
+
}
|
|
273
|
+
Object.keys(field).forEach(f => {
|
|
274
|
+
if( ![...allowedFields, ...otherFields].includes(f))
|
|
275
|
+
delete field[f];
|
|
276
|
+
});
|
|
277
|
+
return field;
|
|
278
|
+
}),
|
|
279
|
+
};
|
|
280
|
+
setGeneratedModels(gen => gen.filter(m => m.name !== newModel.name));
|
|
281
|
+
mutation.mutateAsync(newModel).then(data => {
|
|
282
|
+
queryClient.invalidateQueries('api/models');
|
|
283
|
+
newModel.fields.forEach(field => {
|
|
284
|
+
if( field.type === "relation") {
|
|
285
|
+
queryClient.invalidateQueries(['api/data', field.relation, relationIds[field.relation]]);
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
if (onModelSaved) {
|
|
289
|
+
onModelSaved(data.data);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
};
|
|
294
|
+
const swapElements = (array, index1, index2) => {
|
|
295
|
+
if( index1 < 0 || index2 < 0 || index1 >= array.length || index2 >= array.length)
|
|
296
|
+
return;
|
|
297
|
+
let temp = array[index1];
|
|
298
|
+
array[index1] = array[index2];
|
|
299
|
+
array[index2] = temp;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const handleUp = (index) => {
|
|
303
|
+
const nf = [...fields];
|
|
304
|
+
swapElements(nf, index, index -1);
|
|
305
|
+
setFields(nf);
|
|
306
|
+
};
|
|
307
|
+
const handleDown = (index) => {
|
|
308
|
+
const nf = [...fields];
|
|
309
|
+
swapElements(nf, index, index + 1);
|
|
310
|
+
setFields(nf);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const handleAddValue = (fi) => {
|
|
314
|
+
const newFields = [...fields];
|
|
315
|
+
if( !newFields[fi].items )
|
|
316
|
+
newFields[fi].items = [];
|
|
317
|
+
newFields[fi].items.push("");
|
|
318
|
+
setFields(newFields)
|
|
319
|
+
}
|
|
320
|
+
const handleRemoveValue = (fi, index) => {
|
|
321
|
+
const newFields = [...fields];
|
|
322
|
+
const field = newFields[fi];
|
|
323
|
+
field.items = field.items.filter((f,i) => i !== index);
|
|
324
|
+
setFields(newFields)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const handleRenameField = (fi, oldVal) => {
|
|
328
|
+
const prompted = window.prompt(t('core.renameFields', 'Renommer le champ'), oldVal);
|
|
329
|
+
if (prompted && prompted !== oldVal) {
|
|
330
|
+
mutationRename.mutateAsync({oldName: oldVal, newName: prompted}).then(e =>{
|
|
331
|
+
const newFields = [...fields];
|
|
332
|
+
const field = newFields[fi];
|
|
333
|
+
field.name = prompted;
|
|
334
|
+
setFields(newFields)
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
const modelLocked = !!initialModel && (!initialModel?._user ? true : isLocalUser(me) && initialModel?.locked);
|
|
341
|
+
|
|
342
|
+
const hint = (description) => t(description, '') && <div className="hint-icon"><FaCircleInfo data-tooltip-id={`tooltipHint`} data-tooltip-content={description} /></div>
|
|
343
|
+
|
|
344
|
+
const handleMoveDown = (field, index, i) => {
|
|
345
|
+
const newFields = [...fields];
|
|
346
|
+
if( i + 1 >= newFields[index].items.length )
|
|
347
|
+
return;
|
|
348
|
+
const r = newFields[index].items[i + 1];
|
|
349
|
+
newFields[index].items[i + 1] = newFields[index].items[i];
|
|
350
|
+
newFields[index].items[i] = r;
|
|
351
|
+
setFields(newFields);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const handleMoveUp = (field, index, i) => {
|
|
355
|
+
const newFields = [...fields];
|
|
356
|
+
if( i < 1 )
|
|
357
|
+
return;
|
|
358
|
+
const r = newFields[index].items[i - 1];
|
|
359
|
+
newFields[index].items[i - 1] = newFields[index].items[i];
|
|
360
|
+
newFields[index].items[i] = r;
|
|
361
|
+
setFields(newFields);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const [useAI, setUseAI] = useState(true);
|
|
365
|
+
const [showModel, setModelVisible] = useState(false);
|
|
366
|
+
const [prompt, setPrompt] = useState('');
|
|
367
|
+
|
|
368
|
+
const [homePrompt, setHomePrompt] = useLocalStorage("ai_model_prompt", null);
|
|
369
|
+
const [promptResult, setPromptResult] = useLocalStorage("ai_model_prompt_result", null);
|
|
370
|
+
|
|
371
|
+
// NOUVEAU : Créer une référence pour suivre le déclenchement
|
|
372
|
+
const hasTriggeredAutoGenerate = useRef(false);
|
|
373
|
+
|
|
374
|
+
const[generationIsLoading, setGenerationIsLoading] =useState(false);
|
|
375
|
+
|
|
376
|
+
const generateModelMutation = useMutation(
|
|
377
|
+
async ({userPrompt, modelToEdit}) => {
|
|
378
|
+
const bodyPayload = { prompt: userPrompt };
|
|
379
|
+
// Si on est en mode édition, on ajoute le modèle au corps de la requête
|
|
380
|
+
if (modelToEdit) {
|
|
381
|
+
bodyPayload.existingModel = modelToEdit;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const response = await fetch(`/api/model/generate?lang=${lang}`, {
|
|
385
|
+
method: 'POST',
|
|
386
|
+
headers: { 'Content-Type': 'application/json' },
|
|
387
|
+
body: JSON.stringify(bodyPayload),
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
if (!response.ok) {
|
|
391
|
+
const err = await response.json();
|
|
392
|
+
throw new Error(err.error || 'Failed to generate model');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return response.json();
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
onSuccess: (data) => {
|
|
399
|
+
const modelsList = data?.models || data || [];
|
|
400
|
+
|
|
401
|
+
if (modelsList && Array.isArray(modelsList) && modelsList.length > 0) {
|
|
402
|
+
const mds = modelsList.map(m => ({ ...m, _user: getUserId(me) }));
|
|
403
|
+
setGeneratedModels(g=>[...g, ...mds]);
|
|
404
|
+
onModelGenerated?.(mds);
|
|
405
|
+
modelsList.forEach(d => gtag('event', 'model generation "' + d.name + '"'));
|
|
406
|
+
|
|
407
|
+
setSelectedGeneratedModelIndex(0); // Sélectionne le premier par défaut
|
|
408
|
+
setModelVisible(true); // Affiche la section avec la liste et le formulaire
|
|
409
|
+
setHomePrompt(null);
|
|
410
|
+
addNotification({ title: t('modelcreator.generate.success'), status: 'completed' });
|
|
411
|
+
} else {
|
|
412
|
+
// GA ne retourne aucun modèle
|
|
413
|
+
setModelVisible(false);
|
|
414
|
+
setHomePrompt(null);
|
|
415
|
+
addNotification({
|
|
416
|
+
title: t('modelcreator.generate.error'),
|
|
417
|
+
description: t('modelcreator.generate.no_models', "Aucun modèle n'a pu être généré."),
|
|
418
|
+
status: 'error'
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
setGenerationIsLoading(false);
|
|
422
|
+
},
|
|
423
|
+
onError: (error) => {
|
|
424
|
+
setPromptResult(false);
|
|
425
|
+
addNotification({
|
|
426
|
+
title: t('modelcreator.generate.error'),
|
|
427
|
+
description: error.message,
|
|
428
|
+
status: 'error'
|
|
429
|
+
});
|
|
430
|
+
},
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
const handleGenerate = () => {
|
|
435
|
+
if( prompt?.trim() ){
|
|
436
|
+
gtag("event", "generate model by AI");
|
|
437
|
+
setPromptResult(null);
|
|
438
|
+
setGenerationIsLoading(true);
|
|
439
|
+
generateModelMutation.mutate({
|
|
440
|
+
userPrompt: prompt,
|
|
441
|
+
modelToEdit: initialModel
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
useEffect(() => {
|
|
447
|
+
// on ne veut la génération du prompt que si il y a un prompt en attente
|
|
448
|
+
if(homePrompt && !hasTriggeredAutoGenerate.current){
|
|
449
|
+
setPrompt(homePrompt);
|
|
450
|
+
hasTriggeredAutoGenerate.current = true;
|
|
451
|
+
setUseAI(true);
|
|
452
|
+
setGenerationIsLoading(true);
|
|
453
|
+
generateModelMutation.mutate({
|
|
454
|
+
userPrompt: homePrompt,
|
|
455
|
+
modelToEdit: initialModel
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
}, [initialModel]); // Le tableau vide est toujours correct
|
|
460
|
+
return (
|
|
461
|
+
<div className="model-creator" ref={ref}>
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
<Tooltip id={"tooltipHint"}
|
|
465
|
+
place={"top-end"}
|
|
466
|
+
globalCloseEvents={{ clickOutsideAnchor: true }}
|
|
467
|
+
render={({ content, activeAnchor }) => {
|
|
468
|
+
gtag('render hint ' + content);
|
|
469
|
+
const c = t(content, content);
|
|
470
|
+
return c && (
|
|
471
|
+
<><p className="ws-pre-line">{c}</p></>)
|
|
472
|
+
}} />
|
|
473
|
+
<h2>
|
|
474
|
+
{!initialModel && <Trans i18nKey={"btns.createModel"}>Créer un modèle</Trans>}
|
|
475
|
+
{!!initialModel && <><Trans i18nKey={"btns.editModel"}>Editer le modèle</Trans> "{t(`model_${modelName}`, modelName)}"</>}
|
|
476
|
+
</h2>
|
|
477
|
+
<form onSubmit={handleSubmit}>
|
|
478
|
+
|
|
479
|
+
{/* Section pour choisir le mode de création (IA ou Manuel) */}
|
|
480
|
+
{!initialModel && (
|
|
481
|
+
<CheckboxField
|
|
482
|
+
label={<Trans i18nKey="modelcreator.useAI" />}
|
|
483
|
+
checked={useAI}
|
|
484
|
+
onChange={() => setUseAI(!useAI)}
|
|
485
|
+
/>
|
|
486
|
+
)}
|
|
487
|
+
|
|
488
|
+
{/* Section pour le prompt de l'IA (uniquement si création par IA et avant génération) */}
|
|
489
|
+
{useAI && !selectedModel && !showModel && (
|
|
490
|
+
<>
|
|
491
|
+
<div className="ai-prompt-container">
|
|
492
|
+
<>
|
|
493
|
+
<TextField
|
|
494
|
+
value={prompt}
|
|
495
|
+
onChange={(e) => setPrompt(e.target.value)}
|
|
496
|
+
multiline
|
|
497
|
+
help={t("modelcreator.generate.help")}
|
|
498
|
+
required
|
|
499
|
+
disabled={generationIsLoading}
|
|
500
|
+
/>
|
|
501
|
+
<div className="examples" dangerouslySetInnerHTML={{ __html: t('modelcreator.generate.examples') }} />
|
|
502
|
+
<Button
|
|
503
|
+
role={"button"}
|
|
504
|
+
onClick={handleGenerate}
|
|
505
|
+
disabled={generationIsLoading}
|
|
506
|
+
>
|
|
507
|
+
{generationIsLoading
|
|
508
|
+
? <Trans i18nKey="modelcreator.generating" />
|
|
509
|
+
: <Trans i18nKey="modelcreator.generate" />
|
|
510
|
+
}
|
|
511
|
+
</Button>
|
|
512
|
+
</>
|
|
513
|
+
</div>
|
|
514
|
+
{generationIsLoading && <p><Trans i18nKey="modelcreator.generating" /></p>}
|
|
515
|
+
</>
|
|
516
|
+
)}
|
|
517
|
+
|
|
518
|
+
{/* Layout principal pour afficher la liste et le formulaire côte à côte APRES génération */}
|
|
519
|
+
{useAI && showModel && !initialModel && (
|
|
520
|
+
<div className="flex model-generation-layout">
|
|
521
|
+
{/* Colonne de gauche: Liste des modèles générés */}
|
|
522
|
+
{generatedModels.some(g => models.find(f => f.name === g.name && f._user === g._user)) && (
|
|
523
|
+
<>
|
|
524
|
+
<div className="generated-models-list">
|
|
525
|
+
<h4>{t('modelcreator.generate.results_title', 'Suggestions de l\'IA')}</h4>
|
|
526
|
+
<ul>
|
|
527
|
+
{generatedModels.map((model, index) => (
|
|
528
|
+
<li
|
|
529
|
+
key={index}
|
|
530
|
+
className={index === selectedGeneratedModelIndex ? 'active' : ''}
|
|
531
|
+
onClick={() => setSelectedGeneratedModelIndex(index)}
|
|
532
|
+
>
|
|
533
|
+
{model.name}
|
|
534
|
+
</li>
|
|
535
|
+
))}
|
|
536
|
+
</ul>
|
|
537
|
+
</div>
|
|
538
|
+
|
|
539
|
+
{/* Colonne de droite: Formulaire du modèle sélectionné */}
|
|
540
|
+
<div className="model-form-container">
|
|
541
|
+
{/* Le formulaire existant est placé ici */}
|
|
542
|
+
<div className="field">
|
|
543
|
+
<div className="flex field-bg">
|
|
544
|
+
<label htmlFor="modelName"><Trans i18nKey={"modelcreator.name"}>Nom:</Trans></label>
|
|
545
|
+
</div>
|
|
546
|
+
<TextField
|
|
547
|
+
type="text"
|
|
548
|
+
id="modelName"
|
|
549
|
+
disabled={modelLocked}
|
|
550
|
+
value={modelName}
|
|
551
|
+
help={t('modelcreator.field.name.hint')}
|
|
552
|
+
onChange={(e) => setModelName(e.target.value)}
|
|
553
|
+
required
|
|
554
|
+
/>
|
|
555
|
+
</div>
|
|
556
|
+
|
|
557
|
+
<div className="field">
|
|
558
|
+
<div className="checkbox-label flex flex-1">
|
|
559
|
+
<CheckboxField
|
|
560
|
+
label={<Trans i18nKey={"history"}>Historique</Trans>}
|
|
561
|
+
help={t('modelcreator.field.history', '')}
|
|
562
|
+
disabled={modelLocked}
|
|
563
|
+
checked={!!modelHistory}
|
|
564
|
+
onChange={(e) => {
|
|
565
|
+
setModelHistory(e? { enabled: true }: false);
|
|
566
|
+
}}
|
|
567
|
+
/>
|
|
568
|
+
</div>
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
<h3><Trans i18nKey={"modelcreator.fields"}>Champs du modèle :</Trans></h3>
|
|
573
|
+
{fields.map((field, index) => <ModelCreatorField
|
|
574
|
+
key={initialModel?.name + '_field_' + index}
|
|
575
|
+
handleRemoveValue={handleRemoveValue}
|
|
576
|
+
handleAddValue={handleAddValue}
|
|
577
|
+
handleRenameField={handleRenameField}
|
|
578
|
+
handleUp={handleUp}
|
|
579
|
+
handleDown={handleDown}
|
|
580
|
+
handleRemoveField={handleRemoveField}
|
|
581
|
+
index={index} fields={fields} field={field} model={initialModel} setFields={setFields} />)}
|
|
582
|
+
</div></>)}
|
|
583
|
+
</div>
|
|
584
|
+
)}
|
|
585
|
+
|
|
586
|
+
{/* Affichage du formulaire en mode manuel ou édition */}
|
|
587
|
+
{(!useAI || !!initialModel) && (
|
|
588
|
+
<div className="model-form-container">
|
|
589
|
+
<div className="flex field-bg">
|
|
590
|
+
<label htmlFor="modelName"><Trans i18nKey={"modelcreator.name"}>Nom:</Trans></label>
|
|
591
|
+
</div>
|
|
592
|
+
<TextField
|
|
593
|
+
type="text"
|
|
594
|
+
id="modelName"
|
|
595
|
+
disabled={modelLocked}
|
|
596
|
+
value={modelName}
|
|
597
|
+
help={t('modelcreator.field.name.hint')}
|
|
598
|
+
onChange={(e) => setModelName(e.target.value)}
|
|
599
|
+
required
|
|
600
|
+
/>
|
|
601
|
+
|
|
602
|
+
<div className="flex field-bg">
|
|
603
|
+
<label htmlFor="modelDescription"><Trans i18nKey={"modelcreator.description"}>Description:</Trans></label>
|
|
604
|
+
</div>
|
|
605
|
+
<TextField
|
|
606
|
+
multiline
|
|
607
|
+
help={t('modelcreator.field.description')}
|
|
608
|
+
id="modelDescription"
|
|
609
|
+
disabled={modelLocked}
|
|
610
|
+
value={modelDescription}
|
|
611
|
+
onChange={(e) => {
|
|
612
|
+
setModelDescription(e.target.value);
|
|
613
|
+
setChanged(true)
|
|
614
|
+
}}
|
|
615
|
+
/>
|
|
616
|
+
|
|
617
|
+
<div className="flex field-bg">
|
|
618
|
+
<label htmlFor="modelIcon"><Trans i18nKey={"modelcreator.icon"}>Icône:</Trans></label>
|
|
619
|
+
</div>
|
|
620
|
+
<IconField
|
|
621
|
+
help={t('modelcreator.field.icon')}
|
|
622
|
+
id="modelIcon"
|
|
623
|
+
disabled={modelLocked}
|
|
624
|
+
value={modelIcon}
|
|
625
|
+
onChange={(e) => {
|
|
626
|
+
setModelIcon(e);
|
|
627
|
+
setChanged(true)
|
|
628
|
+
}}
|
|
629
|
+
/>
|
|
630
|
+
|
|
631
|
+
<div className="flex flex-no-wrap">
|
|
632
|
+
<div className="checkbox-label flex flex-1">
|
|
633
|
+
<CheckboxField
|
|
634
|
+
label={<Trans i18nKey={"history"}>Historique</Trans>}
|
|
635
|
+
help={t('modelcreator.field.history', '')}
|
|
636
|
+
disabled={modelLocked}
|
|
637
|
+
checked={!!modelHistory}
|
|
638
|
+
onChange={(e) => {
|
|
639
|
+
setModelHistory(e? { enabled: true }: false);
|
|
640
|
+
}}
|
|
641
|
+
/>
|
|
642
|
+
</div>
|
|
643
|
+
</div>
|
|
644
|
+
|
|
645
|
+
<h3><Trans i18nKey={"modelcreator.fields"}>Champs du modèle :</Trans></h3>
|
|
646
|
+
{fields.map((field, index) => <ModelCreatorField
|
|
647
|
+
key={initialModel?.name + '_field_' + index}
|
|
648
|
+
handleRemoveValue={handleRemoveValue}
|
|
649
|
+
handleAddValue={handleAddValue}
|
|
650
|
+
handleRenameField={handleRenameField}
|
|
651
|
+
handleUp={handleUp}
|
|
652
|
+
handleDown={handleDown}
|
|
653
|
+
handleRemoveField={handleRemoveField}
|
|
654
|
+
index={index} fields={fields} field={field} model={initialModel} setFields={setFields} />)}
|
|
655
|
+
</div>
|
|
656
|
+
)}
|
|
657
|
+
|
|
658
|
+
{/* Boutons d'action, visibles si un modèle est affiché ou en mode manuel */}
|
|
659
|
+
{(showModel || !useAI || initialModel) && (
|
|
660
|
+
<div className="actions flex">
|
|
661
|
+
|
|
662
|
+
<Button type="button" onClick={handleAddField}>
|
|
663
|
+
<FaPlus /> <Trans i18nKey={"btns.addField"}>Ajouter un champ</Trans>
|
|
664
|
+
</Button>
|
|
665
|
+
|
|
666
|
+
<Button type="submit">
|
|
667
|
+
<FaSave />
|
|
668
|
+
<Trans i18nKey={"btns.saveModel"}>Enregistrer le modèle</Trans>
|
|
669
|
+
</Button>
|
|
670
|
+
{initialModel && (
|
|
671
|
+
<Button type="button" onClick={handleDelete}>
|
|
672
|
+
<FaTrash /><Trans i18nKey={"btns.del"}>Supprimer le modèle</Trans>
|
|
673
|
+
</Button>
|
|
674
|
+
)}
|
|
675
|
+
</div>
|
|
676
|
+
)}
|
|
677
|
+
|
|
678
|
+
</form>
|
|
679
|
+
</div>
|
|
680
|
+
);
|
|
681
|
+
});
|
|
682
|
+
ModelCreator.displayName = "ModelCreator";
|
|
683
|
+
|
|
687
684
|
export default ModelCreator;
|