@nyaruka/temba-components 0.156.17 → 0.156.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyaruka/temba-components",
3
- "version": "0.156.17",
3
+ "version": "0.156.18",
4
4
  "description": "Web components to support rapidpro and related projects",
5
5
  "author": "Nyaruka <code@nyaruka.coim>",
6
6
  "main": "dist/index.js",
@@ -9,6 +9,7 @@ import { fetchResults } from '../utils';
9
9
  import { FLOW_SPEC_VERSION } from '../store/AppState';
10
10
  import {
11
11
  labelsFor,
12
+ normalizeChanges,
12
13
  RevisionChanges,
13
14
  summarizeChanges
14
15
  } from './revision-summary';
@@ -151,7 +152,7 @@ export class RevisionsWindow extends RapidElement {
151
152
  value=${rev.created_on}
152
153
  display="duration"
153
154
  ></temba-date>
154
- · ${rev.user.name || rev.user.username}
155
+ · ${this.renderUser(rev.user)}
155
156
  </div>
156
157
  ${isCurrent
157
158
  ? html`<div
@@ -192,6 +193,13 @@ export class RevisionsWindow extends RapidElement {
192
193
 
193
194
  // --- Private ---
194
195
 
196
+ private renderUser(user: Revision['user']): TemplateResult | string {
197
+ if (user?.email === 'system') {
198
+ return html`<em>System update</em>`;
199
+ }
200
+ return user?.name || user?.username || '';
201
+ }
202
+
195
203
  private async fetchRevisions() {
196
204
  const requestId = ++this.fetchRequestId;
197
205
  this.isLoading = true;
@@ -217,19 +225,36 @@ export class RevisionsWindow extends RapidElement {
217
225
  // the window. The merged revision is capped at three distinct displayed
218
226
  // labels — once a fourth would be introduced we break out into a new row.
219
227
  private collapseRevisions(revisions: Revision[]): Revision[] {
228
+ // Normalize at the boundary so the rest of the logic reasons about real
229
+ // edits only. After this step, `changes === null` is the single signal
230
+ // for "no-op" — used both for the author-barrier bypass and for keeping
231
+ // housekeeping tags out of the merged tag set and label cap.
232
+ const cleaned = revisions.map((r) => ({
233
+ ...r,
234
+ changes: normalizeChanges(r.changes)
235
+ }));
220
236
  // The API returns newest-first today; sort defensively so the head/window
221
237
  // logic stays correct if that ever changes.
222
- const sorted = [...revisions].sort(
238
+ const sorted = [...cleaned].sort(
223
239
  (a, b) =>
224
240
  new Date(b.created_on).getTime() - new Date(a.created_on).getTime()
225
241
  );
226
242
  const result: Revision[] = [];
227
243
  let group: Revision[] = [];
228
244
  let groupLabels = new Set<string>();
245
+ let groupHasRealChange = false;
229
246
 
230
247
  const flush = () => {
231
248
  if (group.length === 0) return;
232
249
  const head = group[0];
250
+ // Pick the user from the most recent real-change revision in the
251
+ // group. No-op authors (typically the system, doing spec bumps)
252
+ // shouldn't appear as the editor when a real user's edit was
253
+ // absorbed into the row — that would mislabel the change as
254
+ // "System update" even though a real person did the work. Fall back
255
+ // to the head if every revision was a no-op.
256
+ const realChange = group.find((r) => r.changes);
257
+ const displayUser = realChange?.user ?? head.user;
233
258
  const tagSet = new Set<string>();
234
259
  let anyKnown = false;
235
260
  for (const r of group) {
@@ -240,41 +265,62 @@ export class RevisionsWindow extends RapidElement {
240
265
  }
241
266
  result.push({
242
267
  ...head,
268
+ user: displayUser,
243
269
  changes: anyKnown ? { tags: Array.from(tagSet) } : null
244
270
  });
245
271
  group = [];
246
272
  groupLabels = new Set();
273
+ groupHasRealChange = false;
247
274
  };
248
275
 
249
276
  for (const rev of sorted) {
250
277
  if (group.length === 0) {
251
278
  group.push(rev);
252
279
  groupLabels = labelsFor(rev.changes);
280
+ groupHasRealChange = !!rev.changes;
253
281
  continue;
254
282
  }
255
283
  const head = group[0];
256
284
  const headTime = new Date(head.created_on).getTime();
257
285
  const revTime = new Date(rev.created_on).getTime();
258
- const withinWindow = headTime - revTime < GROUP_WINDOW_MS;
259
286
  // Compare on whichever identifier the server provides — real data
260
287
  // arrives with `email`, while test fixtures use `username`. Falling
261
288
  // back through the chain keeps both shapes working.
262
289
  const headId = head.user?.email ?? head.user?.username;
263
290
  const revId = rev.user?.email ?? rev.user?.username;
264
- const sameAuthor = headId === revId;
265
- const prospective = new Set([
266
- ...groupLabels,
267
- ...labelsFor(rev.changes)
268
- ]);
269
- const fitsLabelCap = prospective.size <= MAX_GROUP_LABELS;
291
+ // Two conditions bypass the time/author barriers:
292
+ // 1. The incoming rev is itself a no-op — it carries no editorial
293
+ // intent and should disappear into whichever group it neighbors.
294
+ // 2. The group hasn't accumulated a real change yet — we never want
295
+ // to surface a row showing "nothing changed", so a no-op-only
296
+ // chain reaches forward to absorb the first real edit even if
297
+ // that edit is far away in time or by a different author.
298
+ const isNoOp = !rev.changes;
299
+ const bypassBarriers = isNoOp || !groupHasRealChange;
300
+ const withinWindow =
301
+ bypassBarriers || headTime - revTime < GROUP_WINDOW_MS;
302
+ const sameAuthor = bypassBarriers || headId === revId;
303
+ const prospective = new Set([...groupLabels, ...labelsFor(rev.changes)]);
304
+ // The label cap is meaningful only when adding a real change to a
305
+ // group that already has one. A no-op contributes zero labels by
306
+ // construction, so it never trips the cap; and a no-op-only chain
307
+ // reaching forward to absorb its first real edit must ignore the cap
308
+ // too, or a sweeping edit (4+ label areas) would still strand the
309
+ // no-op group as an empty-summary row.
310
+ const fitsLabelCap =
311
+ isNoOp ||
312
+ !groupHasRealChange ||
313
+ prospective.size <= MAX_GROUP_LABELS;
270
314
 
271
315
  if (withinWindow && sameAuthor && fitsLabelCap) {
272
316
  group.push(rev);
273
317
  groupLabels = prospective;
318
+ if (!isNoOp) groupHasRealChange = true;
274
319
  } else {
275
320
  flush();
276
321
  group.push(rev);
277
322
  groupLabels = labelsFor(rev.changes);
323
+ groupHasRealChange = !!rev.changes;
278
324
  }
279
325
  }
280
326
  flush();
@@ -2,6 +2,23 @@ export interface RevisionChanges {
2
2
  tags: string[];
3
3
  }
4
4
 
5
+ // "spec" is the housekeeping tag the system attaches when it bumps a flow's
6
+ // spec version. It carries no editorial intent, so we strip it at the
7
+ // boundary — every downstream consumer (summaries, label caps, no-op
8
+ // detection) then operates on a clean tag set without needing special cases.
9
+ const NOOP_TAGS = new Set(['spec']);
10
+
11
+ // Drop tags that don't represent real edits and collapse to null when nothing
12
+ // meaningful remains. Returning null lets `isNoOpChanges` and the collapse
13
+ // logic treat empty-after-filtering and originally-null the same way.
14
+ export function normalizeChanges(
15
+ changes: RevisionChanges | null | undefined
16
+ ): RevisionChanges | null {
17
+ if (!changes) return null;
18
+ const tags = (changes.tags || []).filter((t) => !NOOP_TAGS.has(t));
19
+ return tags.length === 0 ? null : { tags };
20
+ }
21
+
5
22
  const TAG_LABELS: Record<string, { label: string; order: number }> = {
6
23
  metadata: { label: 'metadata', order: 0 },
7
24
  nodes: { label: 'nodes', order: 1 },
@@ -32,6 +49,14 @@ export function labelsFor(
32
49
  return result;
33
50
  }
34
51
 
52
+ // A revision is a no-op when, after stripping housekeeping tags, nothing
53
+ // meaningful is left. These shouldn't break up adjacent edits in the browser.
54
+ export function isNoOpChanges(
55
+ changes: RevisionChanges | null | undefined
56
+ ): boolean {
57
+ return normalizeChanges(changes) === null;
58
+ }
59
+
35
60
  export function summarizeChanges(
36
61
  changes: RevisionChanges | null | undefined
37
62
  ): string {