@ai-matrx/records-ui 0.95.14 → 0.95.15

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
@@ -7082,6 +7082,11 @@ function tableArchiveSentence(s) {
7082
7082
  if (s.interrupted) return `Stopped: ${sofar}. Carry on whenever you like; it picks up where it stopped.`;
7083
7083
  return `Its ${recordsWord(p.remaining)} ${p.remaining === 1 ? "goes" : "go"} with it.`;
7084
7084
  }
7085
+ function readersSentence(count, tableName2) {
7086
+ if (count <= 0) return "";
7087
+ const rollups = count === 1 ? "1 rollup" : `${count} rollups`;
7088
+ return `${rollups} on ${tableName2 ?? "this table"} read through this.`;
7089
+ }
7085
7090
 
7086
7091
  // src/tableDecorations.ts
7087
7092
  import { useCallback as useCallback9, useEffect as useEffect16, useRef as useRef13, useState as useState20 } from "react";
@@ -10420,9 +10425,15 @@ function FieldEditor(props) {
10420
10425
  const reverse = useReverseColumns2(onEntity ? null : tableId);
10421
10426
  const backLinks = useMemo18(() => (reverse.data ?? []).map(backLinkAsSource), [reverse.data]);
10422
10427
  const totalSources = useMemo18(() => [...relations, ...backLinks], [relations, backLinks]);
10423
- const sourcesFor = (kind) => kind === "rollup" ? totalSources : relations;
10428
+ const sourcesFor = (kind) => kind === "rollup" || kind === "count" ? totalSources : relations;
10424
10429
  const choice = fieldTypeChoice(type);
10425
10430
  const editing = Boolean(field2);
10431
+ const farFieldsOfLink = useFields4(field2 && sourceKindOf(field2) === "link" && !onEntity ? field2.relation_target ?? null : null);
10432
+ const farTable = useTable2(field2 && sourceKindOf(field2) === "link" && !onEntity ? field2.relation_target ?? null : null);
10433
+ const linkReaders = useMemo18(
10434
+ () => field2 ? readingThroughLink(field2, farFieldsOfLink.data ?? []) : [],
10435
+ [field2, farFieldsOfLink.data]
10436
+ );
10426
10437
  const isTitle = Boolean(field2) && !onEntity && table.data?.title_field === field2?.key;
10427
10438
  const offersMany = multiApplies(type) && !isTitle;
10428
10439
  if (!mayShape) {
@@ -10438,7 +10449,7 @@ function FieldEditor(props) {
10438
10449
  const noun = onEntity ? "field" : "column";
10439
10450
  const listsChoices = type === "select" || type === "multi_select" || type === "status";
10440
10451
  const missing = editing ? formulaMissing ?? (listsChoices ? whatTheChoiceListIsMissing(choiceList) : null) : formulaMissing ?? (listsChoices ? whatTheChoiceListIsMissing(newChoices) : null) ?? (type === "formula" && formulaWritten ? null : whatIsMissing(
10441
- type === "count" ? { type: "rollup", label, options, via, pick, agg: "count", of, relations, formulaFields, relationTarget, allowedTypes, noun } : { type, label, options, via, pick, agg, of, relations: sourcesFor(type), formulaFields, relationTarget, allowedTypes, noun }
10452
+ type === "count" ? { type: "rollup", label, options, via, pick, agg: "count", of, relations: totalSources, formulaFields, relationTarget, allowedTypes, noun } : { type, label, options, via, pick, agg, of, relations: sourcesFor(type), formulaFields, relationTarget, allowedTypes, noun }
10442
10453
  ));
10443
10454
  const save = async () => {
10444
10455
  if (missing) return;
@@ -10932,7 +10943,8 @@ function FieldEditor(props) {
10932
10943
  field2 ? /* @__PURE__ */ jsx39("div", { className: "ml-auto flex items-center gap-2", children: askingToRemove ? /* @__PURE__ */ jsxs35(Fragment12, { children: [
10933
10944
  /* @__PURE__ */ jsxs35("span", { className: "text-destructive", children: [
10934
10945
  archiveConfirmSentence(`the field \u201C${fieldName(field2)}\u201D`),
10935
- " Its values stay in every record and come back with it."
10946
+ " Its values stay in every record and come back with it.",
10947
+ linkReaders.length > 0 ? ` ${readersSentence(linkReaders.length, farTable.data?.name ?? null)}` : ""
10936
10948
  ] }),
10937
10949
  /* @__PURE__ */ jsx39(Button21, { size: "sm", variant: "destructive", disabled: mutation.saving, onClick: () => void remove(), children: "Remove it" }),
10938
10950
  /* @__PURE__ */ jsx39(Button21, { size: "sm", variant: "ghost", onClick: () => setAskingToRemove(false), children: "Keep it" })
@@ -11192,6 +11204,13 @@ function backLinkAsSource(column) {
11192
11204
  function isBackLinkSource(field2) {
11193
11205
  return field2[BACK_LINK] !== void 0;
11194
11206
  }
11207
+ function readingThroughLink(link, farFields) {
11208
+ const key = link.inverse_key ?? `linked_${link.id}`;
11209
+ return farFields.filter((f) => {
11210
+ const kind = editorKindFor(f);
11211
+ return (kind === "rollup" || kind === "lookup") && f.config?.["via"] === key;
11212
+ });
11213
+ }
11195
11214
  function rollupFilterLead(agg) {
11196
11215
  return agg === "count" ? "Only count records where" : "Only use records where";
11197
11216
  }
@@ -12703,8 +12722,7 @@ function readersThrough(fields, key) {
12703
12722
  function backLinkSentence(column, readers = [], tableName2 = null) {
12704
12723
  const base = `It goes when ${column.source_field_label} is archived on ${column.source_table_name}. Archiving it removes the links it holds there too; it can be brought back from Archived.`;
12705
12724
  if (readers.length === 0) return base;
12706
- const rollups = readers.length === 1 ? "1 rollup" : `${readers.length} rollups`;
12707
- return `${rollups} on ${tableName2 ?? "this table"} read through this. ${base}`;
12725
+ return `${readersSentence(readers.length, tableName2)} ${base}`;
12708
12726
  }
12709
12727
 
12710
12728
  // src/Grid.tsx