data-primals-engine 1.6.5 → 1.7.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 (40) hide show
  1. package/README.md +160 -113
  2. package/client/index.js +3 -0
  3. package/client/package-lock.json +8121 -8824
  4. package/client/package.json +10 -3
  5. package/client/src/AssistantChat.jsx +369 -362
  6. package/client/src/DataEditor.jsx +383 -383
  7. package/client/src/DataLayout.jsx +54 -20
  8. package/client/src/ModelList.jsx +280 -280
  9. package/client/src/ViewSwitcher.scss +0 -31
  10. package/client/src/constants.js +81 -100
  11. package/client/src/contexts/CommandContext.jsx +274 -259
  12. package/client/vite.config.js +30 -30
  13. package/doc/AI-assistance.md +93 -0
  14. package/doc/Advanced-workflows.md +90 -0
  15. package/doc/Event-system.md +79 -0
  16. package/doc/Packs-gallery.md +73 -0
  17. package/package.json +30 -16
  18. package/src/constants.js +1 -1
  19. package/src/core.js +487 -477
  20. package/src/defaultModels.js +1 -1
  21. package/src/email.js +0 -2
  22. package/src/engine.js +342 -335
  23. package/src/filter.js +348 -343
  24. package/src/migrate.js +1 -1
  25. package/src/modules/assistant/assistant.js +30 -20
  26. package/src/modules/data/data.backup.js +4 -4
  27. package/src/modules/data/data.js +311 -302
  28. package/src/modules/data/data.operations.js +79 -64
  29. package/src/modules/data/data.relations.js +2 -1
  30. package/src/modules/data/data.scheduling.js +1 -1
  31. package/src/modules/mongodb.js +16 -8
  32. package/src/modules/user.js +0 -1
  33. package/src/modules/workflow.js +1828 -1815
  34. package/src/packs.js +5701 -5697
  35. package/src/profiles.js +19 -0
  36. package/swagger-en.yml +3390 -3385
  37. package/swagger-fr.yml +3385 -3380
  38. package/test/assistant.test.js +2 -2
  39. package/test/data.backup.integration.test.js +3 -1
  40. package/test/data.history.integration.test.js +0 -1
@@ -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 * as FaIcons from "react-icons/fa";
12
+ import * as Fa6Icons from "react-icons/fa6";
13
+ import {profiles} from "../../src/profiles.js";
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
+ }
@@ -11,10 +11,7 @@ $vs-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
11
11
  .view-switcher {
12
12
  display: inline-flex;
13
13
  align-items: center;
14
- background-color: $vs-background;
15
- border-radius: 8px;
16
14
  padding: 4px;
17
- border: 1px solid $vs-border-color;
18
15
 
19
16
  // Chaque option (bouton + potentiellement le bouton de configuration) est dans un wrapper
20
17
  .view-option-wrapper {
@@ -24,36 +21,8 @@ $vs-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
24
21
  // La magie de la transition pour un effet fluide
25
22
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
26
23
 
27
- // Le style du wrapper quand il est actif
28
- &.is-active {
29
- background-color: $vs-white;
30
- box-shadow: $vs-shadow;
31
- }
32
- }
33
-
34
- .btn-view {
35
- background-color: transparent;
36
- border: none;
37
- padding: 6px 12px;
38
- display: flex;
39
- align-items: center;
40
- gap: 8px;
41
- cursor: pointer;
42
- color: $vs-text-color;
43
- font-weight: 500;
44
- transition: color 0.2s ease-in-out;
45
- white-space: nowrap; // Emphe le texte de passer à la ligne
46
-
47
- .md\:inline-block {
48
- font-size: 0.9rem;
49
- }
50
24
  }
51
25
 
52
- // Quand le wrapper est actif, le bouton principal change de couleur
53
- .is-active .btn-view {
54
- color: $vs-primary-color;
55
- font-weight: 600;
56
- }
57
26
 
58
27
  // Le bouton de configuration (roue crantée)
59
28
  .btn-view-settings {