@ai-matrx/records-ui 0.78.0 → 0.79.0

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
@@ -4929,6 +4929,9 @@ var ROLLUP_OPERATIONS = ROLLUP_AGG_VALUES.map((value) => ({
4929
4929
  value,
4930
4930
  label: ROLLUP_AGG_LABEL[value]
4931
4931
  }));
4932
+ var FORMULA_SEPARATOR_LABEL = "Joined by";
4933
+ var EDITING_A_WORKED_OUT_COLUMN = "This column works out its answer from other columns. Which columns it uses, and what joins them, cannot be changed on this screen yet \u2014 remove it and add it again to change them.";
4934
+ var FORMULA_DEFAULT_SEPARATOR = " \u2014 ";
4932
4935
  var FORMULA_OPERATIONS = FORMULA_OP_VALUES.map((value) => ({
4933
4936
  value,
4934
4937
  label: FORMULA_OP_LABEL[value],
@@ -4965,8 +4968,9 @@ function FieldEditor({ tableId, field, onSaved, onCancel, onRemoved, className }
4965
4968
  const [of, setOf] = useState15(String(field?.config?.["of"] ?? ""));
4966
4969
  const [relationTarget, setRelationTarget] = useState15(String(field?.relation_target ?? ""));
4967
4970
  const [display, setDisplay] = useState15(field?.display ?? null);
4968
- const [formulaOp, setFormulaOp] = useState15("concat");
4969
- const [formulaFields, setFormulaFields] = useState15([]);
4971
+ const [formulaOp, setFormulaOp] = useState15(() => formulaOpOf(field));
4972
+ const [formulaFields, setFormulaFields] = useState15(() => formulaFieldIdsOf(field));
4973
+ const [formulaSeparator, setFormulaSeparator] = useState15(() => formulaSeparatorOf(field));
4970
4974
  const [askingToRemove, setAskingToRemove] = useState15(false);
4971
4975
  const [notLanded, setNotLanded] = useState15(false);
4972
4976
  const others = useMemo12(
@@ -5040,7 +5044,7 @@ function FieldEditor({ tableId, field, onSaved, onCancel, onRemoved, className }
5040
5044
  ...type === "datetime" ? { kind: withTime ? "datetime" : "date" } : {},
5041
5045
  ...type === "lookup" ? { via, pick } : {},
5042
5046
  ...type === "rollup" ? { via, agg, ...agg === "count" ? {} : { of } } : {},
5043
- ...type === "formula" ? { expr: formulaExpression(formulaOp, formulaFields) } : {}
5047
+ ...type === "formula" ? { expr: formulaExpression(formulaOp, formulaFields, formulaSeparator) } : {}
5044
5048
  };
5045
5049
  const written = await mutation.declare({ table_id: tableId, spec });
5046
5050
  if (written === null) return;
@@ -5098,6 +5102,7 @@ function FieldEditor({ tableId, field, onSaved, onCancel, onRemoved, className }
5098
5102
  /* @__PURE__ */ jsx18("p", { className: "text-[11px] text-muted-foreground", children: editing ? "What a column holds cannot be changed here \u2014 every value already saved would have to be converted. Add a new column and move the values across." : choice?.explanation ?? "" })
5099
5103
  ] })
5100
5104
  ] }),
5105
+ editing && type === "formula" ? /* @__PURE__ */ jsx18("p", { className: "text-[11px] text-muted-foreground", children: EDITING_A_WORKED_OUT_COLUMN }) : null,
5101
5106
  !editing || type === "select" || type === "multi_select" || type === "relation" ? /* @__PURE__ */ jsx18(
5102
5107
  TypeQuestions,
5103
5108
  {
@@ -5126,6 +5131,8 @@ function FieldEditor({ tableId, field, onSaved, onCancel, onRemoved, className }
5126
5131
  setFormulaOp,
5127
5132
  formulaFields,
5128
5133
  setFormulaFields,
5134
+ formulaSeparator,
5135
+ setFormulaSeparator,
5129
5136
  relations,
5130
5137
  others,
5131
5138
  existingOptionsTable: Boolean(field?.options_table_id ?? field?.config?.["options_table_id"])
@@ -5310,10 +5317,30 @@ function startingType(field) {
5310
5317
  if (fieldTypeChoice(kind)) return kind;
5311
5318
  return "text";
5312
5319
  }
5313
- function formulaExpression(op, fieldIds) {
5320
+ function formulaExpression(op, fieldIds, separator) {
5314
5321
  const args = fieldIds.filter((id) => id !== "").map((id) => ({ field: id }));
5315
- if (args.length === 0) return { op, args: [{ const: "" }] };
5316
- return { op, args };
5322
+ const joined = op === "concat" && separator !== "" ? { separator } : {};
5323
+ if (args.length === 0) return { op, ...joined, args: [{ const: "" }] };
5324
+ return { op, ...joined, args };
5325
+ }
5326
+ function formulaExprOf(field) {
5327
+ const expr = field?.config?.["expr"];
5328
+ return expr !== null && typeof expr === "object" ? expr : null;
5329
+ }
5330
+ function formulaOpOf(field) {
5331
+ const op = formulaExprOf(field)?.["op"];
5332
+ return typeof op === "string" && op !== "" ? op : "concat";
5333
+ }
5334
+ function formulaFieldIdsOf(field) {
5335
+ const args = formulaExprOf(field)?.["args"];
5336
+ if (!Array.isArray(args)) return [];
5337
+ return args.map((a) => a !== null && typeof a === "object" ? a["field"] : void 0).filter((id) => typeof id === "string" && id !== "");
5338
+ }
5339
+ function formulaSeparatorOf(field) {
5340
+ const expr = formulaExprOf(field);
5341
+ if (expr === null) return FORMULA_DEFAULT_SEPARATOR;
5342
+ const sep = expr["separator"];
5343
+ return typeof sep === "string" ? sep : "";
5317
5344
  }
5318
5345
  function TypeQuestions(props) {
5319
5346
  const { type } = props;
@@ -5452,7 +5479,21 @@ function TypeQuestions(props) {
5452
5479
  );
5453
5480
  }) }),
5454
5481
  /* @__PURE__ */ jsx18("p", { className: "text-[11px] text-muted-foreground", children: "In the order you pick them. Columns are remembered by which column they are, so renaming one never breaks this." })
5455
- ] })
5482
+ ] }),
5483
+ props.formulaOp === "concat" ? /* @__PURE__ */ jsxs14("div", { className: "flex flex-col gap-1", children: [
5484
+ /* @__PURE__ */ jsx18(Label4, { className: "text-xs", children: FORMULA_SEPARATOR_LABEL }),
5485
+ /* @__PURE__ */ jsx18(
5486
+ BasicInput5,
5487
+ {
5488
+ value: props.formulaSeparator,
5489
+ "aria-label": FORMULA_SEPARATOR_LABEL,
5490
+ placeholder: "\u2014",
5491
+ className: "max-w-[10rem]",
5492
+ onChange: (e) => props.setFormulaSeparator(e.target.value)
5493
+ }
5494
+ ),
5495
+ /* @__PURE__ */ jsx18("p", { className: "text-[11px] text-muted-foreground", children: "What goes between the columns. Leave it empty to run them straight together." })
5496
+ ] }) : null
5456
5497
  ] });
5457
5498
  }
5458
5499
  return null;