@ai-matrx/records-ui 0.115.86 → 0.115.88

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.js CHANGED
@@ -2590,6 +2590,11 @@ function useKeptPeople(value, roster) {
2590
2590
  return people;
2591
2591
  }
2592
2592
 
2593
+ // src/recordVersions.ts
2594
+ var recordVersions_exports = {};
2595
+ __reExport(recordVersions_exports, versions_star2);
2596
+ import * as versions_star2 from "@ai-matrx/records/versions";
2597
+
2593
2598
  // src/personRetype.ts
2594
2599
  var PAGE = 500;
2595
2600
  var CEILING = 2e4;
@@ -2600,7 +2605,7 @@ async function readPersonColumn(client, tableId, key) {
2600
2605
  const out = [];
2601
2606
  for (let offset = 0; offset < CEILING; offset += PAGE) {
2602
2607
  const page = await client.list({ table_id: tableId, limit: PAGE, offset });
2603
- if (!page.ok) throw new Error(page.error.message ?? "The records could not be read");
2608
+ if (!page.ok) throw new Error(refusalSentence(page.error));
2604
2609
  for (const row of page.data.rows) {
2605
2610
  const doc = row.document ?? {};
2606
2611
  let ids = idsIn(doc[key]);
@@ -2638,17 +2643,36 @@ function previewPersonWords(rows, people, as) {
2638
2643
  }
2639
2644
  return { converts, keptAside, examples, partial: false };
2640
2645
  }
2646
+ async function versionsNow(client, ids) {
2647
+ const out = /* @__PURE__ */ new Map();
2648
+ for (let i = 0; i < ids.length; i += 200) {
2649
+ const got = await client.recordHeaders({ ids: ids.slice(i, i + 200) });
2650
+ if (!got.ok) throw new Error(refusalSentence(got.error));
2651
+ for (const h of got.data ?? []) if (typeof h.version === "number") out.set(h.id, h.version);
2652
+ }
2653
+ return out;
2654
+ }
2655
+ async function writeRecordPatches(client, tableId, patches) {
2656
+ const versions = await versionsNow(client, patches.map((p) => p.recordId));
2657
+ for (let i = 0; i < patches.length; i += 100) {
2658
+ const changes = patches.slice(i, i + 100).map((p) => ({
2659
+ op: "update",
2660
+ record_id: p.recordId,
2661
+ patch: p.patch,
2662
+ expected_version: versions.get(p.recordId) ?? null
2663
+ }));
2664
+ const done = await (0, recordVersions_exports.changeRecordsAt)(client, { table_id: tableId, changes });
2665
+ if (!done.ok) throw new Error(refusalSentence(done.error));
2666
+ }
2667
+ }
2641
2668
  async function writePersonWords(client, tableId, rows, people, key, as) {
2642
- const changes = [];
2669
+ const patches = [];
2643
2670
  for (const row of rows) {
2644
2671
  const words2 = wordsFor(row.ids, people, as);
2645
- if (words2 !== null) changes.push({ op: "update", record_id: row.recordId, patch: { [key]: words2 } });
2646
- }
2647
- for (let i = 0; i < changes.length; i += 100) {
2648
- const done = await client.recordChangeMany({ table_id: tableId, changes: changes.slice(i, i + 100) });
2649
- if (!done.ok) throw new Error(done.error.message ?? "The words could not be written");
2672
+ if (words2 !== null) patches.push({ recordId: row.recordId, patch: { [key]: words2 } });
2650
2673
  }
2651
- return changes.length;
2674
+ await writeRecordPatches(client, tableId, patches);
2675
+ return patches.length;
2652
2676
  }
2653
2677
 
2654
2678
  // src/FieldRetype.tsx
@@ -2770,6 +2794,28 @@ function FieldRetype({ field: field2, tableId, onRetyped }) {
2770
2794
  setRefusal(null);
2771
2795
  let holding;
2772
2796
  let aside;
2797
+ const offerUndo = (migration) => {
2798
+ if (!migration || !notify?.reversible) return;
2799
+ const wasPerson = person && read && (to.id === "text" || to.id === "email") ? read : null;
2800
+ notify.reversible({
2801
+ verb: "change",
2802
+ noun: "column",
2803
+ subject: name,
2804
+ undo: async () => {
2805
+ const back = await client.migrateUndo({ migration_id: migration });
2806
+ if (!back.ok) throw new Error(refusalSentence(back.error));
2807
+ if (wasPerson) {
2808
+ await writeRecordPatches(
2809
+ client,
2810
+ tableId,
2811
+ wasPerson.rows.map((r) => ({ recordId: r.recordId, patch: { [field2.key]: field2.multi ? r.ids : r.ids[0] ?? null } }))
2812
+ );
2813
+ }
2814
+ tableShapeChanged(tableId);
2815
+ onRetyped?.();
2816
+ }
2817
+ });
2818
+ };
2773
2819
  if (to.via !== "behaviour") {
2774
2820
  const done = await client.fieldUpdate({ field_id: field2.id, patch: { parity_type: to.parity } });
2775
2821
  setBusy(false);
@@ -2779,6 +2825,9 @@ function FieldRetype({ field: field2, tableId, onRetyped }) {
2779
2825
  }
2780
2826
  holding = preview?.converts ?? 0;
2781
2827
  aside = preview?.keptAside ?? 0;
2828
+ const recorded = await client.migrations({ target_id: field2.id, limit: 1 });
2829
+ const newest = recorded.ok ? recorded.data[0] : void 0;
2830
+ if (newest && !newest.undone_at) offerUndo(newest.id);
2782
2831
  } else {
2783
2832
  const done = await client.migrateRetype({ field_id: field2.id, to: to.behaviour });
2784
2833
  setBusy(false);
@@ -2788,27 +2837,7 @@ function FieldRetype({ field: field2, tableId, onRetyped }) {
2788
2837
  }
2789
2838
  holding = done.data.records_still_holding_a_value ?? 0;
2790
2839
  aside = done.data.values_in_retired_for_this_field ?? 0;
2791
- const migration = done.data.migration_id;
2792
- if (migration && notify?.reversible) {
2793
- notify.reversible({
2794
- verb: "change",
2795
- noun: "column",
2796
- subject: name,
2797
- undo: async () => {
2798
- const back = await client.migrateUndo({ migration_id: migration });
2799
- if (!back.ok) throw new Error(refusalSentence(back.error));
2800
- if (person && read && (to.id === "text" || to.id === "email")) {
2801
- const changes = read.rows.map((r) => ({ op: "update", record_id: r.recordId, patch: { [field2.key]: field2.multi ? r.ids : r.ids[0] ?? null } }));
2802
- for (let i = 0; i < changes.length; i += 100) {
2803
- const put = await client.recordChangeMany({ table_id: tableId, changes: changes.slice(i, i + 100) });
2804
- if (!put.ok) throw new Error(refusalSentence(put.error));
2805
- }
2806
- }
2807
- tableShapeChanged(tableId);
2808
- onRetyped?.();
2809
- }
2810
- });
2811
- }
2840
+ offerUndo(done.data.migration_id);
2812
2841
  }
2813
2842
  if (person && read && (to.id === "text" || to.id === "email")) {
2814
2843
  const as = to.id === "email" ? "email" : "name";
@@ -3324,11 +3353,6 @@ function groupsOf(options) {
3324
3353
  return out;
3325
3354
  }
3326
3355
 
3327
- // src/recordVersions.ts
3328
- var recordVersions_exports = {};
3329
- __reExport(recordVersions_exports, versions_star2);
3330
- import * as versions_star2 from "@ai-matrx/records/versions";
3331
-
3332
3356
  // src/writeOnTheWinningVersion.ts
3333
3357
  var writeOnTheWinningVersion_exports = {};
3334
3358
  __reExport(writeOnTheWinningVersion_exports, versions_star3);
@@ -54454,7 +54478,11 @@ function TablePage({
54454
54478
  setOpenRecord(activeRecordId);
54455
54479
  setSurface((now) => ({ ...now, rail: "record" }));
54456
54480
  }, [activeRecordId]);
54457
- const [shownIds, setShownIds] = useState152([]);
54481
+ const [shownIds, setShownIdsRaw] = useState152([]);
54482
+ const setShownIds = useCallback70(
54483
+ (next) => setShownIdsRaw((prev) => prev.length === next.length && prev.every((id, i) => id === next[i]) ? prev : next),
54484
+ []
54485
+ );
54458
54486
  const [recordExpanded, setRecordExpanded] = useState152(false);
54459
54487
  const shownRecord = rail === "record" ? openRecord : null;
54460
54488
  const reportedRecord = useRef64(activeRecordId ?? null);