@ai-matrx/records-ui 0.115.94 → 0.115.96
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/CHANGELOG.md +17 -0
- package/dist/index.cjs +103 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +676 -622
- package/dist/index.js.map +1 -1
- package/dist/pickers.cjs +103 -49
- package/dist/pickers.cjs.map +1 -1
- package/dist/pickers.js +127 -73
- package/dist/pickers.js.map +1 -1
- package/package.json +4 -4
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,76 +8162,121 @@ 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);
|
|
8159
8170
|
const tableId = field.entity_definition_id;
|
|
8160
8171
|
const press = async () => {
|
|
8161
8172
|
if (!client || !recordId) return setSaid({ kind: "public" });
|
|
8162
|
-
if (needs) return setSaid({ kind: "needs", says: needs });
|
|
8173
|
+
if (needs && b.do) return setSaid({ kind: "needs", says: needs });
|
|
8163
8174
|
setBusy(true);
|
|
8164
8175
|
const answered = await client.buttonPress({ record_id: recordId, field_id: field.id });
|
|
8165
8176
|
setBusy(false);
|
|
8166
|
-
if (!answered.ok)
|
|
8177
|
+
if (!answered.ok) {
|
|
8178
|
+
if (needs && (answered.error.sqlstate === "22023" || answered.error.code === "invalid_argument")) return setSaid({ kind: "needs", says: needs });
|
|
8179
|
+
return setSaid({ kind: "refused", error: answered.error });
|
|
8180
|
+
}
|
|
8167
8181
|
const pressed = answered.data;
|
|
8168
8182
|
if (pressed.do === "open_url") {
|
|
8169
8183
|
const opened = typeof window !== "undefined" ? (0, import_outbound.openOutbound)(pressed.url, "_blank", "noopener") : null;
|
|
8170
8184
|
return setSaid({ kind: "ran", says: opened ? `${b.label} opened.` : `${b.label} is ready:`, link: pressed.url });
|
|
8171
8185
|
}
|
|
8172
|
-
|
|
8186
|
+
const words = buttonPressWords(b.label, pressed);
|
|
8187
|
+
if (pressed.do === "run_automation" && pressed.status === "waiting" && pressed.run_id && b.automation_id) {
|
|
8188
|
+
const mine = waitingOn.current += 1;
|
|
8189
|
+
setBusy(true);
|
|
8190
|
+
setSaid({ kind: "waiting", says: `${b.label} is running` });
|
|
8191
|
+
const until = Date.now() + POLL_FOR_MS;
|
|
8192
|
+
while (waitingOn.current === mine) {
|
|
8193
|
+
await new Promise((r) => setTimeout(r, POLL_EVERY_MS));
|
|
8194
|
+
if (waitingOn.current !== mine) return;
|
|
8195
|
+
const runs = await client.automationRuns({ automation_id: b.automation_id, limit: 10 });
|
|
8196
|
+
if (!runs.ok) {
|
|
8197
|
+
setBusy(false);
|
|
8198
|
+
return setSaid({ kind: "refused", error: runs.error });
|
|
8199
|
+
}
|
|
8200
|
+
const run = runs.data.runs.find((r) => r.run_id === pressed.run_id);
|
|
8201
|
+
if (run && run.status !== "waiting") {
|
|
8202
|
+
setBusy(false);
|
|
8203
|
+
return setSaid(run.status === "ran" ? { kind: "ran", says: runAnswerWords(b.label, run) } : { kind: "failed", says: runAnswerWords(b.label, run) });
|
|
8204
|
+
}
|
|
8205
|
+
if (Date.now() > until) {
|
|
8206
|
+
setBusy(false);
|
|
8207
|
+
return setSaid({ kind: "ran", says: `${b.label} is still running. Its answer will be in the automation's runs.` });
|
|
8208
|
+
}
|
|
8209
|
+
}
|
|
8210
|
+
return;
|
|
8211
|
+
}
|
|
8212
|
+
setSaid({ kind: "ran", says: words });
|
|
8173
8213
|
};
|
|
8174
8214
|
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
|
|
8175
|
-
/* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
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)(
|
|
8215
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
|
|
8216
|
+
import_design_system32.Popover,
|
|
8217
|
+
{
|
|
8218
|
+
open: said2 !== null,
|
|
8219
|
+
onOpenChange: (open) => {
|
|
8220
|
+
if (open) return;
|
|
8221
|
+
waitingOn.current += 1;
|
|
8222
|
+
setBusy(false);
|
|
8223
|
+
setSaid(null);
|
|
8224
|
+
},
|
|
8225
|
+
children: [
|
|
8226
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_design_system32.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
|
8208
8227
|
import_design_system32.Button,
|
|
8209
8228
|
{
|
|
8210
8229
|
type: "button",
|
|
8211
|
-
size: "
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8230
|
+
size: "xs",
|
|
8231
|
+
variant: "outline",
|
|
8232
|
+
"data-records-button": field.key,
|
|
8233
|
+
"data-records-button-unset": needs ? "" : void 0,
|
|
8234
|
+
"aria-busy": busy || void 0,
|
|
8235
|
+
disabled: busy,
|
|
8236
|
+
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"),
|
|
8237
|
+
onPointerDown: stop,
|
|
8238
|
+
onDoubleClick: stop,
|
|
8239
|
+
onClick: (event) => {
|
|
8240
|
+
event.stopPropagation();
|
|
8241
|
+
event.preventDefault();
|
|
8242
|
+
void press();
|
|
8216
8243
|
},
|
|
8217
|
-
children:
|
|
8218
|
-
"Set up ",
|
|
8219
|
-
b.label
|
|
8220
|
-
]
|
|
8244
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: "truncate", children: b.label })
|
|
8221
8245
|
}
|
|
8222
|
-
)
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8246
|
+
) }),
|
|
8247
|
+
/* @__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: [
|
|
8248
|
+
said2?.kind === "refused" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(RefusalLine, { error: said2.error }) : null,
|
|
8249
|
+
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,
|
|
8250
|
+
said2?.kind === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { className: "break-words text-destructive", role: "alert", children: said2.says }) : null,
|
|
8251
|
+
said2?.kind === "public" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { children: "Buttons run for signed-in people." }) : null,
|
|
8252
|
+
said2?.kind === "ran" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("p", { className: "break-words", children: [
|
|
8253
|
+
said2.says,
|
|
8254
|
+
" ",
|
|
8255
|
+
said2.link ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_outbound_react6.OutboundLink, { href: said2.link, className: "text-primary underline", children: said2.link }) : null
|
|
8256
|
+
] }) : null,
|
|
8257
|
+
said2?.kind === "needs" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
|
|
8258
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("p", { children: said2.says }),
|
|
8259
|
+
tableId ? /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
|
|
8260
|
+
import_design_system32.Button,
|
|
8261
|
+
{
|
|
8262
|
+
type: "button",
|
|
8263
|
+
size: "sm",
|
|
8264
|
+
"data-records-button-set-up": "",
|
|
8265
|
+
onClick: () => {
|
|
8266
|
+
setSaid(null);
|
|
8267
|
+
setSettingUp(true);
|
|
8268
|
+
},
|
|
8269
|
+
children: [
|
|
8270
|
+
"Set up ",
|
|
8271
|
+
b.label
|
|
8272
|
+
]
|
|
8273
|
+
}
|
|
8274
|
+
) : null
|
|
8275
|
+
] }) : null
|
|
8276
|
+
] })
|
|
8277
|
+
]
|
|
8278
|
+
}
|
|
8279
|
+
),
|
|
8226
8280
|
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
8281
|
/* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_design_system32.DialogHeader, { children: [
|
|
8228
8282
|
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(import_design_system32.DialogTitle, { children: `Column settings \xB7 ${fieldName(field)}` }),
|