@ai-matrx/records-ui 0.41.0 → 0.43.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
@@ -4898,6 +4898,27 @@ import {
4898
4898
  } from "@ai-matrx/records/react";
4899
4899
  import { Button as Button15, Skeleton as Skeleton5, cn as cn17 } from "@ai-matrx/design-system";
4900
4900
  import { jsx as jsx20, jsxs as jsxs17 } from "react/jsx-runtime";
4901
+ var UNPLACED = "\0unplaced";
4902
+ function stageOfCard(row, stageKey, stages) {
4903
+ const document2 = row.document ?? {};
4904
+ const choices = document2["_choices"];
4905
+ if (choices && typeof choices === "object") {
4906
+ const chosen = choices[stageKey];
4907
+ if (chosen && typeof chosen === "object") {
4908
+ const key = chosen["key"];
4909
+ if (typeof key === "string" && key !== "") {
4910
+ return stages.some((s) => s.key === key) ? key : null;
4911
+ }
4912
+ }
4913
+ }
4914
+ const raw = document2[stageKey];
4915
+ if (raw === null || raw === void 0 || raw === "") return null;
4916
+ const said = String(raw).trim();
4917
+ const byKey = stages.find((s) => s.key === said);
4918
+ if (byKey) return byKey.key;
4919
+ const byLabel = stages.find((s) => s.label.toLowerCase() === said.toLowerCase());
4920
+ return byLabel ? byLabel.key : null;
4921
+ }
4901
4922
  function PipelineBoard({
4902
4923
  tableId,
4903
4924
  rows,
@@ -4947,12 +4968,12 @@ function PipelineBoard({
4947
4968
  const map = /* @__PURE__ */ new Map();
4948
4969
  if (!stageKey) return map;
4949
4970
  for (const row of rows) {
4950
- const raw = (row.document ?? {})[stageKey];
4951
- const key = raw === null || raw === void 0 || raw === "" ? "" : String(raw);
4952
- map.set(key, [...map.get(key) ?? [], row]);
4971
+ const key = stageOfCard(row, stageKey, definition?.stages ?? []);
4972
+ map.set(key ?? UNPLACED, [...map.get(key ?? UNPLACED) ?? [], row]);
4953
4973
  }
4954
4974
  return map;
4955
- }, [rows, stageKey]);
4975
+ }, [rows, stageKey, definition?.stages]);
4976
+ const unplaced = cardsByStage.get(UNPLACED) ?? [];
4956
4977
  const all = fields.data ?? [];
4957
4978
  const titleField = useMemo14(
4958
4979
  () => all.find((f) => f.key !== stageKey) ?? all[0],
@@ -5099,7 +5120,14 @@ function PipelineBoard({
5099
5120
  },
5100
5121
  stage.key
5101
5122
  );
5102
- }) })
5123
+ }) }),
5124
+ unplaced.length > 0 ? /* @__PURE__ */ jsxs17("p", { className: "text-xs text-muted-foreground", "data-testid": "pipeline-unplaced", children: [
5125
+ unplaced.length === 1 ? "One record is" : `${unplaced.length} records are`,
5126
+ " not in any of these columns \u2014 ",
5127
+ unplaced.slice(0, 3).map((r) => rowName(r, titleField?.key ?? null, "Untitled")).join(", "),
5128
+ unplaced.length > 3 ? ` and ${unplaced.length - 3} more` : "",
5129
+ ". Their stage is not one this pipeline offers, so nothing here can draw them; open one from the grid to move it."
5130
+ ] }) : null
5103
5131
  ] });
5104
5132
  }
5105
5133
  function formatTotal(total) {
@@ -5308,7 +5336,7 @@ function offerableFields(all, want) {
5308
5336
  return kind === "datetime" || kind === "date";
5309
5337
  });
5310
5338
  }
5311
- function useIsPipeline(tableId, groupField) {
5339
+ function useStageField(tableId) {
5312
5340
  const client = useRecordsClient13();
5313
5341
  const [stage, setStage] = useState19({
5314
5342
  asked: false,
@@ -5325,8 +5353,17 @@ function useIsPipeline(tableId, groupField) {
5325
5353
  cancelled = true;
5326
5354
  };
5327
5355
  }, [client, tableId]);
5328
- if (!stage.asked) return null;
5329
- return stage.key != null && stage.key === groupField;
5356
+ return stage;
5357
+ }
5358
+ function boardColumnChoice(fields, chosenKey, stage) {
5359
+ const has = (key) => key != null && fields.some((f) => f.key === key) ? key : null;
5360
+ const chosen = has(chosenKey);
5361
+ if (chosen) {
5362
+ return { groupKey: chosen, isPipeline: stage.asked ? stage.key === chosen : null, stillAsking: false };
5363
+ }
5364
+ if (!stage.asked) return { groupKey: null, isPipeline: null, stillAsking: true };
5365
+ const fromTable = has(stage.key);
5366
+ return { groupKey: fromTable, isPipeline: fromTable != null, stillAsking: false };
5330
5367
  }
5331
5368
  function Board({
5332
5369
  view,
@@ -5338,7 +5375,7 @@ function Board({
5338
5375
  }) {
5339
5376
  const fields = useFields10(view.subject);
5340
5377
  const records = useViewRecords(view, pageSize);
5341
- const isPipeline = useIsPipeline(view.subject, view.groupField);
5378
+ const stage = useStageField(view.subject);
5342
5379
  if (fields.error) return /* @__PURE__ */ jsx21(RefusalNotice, { error: fields.error });
5343
5380
  if (records.error) return /* @__PURE__ */ jsx21(RefusalNotice, { error: records.error });
5344
5381
  if (fields.loading || records.loading) return /* @__PURE__ */ jsx21(Skeleton6, { className: "h-40 w-full" });
@@ -5346,7 +5383,9 @@ function Board({
5346
5383
  const byKey = (key) => all.find((f) => f.key === key);
5347
5384
  const titleField = byKey(view.groupField) ? all.find((f) => f.key !== view.groupField) ?? all[0] : all[0];
5348
5385
  if (view.layout === "kanban") {
5349
- const groupField = byKey(view.groupField);
5386
+ const choice = boardColumnChoice(all, view.groupField, stage);
5387
+ const groupField = byKey(choice.groupKey);
5388
+ const isPipeline = choice.isPipeline;
5350
5389
  const picker = /* @__PURE__ */ jsx21(
5351
5390
  FieldPicker,
5352
5391
  {
@@ -5358,6 +5397,7 @@ function Board({
5358
5397
  onPick: (key) => onChange({ groupField: key })
5359
5398
  }
5360
5399
  );
5400
+ if (choice.stillAsking) return /* @__PURE__ */ jsx21(Skeleton6, { className: "h-40 w-full" });
5361
5401
  if (!groupField) return /* @__PURE__ */ jsx21(Needs, { layout: "kanban", picker });
5362
5402
  return /* @__PURE__ */ jsxs18("div", { className: "flex min-h-0 flex-col gap-2", children: [
5363
5403
  picker,