@tekkare/romulus 0.1.332 → 0.1.333

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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "0.1.331",
7
+ "version": "0.1.332",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -48,6 +48,7 @@ const emit = defineEmits<{
48
48
  toggle: [id: string]
49
49
  rearm: [id: string]
50
50
  menu: [payload: { key: string; id: string }]
51
+ 'open-event': [id: string]
51
52
  }>()
52
53
 
53
54
  const FR = {
@@ -366,7 +367,12 @@ function pick(item: RmAlertMenuItem) {
366
367
 
367
368
  <div v-if="expanded" class="rm-alert__journal">
368
369
  <RmLoadingState v-if="eventsLoading" />
369
- <RmAlertEvents v-else-if="events.length" :events="events" :lang="lang" />
370
+ <RmAlertEvents
371
+ v-else-if="events.length"
372
+ :events="events"
373
+ :lang="lang"
374
+ @open-event="emit('open-event', $event)"
375
+ />
370
376
  <p v-else class="rm-alert__journal-empty">{{ T.noEvents }}</p>
371
377
  </div>
372
378
  </div>
@@ -23,22 +23,29 @@ const props = withDefaults(
23
23
  { showSource: false, lang: 'fr' },
24
24
  )
25
25
 
26
+ const emit = defineEmits<{
27
+ /** Une carte cliquable est ouverte : l'appelant mene a la fiche. */
28
+ 'open-event': [id: string]
29
+ }>()
30
+
26
31
  const FR = {
27
32
  appeared: 'Nouveau',
28
33
  changed: 'Modifié',
29
34
  disappeared: 'Sorti du périmètre',
30
- becomes: 'devient',
31
35
  empty: '(vide)',
32
- more: (n: number) => `et ${n} autre${n > 1 ? 's' : ''} champ${n > 1 ? 's' : ''}`,
36
+ more: (n: number) => `et ${n} autre${n > 1 ? 's' : ''} changement${n > 1 ? 's' : ''}`,
37
+ open: 'Voir la fiche',
38
+ from: 'Alerte',
33
39
  }
34
40
 
35
41
  const EN = {
36
42
  appeared: 'New',
37
43
  changed: 'Changed',
38
44
  disappeared: 'Left the scope',
39
- becomes: 'becomes',
40
45
  empty: '(empty)',
41
- more: (n: number) => `and ${n} other field${n > 1 ? 's' : ''}`,
46
+ more: (n: number) => `and ${n} other change${n > 1 ? 's' : ''}`,
47
+ open: 'Open the record',
48
+ from: 'Alert',
42
49
  }
43
50
 
44
51
  const T = computed(() => (props.lang === 'en' ? EN : FR))
@@ -51,7 +58,7 @@ const T = computed(() => (props.lang === 'en' ? EN : FR))
51
58
  * des autres reste affiche : masquer sans le dire ferait croire que c'est
52
59
  * tout ce qui a bouge.
53
60
  */
54
- const MAX_LINES = 4
61
+ const MAX_LINES = 3
55
62
 
56
63
  function shown(event: RmAlertEvent) {
57
64
  return (event.changes ?? []).slice(0, MAX_LINES)
@@ -83,6 +90,10 @@ function blocks(event: RmAlertEvent) {
83
90
  function hidden(event: RmAlertEvent) {
84
91
  return Math.max((event.changes ?? []).length - MAX_LINES, 0)
85
92
  }
93
+
94
+ function open(event: RmAlertEvent) {
95
+ if (event.openable) emit('open-event', event.id)
96
+ }
86
97
  </script>
87
98
 
88
99
  <template>
@@ -91,7 +102,14 @@ function hidden(event: RmAlertEvent) {
91
102
  v-for="event in events"
92
103
  :key="event.id"
93
104
  class="rm-alert-events__item"
94
- :class="{ 'rm-alert-events__item--unread': !event.read }"
105
+ :class="{
106
+ 'rm-alert-events__item--unread': !event.read,
107
+ 'rm-alert-events__item--openable': event.openable,
108
+ }"
109
+ :role="event.openable ? 'link' : undefined"
110
+ :tabindex="event.openable ? 0 : undefined"
111
+ @click="open(event)"
112
+ @keydown.enter="open(event)"
95
113
  >
96
114
  <header class="rm-alert-events__head">
97
115
  <span class="rm-alert-events__kind" :class="`rm-alert-events__kind--${event.kind}`">
@@ -117,13 +135,16 @@ function hidden(event: RmAlertEvent) {
117
135
  :key="line"
118
136
  class="rm-alert-events__change"
119
137
  >
120
- <span class="rm-alert-events__field">{{ change.label || change.field }} :</span>
138
+ <!-- Espaces explicites : entre une balise et la suivante, le
139
+ compilateur retire le blanc, et on lisait « Code ATC4 :L01FF ». -->
140
+ <span class="rm-alert-events__field">{{ change.label || change.field }} :</span>{{ ' ' }}
141
+ <!-- Une phrase quand les valeurs ne se lisent pas (entree resumee,
142
+ texte long) ; sinon l'avant et l'apres, separes d'une fleche. -->
143
+ <template v-if="change.note">{{ change.note }}</template>
121
144
  <!-- Une entree qui entre ou qui sort n'a qu'un cote : annoncer
122
145
  « (vide) devient X » remplissait la ligne de ce qui n'existe pas. -->
123
- <template v-if="change.before && change.after">
124
- <s>{{ change.before }}</s>
125
- {{ T.becomes }}
126
- <strong>{{ change.after }}</strong>
146
+ <template v-else-if="change.before && change.after">
147
+ <s>{{ change.before }}</s>{{ ' → ' }}<strong>{{ change.after }}</strong>
127
148
  </template>
128
149
  <s v-else-if="change.before">{{ change.before }}</s>
129
150
  <strong v-else>{{ change.after || T.empty }}</strong>
@@ -132,13 +153,22 @@ function hidden(event: RmAlertEvent) {
132
153
  <p v-if="hidden(event)" class="rm-alert-events__more">
133
154
  {{ T.more(hidden(event)) }}
134
155
  </p>
135
- <p v-if="showSource && event.alertTitle" class="rm-alert-events__from">
136
- {{ event.alertTitle }}
137
- </p>
156
+ <footer
157
+ v-if="(showSource && event.alertTitle) || event.openable"
158
+ class="rm-alert-events__foot"
159
+ >
160
+ <span v-if="showSource && event.alertTitle" class="rm-alert-events__from">
161
+ {{ T.from }} : {{ event.alertTitle }}
162
+ </span>
163
+ <span v-if="event.openable" class="rm-alert-events__open">
164
+ {{ T.open }}
165
+ <RmIcon name="ArrowRight" :size="12" />
166
+ </span>
167
+ </footer>
138
168
  </article>
139
169
  </div>
140
170
  </template>
141
171
 
142
172
  <style scoped>
143
- .rm-alert-events{display:flex;flex-direction:column;gap:10px}.rm-alert-events__item{border:1px solid var(--border-default);border-radius:9px;display:flex;flex-direction:column;gap:3px;padding:10px 12px}.rm-alert-events__item--unread{border-left:3px solid var(--color-primary)}.rm-alert-events__head{align-items:center;display:flex;gap:8px;justify-content:space-between}.rm-alert-events__source{color:var(--text-muted);font-size:11px;font-weight:600;margin:0}.rm-alert-events__kind{color:var(--text-secondary);font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase}.rm-alert-events__kind--appeared{color:var(--color-success)}.rm-alert-events__kind--changed{color:var(--color-info)}.rm-alert-events__kind--disappeared{color:var(--color-warning)}.rm-alert-events__date{color:var(--text-muted);font-size:11px}.rm-alert-events__title{color:var(--text-primary);font-size:13.5px;line-height:1.4;margin:0}.rm-alert-events__from,.rm-alert-events__sub{color:var(--text-muted);font-size:11.5px;margin:0}.rm-alert-events__block{margin-top:4px}.rm-alert-events__block--grouped{border-left:2px solid var(--border-default);padding-left:8px}.rm-alert-events__group{color:var(--text-primary);font-size:11.5px;font-weight:600;margin:0}.rm-alert-events__change{color:var(--text-secondary);font-size:12.5px;margin:2px 0 0}.rm-alert-events__field{color:var(--text-muted)}.rm-alert-events__change s{opacity:.65}.rm-alert-events__more{color:var(--text-muted);font-size:12px;font-style:italic;margin:2px 0 0}
173
+ .rm-alert-events{display:flex;flex-direction:column;gap:10px}.rm-alert-events__item{border:1px solid var(--border-default);border-radius:9px;display:flex;flex-direction:column;gap:3px;padding:10px 12px}.rm-alert-events__item--unread{border-left:3px solid var(--color-primary)}.rm-alert-events__item--openable{cursor:pointer}.rm-alert-events__item--openable:hover{background:var(--bg-hover)}.rm-alert-events__item--openable:focus-visible{outline:2px solid var(--color-secondary);outline-offset:2px}.rm-alert-events__head{align-items:center;display:flex;gap:8px;justify-content:space-between}.rm-alert-events__source{color:var(--text-muted);font-size:11px;font-weight:600;margin:0}.rm-alert-events__kind{color:var(--text-secondary);font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase}.rm-alert-events__kind--appeared{color:var(--color-success)}.rm-alert-events__kind--changed{color:var(--color-info)}.rm-alert-events__kind--disappeared{color:var(--color-warning)}.rm-alert-events__date{color:var(--text-muted);font-size:11px}.rm-alert-events__title{display:-webkit-box;margin:0;overflow:hidden;-webkit-box-orient:vertical;color:var(--text-primary);font-size:13.5px;font-weight:600;-webkit-line-clamp:3;line-clamp:3;line-height:1.4}.rm-alert-events__from,.rm-alert-events__sub{color:var(--text-muted);font-size:11.5px;margin:0}.rm-alert-events__block{margin-top:4px}.rm-alert-events__block--grouped{border-left:2px solid var(--border-default);padding-left:8px}.rm-alert-events__group{color:var(--text-primary);font-size:11.5px;font-weight:600;margin:0}.rm-alert-events__change{color:var(--text-secondary);font-size:12.5px;margin:2px 0 0}.rm-alert-events__field{color:var(--text-muted)}.rm-alert-events__change s{opacity:.65}.rm-alert-events__foot{align-items:center;display:flex;gap:8px;justify-content:space-between;margin-top:4px}.rm-alert-events__open{align-items:center;color:var(--color-primary);display:inline-flex;font-size:12px;font-weight:600;gap:4px;margin-left:auto;white-space:nowrap}.rm-alert-events__more{color:var(--text-muted);font-size:12px;font-style:italic;margin:2px 0 0}
144
174
  </style>
@@ -66,6 +66,8 @@ const emit = defineEmits<{
66
66
  rearm: [id: string]
67
67
  menu: [payload: { key: string; id: string }]
68
68
  'read-all': []
69
+ /** Un evenement du journal est ouvert : mener a sa fiche. */
70
+ 'open-event': [id: string]
69
71
  }>()
70
72
 
71
73
  const FR = {
@@ -202,7 +204,12 @@ function setTab(value: 'active' | 'paused' | 'events') {
202
204
  {{ T.readAll }}
203
205
  </button>
204
206
 
205
- <RmAlertEvents :events="events" show-source :lang="lang" />
207
+ <RmAlertEvents
208
+ :events="events"
209
+ show-source
210
+ :lang="lang"
211
+ @open-event="emit('open-event', $event)"
212
+ />
206
213
  </div>
207
214
 
208
215
  <RmEmptyState v-else framed icon="Bell" :title="T.emptyEvents" :text="T.emptyEventsText" />
@@ -232,6 +239,7 @@ function setTab(value: 'active' | 'paused' | 'events') {
232
239
  @open="emit('open', $event)"
233
240
  @rearm="emit('rearm', $event)"
234
241
  @menu="emit('menu', $event)"
242
+ @open-event="emit('open-event', $event)"
235
243
  />
236
244
  </div>
237
245
  </RmCollapse>
@@ -253,6 +261,7 @@ function setTab(value: 'active' | 'paused' | 'events') {
253
261
  @open="emit('open', $event)"
254
262
  @rearm="emit('rearm', $event)"
255
263
  @menu="emit('menu', $event)"
264
+ @open-event="emit('open-event', $event)"
256
265
  />
257
266
  </section>
258
267
  </template>
@@ -97,6 +97,11 @@ export interface RmAlertChange {
97
97
  group?: string | null;
98
98
  before: string;
99
99
  after: string;
100
+ /**
101
+ * Phrase qui remplace les valeurs quand elles ne se lisent pas : une entree
102
+ * resumee (« retrait de KEYTRUDA 50 MG »), un texte long (« modifie »).
103
+ */
104
+ note?: string | null;
100
105
  }
101
106
  export interface RmAlertEvent {
102
107
  id: string;
@@ -115,6 +120,8 @@ export interface RmAlertEvent {
115
120
  source?: string | null;
116
121
  alertTitle?: string | null;
117
122
  read?: boolean;
123
+ /** La carte mene a la fiche du document : un clic emet `open-event`. */
124
+ openable?: boolean;
118
125
  }
119
126
  /** Un champ que la page propose de surveiller. */
120
127
  export interface RmAlertField {
@@ -14,6 +14,15 @@
14
14
  <script setup lang="ts">
15
15
  import { sameViewPage } from "../../../utils/viewPages";
16
16
  import { ALERT_BRAND_DIRECTORY, alertEventSourceLabel, alertProjectPath } from "#oip-app/alerts";
17
+ // Par namespace, avec repli : une app qui fournit son propre `#oip-app/alerts`
18
+ // sans ces deux fonctions (ajoutees en nov. 2026) doit continuer de builder.
19
+ // Sans elles, aucune carte du journal n'est cliquable.
20
+ import * as appAlerts from "#oip-app/alerts";
21
+
22
+ const alertEventOpenable = (docId: string | null | undefined): boolean =>
23
+ (appAlerts as any).alertEventOpenable?.(docId) ?? false;
24
+ const alertEventPath = async (docId: string): Promise<string | null> =>
25
+ (await (appAlerts as any).alertEventPath?.(docId)) ?? null;
17
26
  import { oipSnackbar } from "#oip-app/ui";
18
27
  import type {
19
28
  RmAlert,
@@ -297,14 +306,29 @@ function toEventCard(event: any, alertTitle: string) {
297
306
  // Les cles techniques ne se montrent pas : un identifiant interne qui
298
307
  // bouge n'apprend rien et noie la ligne d'a cote. Le moteur ne les
299
308
  // rapporte plus, ce filtre vaut pour ce qui est deja journalise.
300
- changes: (event.changes ?? [])
301
- .filter((change: any) => !isAlertNoiseField(change.field))
302
- .map((change: any) => ({
303
- ...change,
304
- ...alertFieldLabel(change.field, change.label, t, locale.value),
305
- before: alertChangeValue(change.before, t, locale.value),
306
- after: alertChangeValue(change.after, t, locale.value),
307
- })),
309
+ // Puis le diff devient quelques lignes lisibles : entrees nommees et
310
+ // comptees, textes longs resumes, doublon de langue tu (cf.
311
+ // simplifyAlertChanges). Une entree garde son resume brut : c'est la
312
+ // qu'on lit son libelle et son identifiant.
313
+ changes: simplifyAlertChanges(
314
+ (event.changes ?? [])
315
+ .filter((change: any) => !isAlertNoiseField(change.field))
316
+ .map((change: any) => {
317
+ const named = alertFieldLabel(change.field, change.label, t, locale.value);
318
+ return {
319
+ field: change.field,
320
+ label: named.label,
321
+ what: named.what,
322
+ entry: named.entry,
323
+ before: named.entry ? change.before ?? "" : alertChangeValue(change.before, t, locale.value),
324
+ after: named.entry ? change.after ?? "" : alertChangeValue(change.after, t, locale.value),
325
+ };
326
+ }),
327
+ lang.value,
328
+ ),
329
+ // Un clic mene a la fiche, quand l'app sait la retrouver.
330
+ docId: event.docId,
331
+ openable: alertEventOpenable(event.docId),
308
332
  dateLabel: whenExact(event.detectedAt),
309
333
  // Une alerte de marque traverse tout le hub : sans la provenance, la carte
310
334
  // dit qu'il s'est passe quelque chose sans dire ou aller le lire.
@@ -381,6 +405,26 @@ async function onOpen(id: string) {
381
405
  }
382
406
  }
383
407
 
408
+ /**
409
+ * Un evenement ouvre sa fiche : c'est la qu'on lit ce qui a change, en entier
410
+ * et en contexte. L'app seule sait ou vit la fiche d'un document (certaines se
411
+ * construisent avec un champ du document, relu a la demande). L'evenement
412
+ * passe lu au passage : on vient de le consulter.
413
+ */
414
+ async function onOpenEvent(id: string) {
415
+ const card: any =
416
+ events.value.find((event) => event.id === id) ??
417
+ expandedEvents.value.find((event) => event.id === id);
418
+ if (!card?.docId) return;
419
+ const path = await alertEventPath(card.docId);
420
+ if (!path) {
421
+ notify(lang.value === "en" ? "This record cannot be opened any more." : "Cette fiche ne peut plus être ouverte.");
422
+ return;
423
+ }
424
+ if (!card.read) void alerts.markRead({ eventIds: [id] }).catch(() => {});
425
+ await navigateTo(localePath(path));
426
+ }
427
+
384
428
  const menu = computed<RmAlertMenuItem[]>(() => [
385
429
  {
386
430
  key: "edit",
@@ -852,6 +896,7 @@ const onWatchedPage = computed(
852
896
  :expanded-loading="expandedLoading"
853
897
  :lang="lang"
854
898
  @open="onOpen"
899
+ @open-event="onOpenEvent"
855
900
  @create="editing = null; creating = true"
856
901
  @rearm="onRearm"
857
902
  @menu="onMenu"
@@ -51,6 +51,23 @@ export function alertEventSourceLabel(
51
51
  return null;
52
52
  }
53
53
 
54
+ /**
55
+ * Un evenement mene-t-il a une fiche ? Rend vite, sans appel : la carte s'en
56
+ * sert pour se dire cliquable. Par defaut, aucune.
57
+ */
58
+ export function alertEventOpenable(_docId: string | null | undefined): boolean {
59
+ return false;
60
+ }
61
+
62
+ /**
63
+ * Le chemin de la fiche d'un evenement, sans prefixe de langue. Peut relire le
64
+ * document quand le chemin se construit avec l'un de ses champs. `null` quand
65
+ * la fiche n'existe pas (ou plus).
66
+ */
67
+ export async function alertEventPath(_docId: string): Promise<string | null> {
68
+ return null;
69
+ }
70
+
54
71
  /** La page d'un projet. */
55
72
  export const alertProjectPath = (id: string) => `/projects/${id}`;
56
73
 
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Les changements d'un evenement d'alerte, dits en quelques lignes lisibles.
3
+ *
4
+ * Le moteur rapporte un diff : un changement par champ, le chemin complet du
5
+ * champ, et pour une entree entiere qui entre ou qui sort, le resume brut de
6
+ * son contenu (`cip_code 3400894095354, cip_ucd_type UCD, product_label ...`).
7
+ * Lu tel quel dans le journal, c'etait illisible : des clefs de collection
8
+ * (`c_2639673`), des identifiants, la meme maladie en francais puis en
9
+ * anglais, deux paragraphes d'indication barre et gras.
10
+ *
11
+ * Ici, chaque changement devient une ligne courte :
12
+ * - une entree qui entre ou sort se nomme par son libelle, et les entrees d'une
13
+ * meme collection se comptent ensemble (« 2 retraits : A, B ») ;
14
+ * - une entree qui sort et revient avec le meme identifiant est une mise a
15
+ * jour, pas un retrait suivi d'un ajout ;
16
+ * - un texte long ne se recopie pas, la ligne dit qu'il a change ;
17
+ * - le doublon anglais d'un champ francais (et l'inverse) se tait.
18
+ *
19
+ * Fonction pure : le layer lui passe des changements deja libelles avec les
20
+ * mots de l'app, elle ne connait aucun index.
21
+ */
22
+
23
+ export interface AlertRawChange {
24
+ /** Chemin du champ, tel que le moteur le rapporte. */
25
+ field: string
26
+ /** Libelle du champ, deja traduit. */
27
+ label: string
28
+ /** Libelle de la collection (premier segment du chemin), deja traduit. */
29
+ what: string
30
+ /** Une entree entiere qui entre ou qui sort, et non un champ qui change. */
31
+ entry: boolean
32
+ before: string
33
+ after: string
34
+ }
35
+
36
+ export interface AlertSimpleChange {
37
+ field: string
38
+ label: string
39
+ before: string
40
+ after: string
41
+ /** Phrase qui remplace les valeurs, quand elles ne se lisent pas. */
42
+ note?: string
43
+ }
44
+
45
+ /** Clefs d'une entree qui la nomment, par ordre de preference. */
46
+ const NAME_KEYS = [
47
+ 'preferred_label',
48
+ 'product_label',
49
+ 'presentation_label',
50
+ 'label',
51
+ 'name',
52
+ 'title',
53
+ 'brand',
54
+ 'disease_name',
55
+ 'libelle',
56
+ 'indication',
57
+ ]
58
+
59
+ /** Au-dela, une valeur est un texte, pas une donnee : on dit qu'il a change. */
60
+ const LONG_VALUE = 60
61
+ /** Noms cites par ligne ; le reste se compte. */
62
+ const MAX_NAMES = 2
63
+ /** Un nom trop long se coupe : la ligne doit tenir dans le rail. */
64
+ const MAX_NAME_LENGTH = 48
65
+
66
+ const CHUNK = /^([a-z0-9_]+) (.+)$/
67
+
68
+ const WORDS = {
69
+ fr: {
70
+ added: (n: number) => (n > 1 ? `${n} ajouts` : '1 ajout'),
71
+ removed: (n: number) => (n > 1 ? `${n} retraits` : '1 retrait'),
72
+ updated: (n: number) => (n > 1 ? `${n} mises à jour` : '1 mise à jour'),
73
+ addedOf: 'ajout de',
74
+ removedOf: 'retrait de',
75
+ updatedOf: 'mise à jour de',
76
+ others: (n: number) => `et ${n} autre${n > 1 ? 's' : ''}`,
77
+ changed: 'modifié',
78
+ filled: 'renseigné',
79
+ emptied: 'retiré',
80
+ },
81
+ en: {
82
+ added: (n: number) => (n > 1 ? `${n} added` : '1 added'),
83
+ removed: (n: number) => (n > 1 ? `${n} removed` : '1 removed'),
84
+ updated: (n: number) => (n > 1 ? `${n} updated` : '1 updated'),
85
+ addedOf: 'added',
86
+ removedOf: 'removed',
87
+ updatedOf: 'updated',
88
+ others: (n: number) => `and ${n} more`,
89
+ changed: 'changed',
90
+ filled: 'filled in',
91
+ emptied: 'removed',
92
+ },
93
+ }
94
+
95
+ /** Le resume brut d'une entree, en paires clef/valeur. Vide s'il n'en est pas un. */
96
+ function chunks(summary: string): Array<[string, string]> {
97
+ const out: Array<[string, string]> = []
98
+ for (const part of String(summary ?? '').split(', ')) {
99
+ const match = part.match(CHUNK)
100
+ if (!match) return []
101
+ out.push([match[1]!, match[2]!])
102
+ }
103
+ return out
104
+ }
105
+
106
+ function nameOf(summary: string): string | null {
107
+ const pairs = chunks(summary)
108
+ for (const key of NAME_KEYS) {
109
+ const found = pairs.find(([k]) => k === key)
110
+ if (found) return shorten(found[1].replace(/…$/, '').trim())
111
+ }
112
+ return null
113
+ }
114
+
115
+ /** Ce qui identifie l'entree d'un releve a l'autre. */
116
+ function idOf(summary: string): string | null {
117
+ const found = chunks(summary).find(([key]) => key === 'id' || key.endsWith('_id'))
118
+ return found ? found[1].replace(/…$/, '').trim() : null
119
+ }
120
+
121
+ function shorten(value: string): string {
122
+ return value.length > MAX_NAME_LENGTH ? `${value.slice(0, MAX_NAME_LENGTH - 1).trimEnd()}…` : value
123
+ }
124
+
125
+ /** Le segment de tete, sans son suffixe de langue. */
126
+ function base(field: string): { root: string; lang: 'fr' | 'en' | null } {
127
+ const top = String(field ?? '').split('.')[0] ?? ''
128
+ const match = top.match(/^(.*)_(fr|en)$/)
129
+ return match ? { root: match[1]!, lang: match[2] as 'fr' | 'en' } : { root: top, lang: null }
130
+ }
131
+
132
+ /**
133
+ * Le doublon d'un champ dans l'autre langue se tait quand sa version dans la
134
+ * langue de l'ecran a aussi bouge : c'est le meme mouvement, dit deux fois.
135
+ */
136
+ function dropOtherLanguage(changes: AlertRawChange[], lang: 'fr' | 'en'): AlertRawChange[] {
137
+ const roots = new Set(
138
+ changes.map((change) => base(change.field)).filter((b) => b.lang !== (lang === 'fr' ? 'en' : 'fr')).map((b) => b.root),
139
+ )
140
+ return changes.filter((change) => {
141
+ const b = base(change.field)
142
+ return !(b.lang && b.lang !== lang && roots.has(b.root))
143
+ })
144
+ }
145
+
146
+ function listOf(names: string[], count: number, W: (typeof WORDS)['fr']): string {
147
+ const shown = names.slice(0, MAX_NAMES).join(', ')
148
+ const rest = count - Math.min(names.length, MAX_NAMES)
149
+ return rest > 0 ? `${shown} ${W.others(rest)}` : shown
150
+ }
151
+
152
+ export function simplifyAlertChanges(
153
+ raw: AlertRawChange[],
154
+ lang: 'fr' | 'en' = 'fr',
155
+ ): AlertSimpleChange[] {
156
+ const W = WORDS[lang]
157
+ const changes = dropOtherLanguage(raw, lang)
158
+
159
+ // Les entrees se rassemblent par collection et par sens ; leur ligne prend
160
+ // la place du premier changement de la collection, pour garder l'ordre du
161
+ // moteur (cf. R-05 : il a deja classe par portee metier).
162
+ type Bucket = { what: string; field: string; added: string[]; removed: string[]; updated: string[]; counts: Record<'added' | 'removed' | 'updated', number> }
163
+ const buckets = new Map<string, Bucket>()
164
+ const order: Array<{ bucket: string } | { change: AlertSimpleChange }> = []
165
+
166
+ const entries = changes.filter((change) => change.entry)
167
+ // Une entree qui sort et revient sous le meme identifiant : mise a jour.
168
+ const removedIds = new Map<string, AlertRawChange>()
169
+ for (const change of entries) {
170
+ if (change.before && !change.after) {
171
+ const id = idOf(change.before)
172
+ if (id) removedIds.set(`${change.what}|${id}`, change)
173
+ }
174
+ }
175
+ const paired = new Set<AlertRawChange>()
176
+ for (const change of entries) {
177
+ if (!change.before && change.after) {
178
+ const id = idOf(change.after)
179
+ const twin = id ? removedIds.get(`${change.what}|${id}`) : undefined
180
+ if (twin && !paired.has(twin)) {
181
+ paired.add(twin)
182
+ paired.add(change)
183
+ ;(change as AlertRawChange & { updated?: boolean }).updated = true
184
+ }
185
+ }
186
+ }
187
+
188
+ for (const change of changes) {
189
+ if (!change.entry) {
190
+ if (sameList(change.before, change.after)) continue
191
+ order.push({ change: simpleField(change, W) })
192
+ continue
193
+ }
194
+ const isUpdate = (change as AlertRawChange & { updated?: boolean }).updated === true
195
+ // Le retrait apparie se fond dans la mise a jour, il ne compte pas a part.
196
+ if (paired.has(change) && !isUpdate) continue
197
+
198
+ const key = change.what || change.field.split('.')[0] || change.field
199
+ let bucket = buckets.get(key)
200
+ if (!bucket) {
201
+ bucket = { what: key, field: change.field, added: [], removed: [], updated: [], counts: { added: 0, removed: 0, updated: 0 } }
202
+ buckets.set(key, bucket)
203
+ order.push({ bucket: key })
204
+ }
205
+ const side = isUpdate ? 'updated' : change.after ? 'added' : 'removed'
206
+ const name = nameOf(isUpdate ? change.after : change.after || change.before)
207
+ bucket.counts[side] += 1
208
+ if (name && !bucket[side].includes(name)) bucket[side].push(name)
209
+ }
210
+
211
+ const out: AlertSimpleChange[] = []
212
+ for (const item of order) {
213
+ if ('change' in item) {
214
+ out.push(item.change)
215
+ continue
216
+ }
217
+ const bucket = buckets.get(item.bucket)!
218
+ for (const side of ['updated', 'added', 'removed'] as const) {
219
+ const count = bucket.counts[side]
220
+ if (!count) continue
221
+ const names = bucket[side]
222
+ const of = side === 'added' ? W.addedOf : side === 'removed' ? W.removedOf : W.updatedOf
223
+ const note = names.length
224
+ ? `${of} ${listOf(names, count, W)}`
225
+ : (side === 'added' ? W.added : side === 'removed' ? W.removed : W.updated)(count)
226
+ out.push({ field: bucket.field, label: bucket.what, before: '', after: '', note })
227
+ }
228
+ }
229
+ return out
230
+ }
231
+
232
+ /**
233
+ * La meme liste dans un autre ordre (« L01XC, L01FF » puis « L01FF, L01XC ») :
234
+ * le moteur la voit changer, le lecteur n'y apprend rien.
235
+ */
236
+ function sameList(before: string, after: string): boolean {
237
+ if (!before || !after || before === after || !before.includes(', ')) return false
238
+ const sorted = (value: string) => value.split(', ').map((v) => v.trim()).sort().join('\u0000')
239
+ return sorted(before) === sorted(after)
240
+ }
241
+
242
+ function simpleField(change: AlertRawChange, W: (typeof WORDS)['fr']): AlertSimpleChange {
243
+ const { field, label, before, after } = change
244
+ const long = (value: string) => value.length > LONG_VALUE || value.includes('\n')
245
+ if (long(before) || long(after)) {
246
+ const note = before && after ? W.changed : after ? W.filled : W.emptied
247
+ return { field, label, before: '', after: '', note }
248
+ }
249
+ return { field, label, before, after }
250
+ }
@@ -92,11 +92,11 @@ export function alertFieldLabel(
92
92
  serverLabel: string | null | undefined,
93
93
  t: (key: string) => string,
94
94
  locale: string,
95
- ): { group: string | null; label: string } {
95
+ ): { group: string | null; label: string; what: string; entry: boolean } {
96
96
  // Le compteur de debordement n'est pas un champ : son libelle est deja une
97
97
  // phrase.
98
98
  if (!field || field.startsWith("__")) {
99
- return { group: null, label: serverLabel || field };
99
+ return { group: null, label: serverLabel || field, what: "", entry: false };
100
100
  }
101
101
 
102
102
  const segments = field.split(".");
@@ -108,6 +108,9 @@ export function alertFieldLabel(
108
108
  return translate(NESTED, part, t);
109
109
  })
110
110
  .filter(Boolean);
111
+ // La collection que le changement touche, pour les lignes qui la resument
112
+ // (cf. simplifyAlertChanges).
113
+ const what = parts[0] ?? field;
111
114
 
112
115
  // Une entree entiere qui entre ou qui sort : le chemin ne nomme aucun champ,
113
116
  // c'est la marque qui dit ce qui s'est passe. Elle remplace alors le champ,
@@ -117,7 +120,7 @@ export function alertFieldLabel(
117
120
  (serverLabel ?? "").endsWith(entry),
118
121
  );
119
122
  if (marker) {
120
- return { group: parts.join(" · ") || null, label: t(ENTRY_MARKERS[marker]!) };
123
+ return { group: parts.join(" · ") || null, label: t(ENTRY_MARKERS[marker]!), what, entry: true };
121
124
  }
122
125
 
123
126
  // Champ inconnu du catalogue : le libelle que la page a envoye avec l'alerte
@@ -130,7 +133,7 @@ export function alertFieldLabel(
130
133
  if (!known && fallback && parts.length > 0) parts[parts.length - 1] = fallback;
131
134
 
132
135
  const label = parts.pop() ?? field;
133
- return { group: parts.join(" · ") || null, label };
136
+ return { group: parts.join(" · ") || null, label, what, entry: false };
134
137
  }
135
138
 
136
139
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tekkare/romulus",
3
- "version": "0.1.332",
3
+ "version": "0.1.333",
4
4
  "description": "Romulus Design System - Nuxt module by Tekkare",
5
5
  "license": "MIT",
6
6
  "type": "module",