@firecms/entity_history 3.0.0 → 3.0.1

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,4 +1,4 @@
1
1
  import { EntityCallbacks } from "@firecms/core";
2
2
  import { NewHistoryEntryParams } from "./types";
3
- export declare function createHistoryEntry<T = any>({ context, previousValues, values, path, entityId }: NewHistoryEntryParams<T>): void;
3
+ export declare function createHistoryEntry<T = any>({ context, previousValues, values, path, entityId, collection }: NewHistoryEntryParams<T>): void;
4
4
  export declare const entityHistoryCallbacks: EntityCallbacks;
package/dist/index.es.js CHANGED
@@ -88,7 +88,7 @@ function PreviousValueView(t0) {
88
88
  const {
89
89
  previousValueInPath,
90
90
  childProperty,
91
- key
91
+ propertyKey
92
92
  } = t0;
93
93
  if (typeof previousValueInPath === "string" || typeof previousValueInPath === "number") {
94
94
  let t1;
@@ -114,13 +114,13 @@ function PreviousValueView(t0) {
114
114
  return t2;
115
115
  } else {
116
116
  let t1;
117
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
117
+ if ($[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
118
118
  t1 = /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: "Previous value" });
119
119
  $[4] = t1;
120
120
  } else {
121
121
  t1 = $[4];
122
122
  }
123
- const t2 = key;
123
+ const t2 = propertyKey;
124
124
  const t3 = childProperty;
125
125
  let t4;
126
126
  if ($[5] !== previousValueInPath || $[6] !== t2 || $[7] !== t3) {
@@ -136,7 +136,7 @@ function PreviousValueView(t0) {
136
136
  t4 = $[8];
137
137
  }
138
138
  let t5;
139
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
139
+ if ($[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
140
140
  t5 = /* @__PURE__ */ jsx(KeyboardBackspaceIcon, { size: "smallest", color: "disabled", className: "mb-1" });
141
141
  $[9] = t5;
142
142
  } else {
@@ -191,7 +191,7 @@ function EntityHistoryEntry({
191
191
  !user && updatedBy && /* @__PURE__ */ jsx(Chip, { size: "small", children: updatedBy }),
192
192
  user && /* @__PURE__ */ jsx(UserChip, { user })
193
193
  ] }),
194
- /* @__PURE__ */ jsxs("div", { className: cls("bg-white dark:bg-surface-900", "min-h-[42px]", "w-full", "items-center", hover ? "hover:bg-surface-accent-50 dark:hover:bg-surface-800 group-hover:bg-surface-accent-50 dark:group-hover:bg-surface-800" : "", size === "small" ? "p-1" : "px-2 py-1", "flex border rounded-lg", onClick ? "cursor-pointer" : "", defaultBorderMixin), children: [
194
+ /* @__PURE__ */ jsxs("div", { className: cls("bg-white dark:bg-surface-900", "min-h-[44px]", "w-full", "items-center", hover ? "hover:bg-surface-accent-50 dark:hover:bg-surface-800 group-hover:bg-surface-accent-50 dark:group-hover:bg-surface-800" : "", size === "small" ? "p-1" : "px-2 py-1", "flex border rounded-lg", onClick ? "cursor-pointer" : "", defaultBorderMixin), children: [
195
195
  actions,
196
196
  entity && /* @__PURE__ */ jsx(Tooltip, { title: "See details for this revision", className: "my-2 grow-0 shrink-0 self-start", children: /* @__PURE__ */ jsx(IconButton, { color: "inherit", className: "", onClick: (e) => {
197
197
  sideEntityController.open({
@@ -220,7 +220,7 @@ function EntityHistoryEntry({
220
220
  return /* @__PURE__ */ jsxs("div", { className: "flex w-full my-1 items-center", children: [
221
221
  /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", className: "min-w-[140px] md:min-w-[200px] w-1/5 pr-8 overflow-hidden text-ellipsis text-right", children: key }),
222
222
  /* @__PURE__ */ jsxs("div", { className: "w-4/5", children: [
223
- previousValueInPath !== void 0 && previousValueInPath !== valueInPath && /* @__PURE__ */ jsx(PreviousValueView, { previousValueInPath, childProperty }, key),
223
+ previousValueInPath !== void 0 && previousValueInPath !== valueInPath && /* @__PURE__ */ jsx(PreviousValueView, { previousValueInPath, childProperty, propertyKey: key }),
224
224
  element
225
225
  ] })
226
226
  ] }, "ref_prev_" + key);
@@ -229,7 +229,7 @@ function EntityHistoryEntry({
229
229
  ] });
230
230
  }
231
231
  function EntityHistoryView(t0) {
232
- const $ = c(58);
232
+ const $ = c(62);
233
233
  const {
234
234
  entity,
235
235
  collection,
@@ -242,7 +242,7 @@ function EntityHistoryView(t0) {
242
242
  const pathAndId = entity ? entity?.path + "/" + entity?.id : void 0;
243
243
  const [revertVersionDialog, setRevertVersionDialog] = useState(void 0);
244
244
  let t1;
245
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
245
+ if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
246
246
  t1 = [];
247
247
  $[0] = t1;
248
248
  } else {
@@ -256,8 +256,7 @@ function EntityHistoryView(t0) {
256
256
  const observerRef = useRef(null);
257
257
  const loadMoreRef = useRef(null);
258
258
  let t2;
259
- let t3;
260
- if ($[1] !== dataSource || $[2] !== limit || $[3] !== pathAndId) {
259
+ if ($[1] !== collection || $[2] !== dataSource || $[3] !== limit || $[4] !== pathAndId) {
261
260
  t2 = () => {
262
261
  if (!pathAndId) {
263
262
  return;
@@ -265,6 +264,7 @@ function EntityHistoryView(t0) {
265
264
  setIsLoading(true);
266
265
  const listener = dataSource.listenCollection?.({
267
266
  path: pathAndId + "/__history",
267
+ collection,
268
268
  order: "desc",
269
269
  orderBy: "__metadata.updated_on",
270
270
  limit,
@@ -286,19 +286,27 @@ function EntityHistoryView(t0) {
286
286
  }
287
287
  };
288
288
  };
289
+ $[1] = collection;
290
+ $[2] = dataSource;
291
+ $[3] = limit;
292
+ $[4] = pathAndId;
293
+ $[5] = t2;
294
+ } else {
295
+ t2 = $[5];
296
+ }
297
+ let t3;
298
+ if ($[6] !== dataSource || $[7] !== limit || $[8] !== pathAndId) {
289
299
  t3 = [pathAndId, limit, dataSource];
290
- $[1] = dataSource;
291
- $[2] = limit;
292
- $[3] = pathAndId;
293
- $[4] = t2;
294
- $[5] = t3;
300
+ $[6] = dataSource;
301
+ $[7] = limit;
302
+ $[8] = pathAndId;
303
+ $[9] = t3;
295
304
  } else {
296
- t2 = $[4];
297
- t3 = $[5];
305
+ t3 = $[9];
298
306
  }
299
307
  useEffect(t2, t3);
300
308
  let t4;
301
- if ($[6] !== hasMore || $[7] !== isLoading) {
309
+ if ($[10] !== hasMore || $[11] !== isLoading) {
302
310
  t4 = () => {
303
311
  const currentContainer = containerRef.current;
304
312
  const currentLoadMore = loadMoreRef.current;
@@ -330,35 +338,35 @@ function EntityHistoryView(t0) {
330
338
  }
331
339
  };
332
340
  };
333
- $[6] = hasMore;
334
- $[7] = isLoading;
335
- $[8] = t4;
341
+ $[10] = hasMore;
342
+ $[11] = isLoading;
343
+ $[12] = t4;
336
344
  } else {
337
- t4 = $[8];
345
+ t4 = $[12];
338
346
  }
339
347
  let t5;
340
- if ($[9] !== hasMore || $[10] !== isLoading || $[11] !== revisions.length) {
348
+ if ($[13] !== hasMore || $[14] !== isLoading || $[15] !== revisions.length) {
341
349
  t5 = [hasMore, isLoading, revisions.length];
342
- $[9] = hasMore;
343
- $[10] = isLoading;
344
- $[11] = revisions.length;
345
- $[12] = t5;
350
+ $[13] = hasMore;
351
+ $[14] = isLoading;
352
+ $[15] = revisions.length;
353
+ $[16] = t5;
346
354
  } else {
347
- t5 = $[12];
355
+ t5 = $[16];
348
356
  }
349
357
  useEffect(t4, t5);
350
358
  if (!entity) {
351
359
  let t62;
352
- if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
360
+ if ($[17] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
353
361
  t62 = /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsx(Label, { children: "History is only available for existing entities" }) });
354
- $[13] = t62;
362
+ $[17] = t62;
355
363
  } else {
356
- t62 = $[13];
364
+ t62 = $[17];
357
365
  }
358
366
  return t62;
359
367
  }
360
368
  let t6;
361
- if ($[14] !== authController || $[15] !== collection || $[16] !== dataSource || $[17] !== entity || $[18] !== formContext || $[19] !== snackbarController) {
369
+ if ($[18] !== authController || $[19] !== collection || $[20] !== dataSource || $[21] !== entity || $[22] !== formContext || $[23] !== snackbarController) {
362
370
  t6 = function doRevert2(revertVersion) {
363
371
  if (!entity) {
364
372
  throw new Error("No entity to revert");
@@ -403,46 +411,46 @@ function EntityHistoryView(t0) {
403
411
  });
404
412
  });
405
413
  };
406
- $[14] = authController;
407
- $[15] = collection;
408
- $[16] = dataSource;
409
- $[17] = entity;
410
- $[18] = formContext;
411
- $[19] = snackbarController;
412
- $[20] = t6;
414
+ $[18] = authController;
415
+ $[19] = collection;
416
+ $[20] = dataSource;
417
+ $[21] = entity;
418
+ $[22] = formContext;
419
+ $[23] = snackbarController;
420
+ $[24] = t6;
413
421
  } else {
414
- t6 = $[20];
422
+ t6 = $[24];
415
423
  }
416
424
  const doRevert = t6;
417
425
  let t7;
418
- if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
426
+ if ($[25] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
419
427
  t7 = cls("relative flex-1 h-full overflow-auto w-full flex flex-col gap-4 p-8");
420
- $[21] = t7;
428
+ $[25] = t7;
421
429
  } else {
422
- t7 = $[21];
430
+ t7 = $[25];
423
431
  }
424
432
  let t8;
425
- if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
433
+ if ($[26] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
426
434
  t8 = /* @__PURE__ */ jsx(Typography, { variant: "h5", className: "mt-24 ml-4", children: "History" });
427
- $[22] = t8;
435
+ $[26] = t8;
428
436
  } else {
429
- t8 = $[22];
437
+ t8 = $[26];
430
438
  }
431
439
  let t9;
432
- if ($[23] !== revisions.length) {
440
+ if ($[27] !== revisions.length) {
433
441
  t9 = revisions.length === 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
434
442
  /* @__PURE__ */ jsx(Label, { className: "ml-4 mt-8", children: "No history available" }),
435
443
  /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "ml-4", children: "When you save an entity, a new version is created and stored in the history." })
436
444
  ] });
437
- $[23] = revisions.length;
438
- $[24] = t9;
445
+ $[27] = revisions.length;
446
+ $[28] = t9;
439
447
  } else {
440
- t9 = $[24];
448
+ t9 = $[28];
441
449
  }
442
450
  let t10;
443
- if ($[25] !== collection || $[26] !== dirty || $[27] !== revisions || $[28] !== snackbarController) {
451
+ if ($[29] !== collection || $[30] !== dirty || $[31] !== revisions || $[32] !== snackbarController) {
444
452
  let t112;
445
- if ($[30] !== collection || $[31] !== dirty || $[32] !== snackbarController) {
453
+ if ($[34] !== collection || $[35] !== dirty || $[36] !== snackbarController) {
446
454
  t112 = (revision, index) => {
447
455
  const previewKeys = revision.values?.__metadata?.changed_fields;
448
456
  const previousValues = revision.values?.__metadata?.previous_values;
@@ -457,109 +465,109 @@ function EntityHistoryView(t0) {
457
465
  }
458
466
  }, children: /* @__PURE__ */ jsx(HistoryIcon, {}) }) }) }) }, index);
459
467
  };
460
- $[30] = collection;
461
- $[31] = dirty;
462
- $[32] = snackbarController;
463
- $[33] = t112;
468
+ $[34] = collection;
469
+ $[35] = dirty;
470
+ $[36] = snackbarController;
471
+ $[37] = t112;
464
472
  } else {
465
- t112 = $[33];
473
+ t112 = $[37];
466
474
  }
467
475
  t10 = revisions.map(t112);
468
- $[25] = collection;
469
- $[26] = dirty;
470
- $[27] = revisions;
471
- $[28] = snackbarController;
472
- $[29] = t10;
476
+ $[29] = collection;
477
+ $[30] = dirty;
478
+ $[31] = revisions;
479
+ $[32] = snackbarController;
480
+ $[33] = t10;
473
481
  } else {
474
- t10 = $[29];
482
+ t10 = $[33];
475
483
  }
476
484
  let t11;
477
- if ($[34] !== hasMore || $[35] !== isLoading || $[36] !== revisions.length) {
485
+ if ($[38] !== hasMore || $[39] !== isLoading || $[40] !== revisions.length) {
478
486
  t11 = revisions.length > 0 && /* @__PURE__ */ jsxs("div", { ref: loadMoreRef, className: "py-4 text-center", children: [
479
487
  isLoading && /* @__PURE__ */ jsx(Label, { children: "Loading more..." }),
480
488
  !hasMore && revisions.length > 5 && /* @__PURE__ */ jsx(Label, { children: "No more history available" })
481
489
  ] });
482
- $[34] = hasMore;
483
- $[35] = isLoading;
484
- $[36] = revisions.length;
485
- $[37] = t11;
490
+ $[38] = hasMore;
491
+ $[39] = isLoading;
492
+ $[40] = revisions.length;
493
+ $[41] = t11;
486
494
  } else {
487
- t11 = $[37];
495
+ t11 = $[41];
488
496
  }
489
497
  let t12;
490
- if ($[38] !== t10 || $[39] !== t11 || $[40] !== t9) {
498
+ if ($[42] !== t10 || $[43] !== t11 || $[44] !== t9) {
491
499
  t12 = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 max-w-6xl mx-auto w-full", children: [
492
500
  t8,
493
501
  t9,
494
502
  t10,
495
503
  t11
496
504
  ] });
497
- $[38] = t10;
498
- $[39] = t11;
499
- $[40] = t9;
500
- $[41] = t12;
505
+ $[42] = t10;
506
+ $[43] = t11;
507
+ $[44] = t9;
508
+ $[45] = t12;
501
509
  } else {
502
- t12 = $[41];
510
+ t12 = $[45];
503
511
  }
504
512
  const t13 = Boolean(revertVersionDialog);
505
513
  let t14;
506
- if ($[42] !== doRevert || $[43] !== revertVersionDialog) {
514
+ if ($[46] !== doRevert || $[47] !== revertVersionDialog) {
507
515
  t14 = function() {
508
516
  if (!revertVersionDialog) {
509
517
  return;
510
518
  }
511
519
  doRevert(revertVersionDialog);
512
520
  };
513
- $[42] = doRevert;
514
- $[43] = revertVersionDialog;
515
- $[44] = t14;
521
+ $[46] = doRevert;
522
+ $[47] = revertVersionDialog;
523
+ $[48] = t14;
516
524
  } else {
517
- t14 = $[44];
525
+ t14 = $[48];
518
526
  }
519
527
  let t15;
520
528
  let t16;
521
- if ($[45] === Symbol.for("react.memo_cache_sentinel")) {
529
+ if ($[49] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
522
530
  t15 = function() {
523
531
  setRevertVersionDialog(void 0);
524
532
  };
525
533
  t16 = /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", children: "Revert data to this version?" });
526
- $[45] = t15;
527
- $[46] = t16;
534
+ $[49] = t15;
535
+ $[50] = t16;
528
536
  } else {
529
- t15 = $[45];
530
- t16 = $[46];
537
+ t15 = $[49];
538
+ t16 = $[50];
531
539
  }
532
540
  let t17;
533
- if ($[47] !== collection || $[48] !== entity?.path || $[49] !== revertVersionDialog) {
541
+ if ($[51] !== collection || $[52] !== entity?.path || $[53] !== revertVersionDialog) {
534
542
  t17 = revertVersionDialog ? /* @__PURE__ */ jsx(EntityView, { entity: revertVersionDialog, collection, path: entity?.path }) : null;
535
- $[47] = collection;
536
- $[48] = entity?.path;
537
- $[49] = revertVersionDialog;
538
- $[50] = t17;
543
+ $[51] = collection;
544
+ $[52] = entity?.path;
545
+ $[53] = revertVersionDialog;
546
+ $[54] = t17;
539
547
  } else {
540
- t17 = $[50];
548
+ t17 = $[54];
541
549
  }
542
550
  let t18;
543
- if ($[51] !== t13 || $[52] !== t14 || $[53] !== t17) {
551
+ if ($[55] !== t13 || $[56] !== t14 || $[57] !== t17) {
544
552
  t18 = /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(ConfirmationDialog, { open: t13, onAccept: t14, onCancel: t15, title: t16, body: t17 }) });
545
- $[51] = t13;
546
- $[52] = t14;
547
- $[53] = t17;
548
- $[54] = t18;
553
+ $[55] = t13;
554
+ $[56] = t14;
555
+ $[57] = t17;
556
+ $[58] = t18;
549
557
  } else {
550
- t18 = $[54];
558
+ t18 = $[58];
551
559
  }
552
560
  let t19;
553
- if ($[55] !== t12 || $[56] !== t18) {
561
+ if ($[59] !== t12 || $[60] !== t18) {
554
562
  t19 = /* @__PURE__ */ jsxs("div", { ref: containerRef, className: t7, children: [
555
563
  t12,
556
564
  t18
557
565
  ] });
558
- $[55] = t12;
559
- $[56] = t18;
560
- $[57] = t19;
566
+ $[59] = t12;
567
+ $[60] = t18;
568
+ $[61] = t19;
561
569
  } else {
562
- t19 = $[57];
570
+ t19 = $[61];
563
571
  }
564
572
  return t19;
565
573
  }
@@ -571,7 +579,8 @@ function createHistoryEntry({
571
579
  previousValues,
572
580
  values,
573
581
  path,
574
- entityId
582
+ entityId,
583
+ collection
575
584
  }) {
576
585
  const uid = context.authController.user?.uid;
577
586
  const dataSource = context.dataSource;
@@ -588,7 +597,8 @@ function createHistoryEntry({
588
597
  dataSource.saveEntity({
589
598
  path: path + "/" + entityId + "/__history",
590
599
  values: entry,
591
- status: "new"
600
+ status: "new",
601
+ collection
592
602
  }).then(() => {
593
603
  console.debug("History saved for", path, entityId);
594
604
  });
@@ -600,12 +610,14 @@ const entityHistoryCallbacks = {
600
610
  const path = props.path;
601
611
  const entityId = props.entityId;
602
612
  const context = props.context;
613
+ const collection = props.collection;
603
614
  createHistoryEntry({
604
615
  context,
605
616
  previousValues,
606
617
  values,
607
618
  path,
608
- entityId
619
+ entityId,
620
+ collection
609
621
  });
610
622
  }
611
623
  };