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.
Files changed (70) hide show
  1. package/README.md +938 -915
  2. package/client/README.md +136 -136
  3. package/client/index.js +0 -1
  4. package/client/public/doc/API.postman_collection.json +213 -213
  5. package/client/public/react.svg +9 -9
  6. package/client/src/AddWidgetTypeModal.jsx +47 -47
  7. package/client/src/App.css +42 -42
  8. package/client/src/App.jsx +92 -150
  9. package/client/src/App.scss +6 -0
  10. package/client/src/AssistantChat.jsx +362 -363
  11. package/client/src/Button.jsx +12 -12
  12. package/client/src/Dashboard.jsx +480 -480
  13. package/client/src/DashboardHtmlViewItem.jsx +146 -146
  14. package/client/src/DashboardView.jsx +654 -654
  15. package/client/src/DataEditor.jsx +383 -383
  16. package/client/src/DataLayout.jsx +779 -808
  17. package/client/src/DataTable.jsx +782 -822
  18. package/client/src/DataTable.scss +186 -186
  19. package/client/src/GeolocationField.jsx +93 -93
  20. package/client/src/HistoryDialog.jsx +307 -307
  21. package/client/src/HistoryDialog.scss +319 -319
  22. package/client/src/HtmlViewBuilderModal.jsx +90 -90
  23. package/client/src/HtmlViewBuilderModal.scss +17 -17
  24. package/client/src/HtmlViewCard.jsx +43 -43
  25. package/client/src/ModelCreator.jsx +683 -686
  26. package/client/src/ModelCreator.scss +1 -1
  27. package/client/src/ModelCreatorField.jsx +950 -950
  28. package/client/src/ModelImporter.jsx +3 -0
  29. package/client/src/ModelList.jsx +280 -280
  30. package/client/src/Notification.jsx +136 -136
  31. package/client/src/PackGallery.jsx +391 -391
  32. package/client/src/PackGallery.scss +231 -231
  33. package/client/src/Pagination.jsx +143 -143
  34. package/client/src/RelationField.jsx +354 -354
  35. package/client/src/RelationSelectorWidget.jsx +172 -172
  36. package/client/src/RelationValue.jsx +2 -1
  37. package/client/src/contexts/CommandContext.jsx +260 -0
  38. package/client/src/contexts/ModelContext.jsx +4 -1
  39. package/client/src/contexts/UIContext.jsx +72 -72
  40. package/client/src/filter.js +263 -263
  41. package/client/src/index.css +90 -90
  42. package/package.json +6 -5
  43. package/perf/artillery-hooks.js +37 -37
  44. package/perf/setup.yml +25 -25
  45. package/src/constants.js +4 -0
  46. package/src/defaultModels.js +7 -0
  47. package/src/engine.js +335 -335
  48. package/src/events.js +232 -137
  49. package/src/filter.js +274 -274
  50. package/src/index.js +1 -0
  51. package/src/modules/assistant/assistant.js +225 -83
  52. package/src/modules/auth-google/index.js +50 -50
  53. package/src/modules/auth-microsoft/index.js +81 -81
  54. package/src/modules/data/data.core.js +118 -118
  55. package/src/modules/data/data.history.js +555 -555
  56. package/src/modules/data/data.operations.js +112 -9
  57. package/src/modules/data/data.relations.js +686 -686
  58. package/src/modules/data/data.routes.js +1879 -1879
  59. package/src/modules/data/data.validation.js +2 -2
  60. package/src/modules/file.js +247 -247
  61. package/src/modules/user.js +14 -9
  62. package/src/packs.js +2 -2
  63. package/src/providers.js +2 -2
  64. package/src/services/stripe.js +196 -196
  65. package/src/sso.js +193 -193
  66. package/test/data.history.integration.test.js +264 -264
  67. package/test/data.integration.test.js +1281 -1206
  68. package/test/events.test.js +108 -10
  69. package/test/model.integration.test.js +377 -377
  70. package/test/user.test.js +106 -1
@@ -94,6 +94,9 @@ const ModelImporterItem = ({ model, onUnselect, onSelect, selected }) => {
94
94
  useEffect(() => {
95
95
  setSelected(selected);
96
96
  }, [selected]);
97
+
98
+ if( !model )
99
+ return;
97
100
  const deps = [...new Set((model.fields || []).filter(f=> f.type === 'relation' && f.relation !== model?.name).map(f=> t(`model_${f.relation}`, f.relation)))];
98
101
  return <div className={`model-importer-item ${selected ? 'active' : ''}`} onClick={() => {
99
102
  setSelected(!selected);
@@ -1,280 +1,280 @@
1
- import {useModelContext} from "./contexts/ModelContext.jsx";
2
- import {Trans, useTranslation} from "react-i18next";
3
- import {useAuthContext} from "./contexts/AuthContext.jsx";
4
- import {useMutation, useQueryClient} from "react-query";
5
- import React, {useEffect, useMemo, useState} from "react";
6
- import {FaBook, FaBoxOpen, FaEdit, FaFileImport, FaPlus} from "react-icons/fa";
7
- import Button from "./Button.jsx";
8
- import useLocalStorage from "./hooks/useLocalStorage.js";
9
- import {Tooltip} from "react-tooltip";
10
- import {useUI} from "./contexts/UIContext.jsx";
11
- import {profiles} from "./constants.js";
12
- import * as FaIcons from "react-icons/fa";
13
- import * as Fa6Icons from "react-icons/fa6";
14
-
15
- // --- SUGGESTION: Extraire cette logique dans un composant dédié si elle devient plus complexe ---
16
- // Fonction pour obtenir le composant icône par son nom
17
- const getIconComponent = (iconName) => {
18
- if (!iconName) return null;
19
- const IconComponent = FaIcons[iconName] || Fa6Icons[iconName];
20
- return IconComponent ? <IconComponent /> : null; // Retourne l'élément React ou null
21
- };
22
-
23
- // --- SUGGESTION: Créer un petit composant pour la lisibilité de l'affichage du nom du modèle ---
24
- const ModelListItemLabel = ({ model, count, isGenerated, t }) => {
25
- const modelName = t(`model_${model.name}`, model.name);
26
-
27
- let suffix = '';
28
- if (isGenerated) {
29
- suffix = ` (${t('models.status.tmp', 'brouillon')})`; // Utiliser i18n pour 'tmp'
30
- } else if (count > 0) {
31
- suffix = ` (${count})`;
32
- }
33
-
34
- return <>{modelName}{suffix}</>;
35
- };
36
-
37
-
38
- export function ModelList({ editionMode, onModelSelect, onCreateModel, onImportModel, onEditModel, onAPIInfo, onNewData, onImportPack }) {
39
- const {allTourSteps, setIsTourOpen,setCurrentTourSteps, setTourStepIndex, currentTour, setCurrentTour} = useUI();
40
-
41
- const {models, setSelectedModel, selectedModel, countByModel, generatedModels} = useModelContext();
42
- const {t} = useTranslation();
43
- const {me} = useAuthContext();
44
- const queryClient = useQueryClient()
45
- const [searchTerm, setSearchTerm] = useState('');
46
- const [selectedTag, setSelectedTag] = useLocalStorage('modelList-selectedTag', 'all');
47
-
48
- const [currentProfile, setCurrentProfile] = useLocalStorage('profile', null);
49
- useEffect(() =>{
50
- if (me) {
51
- queryClient.invalidateQueries('api/models');
52
- }
53
- }, [me])
54
-
55
- const allTags = useMemo(() => {
56
- if (!models) return [];
57
- const tagsSet = new Set();
58
- models
59
- .filter(model => model._user === me?.username) // On ne prend que les tags des modèles de l'utilisateur
60
- .forEach(model => {
61
- if (model.tags && Array.isArray(model.tags)) {
62
- model.tags.forEach(tag => tagsSet.add(tag));
63
- }
64
- });
65
- return Array.from(tagsSet).sort();
66
- }, [models, me?.username]);
67
-
68
- console.log(allTags,"t");
69
- const filteredModels = useMemo(() => {
70
- if (!models) return [];
71
- let results = models.filter(model => model._user === me?.username);
72
-
73
- // Filtrage par tag
74
- if (selectedTag && selectedTag !== 'all') {
75
- results = results.filter(model => model.tags?.includes(selectedTag));
76
- }
77
-
78
- // Filtrage par terme de recherche
79
- if (searchTerm.trim()) {
80
- const lowerSearchTerm = searchTerm.toLowerCase();
81
- results = results.filter(model =>
82
- (t('model_' + model.name, model.name).toLowerCase().includes(lowerSearchTerm)) ||
83
- (model.description && model.description.toLowerCase().includes(lowerSearchTerm)));
84
- }
85
- return results;
86
- }, [models, searchTerm, selectedTag, me?.username, t]);
87
-
88
- const handleSelectModel = (model) => {
89
- setSelectedModel(model);
90
- if (onModelSelect) {
91
- onModelSelect(model); // Si vous avez une prop callback supplémentaire
92
- }
93
- };
94
-
95
- const demoInitMutation = useMutation((profile) => {
96
- return fetch('/api/demo/initialize', {
97
- method: 'POST',
98
- headers: { "Content-Type": "application/json"},
99
- body: JSON.stringify({profile: profile, packs: profiles[profile].packs}),
100
- });
101
- });
102
-
103
- const handleProfile = (profile) => {
104
- // --- CHANGEMENT ICI : On appelle la nouvelle mutation sans argument ---
105
- demoInitMutation.mutateAsync(profile).then(response => {
106
- // On vérifie que la réponse est OK avant de continuer
107
- if (!response.ok) {
108
- // Gérer l'erreur si l'initialisation échoue
109
- console.error("L'initialisation de la démo a échoué.");
110
- // Vous pourriez afficher une notification à l'utilisateur ici.
111
- return;
112
- }
113
-
114
- // Le reste de la logique est parfait et ne change pas
115
- setCurrentProfile(profile);
116
- gtag('event', 'profile ' + profile);
117
- queryClient.invalidateQueries('api/models');
118
-
119
- const profileSteps = allTourSteps[profile];
120
- if (profileSteps) {
121
- setCurrentTourSteps(profileSteps);
122
- setTourStepIndex(0);
123
- setIsTourOpen(true); // Start the tour
124
- } else {
125
- console.warn(`No tour steps defined for profile: ${profile}`);
126
- }
127
- }).catch(error => {
128
- console.error("Erreur critique lors de l'appel d'initialisation de la démo:", error);
129
- });
130
- };
131
-
132
- // --- NEW: Effect to update tour steps when a profile is already selected on mount ---
133
- useEffect(() => {
134
- if (currentProfile && currentTour && /^demo[0-9]{1,2}$/.test(me?.username)) { // Only run on demo user for simplicity
135
- const profileSteps = allTourSteps[currentProfile];
136
- if (profileSteps) {
137
- setCurrentTourSteps(profileSteps);
138
- setTourStepIndex(0)
139
- setIsTourOpen(true);
140
- } else {
141
- console.warn(`No tour steps defined for profile: ${currentProfile}`);
142
- }
143
- }
144
- }, [currentProfile, me?.username]);
145
-
146
- if (!models) {
147
- return <div className="loading-models">{t('models.loading', 'Chargement des modèles...')}</div>;
148
- }
149
-
150
- return <>
151
- {!currentProfile && /^demo[0-9]{1,2}$/.test(me.username) && <div className="tourStep-profile profiles flex-stretch flex">
152
- <div className=" flex flex-centered flex-big-gap">
153
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.personal.desc')} className="profile-link" onClick={() => handleProfile('personal')}>
154
- <img src="/profilPersonal.jpg" alt={"Personal profile"} width={256} height={256}/>
155
- </a>
156
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.developer.desc')} className="profile-link" onClick={() => handleProfile('developer')}>
157
- <img src="/profilDeveloper.jpg" alt={"Developer profile"} width={256} height={256}/>
158
- </a>
159
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.company.desc')} className="profile-link" onClick={() => handleProfile('company')}>
160
- <img src="/profilCompany.jpg" alt={"Company profile"} width={256} height={256}/>
161
- </a>
162
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.engineer.desc')} className="profile-link" onClick={() => handleProfile('engineer')}>
163
- <img src="/profilEngineer.jpg" alt={"Engineer profile"} width={256} height={256}/>
164
- </a>
165
- <Tooltip id="tooltipProfile" render={({content, activeAnchor}) => {
166
- const pr = activeAnchor?.querySelector('img').getAttribute('alt');
167
- if (pr)
168
- gtag('event', 'info '+ pr);
169
- else
170
- gtag('event', 'info');
171
- return <span dangerouslySetInnerHTML={{__html:content}} />
172
- }} afterShow={() => {
173
-
174
- }} />
175
- </div></div>}
176
- <div className="models">
177
- <h2 className={"field-bg p-2"}><Trans i18nKey="models">Modèles</Trans></h2>
178
- <div className="model-list-container">
179
- <div className="flex flex-no-wrap model-list-search-bar-container">
180
- <input
181
- type="search"
182
- placeholder={t('models.searchPlaceholder', 'Rechercher un modèle...')}
183
- value={searchTerm}
184
- onChange={(e) => setSearchTerm(e.target.value)}
185
- className="model-list-search-input"
186
- />
187
- {allTags.length > 0 && (
188
- <div className="model-list-tag-filter">
189
- <select value={selectedTag} onChange={(e) => setSelectedTag(e.target.value)}>
190
- <option value="all">{t('models.tags.all', 'Tous les tags')}</option>
191
- {allTags.map(tag => (
192
- <option key={tag} value={tag}>
193
- {t(`tags.${tag}`, tag.charAt(0).toUpperCase() + tag.slice(1))}
194
- </option>
195
- ))}
196
- </select>
197
- </div>
198
- )}
199
- </div>
200
- {filteredModels.length > 0 ? (
201
- <div className="model-list">
202
- <Tooltip id="tooltipML" />
203
- <ul>
204
- {filteredModels.sort((a, b) => t('model_' + a.name, a.name).localeCompare(t('model_' + b.name, b.name))).map((model) => {
205
- if (model._user !== me.username)
206
- return <></>
207
-
208
-
209
- const IconComponent = getIconComponent(model.icon);
210
-
211
- // --- SUGGESTION: Rendre le comportement du clic prévisible ---
212
- // Le clic principal sélectionne toujours le modèle. L'édition est une action secondaire via son bouton.
213
- const handleItemClick = () => {
214
- onModelSelect(model);
215
- };
216
-
217
- return (
218
- <li data-testid={'model_'+model.name} className={`${model.name === selectedModel?.name ? 'active' : ''}`}
219
- key={'modellist' + model.name} onClick={handleItemClick}>
220
- <div className="flex flex-center flex-fw">
221
- <div
222
- className="flex flex-1 flex-no-wrap break-word gap-2">
223
- <div className={"icon"}>{IconComponent ? IconComponent : <></>}</div>
224
- {/* --- SUGGESTION: Utiliser le composant pour la clarté --- */}
225
- <div><ModelListItemLabel model={model} count={countByModel?.[model.name]} isGenerated={generatedModels.some(f => f.name === model.name)} t={t} /></div></div>
226
- <div className="btns">
227
- {/* Le bouton "Ajouter" est conditionnel, ce qui est bien */}
228
- {!generatedModels.some(g => g.name === model.name) && (<button data-tooltip-id="tooltipML" data-tooltip-content={t('btns.addData')} onClick={(e) => {
229
- e.stopPropagation();
230
- e.preventDefault();
231
- onNewData?.(model);
232
- }}><FaPlus/></button>)}
233
- {!model.locked && (<button data-tooltip-id="tooltipML" data-tooltip-content={t('btns.editModel')} onClick={(e) => {
234
- e.stopPropagation();
235
- e.preventDefault();
236
- onEditModel(model);
237
- }}><FaEdit/>
238
- </button>)}
239
- {(<button data-tooltip-id="tooltipML" data-tooltip-content={t('doc.api.title')} onClick={(e) => {
240
- e.stopPropagation();
241
- e.preventDefault();
242
- onAPIInfo?.(model);
243
- }}><FaBook/>
244
- </button>)}
245
- </div>
246
- </div>
247
- </li>)
248
- })}
249
- </ul>
250
- </div>) : (
251
- <div className="empty-state-container p-2">
252
- <div className="empty-state-content">
253
- <div className="empty-state-icon">
254
- {/* Une icône SVG simple pour représenter des "blocs de construction" ou des "données" */}
255
- <svg width="80" height="80" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
256
- <path d="M14 10L14 4L20 4L20 10L14 10Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
257
- <path d="M4 20L4 14L10 14L10 20L4 20Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
258
- <path d="M4 10L4 4L10 4L10 10L4 10Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
259
- <path d="M14 20L14 14L20 14L20 20L14 20Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
260
- </svg>
261
- </div>
262
- <h3>{t('models.empty.title', 'Commencez à structurer vos données')}</h3>
263
- <p>
264
- {searchTerm ?
265
- t('models.noMatch', 'Aucun modèle ne correspond à votre recherche.') :
266
- t('models.empty.description', 'Créez votre premier modèle de A à Z ou importez une structure existante pour démarrer rapidement.')
267
- }
268
- </p>
269
- </div>
270
- </div>
271
- )}
272
- </div>
273
- {!editionMode && (<div className="flex actions">
274
- <Button onClick={onCreateModel} className="btn-primary btn-large">
275
- <FaPlus /> {t('btns.addModel', 'Créer un modèle')}
276
- </Button>
277
- </div>)}
278
- </div>
279
- </>
280
- }
1
+ import {useModelContext} from "./contexts/ModelContext.jsx";
2
+ import {Trans, useTranslation} from "react-i18next";
3
+ import {useAuthContext} from "./contexts/AuthContext.jsx";
4
+ import {useMutation, useQueryClient} from "react-query";
5
+ import React, {useEffect, useMemo, useState} from "react";
6
+ import {FaBook, FaBoxOpen, FaEdit, FaFileImport, FaPlus} from "react-icons/fa";
7
+ import Button from "./Button.jsx";
8
+ import useLocalStorage from "./hooks/useLocalStorage.js";
9
+ import {Tooltip} from "react-tooltip";
10
+ import {useUI} from "./contexts/UIContext.jsx";
11
+ import {profiles} from "./constants.js";
12
+ import * as FaIcons from "react-icons/fa";
13
+ import * as Fa6Icons from "react-icons/fa6";
14
+
15
+ // --- SUGGESTION: Extraire cette logique dans un composant dédié si elle devient plus complexe ---
16
+ // Fonction pour obtenir le composant icône par son nom
17
+ const getIconComponent = (iconName) => {
18
+ if (!iconName) return null;
19
+ const IconComponent = FaIcons[iconName] || Fa6Icons[iconName];
20
+ return IconComponent ? <IconComponent /> : null; // Retourne l'élément React ou null
21
+ };
22
+
23
+ // --- SUGGESTION: Créer un petit composant pour la lisibilité de l'affichage du nom du modèle ---
24
+ const ModelListItemLabel = ({ model, count, isGenerated, t }) => {
25
+ const modelName = t(`model_${model.name}`, model.name);
26
+
27
+ let suffix = '';
28
+ if (isGenerated) {
29
+ suffix = ` (${t('models.status.tmp', 'brouillon')})`; // Utiliser i18n pour 'tmp'
30
+ } else if (count > 0) {
31
+ suffix = ` (${count})`;
32
+ }
33
+
34
+ return <>{modelName}{suffix}</>;
35
+ };
36
+
37
+
38
+ export function ModelList({ editionMode, onModelSelect, onCreateModel, onImportModel, onEditModel, onAPIInfo, onNewData, onImportPack }) {
39
+ const {allTourSteps, setIsTourOpen,setCurrentTourSteps, setTourStepIndex, currentTour, setCurrentTour} = useUI();
40
+
41
+ const {models, setSelectedModel, selectedModel, countByModel, generatedModels} = useModelContext();
42
+ const {t} = useTranslation();
43
+ const {me} = useAuthContext();
44
+ const queryClient = useQueryClient()
45
+ const [searchTerm, setSearchTerm] = useState('');
46
+ const [selectedTag, setSelectedTag] = useLocalStorage('modelList-selectedTag', 'all');
47
+
48
+ const [currentProfile, setCurrentProfile] = useLocalStorage('profile', null);
49
+ useEffect(() =>{
50
+ if (me) {
51
+ queryClient.invalidateQueries('api/models');
52
+ }
53
+ }, [me])
54
+
55
+ const allTags = useMemo(() => {
56
+ if (!models) return [];
57
+ const tagsSet = new Set();
58
+ models
59
+ .filter(model => model._user === me?.username) // On ne prend que les tags des modèles de l'utilisateur
60
+ .forEach(model => {
61
+ if (model.tags && Array.isArray(model.tags)) {
62
+ model.tags.forEach(tag => tagsSet.add(tag));
63
+ }
64
+ });
65
+ return Array.from(tagsSet).sort();
66
+ }, [models, me?.username]);
67
+
68
+ console.log(allTags,"t");
69
+ const filteredModels = useMemo(() => {
70
+ if (!models) return [];
71
+ let results = models.filter(model => model._user === me?.username);
72
+
73
+ // Filtrage par tag
74
+ if (selectedTag && selectedTag !== 'all') {
75
+ results = results.filter(model => model.tags?.includes(selectedTag));
76
+ }
77
+
78
+ // Filtrage par terme de recherche
79
+ if (searchTerm.trim()) {
80
+ const lowerSearchTerm = searchTerm.toLowerCase();
81
+ results = results.filter(model =>
82
+ (t('model_' + model.name, model.name).toLowerCase().includes(lowerSearchTerm)) ||
83
+ (model.description && model.description.toLowerCase().includes(lowerSearchTerm)));
84
+ }
85
+ return results;
86
+ }, [models, searchTerm, selectedTag, me?.username, t]);
87
+
88
+ const handleSelectModel = (model) => {
89
+ setSelectedModel(model);
90
+ if (onModelSelect) {
91
+ onModelSelect(model); // Si vous avez une prop callback supplémentaire
92
+ }
93
+ };
94
+
95
+ const demoInitMutation = useMutation((profile) => {
96
+ return fetch('/api/demo/initialize', {
97
+ method: 'POST',
98
+ headers: { "Content-Type": "application/json"},
99
+ body: JSON.stringify({profile: profile, packs: profiles[profile].packs}),
100
+ });
101
+ });
102
+
103
+ const handleProfile = (profile) => {
104
+ // --- CHANGEMENT ICI : On appelle la nouvelle mutation sans argument ---
105
+ demoInitMutation.mutateAsync(profile).then(response => {
106
+ // On vérifie que la réponse est OK avant de continuer
107
+ if (!response.ok) {
108
+ // Gérer l'erreur si l'initialisation échoue
109
+ console.error("L'initialisation de la démo a échoué.");
110
+ // Vous pourriez afficher une notification à l'utilisateur ici.
111
+ return;
112
+ }
113
+
114
+ // Le reste de la logique est parfait et ne change pas
115
+ setCurrentProfile(profile);
116
+ gtag('event', 'profile ' + profile);
117
+ queryClient.invalidateQueries('api/models');
118
+
119
+ const profileSteps = allTourSteps[profile];
120
+ if (profileSteps) {
121
+ setCurrentTourSteps(profileSteps);
122
+ setTourStepIndex(0);
123
+ setIsTourOpen(true); // Start the tour
124
+ } else {
125
+ console.warn(`No tour steps defined for profile: ${profile}`);
126
+ }
127
+ }).catch(error => {
128
+ console.error("Erreur critique lors de l'appel d'initialisation de la démo:", error);
129
+ });
130
+ };
131
+
132
+ // --- NEW: Effect to update tour steps when a profile is already selected on mount ---
133
+ useEffect(() => {
134
+ if (currentProfile && currentTour && /^demo[0-9]{1,2}$/.test(me?.username)) { // Only run on demo user for simplicity
135
+ const profileSteps = allTourSteps[currentProfile];
136
+ if (profileSteps) {
137
+ setCurrentTourSteps(profileSteps);
138
+ setTourStepIndex(0)
139
+ setIsTourOpen(true);
140
+ } else {
141
+ console.warn(`No tour steps defined for profile: ${currentProfile}`);
142
+ }
143
+ }
144
+ }, [currentProfile, me?.username]);
145
+
146
+ if (!models) {
147
+ return <div className="loading-models">{t('models.loading', 'Chargement des modèles...')}</div>;
148
+ }
149
+
150
+ return <>
151
+ {!currentProfile && /^demo[0-9]{1,2}$/.test(me.username) && <div className="tourStep-profile profiles flex-stretch flex">
152
+ <div className=" flex flex-centered flex-big-gap">
153
+ <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.personal.desc')} className="profile-link" onClick={() => handleProfile('personal')}>
154
+ <img src="/profilPersonal.jpg" alt={"Personal profile"} width={256} height={256}/>
155
+ </a>
156
+ <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.developer.desc')} className="profile-link" onClick={() => handleProfile('developer')}>
157
+ <img src="/profilDeveloper.jpg" alt={"Developer profile"} width={256} height={256}/>
158
+ </a>
159
+ <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.company.desc')} className="profile-link" onClick={() => handleProfile('company')}>
160
+ <img src="/profilCompany.jpg" alt={"Company profile"} width={256} height={256}/>
161
+ </a>
162
+ <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.engineer.desc')} className="profile-link" onClick={() => handleProfile('engineer')}>
163
+ <img src="/profilEngineer.jpg" alt={"Engineer profile"} width={256} height={256}/>
164
+ </a>
165
+ <Tooltip id="tooltipProfile" render={({content, activeAnchor}) => {
166
+ const pr = activeAnchor?.querySelector('img').getAttribute('alt');
167
+ if (pr)
168
+ gtag('event', 'info '+ pr);
169
+ else
170
+ gtag('event', 'info');
171
+ return <span dangerouslySetInnerHTML={{__html:content}} />
172
+ }} afterShow={() => {
173
+
174
+ }} />
175
+ </div></div>}
176
+ <div className="models">
177
+ <h2 className={"field-bg p-2"}><Trans i18nKey="models">Modèles</Trans></h2>
178
+ <div className="model-list-container">
179
+ <div className="flex flex-no-wrap model-list-search-bar-container">
180
+ <input
181
+ type="search"
182
+ placeholder={t('models.searchPlaceholder', 'Rechercher un modèle...')}
183
+ value={searchTerm}
184
+ onChange={(e) => setSearchTerm(e.target.value)}
185
+ className="model-list-search-input"
186
+ />
187
+ {allTags.length > 0 && (
188
+ <div className="model-list-tag-filter">
189
+ <select value={selectedTag} onChange={(e) => setSelectedTag(e.target.value)}>
190
+ <option value="all">{t('models.tags.all', 'Tous les tags')}</option>
191
+ {allTags.map(tag => (
192
+ <option key={tag} value={tag}>
193
+ {t(`tags.${tag}`, tag.charAt(0).toUpperCase() + tag.slice(1))}
194
+ </option>
195
+ ))}
196
+ </select>
197
+ </div>
198
+ )}
199
+ </div>
200
+ {filteredModels.length > 0 ? (
201
+ <div className="model-list">
202
+ <Tooltip id="tooltipML" />
203
+ <ul>
204
+ {filteredModels.sort((a, b) => t('model_' + a.name, a.name).localeCompare(t('model_' + b.name, b.name))).map((model) => {
205
+ if (model._user !== me.username)
206
+ return <></>
207
+
208
+
209
+ const IconComponent = getIconComponent(model.icon);
210
+
211
+ // --- SUGGESTION: Rendre le comportement du clic prévisible ---
212
+ // Le clic principal sélectionne toujours le modèle. L'édition est une action secondaire via son bouton.
213
+ const handleItemClick = () => {
214
+ onModelSelect(model);
215
+ };
216
+
217
+ return (
218
+ <li data-testid={'model_'+model.name} className={`${model.name === selectedModel?.name ? 'active' : ''}`}
219
+ key={'modellist' + model.name} onClick={handleItemClick}>
220
+ <div className="flex flex-center flex-fw">
221
+ <div
222
+ className="flex flex-1 flex-no-wrap break-word gap-2">
223
+ <div className={"icon"}>{IconComponent ? IconComponent : <></>}</div>
224
+ {/* --- SUGGESTION: Utiliser le composant pour la clarté --- */}
225
+ <div><ModelListItemLabel model={model} count={countByModel?.[model.name]} isGenerated={generatedModels.some(f => f.name === model.name)} t={t} /></div></div>
226
+ <div className="btns">
227
+ {/* Le bouton "Ajouter" est conditionnel, ce qui est bien */}
228
+ {!generatedModels.some(g => g.name === model.name) && (<button data-tooltip-id="tooltipML" data-tooltip-content={t('btns.addData')} onClick={(e) => {
229
+ e.stopPropagation();
230
+ e.preventDefault();
231
+ onNewData?.(model);
232
+ }}><FaPlus/></button>)}
233
+ {!model.locked && (<button data-tooltip-id="tooltipML" data-tooltip-content={t('btns.editModel')} onClick={(e) => {
234
+ e.stopPropagation();
235
+ e.preventDefault();
236
+ onEditModel(model);
237
+ }}><FaEdit/>
238
+ </button>)}
239
+ {(<button data-tooltip-id="tooltipML" data-tooltip-content={t('doc.api.title')} onClick={(e) => {
240
+ e.stopPropagation();
241
+ e.preventDefault();
242
+ onAPIInfo?.(model);
243
+ }}><FaBook/>
244
+ </button>)}
245
+ </div>
246
+ </div>
247
+ </li>)
248
+ })}
249
+ </ul>
250
+ </div>) : (
251
+ <div className="empty-state-container p-2">
252
+ <div className="empty-state-content">
253
+ <div className="empty-state-icon">
254
+ {/* Une icône SVG simple pour représenter des "blocs de construction" ou des "données" */}
255
+ <svg width="80" height="80" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
256
+ <path d="M14 10L14 4L20 4L20 10L14 10Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
257
+ <path d="M4 20L4 14L10 14L10 20L4 20Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
258
+ <path d="M4 10L4 4L10 4L10 10L4 10Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
259
+ <path d="M14 20L14 14L20 14L20 20L14 20Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
260
+ </svg>
261
+ </div>
262
+ <h3>{t('models.empty.title', 'Commencez à structurer vos données')}</h3>
263
+ <p>
264
+ {searchTerm ?
265
+ t('models.noMatch', 'Aucun modèle ne correspond à votre recherche.') :
266
+ t('models.empty.description', 'Créez votre premier modèle de A à Z ou importez une structure existante pour démarrer rapidement.')
267
+ }
268
+ </p>
269
+ </div>
270
+ </div>
271
+ )}
272
+ </div>
273
+ {!editionMode && (<div className="flex actions">
274
+ <Button onClick={onCreateModel} className="btn-primary btn-large">
275
+ <FaPlus /> {t('btns.addModel', 'Créer un modèle')}
276
+ </Button>
277
+ </div>)}
278
+ </div>
279
+ </>
280
+ }