data-primals-engine 1.3.1 → 1.3.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.
@@ -1,86 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import { Dialog } from "../Dialog.jsx";
3
- import { api } from "../utils/api.js"; // Assurez-vous que le chemin vers votre utilitaire api est correct
4
- import { FaHistory } from "react-icons/fa";
5
- import "./HistoryDialog.scss";
6
-
7
- // Sous-composant pour afficher une seule entrée de l'historique
8
- const HistoryEntry = ({ entry }) => {
9
- // _id: id du doc d'historique, _v: version, _op: type d'opération, _rid: id de l'enregistrement original
10
- const { _id, _v, _op, _updatedAt, _user, _rid, ...data } = entry;
11
- const operationDetails = {
12
- 'i': { label: 'Création', className: 'op-insert' },
13
- 'u': { label: 'Mise à jour', className: 'op-update' },
14
- 'd': { label: 'Suppression', className: 'op-delete' },
15
- };
16
- const opInfo = operationDetails[_op] || { label: _op, className: '' };
17
-
18
- return (
19
- <div className="history-entry">
20
- <div className="history-entry-header">
21
- <span className={`op-badge ${opInfo.className}`}>{opInfo.label}</span>
22
- <span className="history-date">Le {new Date(_updatedAt).toLocaleString()}</span>
23
- {_user && <span className="history-user">par <strong>{_user}</strong></span>}
24
- <span className="history-version">Version: {_v}</span>
25
- </div>
26
- <div className="history-entry-data">
27
- <pre>{JSON.stringify(data, null, 2)}</pre>
28
- </div>
29
- </div>
30
- );
31
- };
32
-
33
- export const HistoryDialog = ({ modelName, recordId, onClose }) => {
34
- const [history, setHistory] = useState([]);
35
- const [loading, setLoading] = useState(true);
36
- const [error, setError] = useState(null);
37
-
38
- useEffect(() => {
39
- if (!modelName || !recordId) return;
40
-
41
- const fetchHistory = async () => {
42
- setLoading(true);
43
- setError(null);
44
- try {
45
- // J'assume que l'endpoint de l'API pour l'historique est structuré ainsi
46
- const response = await api.get(`/data/history/${modelName}/${recordId}`);
47
- if (response.success) {
48
- // L'API devrait retourner l'historique trié du plus récent au plus ancien
49
- setHistory(response.data);
50
- } else {
51
- setError(response.error || "Échec de la récupération de l'historique.");
52
- }
53
- } catch (err) {
54
- setError("Une erreur est survenue lors de la récupération de l'historique.");
55
- console.error(err);
56
- } finally {
57
- setLoading(false);
58
- }
59
- };
60
-
61
- fetchHistory();
62
- }, [modelName, recordId]);
63
-
64
- return (
65
- <Dialog
66
- title={<><FaHistory style={{ marginRight: '8px' }} /> Historique de l'enregistrement</>}
67
- onClose={onClose}
68
- isClosable={true}
69
- className="history-dialog"
70
- >
71
- <div className="history-dialog-content">
72
- {loading && <div>Chargement de l'historique...</div>}
73
- {error && <div className="error-message">{error}</div>}
74
- {!loading && !error && (
75
- <div className="history-list">
76
- {history.length > 0 ? (
77
- history.map(entry => <HistoryEntry key={entry._id} entry={entry} />)
78
- ) : (
79
- <div>Aucun historique trouvé pour cet enregistrement.</div>
80
- )}
81
- </div>
82
- )}
83
- </div>
84
- </Dialog>
85
- );
86
- };
@@ -1,77 +0,0 @@
1
- .history-dialog {
2
- width: 80vw;
3
- max-width: 900px;
4
- height: 70vh;
5
-
6
- .dialog-content {
7
- display: flex;
8
- flex-direction: column;
9
- height: 100%;
10
- padding: 0; // Le padding sera sur le content wrapper
11
- }
12
- }
13
-
14
- .history-dialog-content {
15
- flex-grow: 1;
16
- overflow-y: auto;
17
- padding: 1rem;
18
- background-color: #f4f4f4;
19
- }
20
-
21
- .history-list {
22
- display: flex;
23
- flex-direction: column;
24
- gap: 1rem;
25
- }
26
-
27
- .history-entry {
28
- border: 1px solid #ddd;
29
- border-radius: 4px;
30
- background-color: #fff;
31
- box-shadow: 0 1px 3px rgba(0,0,0,0.05);
32
-
33
- .history-entry-header {
34
- display: flex;
35
- align-items: center;
36
- gap: 1rem;
37
- padding: 0.5rem 1rem;
38
- background-color: #f9f9f9;
39
- border-bottom: 1px solid #eee;
40
- font-size: 0.9em;
41
- color: #333;
42
-
43
- .op-badge {
44
- padding: 0.2rem 0.6rem;
45
- border-radius: 12px;
46
- color: white;
47
- font-weight: bold;
48
- font-size: 0.8em;
49
- text-transform: uppercase;
50
- }
51
-
52
- .op-insert { background-color: #28a745; } // green
53
- .op-update { background-color: #007bff; } // blue
54
- .op-delete { background-color: #dc3545; } // red
55
-
56
- .history-version {
57
- margin-left: auto;
58
- font-weight: bold;
59
- }
60
- }
61
-
62
- .history-entry-data {
63
- padding: 1rem;
64
-
65
- pre {
66
- white-space: pre-wrap;
67
- word-wrap: break-word;
68
- background-color: #2d2d2d;
69
- color: #f8f8f2;
70
- padding: 1rem;
71
- border-radius: 4px;
72
- margin: 0;
73
- font-family: 'Courier New', Courier, monospace;
74
- font-size: 0.85em;
75
- }
76
- }
77
- }