@firecms/entity_history 3.0.0 → 3.1.0-canary.1df3b2c

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/index.umd.js CHANGED
@@ -102,7 +102,7 @@
102
102
  const {
103
103
  previousValueInPath,
104
104
  childProperty,
105
- key
105
+ propertyKey
106
106
  } = t0;
107
107
  if (typeof previousValueInPath === "string" || typeof previousValueInPath === "number") {
108
108
  let t1;
@@ -128,13 +128,13 @@
128
128
  return t2;
129
129
  } else {
130
130
  let t1;
131
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
131
+ if ($[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
132
132
  t1 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "caption", color: "secondary", children: "Previous value" });
133
133
  $[4] = t1;
134
134
  } else {
135
135
  t1 = $[4];
136
136
  }
137
- const t2 = key;
137
+ const t2 = propertyKey;
138
138
  const t3 = childProperty;
139
139
  let t4;
140
140
  if ($[5] !== previousValueInPath || $[6] !== t2 || $[7] !== t3) {
@@ -150,7 +150,7 @@
150
150
  t4 = $[8];
151
151
  }
152
152
  let t5;
153
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
153
+ if ($[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
154
154
  t5 = /* @__PURE__ */ jsxRuntime.jsx(ui.KeyboardBackspaceIcon, { size: "smallest", color: "disabled", className: "mb-1" });
155
155
  $[9] = t5;
156
156
  } else {
@@ -205,7 +205,7 @@
205
205
  !user && updatedBy && /* @__PURE__ */ jsxRuntime.jsx(ui.Chip, { size: "small", children: updatedBy }),
206
206
  user && /* @__PURE__ */ jsxRuntime.jsx(UserChip, { user })
207
207
  ] }),
208
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ui.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" : "", ui.defaultBorderMixin), children: [
208
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ui.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" : "", ui.defaultBorderMixin), children: [
209
209
  actions,
210
210
  entity && /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "See details for this revision", className: "my-2 grow-0 shrink-0 self-start", children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { color: "inherit", className: "", onClick: (e) => {
211
211
  sideEntityController.open({
@@ -234,7 +234,7 @@
234
234
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full my-1 items-center", children: [
235
235
  /* @__PURE__ */ jsxRuntime.jsx(ui.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 }),
236
236
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-4/5", children: [
237
- previousValueInPath !== void 0 && previousValueInPath !== valueInPath && /* @__PURE__ */ jsxRuntime.jsx(PreviousValueView, { previousValueInPath, childProperty }, key),
237
+ previousValueInPath !== void 0 && previousValueInPath !== valueInPath && /* @__PURE__ */ jsxRuntime.jsx(PreviousValueView, { previousValueInPath, childProperty, propertyKey: key }),
238
238
  element
239
239
  ] })
240
240
  ] }, "ref_prev_" + key);
@@ -243,7 +243,7 @@
243
243
  ] });
244
244
  }
245
245
  function EntityHistoryView(t0) {
246
- const $ = reactCompilerRuntime.c(58);
246
+ const $ = reactCompilerRuntime.c(62);
247
247
  const {
248
248
  entity,
249
249
  collection,
@@ -256,7 +256,7 @@
256
256
  const pathAndId = entity ? entity?.path + "/" + entity?.id : void 0;
257
257
  const [revertVersionDialog, setRevertVersionDialog] = React.useState(void 0);
258
258
  let t1;
259
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
259
+ if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
260
260
  t1 = [];
261
261
  $[0] = t1;
262
262
  } else {
@@ -270,8 +270,7 @@
270
270
  const observerRef = React.useRef(null);
271
271
  const loadMoreRef = React.useRef(null);
272
272
  let t2;
273
- let t3;
274
- if ($[1] !== dataSource || $[2] !== limit || $[3] !== pathAndId) {
273
+ if ($[1] !== collection || $[2] !== dataSource || $[3] !== limit || $[4] !== pathAndId) {
275
274
  t2 = () => {
276
275
  if (!pathAndId) {
277
276
  return;
@@ -279,6 +278,7 @@
279
278
  setIsLoading(true);
280
279
  const listener = dataSource.listenCollection?.({
281
280
  path: pathAndId + "/__history",
281
+ collection,
282
282
  order: "desc",
283
283
  orderBy: "__metadata.updated_on",
284
284
  limit,
@@ -300,19 +300,27 @@
300
300
  }
301
301
  };
302
302
  };
303
+ $[1] = collection;
304
+ $[2] = dataSource;
305
+ $[3] = limit;
306
+ $[4] = pathAndId;
307
+ $[5] = t2;
308
+ } else {
309
+ t2 = $[5];
310
+ }
311
+ let t3;
312
+ if ($[6] !== dataSource || $[7] !== limit || $[8] !== pathAndId) {
303
313
  t3 = [pathAndId, limit, dataSource];
304
- $[1] = dataSource;
305
- $[2] = limit;
306
- $[3] = pathAndId;
307
- $[4] = t2;
308
- $[5] = t3;
314
+ $[6] = dataSource;
315
+ $[7] = limit;
316
+ $[8] = pathAndId;
317
+ $[9] = t3;
309
318
  } else {
310
- t2 = $[4];
311
- t3 = $[5];
319
+ t3 = $[9];
312
320
  }
313
321
  React.useEffect(t2, t3);
314
322
  let t4;
315
- if ($[6] !== hasMore || $[7] !== isLoading) {
323
+ if ($[10] !== hasMore || $[11] !== isLoading) {
316
324
  t4 = () => {
317
325
  const currentContainer = containerRef.current;
318
326
  const currentLoadMore = loadMoreRef.current;
@@ -344,35 +352,35 @@
344
352
  }
345
353
  };
346
354
  };
347
- $[6] = hasMore;
348
- $[7] = isLoading;
349
- $[8] = t4;
355
+ $[10] = hasMore;
356
+ $[11] = isLoading;
357
+ $[12] = t4;
350
358
  } else {
351
- t4 = $[8];
359
+ t4 = $[12];
352
360
  }
353
361
  let t5;
354
- if ($[9] !== hasMore || $[10] !== isLoading || $[11] !== revisions.length) {
362
+ if ($[13] !== hasMore || $[14] !== isLoading || $[15] !== revisions.length) {
355
363
  t5 = [hasMore, isLoading, revisions.length];
356
- $[9] = hasMore;
357
- $[10] = isLoading;
358
- $[11] = revisions.length;
359
- $[12] = t5;
364
+ $[13] = hasMore;
365
+ $[14] = isLoading;
366
+ $[15] = revisions.length;
367
+ $[16] = t5;
360
368
  } else {
361
- t5 = $[12];
369
+ t5 = $[16];
362
370
  }
363
371
  React.useEffect(t4, t5);
364
372
  if (!entity) {
365
373
  let t62;
366
- if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
374
+ if ($[17] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
367
375
  t62 = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "History is only available for existing entities" }) });
368
- $[13] = t62;
376
+ $[17] = t62;
369
377
  } else {
370
- t62 = $[13];
378
+ t62 = $[17];
371
379
  }
372
380
  return t62;
373
381
  }
374
382
  let t6;
375
- if ($[14] !== authController || $[15] !== collection || $[16] !== dataSource || $[17] !== entity || $[18] !== formContext || $[19] !== snackbarController) {
383
+ if ($[18] !== authController || $[19] !== collection || $[20] !== dataSource || $[21] !== entity || $[22] !== formContext || $[23] !== snackbarController) {
376
384
  t6 = function doRevert2(revertVersion) {
377
385
  if (!entity) {
378
386
  throw new Error("No entity to revert");
@@ -417,46 +425,46 @@
417
425
  });
418
426
  });
419
427
  };
420
- $[14] = authController;
421
- $[15] = collection;
422
- $[16] = dataSource;
423
- $[17] = entity;
424
- $[18] = formContext;
425
- $[19] = snackbarController;
426
- $[20] = t6;
428
+ $[18] = authController;
429
+ $[19] = collection;
430
+ $[20] = dataSource;
431
+ $[21] = entity;
432
+ $[22] = formContext;
433
+ $[23] = snackbarController;
434
+ $[24] = t6;
427
435
  } else {
428
- t6 = $[20];
436
+ t6 = $[24];
429
437
  }
430
438
  const doRevert = t6;
431
439
  let t7;
432
- if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
440
+ if ($[25] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
433
441
  t7 = ui.cls("relative flex-1 h-full overflow-auto w-full flex flex-col gap-4 p-8");
434
- $[21] = t7;
442
+ $[25] = t7;
435
443
  } else {
436
- t7 = $[21];
444
+ t7 = $[25];
437
445
  }
438
446
  let t8;
439
- if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
447
+ if ($[26] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
440
448
  t8 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "h5", className: "mt-24 ml-4", children: "History" });
441
- $[22] = t8;
449
+ $[26] = t8;
442
450
  } else {
443
- t8 = $[22];
451
+ t8 = $[26];
444
452
  }
445
453
  let t9;
446
- if ($[23] !== revisions.length) {
454
+ if ($[27] !== revisions.length) {
447
455
  t9 = revisions.length === 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
448
456
  /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "ml-4 mt-8", children: "No history available" }),
449
457
  /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "caption", className: "ml-4", children: "When you save an entity, a new version is created and stored in the history." })
450
458
  ] });
451
- $[23] = revisions.length;
452
- $[24] = t9;
459
+ $[27] = revisions.length;
460
+ $[28] = t9;
453
461
  } else {
454
- t9 = $[24];
462
+ t9 = $[28];
455
463
  }
456
464
  let t10;
457
- if ($[25] !== collection || $[26] !== dirty || $[27] !== revisions || $[28] !== snackbarController) {
465
+ if ($[29] !== collection || $[30] !== dirty || $[31] !== revisions || $[32] !== snackbarController) {
458
466
  let t112;
459
- if ($[30] !== collection || $[31] !== dirty || $[32] !== snackbarController) {
467
+ if ($[34] !== collection || $[35] !== dirty || $[36] !== snackbarController) {
460
468
  t112 = (revision, index) => {
461
469
  const previewKeys = revision.values?.__metadata?.changed_fields;
462
470
  const previousValues = revision.values?.__metadata?.previous_values;
@@ -471,109 +479,109 @@
471
479
  }
472
480
  }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.HistoryIcon, {}) }) }) }) }, index);
473
481
  };
474
- $[30] = collection;
475
- $[31] = dirty;
476
- $[32] = snackbarController;
477
- $[33] = t112;
482
+ $[34] = collection;
483
+ $[35] = dirty;
484
+ $[36] = snackbarController;
485
+ $[37] = t112;
478
486
  } else {
479
- t112 = $[33];
487
+ t112 = $[37];
480
488
  }
481
489
  t10 = revisions.map(t112);
482
- $[25] = collection;
483
- $[26] = dirty;
484
- $[27] = revisions;
485
- $[28] = snackbarController;
486
- $[29] = t10;
490
+ $[29] = collection;
491
+ $[30] = dirty;
492
+ $[31] = revisions;
493
+ $[32] = snackbarController;
494
+ $[33] = t10;
487
495
  } else {
488
- t10 = $[29];
496
+ t10 = $[33];
489
497
  }
490
498
  let t11;
491
- if ($[34] !== hasMore || $[35] !== isLoading || $[36] !== revisions.length) {
499
+ if ($[38] !== hasMore || $[39] !== isLoading || $[40] !== revisions.length) {
492
500
  t11 = revisions.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: loadMoreRef, className: "py-4 text-center", children: [
493
501
  isLoading && /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Loading more..." }),
494
502
  !hasMore && revisions.length > 5 && /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "No more history available" })
495
503
  ] });
496
- $[34] = hasMore;
497
- $[35] = isLoading;
498
- $[36] = revisions.length;
499
- $[37] = t11;
504
+ $[38] = hasMore;
505
+ $[39] = isLoading;
506
+ $[40] = revisions.length;
507
+ $[41] = t11;
500
508
  } else {
501
- t11 = $[37];
509
+ t11 = $[41];
502
510
  }
503
511
  let t12;
504
- if ($[38] !== t10 || $[39] !== t11 || $[40] !== t9) {
512
+ if ($[42] !== t10 || $[43] !== t11 || $[44] !== t9) {
505
513
  t12 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 max-w-6xl mx-auto w-full", children: [
506
514
  t8,
507
515
  t9,
508
516
  t10,
509
517
  t11
510
518
  ] });
511
- $[38] = t10;
512
- $[39] = t11;
513
- $[40] = t9;
514
- $[41] = t12;
519
+ $[42] = t10;
520
+ $[43] = t11;
521
+ $[44] = t9;
522
+ $[45] = t12;
515
523
  } else {
516
- t12 = $[41];
524
+ t12 = $[45];
517
525
  }
518
526
  const t13 = Boolean(revertVersionDialog);
519
527
  let t14;
520
- if ($[42] !== doRevert || $[43] !== revertVersionDialog) {
528
+ if ($[46] !== doRevert || $[47] !== revertVersionDialog) {
521
529
  t14 = function() {
522
530
  if (!revertVersionDialog) {
523
531
  return;
524
532
  }
525
533
  doRevert(revertVersionDialog);
526
534
  };
527
- $[42] = doRevert;
528
- $[43] = revertVersionDialog;
529
- $[44] = t14;
535
+ $[46] = doRevert;
536
+ $[47] = revertVersionDialog;
537
+ $[48] = t14;
530
538
  } else {
531
- t14 = $[44];
539
+ t14 = $[48];
532
540
  }
533
541
  let t15;
534
542
  let t16;
535
- if ($[45] === Symbol.for("react.memo_cache_sentinel")) {
543
+ if ($[49] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
536
544
  t15 = function() {
537
545
  setRevertVersionDialog(void 0);
538
546
  };
539
547
  t16 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "subtitle2", children: "Revert data to this version?" });
540
- $[45] = t15;
541
- $[46] = t16;
548
+ $[49] = t15;
549
+ $[50] = t16;
542
550
  } else {
543
- t15 = $[45];
544
- t16 = $[46];
551
+ t15 = $[49];
552
+ t16 = $[50];
545
553
  }
546
554
  let t17;
547
- if ($[47] !== collection || $[48] !== entity?.path || $[49] !== revertVersionDialog) {
555
+ if ($[51] !== collection || $[52] !== entity?.path || $[53] !== revertVersionDialog) {
548
556
  t17 = revertVersionDialog ? /* @__PURE__ */ jsxRuntime.jsx(core.EntityView, { entity: revertVersionDialog, collection, path: entity?.path }) : null;
549
- $[47] = collection;
550
- $[48] = entity?.path;
551
- $[49] = revertVersionDialog;
552
- $[50] = t17;
557
+ $[51] = collection;
558
+ $[52] = entity?.path;
559
+ $[53] = revertVersionDialog;
560
+ $[54] = t17;
553
561
  } else {
554
- t17 = $[50];
562
+ t17 = $[54];
555
563
  }
556
564
  let t18;
557
- if ($[51] !== t13 || $[52] !== t14 || $[53] !== t17) {
565
+ if ($[55] !== t13 || $[56] !== t14 || $[57] !== t17) {
558
566
  t18 = /* @__PURE__ */ jsxRuntime.jsx(core.ErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(core.ConfirmationDialog, { open: t13, onAccept: t14, onCancel: t15, title: t16, body: t17 }) });
559
- $[51] = t13;
560
- $[52] = t14;
561
- $[53] = t17;
562
- $[54] = t18;
567
+ $[55] = t13;
568
+ $[56] = t14;
569
+ $[57] = t17;
570
+ $[58] = t18;
563
571
  } else {
564
- t18 = $[54];
572
+ t18 = $[58];
565
573
  }
566
574
  let t19;
567
- if ($[55] !== t12 || $[56] !== t18) {
575
+ if ($[59] !== t12 || $[60] !== t18) {
568
576
  t19 = /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: containerRef, className: t7, children: [
569
577
  t12,
570
578
  t18
571
579
  ] });
572
- $[55] = t12;
573
- $[56] = t18;
574
- $[57] = t19;
580
+ $[59] = t12;
581
+ $[60] = t18;
582
+ $[61] = t19;
575
583
  } else {
576
- t19 = $[57];
584
+ t19 = $[61];
577
585
  }
578
586
  return t19;
579
587
  }
@@ -585,7 +593,8 @@
585
593
  previousValues,
586
594
  values,
587
595
  path,
588
- entityId
596
+ entityId,
597
+ collection
589
598
  }) {
590
599
  const uid = context.authController.user?.uid;
591
600
  const dataSource = context.dataSource;
@@ -602,7 +611,8 @@
602
611
  dataSource.saveEntity({
603
612
  path: path + "/" + entityId + "/__history",
604
613
  values: entry,
605
- status: "new"
614
+ status: "new",
615
+ collection
606
616
  }).then(() => {
607
617
  console.debug("History saved for", path, entityId);
608
618
  });
@@ -614,12 +624,14 @@
614
624
  const path = props.path;
615
625
  const entityId = props.entityId;
616
626
  const context = props.context;
627
+ const collection = props.collection;
617
628
  createHistoryEntry({
618
629
  context,
619
630
  previousValues,
620
631
  values,
621
632
  path,
622
- entityId
633
+ entityId,
634
+ collection
623
635
  });
624
636
  }
625
637
  };