@ai-matrx/records-ui 0.115.93 → 0.115.95

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/pickers.cjs CHANGED
@@ -8146,6 +8146,15 @@ function buttonPressWords(label, pressed) {
8146
8146
  const status = pressed.status ?? "ran";
8147
8147
  return [`${pressed.automation ?? label}: ${status}.`, pressed.says].filter(Boolean).join(" ");
8148
8148
  }
8149
+ var POLL_EVERY_MS = 1200;
8150
+ var POLL_FOR_MS = 12e4;
8151
+ function runAnswerWords(label, run) {
8152
+ const steps = run.steps ?? [];
8153
+ const failedStep = [...steps].reverse().find((s) => s.status === "failed");
8154
+ if (run.status === "failed") return [failedStep?.output_text ?? failedStep?.says, run.says].filter((t, i, all) => t && all.indexOf(t) === i).join(" ") || `${label} failed.`;
8155
+ const answered = [...steps].reverse().find((s) => s.output_text && s.output_text.trim() !== "");
8156
+ return answered?.output_text?.trim() || run.says || `${label} ran.`;
8157
+ }
8149
8158
  var stop = (event) => event.stopPropagation();
8150
8159
  function ButtonValue({ field, recordId, inCell }) {
8151
8160
  const client = (0, import_react53.useOptionalRecordsClient)();
@@ -8153,6 +8162,8 @@ function ButtonValue({ field, recordId, inCell }) {
8153
8162
  const [busy, setBusy] = (0, import_react52.useState)(false);
8154
8163
  const [said2, setSaid] = (0, import_react52.useState)(null);
8155
8164
  const [settingUp, setSettingUp] = (0, import_react52.useState)(false);
8165
+ const waitingOn = (0, import_react52.useRef)(0);
8166
+ (0, import_react52.useEffect)(() => () => void (waitingOn.current += 1), []);
8156
8167
  if (!b) return null;
8157
8168
  const color = (0, import_data_table6.isStyleColor)(b.color) ? import_data_table6.CHOICE_CHIP_CLASS[b.color] : import_data_table6.NEUTRAL_CHIP_CLASS;
8158
8169
  const needs = (0, import_records27.buttonNeeds)(b);
@@ -8169,60 +8180,100 @@ function ButtonValue({ field, recordId, inCell }) {
8169
8180
  const opened = typeof window !== "undefined" ? (0, import_outbound.openOutbound)(pressed.url, "_blank", "noopener") : null;
8170
8181
  return setSaid({ kind: "ran", says: opened ? `${b.label} opened.` : `${b.label} is ready:`, link: pressed.url });
8171
8182
  }
8172
- setSaid({ kind: "ran", says: buttonPressWords(b.label, pressed) });
8183
+ const words = buttonPressWords(b.label, pressed);
8184
+ if (pressed.do === "run_automation" && pressed.status === "waiting" && pressed.run_id && b.automation_id) {
8185
+ const mine = waitingOn.current += 1;
8186
+ setBusy(true);
8187
+ setSaid({ kind: "waiting", says: `${b.label} is running` });
8188
+ const until = Date.now() + POLL_FOR_MS;
8189
+ while (waitingOn.current === mine) {
8190
+ await new Promise((r) => setTimeout(r, POLL_EVERY_MS));
8191
+ if (waitingOn.current !== mine) return;
8192
+ const runs = await client.automationRuns({ automation_id: b.automation_id, limit: 10 });
8193
+ if (!runs.ok) {
8194
+ setBusy(false);
8195
+ return setSaid({ kind: "refused", error: runs.error });
8196
+ }
8197
+ const run = runs.data.runs.find((r) => r.run_id === pressed.run_id);
8198
+ if (run && run.status !== "waiting") {
8199
+ setBusy(false);
8200
+ return setSaid(run.status === "ran" ? { kind: "ran", says: runAnswerWords(b.label, run) } : { kind: "failed", says: runAnswerWords(b.label, run) });
8201
+ }
8202
+ if (Date.now() > until) {
8203
+ setBusy(false);
8204
+ return setSaid({ kind: "ran", says: `${b.label} is still running. Its answer will be in the automation's runs.` });
8205
+ }
8206
+ }
8207
+ return;
8208
+ }
8209
+ setSaid({ kind: "ran", says: words });
8173
8210
  };
8174
8211
  return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
8175
- /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_design_system32.Popover, { open: said2 !== null, onOpenChange: (open) => open ? null : setSaid(null), children: [
8176
- /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_design_system32.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
8177
- import_design_system32.Button,
8178
- {
8179
- type: "button",
8180
- size: "xs",
8181
- variant: "outline",
8182
- "data-records-button": field.key,
8183
- "data-records-button-unset": needs ? "" : void 0,
8184
- "aria-busy": busy || void 0,
8185
- disabled: busy,
8186
- className: (0, import_design_system32.cn)("max-w-full gap-1 border px-2 font-medium", inCell ? "h-5" : "h-6", color, needs && "border-dashed opacity-80"),
8187
- onPointerDown: stop,
8188
- onDoubleClick: stop,
8189
- onClick: (event) => {
8190
- event.stopPropagation();
8191
- event.preventDefault();
8192
- void press();
8193
- },
8194
- children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: "truncate", children: b.label })
8195
- }
8196
- ) }),
8197
- /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_design_system32.PopoverContent, { className: "w-72 space-y-2 p-3 text-sm", onClick: stop, onPointerDown: stop, "data-records-button-said": said2?.kind, children: [
8198
- said2?.kind === "refused" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(RefusalLine, { error: said2.error }) : null,
8199
- said2?.kind === "public" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { children: "Buttons run for signed-in people." }) : null,
8200
- said2?.kind === "ran" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("p", { className: "break-words", children: [
8201
- said2.says,
8202
- " ",
8203
- said2.link ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_outbound_react6.OutboundLink, { href: said2.link, className: "text-primary underline", children: said2.link }) : null
8204
- ] }) : null,
8205
- said2?.kind === "needs" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
8206
- /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { children: said2.says }),
8207
- tableId ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
8212
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
8213
+ import_design_system32.Popover,
8214
+ {
8215
+ open: said2 !== null,
8216
+ onOpenChange: (open) => {
8217
+ if (open) return;
8218
+ waitingOn.current += 1;
8219
+ setBusy(false);
8220
+ setSaid(null);
8221
+ },
8222
+ children: [
8223
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_design_system32.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
8208
8224
  import_design_system32.Button,
8209
8225
  {
8210
8226
  type: "button",
8211
- size: "sm",
8212
- "data-records-button-set-up": "",
8213
- onClick: () => {
8214
- setSaid(null);
8215
- setSettingUp(true);
8227
+ size: "xs",
8228
+ variant: "outline",
8229
+ "data-records-button": field.key,
8230
+ "data-records-button-unset": needs ? "" : void 0,
8231
+ "aria-busy": busy || void 0,
8232
+ disabled: busy,
8233
+ className: (0, import_design_system32.cn)("max-w-full gap-1 border px-2 font-medium", inCell ? "h-5" : "h-6", color, needs && "border-dashed opacity-80"),
8234
+ onPointerDown: stop,
8235
+ onDoubleClick: stop,
8236
+ onClick: (event) => {
8237
+ event.stopPropagation();
8238
+ event.preventDefault();
8239
+ void press();
8216
8240
  },
8217
- children: [
8218
- "Set up ",
8219
- b.label
8220
- ]
8241
+ children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: "truncate", children: b.label })
8221
8242
  }
8222
- ) : null
8223
- ] }) : null
8224
- ] })
8225
- ] }),
8243
+ ) }),
8244
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_design_system32.PopoverContent, { className: "w-72 space-y-2 p-3 text-sm", onClick: stop, onPointerDown: stop, "data-records-button-said": said2?.kind, children: [
8245
+ said2?.kind === "refused" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(RefusalLine, { error: said2.error }) : null,
8246
+ said2?.kind === "waiting" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { className: "matrx-shimmer rounded px-1 py-0.5", role: "status", "aria-live": "polite", children: said2.says }) : null,
8247
+ said2?.kind === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { className: "break-words text-destructive", role: "alert", children: said2.says }) : null,
8248
+ said2?.kind === "public" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { children: "Buttons run for signed-in people." }) : null,
8249
+ said2?.kind === "ran" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("p", { className: "break-words", children: [
8250
+ said2.says,
8251
+ " ",
8252
+ said2.link ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_outbound_react6.OutboundLink, { href: said2.link, className: "text-primary underline", children: said2.link }) : null
8253
+ ] }) : null,
8254
+ said2?.kind === "needs" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
8255
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { children: said2.says }),
8256
+ tableId ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
8257
+ import_design_system32.Button,
8258
+ {
8259
+ type: "button",
8260
+ size: "sm",
8261
+ "data-records-button-set-up": "",
8262
+ onClick: () => {
8263
+ setSaid(null);
8264
+ setSettingUp(true);
8265
+ },
8266
+ children: [
8267
+ "Set up ",
8268
+ b.label
8269
+ ]
8270
+ }
8271
+ ) : null
8272
+ ] }) : null
8273
+ ] })
8274
+ ]
8275
+ }
8276
+ ),
8226
8277
  settingUp && tableId ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_design_system32.Dialog, { open: true, onOpenChange: (open) => open ? null : setSettingUp(false), children: /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_design_system32.DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", onClick: stop, onPointerDown: stop, children: [
8227
8278
  /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_design_system32.DialogHeader, { children: [
8228
8279
  /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_design_system32.DialogTitle, { children: `Column settings \xB7 ${fieldName(field)}` }),