data-primals-engine 1.5.0 → 1.5.2

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 (63) hide show
  1. package/README.md +37 -0
  2. package/client/src/AddWidgetTypeModal.jsx +47 -43
  3. package/client/src/App.jsx +2 -6
  4. package/client/src/App.scss +13 -1
  5. package/client/src/AssistantChat.jsx +363 -323
  6. package/client/src/AssistantChat.scss +27 -10
  7. package/client/src/Dashboard.jsx +480 -396
  8. package/client/src/Dashboard.scss +1 -1
  9. package/client/src/DashboardHtmlViewItem.jsx +147 -0
  10. package/client/src/DashboardView.jsx +654 -569
  11. package/client/src/DataEditor.jsx +10 -3
  12. package/client/src/DataLayout.jsx +807 -755
  13. package/client/src/DataLayout.scss +14 -0
  14. package/client/src/DataTable.jsx +39 -75
  15. package/client/src/Dialog.scss +1 -1
  16. package/client/src/Field.jsx +2057 -1825
  17. package/client/src/FlexViewCard.jsx +44 -0
  18. package/client/src/HistoryDialog.jsx +69 -14
  19. package/client/src/HtmlViewBuilderModal.jsx +91 -0
  20. package/client/src/HtmlViewBuilderModal.scss +18 -0
  21. package/client/src/HtmlViewCard.jsx +44 -0
  22. package/client/src/HtmlViewCard.scss +35 -0
  23. package/client/src/KanbanCard.jsx +1 -2
  24. package/client/src/ModelCreator.jsx +5 -4
  25. package/client/src/ModelCreatorField.jsx +51 -4
  26. package/client/src/ModelList.jsx +280 -236
  27. package/client/src/Notification.jsx +136 -136
  28. package/client/src/Notification.scss +0 -18
  29. package/client/src/Pagination.jsx +5 -3
  30. package/client/src/RelationField.jsx +354 -258
  31. package/client/src/RelationSelectorWidget.jsx +173 -0
  32. package/client/src/contexts/ModelContext.jsx +10 -1
  33. package/client/src/contexts/UIContext.jsx +72 -63
  34. package/client/src/filter.js +263 -212
  35. package/client/src/hooks/useValidation.js +75 -0
  36. package/client/src/translations.js +24 -24
  37. package/package.json +7 -6
  38. package/src/constants.js +1 -1
  39. package/src/core.js +8 -1
  40. package/src/defaultModels.js +1596 -1544
  41. package/src/engine.js +85 -43
  42. package/src/events.js +137 -113
  43. package/src/i18n.js +710 -10
  44. package/src/index.js +3 -0
  45. package/src/modules/assistant/assistant.js +253 -134
  46. package/src/modules/assistant/constants.js +2 -1
  47. package/src/modules/bucket.js +2 -1
  48. package/src/modules/data/data.core.js +118 -92
  49. package/src/modules/data/data.history.js +555 -492
  50. package/src/modules/data/data.js +3 -53
  51. package/src/modules/data/data.operations.js +3381 -3231
  52. package/src/modules/data/data.relations.js +686 -686
  53. package/src/modules/data/data.routes.js +1879 -1821
  54. package/src/modules/data/data.validation.js +81 -2
  55. package/src/modules/file.js +247 -238
  56. package/src/modules/user.js +1 -0
  57. package/src/modules/workflow.js +2 -2
  58. package/src/openai.jobs.js +3 -2
  59. package/src/packs.js +5482 -5478
  60. package/src/sso.js +2 -2
  61. package/src/workers/import-export-worker.js +1 -1
  62. package/test/data.history.integration.test.js +264 -192
  63. package/test/data.integration.test.js +149 -3
@@ -1,236 +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, 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
-
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
-
24
- export function ModelList({ onModelSelect, onCreateModel, onImportModel, onEditModel, onAPIInfo, onNewData }) {
25
- const {allTourSteps, setIsTourOpen,setCurrentTourSteps, setTourStepIndex, currentTour, setCurrentTour} = useUI();
26
-
27
- const {models, setSelectedModel, selectedModel, countByModel, generatedModels} = useModelContext();
28
- const {t} = useTranslation();
29
- const {me} = useAuthContext();
30
- const queryClient = useQueryClient()
31
- const [searchTerm, setSearchTerm] = useState('');
32
-
33
- const [currentProfile, setCurrentProfile] = useLocalStorage('profile', null);
34
- useEffect(() =>{
35
- if (me) {
36
- queryClient.invalidateQueries('api/models');
37
- }
38
- }, [me])
39
-
40
- const filteredModels = useMemo(() => {
41
- if (!models) return [];
42
- if (!searchTerm.trim()) return models; // Si la recherche est vide, retourne tous les modèles
43
-
44
- const lowerSearchTerm = searchTerm.toLowerCase();
45
- return models.filter(model => {
46
- return (model.name && t('model_' + model.name, model.name).toLowerCase().includes(lowerSearchTerm)) ||
47
- (model.fields.some(f =>
48
- (model.icon && model.icon.toLowerCase().includes(lowerSearchTerm)) ||
49
- f.name?.toLowerCase().includes(lowerSearchTerm) ||
50
- f.hint?.toLowerCase().includes(lowerSearchTerm)) ||
51
- (model.description && model.description.toLowerCase().includes(lowerSearchTerm)))
52
- });
53
- }, [models, searchTerm]);
54
-
55
- const handleSelectModel = (model) => {
56
- setSelectedModel(model);
57
- if (onModelSelect) {
58
- onModelSelect(model); // Si vous avez une prop callback supplémentaire
59
- }
60
- };
61
-
62
- const demoInitMutation = useMutation((profile) => {
63
- return fetch('/api/demo/initialize', {
64
- method: 'POST',
65
- headers: { "Content-Type": "application/json"},
66
- body: JSON.stringify({profile: profile, packs: profiles[profile].packs}),
67
- });
68
- });
69
-
70
- const handleProfile = (profile) => {
71
- // --- CHANGEMENT ICI : On appelle la nouvelle mutation sans argument ---
72
- demoInitMutation.mutateAsync(profile).then(response => {
73
- // On vérifie que la réponse est OK avant de continuer
74
- if (!response.ok) {
75
- // Gérer l'erreur si l'initialisation échoue
76
- console.error("L'initialisation de la démo a échoué.");
77
- // Vous pourriez afficher une notification à l'utilisateur ici.
78
- return;
79
- }
80
-
81
- // Le reste de la logique est parfait et ne change pas
82
- setCurrentProfile(profile);
83
- gtag('event', 'profile ' + profile);
84
- queryClient.invalidateQueries('api/models');
85
-
86
- const profileSteps = allTourSteps[profile];
87
- if (profileSteps) {
88
- setCurrentTourSteps(profileSteps);
89
- setTourStepIndex(0);
90
- setIsTourOpen(true); // Start the tour
91
- } else {
92
- console.warn(`No tour steps defined for profile: ${profile}`);
93
- }
94
- }).catch(error => {
95
- console.error("Erreur critique lors de l'appel d'initialisation de la démo:", error);
96
- });
97
- };
98
-
99
- const [mods, setMods] = useState([]);
100
- useEffect(() => {
101
- if( countByModel && selectedModel)
102
- {
103
- setMods((m) => {
104
- const counts = [...m];
105
- const mod = counts.find(f => f.mod === selectedModel.name);
106
- if( mod ){
107
- mod.count = countByModel[selectedModel.name];
108
- return counts.map((c => {
109
- if( c.mod === mod.mod) {
110
- return {...mod};
111
- }
112
- return c;
113
- }));
114
- }else{
115
- return [...m, { mod: selectedModel.name, count: countByModel[selectedModel.name]}];
116
- }
117
- })
118
- }
119
- }, [countByModel, selectedModel]);
120
-
121
- // --- NEW: Effect to update tour steps when a profile is already selected on mount ---
122
- useEffect(() => {
123
- if (currentProfile && currentTour && /^demo[0-9]{1,2}$/.test(me?.username)) { // Only run on demo user for simplicity
124
- const profileSteps = allTourSteps[currentProfile];
125
- if (profileSteps) {
126
- setCurrentTourSteps(profileSteps);
127
- setTourStepIndex(0)
128
- setIsTourOpen(true);
129
- } else {
130
- console.warn(`No tour steps defined for profile: ${currentProfile}`);
131
- }
132
- }
133
- }, [currentProfile, me?.username]);
134
-
135
- if (!models) {
136
- return <div className="loading-models">{t('models.loading', 'Chargement des modèles...')}</div>;
137
- }
138
-
139
- return <>
140
- {!currentProfile && /^demo[0-9]{1,2}$/.test(me.username) && <div className="tourStep-profile profiles flex-stretch flex">
141
- <div className=" flex flex-centered flex-big-gap">
142
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.personal.desc')} className="profile-link" onClick={() => handleProfile('personal')}>
143
- <img src="/profilPersonal.jpg" alt={"Personal profile"} width={256} height={256}/>
144
- </a>
145
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.developer.desc')} className="profile-link" onClick={() => handleProfile('developer')}>
146
- <img src="/profilDeveloper.jpg" alt={"Developer profile"} width={256} height={256}/>
147
- </a>
148
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.company.desc')} className="profile-link" onClick={() => handleProfile('company')}>
149
- <img src="/profilCompany.jpg" alt={"Company profile"} width={256} height={256}/>
150
- </a>
151
- <a href="#" data-tooltip-id="tooltipProfile" data-tooltip-content={t('profiles.engineer.desc')} className="profile-link" onClick={() => handleProfile('engineer')}>
152
- <img src="/profilEngineer.jpg" alt={"Engineer profile"} width={256} height={256}/>
153
- </a>
154
- <Tooltip id="tooltipProfile" render={({content, activeAnchor}) => {
155
- const pr = activeAnchor?.querySelector('img').getAttribute('alt');
156
- if (pr)
157
- gtag('event', 'info '+ pr);
158
- else
159
- gtag('event', 'info');
160
- return <span dangerouslySetInnerHTML={{__html:content}} />
161
- }} afterShow={() => {
162
-
163
- }} />
164
- </div></div>}
165
- <div className="models">
166
- <h2><Trans i18nKey="models">Modèles</Trans></h2>
167
- <div className="model-list-container">
168
- <div className="model-list-search-bar-container">
169
- <input
170
- type="search"
171
- placeholder={t('models.searchPlaceholder', 'Rechercher un modèle...')}
172
- value={searchTerm}
173
- onChange={(e) => setSearchTerm(e.target.value)}
174
- className="model-list-search-input"
175
- />
176
- </div>
177
- {filteredModels.length > 0 ? (
178
- <div className="model-list">
179
- <Tooltip id="tooltipML" />
180
- <ul>
181
- {filteredModels.sort((a, b) => t('model_' + a.name, a.name).localeCompare(t('model_' + b.name, b.name))).map((model) => {
182
- if (model._user !== me.username)
183
- return <></>
184
-
185
-
186
- const IconComponent = getIconComponent(model.icon);
187
-
188
- return (
189
- <li data-testid={'model_'+model.name} className={`${model.name === selectedModel?.name ? 'active' : ''}`}
190
- key={'modelist' + model.name} onClick={() => generatedModels.some(g => g.name === model.name) ? onEditModel(model) : onModelSelect(model)}>
191
- <div className="flex flex-center flex-fw">
192
- <div
193
- className="flex flex-1 flex-no-wrap break-word gap-2">
194
- <div className={"icon"}>{IconComponent ? IconComponent : <></>}</div>
195
- <div>{t(`model_${model.name}`, model.name)} {generatedModels.some(f => f.name === model.name) ? '(tmp)' : (mods.some(f => f.mod === model.name) ? `(${mods.find(f => f.mod === model.name).count})` : '')}</div></div>
196
- <div className="btns">
197
- {!generatedModels.some(g => g.name === model.name) && (<button data-tooltip-id="tooltipML" data-tooltip-content={t('btns.addData')} onClick={(e) => {
198
- e.stopPropagation();
199
- e.preventDefault();
200
- onNewData?.(model);
201
- }}><FaPlus/></button>)}
202
- {!model.locked && (<button data-tooltip-id="tooltipML" data-tooltip-content={t('btns.editModel')} onClick={(e) => {
203
- e.stopPropagation();
204
- e.preventDefault();
205
- onEditModel(model);
206
- }}><FaEdit/>
207
- </button>)}
208
- {(<button data-tooltip-id="tooltipML" data-tooltip-content={t('doc.api.title')} onClick={(e) => {
209
- e.stopPropagation();
210
- e.preventDefault();
211
- onAPIInfo?.(model);
212
- }}><FaBook/>
213
- </button>)}
214
- </div>
215
- </div>
216
- </li>)
217
- })}
218
- </ul>
219
-
220
- </div>) : (
221
- <p className="no-models-found">
222
- {searchTerm ? t('models.noMatch', 'Aucun modèle ne correspond à votre recherche.') : t('models.noModels', 'Aucun modèle disponible.')}
223
- </p>
224
- )}
225
- <div className="flex actions">
226
- <Button onClick={onCreateModel} className="btn tourStep-create-model"><FaPlus/><Trans
227
- i18nKey="btns.createModel">Créer un modèle</Trans></Button>
228
- <Button onClick={onImportModel}
229
- className="btn tourStep-import-model btn-primary"><FaFileImport/><Trans
230
- i18nKey="btns.importModels">Importer un modèle</Trans></Button>
231
- </div>
232
- </div>
233
- </div>
234
- </>
235
- }
236
-
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
+ }