data-primals-engine 1.5.1 → 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.
- package/README.md +2 -0
- package/client/src/App.scss +1 -1
- package/client/src/DataLayout.jsx +2 -0
- package/client/src/HistoryDialog.jsx +24 -2
- package/client/src/ModelList.jsx +280 -275
- package/client/src/filter.js +1 -0
- package/package.json +6 -6
- package/src/core.js +8 -1
- package/src/engine.js +85 -43
- package/src/events.js +137 -113
- package/src/index.js +3 -0
- package/src/modules/assistant/assistant.js +123 -134
- package/src/modules/assistant/constants.js +2 -1
- package/src/modules/data/data.history.js +32 -8
- package/src/modules/data/data.operations.js +3381 -3282
- package/src/modules/data/data.relations.js +1 -1
- package/src/modules/data/data.routes.js +3 -3
- package/src/modules/user.js +1 -0
- package/src/modules/workflow.js +2 -2
- package/src/openai.jobs.js +3 -2
- package/src/sso.js +2 -2
- package/src/workers/import-export-worker.js +1 -1
- package/test/data.history.integration.test.js +264 -192
- package/test/data.integration.test.js +1206 -1115
package/client/src/ModelList.jsx
CHANGED
|
@@ -1,275 +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({ 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">
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
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
|
+
}
|
package/client/src/filter.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-primals-engine",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "data-primals-engine is a package responsible from handling large amount of data using MongoDB in a practical and performant way. It can also get workflow models working (for automation), and fully supports internationalisation. It also has integrated AI assistant.",
|
|
5
5
|
"main": "src/engine.js",
|
|
6
6
|
"type": "module",
|
|
@@ -57,11 +57,7 @@
|
|
|
57
57
|
"./*": "./src/*.js"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@langchain/anthropic": "^0.3.26",
|
|
61
60
|
"@langchain/core": "^0.3.66",
|
|
62
|
-
"@langchain/deepseek": "^0.1.0",
|
|
63
|
-
"@langchain/google-genai": "^0.2.16",
|
|
64
|
-
"@langchain/openai": "^0.6.3",
|
|
65
61
|
"archiver": "^7.0.1",
|
|
66
62
|
"aws-sdk": "^2.1692.0",
|
|
67
63
|
"bcrypt": "^6.0.0",
|
|
@@ -113,7 +109,11 @@
|
|
|
113
109
|
"passport-google-oauth20": "^2.0.0",
|
|
114
110
|
"react": "18.3.1",
|
|
115
111
|
"react-i18next": "^15.6.1",
|
|
116
|
-
"react-query": ">=3.0.0"
|
|
112
|
+
"react-query": ">=3.0.0",
|
|
113
|
+
"@langchain/anthropic": "^0.3.26",
|
|
114
|
+
"@langchain/deepseek": "^0.1.0",
|
|
115
|
+
"@langchain/google-genai": "^0.2.16",
|
|
116
|
+
"@langchain/openai": "^0.6.3"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@eslint/js": "^9.32.0",
|
package/src/core.js
CHANGED
|
@@ -33,10 +33,17 @@ export function escapeHtml(string){
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export const isUnsecureKey = (key) => {
|
|
37
|
+
return ["__proto__", "constructor", "prototype"].includes(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const parseSafeJSON = (json) => JSON.parse(json, (key, value) => isUnsecureKey(key) ? undefined : value);
|
|
41
|
+
|
|
42
|
+
|
|
36
43
|
export const isDate = dt => String(new Date(dt)) !== 'Invalid Date'
|
|
37
44
|
|
|
38
45
|
export const safeAssignObject = (obj, key, value) => {
|
|
39
|
-
if( !
|
|
46
|
+
if( !isUnsecureKey(key)){
|
|
40
47
|
obj[key] = value;
|
|
41
48
|
}
|
|
42
49
|
}
|