@panneau/actions 5.0.0-alpha.17 → 5.0.0-alpha.18
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/README.md +4 -2
- package/dist/ActionRunnerProvider.d.ts.map +1 -1
- package/dist/ActionRunnerProvider.js +260 -171
- package/dist/ActionRunnerProvider.js.map +1 -1
- package/dist/ActionRuns.d.ts.map +1 -1
- package/dist/ActionRuns.js +49 -36
- package/dist/ActionRuns.js.map +1 -1
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/describe.d.ts +19 -3
- package/dist/describe.d.ts.map +1 -1
- package/dist/describe.js +42 -4
- package/dist/describe.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -63,12 +63,14 @@ function Pages() {
|
|
|
63
63
|
- **`server` actions:**
|
|
64
64
|
1. asks for the parameters (`fields`, in their `layout`) in a dialog, with the forms of `@panneau/forms`: client validation, then the `422` errors of the action endpoint on the fields;
|
|
65
65
|
2. runs the action through the adapter, with the item or the selection (`ids`, or the list query with exceptions), or nothing for the resource;
|
|
66
|
-
3. shows the result in a toast: its `message`, the counts of what didn't succeed, and a "Details" button that lists those items with their message or reason;
|
|
66
|
+
3. shows the result in a toast that names what it was done to (the item by the `itemTitle` of its resource, or the count of items): its `message`, the counts of what didn't succeed, and a "Details" button that lists those items with their message or reason. One toast per action and target: running it again replaces it ([decision 0062](../../docs/decisions/0062-toasts.md));
|
|
67
67
|
4. calls `onResult` (refresh what it changed), opens the `download`, and goes to the `redirect`.
|
|
68
|
-
- **Queued runs** (`202`):
|
|
68
|
+
- **Queued runs** (`202`): no toast when they start (the runs button of the shell shows them), the runner checks the run every `pollInterval` until it ends, then shows its result as above, unless `ActionRuns` is on screen and the result says nothing more than its status. `ActionRuns` lists the runs, with their progress, a button to cancel them (when the adapter has `cancelActionRun()`), and one to dismiss them once they have ended.
|
|
69
69
|
- **`link` actions** go to their `url` (with `{id}`) or `route`, through `onNavigate`.
|
|
70
70
|
- **`client` actions** render the handler that their `component` names: one of `clientActions`, or of the plugins of `PanneauProvider` (`definePlugin({ actions: { 'share-dialog': ShareDialog } })`). It gets `ClientActionProps`, and ends with `onDone(result?)` or `onCancel()`.
|
|
71
71
|
|
|
72
|
+
**Undo** ([decision 0063](../../docs/decisions/0063-undo-instead-of-a-confirmation.md)). When a result has an `undo`, its toast has "Undo" for about 10 seconds: the runner runs that action of the resource on the items it lists, with its `params`, refreshes through `onResult`, and replaces the toast with a short one that says it was undone (or that it failed). The result of a queued run has no "Undo".
|
|
73
|
+
|
|
72
74
|
**Dry runs.** `useActionPreview(resource)` is a list's `previewAction`. For an action that declares `dryRun`, on every item matching a query ("Select all N items"), it asks the backend what the action would do without running it (`"dryRun": true`), so that the list's confirmation says how many items will really be skipped: the list only knows the abilities of the current page. `previewAction(adapter, resource, target)` does the same outside of React.
|
|
73
75
|
|
|
74
76
|
The function resolves with what happened (`{ status: 'done', result }`, `{ status: 'queued', run }` or `{ status: 'navigated', to }`), with `false` when the user cancelled the parameters (a list then keeps its selection), and rejects when the action failed (a list then shows it in a toast).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRunnerProvider.d.ts","sourceRoot":"","sources":["../src/ActionRunnerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA+C,MAAM,OAAO,CAAC;AAIpF,OAAO,KAAK,EAAE,YAAY,EAAa,cAAc,EAAE,MAAM,mBAAmB,CAAC;AASjF,OAAO,KAAK,EACR,aAAa,EACb,cAAc,EAEd,mBAAmB,EAEnB,mBAAmB,EAEtB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,yBAAyB;IACtC,gFAAgF;IAChF,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EA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IACnD,gFAAgF;IAChF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,oFAAoF;IACpF,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAC9D,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAmCD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,EACjC,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAuB,EACvB,UAAyB,EACzB,aAAa,EACb,YAAmB,EACnB,OAAO,GACV,EAAE,yBAAyB,+BAgY3B"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { messages } from "./messages.js";
|
|
2
2
|
import { ParametersDialog } from "./ParametersDialog.js";
|
|
3
|
-
import { buildActionRequest, getLinkTarget, isFinished } from "./request.js";
|
|
4
|
-
import { describeResult } from "./describe.js";
|
|
3
|
+
import { buildActionRequest, getLinkTarget, getResultCounts, isFinished } from "./request.js";
|
|
4
|
+
import { describeResult, describeSubject } from "./describe.js";
|
|
5
5
|
import { ResultsDialog } from "./ResultsDialog.js";
|
|
6
6
|
import { ActionRunnerContext } from "./context.js";
|
|
7
7
|
import { c } from "react/compiler-runtime";
|
|
8
8
|
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
|
9
|
-
import {
|
|
9
|
+
import { usePanneau } from "@panneau/core";
|
|
10
10
|
import { getActionLabel } from "@panneau/intl";
|
|
11
11
|
import { usePanneauIntl, useToast } from "@panneau/ui";
|
|
12
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -33,14 +33,14 @@ function openDownload(download) {
|
|
|
33
33
|
* that runs are followed from page to page. `useActionRunner(resource)` runs an action.
|
|
34
34
|
*/
|
|
35
35
|
function ActionRunnerProvider(t0) {
|
|
36
|
-
const $ = c(
|
|
36
|
+
const $ = c(67);
|
|
37
37
|
const { adapter, children, onResult, onNavigate: t1, onDownload: t2, clientActions, pollInterval: t3, locales } = t0;
|
|
38
38
|
const onNavigate = t1 === void 0 ? navigateTo : t1;
|
|
39
39
|
const onDownload = t2 === void 0 ? openDownload : t2;
|
|
40
40
|
const pollInterval = t3 === void 0 ? 2e3 : t3;
|
|
41
41
|
const intl = usePanneauIntl();
|
|
42
42
|
const toasts = useToast();
|
|
43
|
-
const plugins =
|
|
43
|
+
const { definition, plugins } = usePanneau();
|
|
44
44
|
const [parameters, setParameters] = useState(null);
|
|
45
45
|
const [client, setClient] = useState(null);
|
|
46
46
|
const [details, setDetails] = useState(null);
|
|
@@ -56,148 +56,222 @@ function ActionRunnerProvider(t0) {
|
|
|
56
56
|
$[1] = t5;
|
|
57
57
|
} else t5 = $[1];
|
|
58
58
|
const notified = useRef(t5);
|
|
59
|
+
const watchers = useRef(0);
|
|
59
60
|
let t6;
|
|
60
|
-
if ($[2] !==
|
|
61
|
-
t6 =
|
|
61
|
+
if ($[2] !== definition?.resources || $[3] !== intl) {
|
|
62
|
+
t6 = (resource, target, t7) => {
|
|
63
|
+
const count = t7 === void 0 ? null : t7;
|
|
64
|
+
return describeSubject(target, definition?.resources.find((candidate) => candidate.id === resource), intl, count);
|
|
65
|
+
};
|
|
66
|
+
$[2] = definition?.resources;
|
|
67
|
+
$[3] = intl;
|
|
68
|
+
$[4] = t6;
|
|
69
|
+
} else t6 = $[4];
|
|
70
|
+
const subjectOf = t6;
|
|
71
|
+
const toastKey = _temp;
|
|
72
|
+
let finish;
|
|
73
|
+
let follow;
|
|
74
|
+
if ($[5] !== adapter || $[6] !== definition?.resources || $[7] !== intl || $[8] !== onDownload || $[9] !== onNavigate || $[10] !== onResult || $[11] !== subjectOf || $[12] !== toasts) {
|
|
75
|
+
finish = async (resource_1, target_1, result, t7) => {
|
|
76
|
+
const { queued: t8 } = t7 === void 0 ? {} : t7;
|
|
77
|
+
const queued = t8 === void 0 ? false : t8;
|
|
62
78
|
await onResult?.(result, {
|
|
63
|
-
resource,
|
|
64
|
-
target
|
|
79
|
+
resource: resource_1,
|
|
80
|
+
target: target_1
|
|
65
81
|
});
|
|
66
|
-
const
|
|
82
|
+
const counts = getResultCounts(result);
|
|
83
|
+
const content = describeResult(result, getActionLabel(target_1.action, intl), intl, subjectOf(resource_1, target_1, counts.succeeded));
|
|
67
84
|
const hasDetails = (result.results ?? []).length > 0;
|
|
68
85
|
const download = result.download ?? null;
|
|
69
86
|
if (download !== null) onDownload(download);
|
|
87
|
+
const redirect = result.redirect ?? null;
|
|
88
|
+
const saysMore = (result.message ?? "") !== "" || hasDetails || download !== null;
|
|
89
|
+
if (queued && watchers.current > 0 && !saysMore) {
|
|
90
|
+
if (redirect !== null) onNavigate(redirect);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const undo = !queued ? result.undo ?? null : null;
|
|
70
94
|
toasts.show({
|
|
71
95
|
...content,
|
|
72
|
-
...
|
|
96
|
+
...undo !== null ? { action: {
|
|
97
|
+
label: intl.formatMessage(messages.undo),
|
|
98
|
+
onAction: () => void runUndo(resource_1, target_1, undo)
|
|
99
|
+
} } : hasDetails ? { action: {
|
|
73
100
|
label: intl.formatMessage(messages.details),
|
|
74
101
|
onAction: () => setDetails({
|
|
75
|
-
label: getActionLabel(
|
|
102
|
+
label: getActionLabel(target_1.action, intl),
|
|
76
103
|
result
|
|
77
104
|
})
|
|
78
105
|
} } : download !== null ? { action: {
|
|
79
106
|
label: intl.formatMessage(messages.download),
|
|
80
107
|
onAction: () => onDownload(download)
|
|
81
108
|
} } : {}
|
|
82
|
-
});
|
|
83
|
-
const redirect = result.redirect ?? null;
|
|
109
|
+
}, { key: toastKey(resource_1, target_1) });
|
|
84
110
|
if (redirect !== null) onNavigate(redirect);
|
|
85
111
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
const runUndo = async (resource_2, target_2, undo_0) => {
|
|
113
|
+
const label = getActionLabel(target_2.action, intl);
|
|
114
|
+
const key = { key: toastKey(resource_2, target_2) };
|
|
115
|
+
const undoTarget = {
|
|
116
|
+
action: definition?.resources.find((candidate_0) => candidate_0.id === resource_2)?.actions?.find((action) => action.id === undo_0.action) ?? {
|
|
117
|
+
id: undo_0.action,
|
|
118
|
+
kind: "server",
|
|
119
|
+
scope: ["selection"]
|
|
120
|
+
},
|
|
121
|
+
scope: "selection",
|
|
122
|
+
selection: { ids: undo_0.items },
|
|
123
|
+
count: undo_0.items.length
|
|
124
|
+
};
|
|
125
|
+
await adapter.runAction(resource_2, undo_0.action, {
|
|
126
|
+
selection: { ids: undo_0.items },
|
|
127
|
+
values: undo_0.params ?? {}
|
|
128
|
+
}).then(async (response) => {
|
|
129
|
+
if (response.run !== void 0) {
|
|
130
|
+
follow(resource_2, undoTarget, response.run);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
await onResult?.(response.result, {
|
|
134
|
+
resource: resource_2,
|
|
135
|
+
target: undoTarget
|
|
136
|
+
});
|
|
137
|
+
const subject = subjectOf(resource_2, target_2, undo_0.items.length);
|
|
138
|
+
toasts.show({ title: subject !== null ? intl.formatMessage(messages.undoneFor, {
|
|
139
|
+
action: label,
|
|
140
|
+
subject
|
|
141
|
+
}) : intl.formatMessage(messages.undone, { action: label }) }, key);
|
|
142
|
+
}).catch((error) => {
|
|
143
|
+
toasts.show({
|
|
144
|
+
title: intl.formatMessage(messages.undoFailed, { action: label }),
|
|
145
|
+
...error instanceof Error && error.message !== "" ? { description: error.message } : {},
|
|
146
|
+
tone: "danger"
|
|
147
|
+
}, key);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
follow = (resource_3, target_3, run) => {
|
|
97
151
|
setRuns((current) => [...current.filter((entry) => entry.run.id !== run.id), {
|
|
98
152
|
run,
|
|
99
|
-
resource:
|
|
100
|
-
target:
|
|
153
|
+
resource: resource_3,
|
|
154
|
+
target: target_3
|
|
101
155
|
}]);
|
|
102
|
-
toasts.show({
|
|
103
|
-
title: intl.formatMessage(messages.queued, { action: getActionLabel(target_0.action, intl) }),
|
|
104
|
-
description: intl.formatMessage(messages.queuedDescription),
|
|
105
|
-
tone: "info"
|
|
106
|
-
});
|
|
107
156
|
};
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
110
|
-
$[
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
157
|
+
$[5] = adapter;
|
|
158
|
+
$[6] = definition?.resources;
|
|
159
|
+
$[7] = intl;
|
|
160
|
+
$[8] = onDownload;
|
|
161
|
+
$[9] = onNavigate;
|
|
162
|
+
$[10] = onResult;
|
|
163
|
+
$[11] = subjectOf;
|
|
164
|
+
$[12] = toasts;
|
|
165
|
+
$[13] = finish;
|
|
166
|
+
$[14] = follow;
|
|
167
|
+
} else {
|
|
168
|
+
finish = $[13];
|
|
169
|
+
follow = $[14];
|
|
170
|
+
}
|
|
171
|
+
let t7;
|
|
172
|
+
if ($[15] !== finish || $[16] !== intl || $[17] !== subjectOf || $[18] !== toasts) {
|
|
173
|
+
t7 = async (entry_0) => {
|
|
174
|
+
const { run: run_0, resource: resource_4, target: target_4 } = entry_0;
|
|
117
175
|
if (notified.current.has(run_0.id)) return;
|
|
118
176
|
notified.current.add(run_0.id);
|
|
119
|
-
if (run_0.result !== void 0)
|
|
120
|
-
|
|
177
|
+
if (run_0.result !== void 0) {
|
|
178
|
+
await finish(resource_4, target_4, run_0.result, { queued: true });
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const action_0 = getActionLabel(target_4.action, intl);
|
|
182
|
+
const subject_0 = subjectOf(resource_4, target_4);
|
|
183
|
+
const key_0 = { key: toastKey(resource_4, target_4) };
|
|
184
|
+
if (run_0.status === "cancelled") toasts.show({ title: subject_0 !== null ? intl.formatMessage(messages.cancelledFor, {
|
|
185
|
+
action: action_0,
|
|
186
|
+
subject: subject_0
|
|
187
|
+
}) : intl.formatMessage(messages.cancelled, { action: action_0 }) }, key_0);
|
|
121
188
|
else if (run_0.status === "failed") toasts.show({
|
|
122
|
-
title: intl.formatMessage(messages.
|
|
189
|
+
title: subject_0 !== null ? intl.formatMessage(messages.failedFor, {
|
|
190
|
+
action: action_0,
|
|
191
|
+
subject: subject_0
|
|
192
|
+
}) : intl.formatMessage(messages.failed, { action: action_0 }),
|
|
123
193
|
tone: "danger"
|
|
124
|
-
});
|
|
125
|
-
else toasts.show({
|
|
126
|
-
title: intl.formatMessage(messages.
|
|
194
|
+
}, key_0);
|
|
195
|
+
else if (watchers.current === 0) toasts.show({
|
|
196
|
+
title: subject_0 !== null ? intl.formatMessage(messages.doneFor, {
|
|
197
|
+
action: action_0,
|
|
198
|
+
subject: subject_0
|
|
199
|
+
}) : intl.formatMessage(messages.done, { action: action_0 }),
|
|
127
200
|
tone: "success"
|
|
128
|
-
});
|
|
201
|
+
}, key_0);
|
|
129
202
|
};
|
|
130
|
-
$[
|
|
131
|
-
$[
|
|
132
|
-
$[
|
|
133
|
-
$[
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
203
|
+
$[15] = finish;
|
|
204
|
+
$[16] = intl;
|
|
205
|
+
$[17] = subjectOf;
|
|
206
|
+
$[18] = toasts;
|
|
207
|
+
$[19] = t7;
|
|
208
|
+
} else t7 = $[19];
|
|
209
|
+
const ended = t7;
|
|
210
|
+
let t8;
|
|
211
|
+
if ($[20] !== adapter || $[21] !== finish || $[22] !== follow) {
|
|
212
|
+
t8 = async (resource_5, target_5, t9) => {
|
|
213
|
+
const values = t9 === void 0 ? {} : t9;
|
|
214
|
+
const response_0 = await adapter.runAction(resource_5, target_5.action.id, buildActionRequest(target_5, values));
|
|
215
|
+
if (response_0.run !== void 0) {
|
|
216
|
+
follow(resource_5, target_5, response_0.run);
|
|
143
217
|
return {
|
|
144
218
|
status: "queued",
|
|
145
|
-
run:
|
|
219
|
+
run: response_0.run
|
|
146
220
|
};
|
|
147
221
|
}
|
|
148
|
-
await finish(
|
|
222
|
+
await finish(resource_5, target_5, response_0.result);
|
|
149
223
|
return {
|
|
150
224
|
status: "done",
|
|
151
|
-
result:
|
|
225
|
+
result: response_0.result
|
|
152
226
|
};
|
|
153
227
|
};
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
158
|
-
} else
|
|
159
|
-
const execute =
|
|
160
|
-
let
|
|
161
|
-
if ($[
|
|
162
|
-
|
|
163
|
-
const { action } =
|
|
164
|
-
if (
|
|
165
|
-
const to = getLinkTarget(
|
|
166
|
-
if (to === null) return Promise.reject(/* @__PURE__ */ new Error(`The action "${
|
|
228
|
+
$[20] = adapter;
|
|
229
|
+
$[21] = finish;
|
|
230
|
+
$[22] = follow;
|
|
231
|
+
$[23] = t8;
|
|
232
|
+
} else t8 = $[23];
|
|
233
|
+
const execute = t8;
|
|
234
|
+
let t9;
|
|
235
|
+
if ($[24] !== clientActions || $[25] !== execute || $[26] !== onNavigate || $[27] !== plugins) {
|
|
236
|
+
t9 = (resource_6, target_6) => {
|
|
237
|
+
const { action: action_1 } = target_6;
|
|
238
|
+
if (action_1.kind === "link") {
|
|
239
|
+
const to = getLinkTarget(target_6);
|
|
240
|
+
if (to === null) return Promise.reject(/* @__PURE__ */ new Error(`The action "${action_1.id}" has no URL or route.`));
|
|
167
241
|
onNavigate(to);
|
|
168
242
|
return Promise.resolve({
|
|
169
243
|
status: "navigated",
|
|
170
244
|
to
|
|
171
245
|
});
|
|
172
246
|
}
|
|
173
|
-
if (
|
|
174
|
-
const name =
|
|
247
|
+
if (action_1.kind === "client") {
|
|
248
|
+
const name = action_1.component ?? "";
|
|
175
249
|
const Handler = (clientActions !== void 0 && Object.hasOwn(clientActions, name) ? clientActions[name] : void 0) ?? plugins.actions.get(name);
|
|
176
|
-
if (Handler === void 0) return Promise.reject(/* @__PURE__ */ new Error(`No handler for the client action "${
|
|
250
|
+
if (Handler === void 0) return Promise.reject(/* @__PURE__ */ new Error(`No handler for the client action "${action_1.id}" (${name}).`));
|
|
177
251
|
return new Promise((resolve) => setClient({
|
|
178
|
-
resource:
|
|
179
|
-
target:
|
|
252
|
+
resource: resource_6,
|
|
253
|
+
target: target_6,
|
|
180
254
|
resolve,
|
|
181
255
|
Handler
|
|
182
256
|
}));
|
|
183
257
|
}
|
|
184
|
-
if ((
|
|
185
|
-
resource:
|
|
186
|
-
target:
|
|
258
|
+
if ((action_1.fields ?? []).length > 0) return new Promise((resolve_0) => setParameters({
|
|
259
|
+
resource: resource_6,
|
|
260
|
+
target: target_6,
|
|
187
261
|
resolve: resolve_0
|
|
188
262
|
}));
|
|
189
|
-
return execute(
|
|
263
|
+
return execute(resource_6, target_6);
|
|
190
264
|
};
|
|
191
|
-
$[
|
|
192
|
-
$[
|
|
193
|
-
$[
|
|
194
|
-
$[
|
|
195
|
-
$[
|
|
196
|
-
} else
|
|
197
|
-
const run_1 =
|
|
198
|
-
let
|
|
199
|
-
if ($[
|
|
200
|
-
|
|
265
|
+
$[24] = clientActions;
|
|
266
|
+
$[25] = execute;
|
|
267
|
+
$[26] = onNavigate;
|
|
268
|
+
$[27] = plugins;
|
|
269
|
+
$[28] = t9;
|
|
270
|
+
} else t9 = $[28];
|
|
271
|
+
const run_1 = t9;
|
|
272
|
+
let t10;
|
|
273
|
+
if ($[29] !== adapter || $[30] !== ended || $[31] !== runs) {
|
|
274
|
+
t10 = async (id) => {
|
|
201
275
|
if (adapter.cancelActionRun === void 0) throw new Error("The adapter cannot cancel runs.");
|
|
202
276
|
await adapter.cancelActionRun(id);
|
|
203
277
|
const updated = await adapter.getActionRun(id);
|
|
@@ -205,35 +279,35 @@ function ActionRunnerProvider(t0) {
|
|
|
205
279
|
...entry_1,
|
|
206
280
|
run: updated
|
|
207
281
|
} : entry_1));
|
|
208
|
-
const entry_2 = runs.find((
|
|
282
|
+
const entry_2 = runs.find((candidate_1) => candidate_1.run.id === id);
|
|
209
283
|
if (entry_2 !== void 0 && isFinished(updated.status)) await ended({
|
|
210
284
|
...entry_2,
|
|
211
285
|
run: updated
|
|
212
286
|
});
|
|
213
287
|
};
|
|
214
|
-
$[
|
|
215
|
-
$[
|
|
216
|
-
$[
|
|
217
|
-
$[
|
|
218
|
-
} else
|
|
219
|
-
const cancelRun =
|
|
288
|
+
$[29] = adapter;
|
|
289
|
+
$[30] = ended;
|
|
290
|
+
$[31] = runs;
|
|
291
|
+
$[32] = t10;
|
|
292
|
+
} else t10 = $[32];
|
|
293
|
+
const cancelRun = t10;
|
|
294
|
+
let t11;
|
|
295
|
+
if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
|
|
296
|
+
t11 = (id_0) => setRuns((current_1) => current_1.filter((entry_3) => entry_3.run.id !== id_0));
|
|
297
|
+
$[33] = t11;
|
|
298
|
+
} else t11 = $[33];
|
|
299
|
+
const dismissRun = t11;
|
|
220
300
|
let t12;
|
|
221
|
-
if ($[
|
|
222
|
-
t12 = (
|
|
223
|
-
$[
|
|
224
|
-
|
|
225
|
-
|
|
301
|
+
if ($[34] !== ended) {
|
|
302
|
+
t12 = (entry_4) => ended(entry_4);
|
|
303
|
+
$[34] = ended;
|
|
304
|
+
$[35] = t12;
|
|
305
|
+
} else t12 = $[35];
|
|
306
|
+
const onRunEnded = useEffectEvent(t12);
|
|
226
307
|
let t13;
|
|
227
|
-
if ($[
|
|
228
|
-
t13 = (
|
|
229
|
-
|
|
230
|
-
$[30] = t13;
|
|
231
|
-
} else t13 = $[30];
|
|
232
|
-
const onRunEnded = useEffectEvent(t13);
|
|
233
|
-
let t14;
|
|
234
|
-
if ($[31] !== adapter || $[32] !== onRunEnded || $[33] !== pollInterval || $[34] !== runs) {
|
|
235
|
-
t14 = () => {
|
|
236
|
-
const active = runs.filter(_temp);
|
|
308
|
+
if ($[36] !== adapter || $[37] !== onRunEnded || $[38] !== pollInterval || $[39] !== runs) {
|
|
309
|
+
t13 = () => {
|
|
310
|
+
const active = runs.filter(_temp2);
|
|
237
311
|
if (active.length === 0) return;
|
|
238
312
|
let stopped = false;
|
|
239
313
|
const timer = setTimeout(() => {
|
|
@@ -241,16 +315,16 @@ function ActionRunnerProvider(t0) {
|
|
|
241
315
|
try {
|
|
242
316
|
const next = await adapter.getActionRun(entry_6.run.id);
|
|
243
317
|
if (stopped) return;
|
|
244
|
-
setRuns((current_3) => current_3.map((
|
|
245
|
-
...
|
|
318
|
+
setRuns((current_3) => current_3.map((candidate_2) => candidate_2.run.id === next.id ? {
|
|
319
|
+
...candidate_2,
|
|
246
320
|
run: next
|
|
247
|
-
} :
|
|
321
|
+
} : candidate_2));
|
|
248
322
|
if (isFinished(next.status)) await onRunEnded({
|
|
249
323
|
...entry_6,
|
|
250
324
|
run: next
|
|
251
325
|
});
|
|
252
326
|
} catch {
|
|
253
|
-
if (!stopped) setRuns(
|
|
327
|
+
if (!stopped) setRuns(_temp3);
|
|
254
328
|
}
|
|
255
329
|
}));
|
|
256
330
|
}, pollInterval);
|
|
@@ -259,44 +333,56 @@ function ActionRunnerProvider(t0) {
|
|
|
259
333
|
clearTimeout(timer);
|
|
260
334
|
};
|
|
261
335
|
};
|
|
262
|
-
$[
|
|
263
|
-
$[
|
|
264
|
-
$[
|
|
265
|
-
$[
|
|
266
|
-
$[
|
|
267
|
-
} else
|
|
268
|
-
let
|
|
269
|
-
if ($[
|
|
270
|
-
|
|
336
|
+
$[36] = adapter;
|
|
337
|
+
$[37] = onRunEnded;
|
|
338
|
+
$[38] = pollInterval;
|
|
339
|
+
$[39] = runs;
|
|
340
|
+
$[40] = t13;
|
|
341
|
+
} else t13 = $[40];
|
|
342
|
+
let t14;
|
|
343
|
+
if ($[41] !== adapter || $[42] !== pollInterval || $[43] !== runs) {
|
|
344
|
+
t14 = [
|
|
271
345
|
runs,
|
|
272
346
|
adapter,
|
|
273
347
|
pollInterval
|
|
274
348
|
];
|
|
275
|
-
$[
|
|
276
|
-
$[
|
|
277
|
-
$[
|
|
278
|
-
$[
|
|
279
|
-
} else
|
|
280
|
-
useEffect(
|
|
349
|
+
$[41] = adapter;
|
|
350
|
+
$[42] = pollInterval;
|
|
351
|
+
$[43] = runs;
|
|
352
|
+
$[44] = t14;
|
|
353
|
+
} else t14 = $[44];
|
|
354
|
+
useEffect(t13, t14);
|
|
355
|
+
let t15;
|
|
356
|
+
if ($[45] === Symbol.for("react.memo_cache_sentinel")) {
|
|
357
|
+
t15 = () => {
|
|
358
|
+
watchers.current = watchers.current + 1;
|
|
359
|
+
return () => {
|
|
360
|
+
watchers.current = watchers.current - 1;
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
$[45] = t15;
|
|
364
|
+
} else t15 = $[45];
|
|
365
|
+
const watchRuns = t15;
|
|
281
366
|
let t16;
|
|
282
|
-
if ($[
|
|
367
|
+
if ($[46] !== adapter || $[47] !== cancelRun || $[48] !== run_1 || $[49] !== runs) {
|
|
283
368
|
t16 = {
|
|
284
369
|
adapter,
|
|
285
370
|
run: run_1,
|
|
286
371
|
runs,
|
|
287
372
|
cancelRun,
|
|
288
|
-
dismissRun
|
|
373
|
+
dismissRun,
|
|
374
|
+
watchRuns
|
|
289
375
|
};
|
|
290
|
-
$[
|
|
291
|
-
$[
|
|
292
|
-
$[
|
|
293
|
-
$[
|
|
294
|
-
$[
|
|
295
|
-
} else t16 = $[
|
|
376
|
+
$[46] = adapter;
|
|
377
|
+
$[47] = cancelRun;
|
|
378
|
+
$[48] = run_1;
|
|
379
|
+
$[49] = runs;
|
|
380
|
+
$[50] = t16;
|
|
381
|
+
} else t16 = $[50];
|
|
296
382
|
const value = t16;
|
|
297
383
|
const ClientHandler = client?.Handler;
|
|
298
384
|
let t17;
|
|
299
|
-
if ($[
|
|
385
|
+
if ($[51] !== execute || $[52] !== locales || $[53] !== parameters) {
|
|
300
386
|
t17 = parameters !== null ? /* @__PURE__ */ jsx(ParametersDialog, {
|
|
301
387
|
action: parameters.target.action,
|
|
302
388
|
count: parameters.target.count,
|
|
@@ -311,13 +397,13 @@ function ActionRunnerProvider(t0) {
|
|
|
311
397
|
parameters.resolve(false);
|
|
312
398
|
}
|
|
313
399
|
}) : null;
|
|
314
|
-
$[
|
|
315
|
-
$[
|
|
316
|
-
$[
|
|
317
|
-
$[
|
|
318
|
-
} else t17 = $[
|
|
400
|
+
$[51] = execute;
|
|
401
|
+
$[52] = locales;
|
|
402
|
+
$[53] = parameters;
|
|
403
|
+
$[54] = t17;
|
|
404
|
+
} else t17 = $[54];
|
|
319
405
|
let t18;
|
|
320
|
-
if ($[
|
|
406
|
+
if ($[55] !== ClientHandler || $[56] !== client || $[57] !== finish) {
|
|
321
407
|
t18 = client !== null && ClientHandler !== void 0 ? /* @__PURE__ */ jsx(ClientHandler, {
|
|
322
408
|
action: client.target.action,
|
|
323
409
|
resource: client.resource,
|
|
@@ -341,23 +427,23 @@ function ActionRunnerProvider(t0) {
|
|
|
341
427
|
client.resolve(false);
|
|
342
428
|
}
|
|
343
429
|
}) : null;
|
|
344
|
-
$[
|
|
345
|
-
$[
|
|
346
|
-
$[
|
|
347
|
-
$[
|
|
348
|
-
} else t18 = $[
|
|
430
|
+
$[55] = ClientHandler;
|
|
431
|
+
$[56] = client;
|
|
432
|
+
$[57] = finish;
|
|
433
|
+
$[58] = t18;
|
|
434
|
+
} else t18 = $[58];
|
|
349
435
|
let t19;
|
|
350
|
-
if ($[
|
|
436
|
+
if ($[59] !== details) {
|
|
351
437
|
t19 = details !== null ? /* @__PURE__ */ jsx(ResultsDialog, {
|
|
352
438
|
label: details.label,
|
|
353
439
|
result: details.result,
|
|
354
440
|
onClose: () => setDetails(null)
|
|
355
441
|
}) : null;
|
|
356
|
-
$[
|
|
357
|
-
$[
|
|
358
|
-
} else t19 = $[
|
|
442
|
+
$[59] = details;
|
|
443
|
+
$[60] = t19;
|
|
444
|
+
} else t19 = $[60];
|
|
359
445
|
let t20;
|
|
360
|
-
if ($[
|
|
446
|
+
if ($[61] !== children || $[62] !== t17 || $[63] !== t18 || $[64] !== t19 || $[65] !== value) {
|
|
361
447
|
t20 = /* @__PURE__ */ jsxs(ActionRunnerContext, {
|
|
362
448
|
value,
|
|
363
449
|
children: [
|
|
@@ -367,21 +453,24 @@ function ActionRunnerProvider(t0) {
|
|
|
367
453
|
t19
|
|
368
454
|
]
|
|
369
455
|
});
|
|
370
|
-
$[
|
|
371
|
-
$[
|
|
372
|
-
$[
|
|
373
|
-
$[
|
|
374
|
-
$[
|
|
375
|
-
$[
|
|
376
|
-
} else t20 = $[
|
|
456
|
+
$[61] = children;
|
|
457
|
+
$[62] = t17;
|
|
458
|
+
$[63] = t18;
|
|
459
|
+
$[64] = t19;
|
|
460
|
+
$[65] = value;
|
|
461
|
+
$[66] = t20;
|
|
462
|
+
} else t20 = $[66];
|
|
377
463
|
return t20;
|
|
378
464
|
}
|
|
379
|
-
function
|
|
465
|
+
function _temp3(current_2) {
|
|
380
466
|
return [...current_2];
|
|
381
467
|
}
|
|
382
|
-
function
|
|
468
|
+
function _temp2(entry_5) {
|
|
383
469
|
return !isFinished(entry_5.run.status);
|
|
384
470
|
}
|
|
471
|
+
function _temp(resource_0, target_0) {
|
|
472
|
+
return `panneau-action:${resource_0}:${target_0.action.id}:${target_0.item?.id ?? "selection"}`;
|
|
473
|
+
}
|
|
385
474
|
//#endregion
|
|
386
475
|
export { ActionRunnerProvider };
|
|
387
476
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRunnerProvider.js","names":["ReactNode","useEffect","useEffectEvent","useRef","useState","usePlugins","getActionLabel","ActionResult","ActionRun","RouteReference","usePanneauIntl","useToast","ParametersDialog","ResultsDialog","ActionRunnerContext","ActionRunnerContextValue","describeResult","messages","buildActionRequest","getLinkTarget","isFinished","ActionAdapter","ActionDownload","ActionOutcome","ActionResultContext","ActionTarget","ClientActionHandler","FollowedRun","ActionRunnerProviderProps","adapter","children","onResult","result","context","onNavigate","to","onDownload","download","clientActions","Readonly","Record","pollInterval","locales","Pending","resource","target","resolve","outcome","ClientPending","Handler","navigateTo","window","location","assign","console","warn","route","openDownload","link","document","createElement","href","url","filename","undefined","rel","hidden","body","append","click","remove","ActionRunnerProvider","t0","$","_c","t1","t2","t3","intl","toasts","plugins","parameters","setParameters","client","setClient","details","setDetails","t4","Symbol","for","runs","setRuns","t5","Set","notified","t6","content","action","hasDetails","results","length","show","label","formatMessage","onAction","redirect","finish","t7","resource_0","target_0","run","current","filter","entry","id","title","queued","description","queuedDescription","tone","follow","t8","entry_0","run_0","resource_1","target_1","has","add","status","cancelled","failed","done","ended","t9","resource_2","target_2","t10","values","response","runAction","execute","resource_3","target_3","kind","Promise","reject","Error","name","component","Object","hasOwn","actions","get","fields","resolve_0","run_1","t11","cancelActionRun","updated","getActionRun","current_0","map","entry_1","entry_2","find","candidate","cancelRun","t12","id_0","current_1","entry_3","dismissRun","t13","entry_4","onRunEnded","t14","active","_temp","stopped","timer","setTimeout","all","entry_6","next","current_3","candidate_0","_temp2","clearTimeout","t15","t16","value","ClientHandler","t17","count","values_0","t18","result_0","then","t19","t20","current_2","entry_5","_c"],"sources":["../src/ActionRunnerProvider.tsx"],"sourcesContent":["import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from 'react';\n\nimport { usePlugins } from '@panneau/core';\nimport { getActionLabel } from '@panneau/intl';\nimport type { ActionResult, ActionRun, RouteReference } from '@panneau/protocol';\nimport { usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ParametersDialog } from './ParametersDialog';\nimport { ResultsDialog } from './ResultsDialog';\nimport { ActionRunnerContext, type ActionRunnerContextValue } from './context';\nimport { describeResult } from './describe';\nimport { messages } from './messages';\nimport { buildActionRequest, getLinkTarget, isFinished } from './request';\nimport type {\n ActionAdapter,\n ActionDownload,\n ActionOutcome,\n ActionResultContext,\n ActionTarget,\n ClientActionHandler,\n FollowedRun,\n} from './types';\n\nexport interface ActionRunnerProviderProps {\n /** Runs the actions: a `DataAdapter`, or any object with its action methods. */\n adapter: ActionAdapter;\n children?: ReactNode;\n /**\n * Called with every result: of an action that finished at once, and of a queued run when it\n * finishes. Refresh what it changed here. With `@panneau/data/query`:\n * `invalidateActionResult(client, resource, result, target.selection)`.\n */\n onResult?: (result: ActionResult, context: ActionResultContext) => unknown;\n /**\n * Goes to the `redirect` of a result, or to the URL or route of a `link` action. Defaults to\n * `window.location.assign()` for URLs; routes need it.\n */\n onNavigate?: (to: string | RouteReference) => void;\n /** Opens the `download` of a result. Defaults to a link to its URL, clicked. */\n onDownload?: (download: ActionDownload) => void;\n /** Handlers of `client` actions by their `component`, over those of the plugins. */\n clientActions?: Readonly<Record<string, ClientActionHandler>>;\n /** Milliseconds between two checks of a queued run. Defaults to 2000. */\n pollInterval?: number;\n /** Locales of localized parameters. Defaults to the definition's. */\n locales?: readonly string[];\n}\n\ninterface Pending {\n resource: string;\n target: ActionTarget;\n resolve: (outcome: ActionOutcome | false) => void;\n}\n\ninterface ClientPending extends Pending {\n Handler: ClientActionHandler;\n}\n\nfunction navigateTo(to: string | RouteReference) {\n if (typeof to === 'string') {\n window.location.assign(to);\n } else {\n console.warn(\n `[panneau] An action goes to the route \"${to.route}\": give ActionRunnerProvider an onNavigate.`,\n );\n }\n}\n\nfunction openDownload(download: ActionDownload) {\n const link = document.createElement('a');\n link.href = download.url;\n if (download.filename !== undefined) {\n link.download = download.filename;\n }\n link.rel = 'noopener';\n link.hidden = true;\n document.body.append(link);\n link.click();\n link.remove();\n}\n\n/**\n * Runs the actions that lists and forms hand over ([decision 0023]): it asks for their parameters\n * in a dialog, runs them through the adapter, shows their result (a toast, and the items that\n * didn't succeed), follows queued runs until they end, refreshes through `onResult`, follows\n * redirects and opens downloads. Put it inside `PanneauRoot`, and above the router of an app, so\n * that runs are followed from page to page. `useActionRunner(resource)` runs an action.\n */\nexport function ActionRunnerProvider({\n adapter,\n children,\n onResult,\n onNavigate = navigateTo,\n onDownload = openDownload,\n clientActions,\n pollInterval = 2000,\n locales,\n}: ActionRunnerProviderProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const plugins = usePlugins();\n const [parameters, setParameters] = useState<Pending | null>(null);\n const [client, setClient] = useState<ClientPending | null>(null);\n const [details, setDetails] = useState<{ label: string; result: ActionResult } | null>(null);\n const [runs, setRuns] = useState<readonly FollowedRun[]>([]);\n // Runs whose end was already shown, so that a late poll doesn't show it twice.\n const notified = useRef(new Set<string>());\n\n const finish = async (resource: string, target: ActionTarget, result: ActionResult) => {\n await onResult?.(result, { resource, target });\n const content = describeResult(result, getActionLabel(target.action, intl), intl);\n const hasDetails = (result.results ?? []).length > 0;\n const download = result.download ?? null;\n if (download !== null) {\n onDownload(download);\n }\n toasts.show({\n ...content,\n ...(hasDetails\n ? {\n action: {\n label: intl.formatMessage(messages.details),\n onAction: () =>\n setDetails({ label: getActionLabel(target.action, intl), result }),\n },\n }\n : download !== null\n ? {\n action: {\n label: intl.formatMessage(messages.download),\n onAction: () => onDownload(download),\n },\n }\n : {}),\n });\n const redirect = result.redirect ?? null;\n if (redirect !== null) {\n onNavigate(redirect);\n }\n };\n\n const follow = (resource: string, target: ActionTarget, run: ActionRun) => {\n setRuns((current) => [\n ...current.filter((entry) => entry.run.id !== run.id),\n { run, resource, target },\n ]);\n toasts.show({\n title: intl.formatMessage(messages.queued, {\n action: getActionLabel(target.action, intl),\n }),\n description: intl.formatMessage(messages.queuedDescription),\n tone: 'info',\n });\n };\n\n const ended = async (entry: FollowedRun) => {\n const { run, resource, target } = entry;\n if (notified.current.has(run.id)) {\n return;\n }\n notified.current.add(run.id);\n if (run.result !== undefined) {\n await finish(resource, target, run.result);\n } else if (run.status === 'cancelled') {\n toasts.show({\n title: intl.formatMessage(messages.cancelled, {\n action: getActionLabel(target.action, intl),\n }),\n });\n } else if (run.status === 'failed') {\n toasts.show({\n title: intl.formatMessage(messages.failed, {\n action: getActionLabel(target.action, intl),\n }),\n tone: 'danger',\n });\n } else {\n toasts.show({\n title: intl.formatMessage(messages.done, {\n action: getActionLabel(target.action, intl),\n }),\n tone: 'success',\n });\n }\n };\n\n const execute = async (\n resource: string,\n target: ActionTarget,\n values: Record<string, unknown> = {},\n ): Promise<ActionOutcome> => {\n const response = await adapter.runAction(\n resource,\n target.action.id,\n buildActionRequest(target, values),\n );\n if (response.run !== undefined) {\n follow(resource, target, response.run);\n return { status: 'queued', run: response.run };\n }\n await finish(resource, target, response.result);\n return { status: 'done', result: response.result };\n };\n\n const run = (resource: string, target: ActionTarget): Promise<ActionOutcome | false> => {\n const { action } = target;\n if (action.kind === 'link') {\n const to = getLinkTarget(target);\n if (to === null) {\n return Promise.reject(new Error(`The action \"${action.id}\" has no URL or route.`));\n }\n onNavigate(to);\n return Promise.resolve({ status: 'navigated', to });\n }\n if (action.kind === 'client') {\n const name = action.component ?? '';\n const Handler =\n (clientActions !== undefined && Object.hasOwn(clientActions, name)\n ? clientActions[name]\n : undefined) ?? (plugins.actions.get(name) as ClientActionHandler | undefined);\n if (Handler === undefined) {\n return Promise.reject(\n new Error(`No handler for the client action \"${action.id}\" (${name}).`),\n );\n }\n return new Promise((resolve) => setClient({ resource, target, resolve, Handler }));\n }\n if ((action.fields ?? []).length > 0) {\n return new Promise((resolve) => setParameters({ resource, target, resolve }));\n }\n return execute(resource, target);\n };\n\n const cancelRun = async (id: string) => {\n if (adapter.cancelActionRun === undefined) {\n throw new Error('The adapter cannot cancel runs.');\n }\n await adapter.cancelActionRun(id);\n const updated = await adapter.getActionRun(id);\n setRuns((current) =>\n current.map((entry) => (entry.run.id === id ? { ...entry, run: updated } : entry)),\n );\n const entry = runs.find((candidate) => candidate.run.id === id);\n if (entry !== undefined && isFinished(updated.status)) {\n await ended({ ...entry, run: updated });\n }\n };\n\n const dismissRun = (id: string) =>\n setRuns((current) => current.filter((entry) => entry.run.id !== id));\n\n const onRunEnded = useEffectEvent((entry: FollowedRun) => ended(entry));\n\n // Checks the unfinished runs, one interval after the last change of the runs.\n useEffect(() => {\n const active = runs.filter((entry) => !isFinished(entry.run.status));\n if (active.length === 0) {\n return undefined;\n }\n let stopped = false;\n const timer = setTimeout(() => {\n void Promise.all(\n active.map(async (entry) => {\n try {\n const next = await adapter.getActionRun(entry.run.id);\n if (stopped) {\n return;\n }\n setRuns((current) =>\n current.map((candidate) =>\n candidate.run.id === next.id\n ? { ...candidate, run: next }\n : candidate,\n ),\n );\n if (isFinished(next.status)) {\n await onRunEnded({ ...entry, run: next });\n }\n } catch {\n // Checked again at the next interval.\n if (!stopped) {\n setRuns((current) => [...current]);\n }\n }\n }),\n );\n }, pollInterval);\n return () => {\n stopped = true;\n clearTimeout(timer);\n };\n }, [runs, adapter, pollInterval]);\n\n const value: ActionRunnerContextValue = { adapter, run, runs, cancelRun, dismissRun };\n\n const ClientHandler = client?.Handler;\n return (\n <ActionRunnerContext value={value}>\n {children}\n {parameters !== null ? (\n <ParametersDialog\n action={parameters.target.action}\n count={parameters.target.count}\n locales={locales}\n onSubmit={(values) => execute(parameters.resource, parameters.target, values)}\n onDone={(outcome) => {\n setParameters(null);\n parameters.resolve(outcome);\n }}\n onCancel={() => {\n setParameters(null);\n parameters.resolve(false);\n }}\n />\n ) : null}\n {client !== null && ClientHandler !== undefined ? (\n <ClientHandler\n action={client.target.action}\n resource={client.resource}\n target={client.target}\n onDone={(result) => {\n setClient(null);\n if (result === undefined) {\n client.resolve({ status: 'done', result: {} });\n return;\n }\n void finish(client.resource, client.target, result).then(() =>\n client.resolve({ status: 'done', result }),\n );\n }}\n onCancel={() => {\n setClient(null);\n client.resolve(false);\n }}\n />\n ) : null}\n {details !== null ? (\n <ResultsDialog\n label={details.label}\n result={details.result}\n onClose={() => setDetails(null)}\n />\n ) : null}\n </ActionRunnerContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA0DA,SAASkD,WAAWf,IAA6B;CAC7C,IAAI,OAAOA,OAAO,UACdgB,OAAOC,SAASC,OAAOlB,EA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AAEA;IAAO,CAAC,CAC7C;GAAC;GAEK,gBAAA;IACNoD,UAAU,IAAI;IACdD,OAAMrC,QAAS,KAAK;GAAC;EACxB,CAAA,IAlBR;EAoBO2B,EAAA,MAAAsH;EAAAtH,EAAA,MAAAU;EAAAV,EAAA,MAAAiC;EAAAjC,EAAA,MAAA0H;CAAA,OAAAA,MAAA1H,EAAA;CAAA,IAAA6H;CAAA,IAAA7H,EAAA,QAAAY,SAAA;EACPiH,MAAAjH,YAAY,OACT,oBAAC,eAAD;GACW,OAAAA,QAAOiB;GACN,QAAAjB,QAAOrD;GACN,eAAMsD,WAAW,IAAI;EAAC,CAAA,IAJtC;EAMOb,EAAA,MAAAY;EAAAZ,EAAA,MAAA6H;CAAA,OAAAA,MAAA7H,EAAA;CAAA,IAAA8H;CAAA,IAAA9H,EAAA,QAAA3C,YAAA2C,EAAA,QAAAuH,OAAAvH,EAAA,QAAA0H,OAAA1H,EAAA,QAAA6H,OAAA7H,EAAA,QAAAqH,OAAA;EA7CZS,MAAA,qBAAC,qBAAD;GAA4BT;GAA5B,UAAA;IACKhK;IACAkK;IAgBAG;IAqBAG;GAvCe;;EA8CE7H,EAAA,MAAA3C;EAAA2C,EAAA,MAAAuH;EAAAvH,EAAA,MAAA0H;EAAA1H,EAAA,MAAA6H;EAAA7H,EAAA,MAAAqH;EAAArH,EAAA,MAAA8H;CAAA,OAAAA,MAAA9H,EAAA;CAAA,OA9CtB8H;AA8CsB;AA/PvB,SAAAb,OAAAc,WAAA;CAAA,OAiM0C,CAAA,GAAIzF,SAAO;AAAC;AAjMtD,SAAAkE,MAAAwB,SAAA;CAAA,OAuKuC,CAACrL,WAAW6F,QAAKH,IAAIkB,MAAO;AAAC"}
|
|
1
|
+
{"version":3,"file":"ActionRunnerProvider.js","names":["ReactNode","useEffect","useEffectEvent","useRef","useState","usePanneau","getActionLabel","ActionResult","ActionRun","RouteReference","usePanneauIntl","useToast","ParametersDialog","ResultsDialog","ActionRunnerContext","ActionRunnerContextValue","describeResult","describeSubject","messages","buildActionRequest","getLinkTarget","getResultCounts","isFinished","ActionAdapter","ActionDownload","ActionOutcome","ActionResultContext","ActionTarget","ClientActionHandler","FollowedRun","ActionRunnerProviderProps","adapter","children","onResult","result","context","onNavigate","to","onDownload","download","clientActions","Readonly","Record","pollInterval","locales","Pending","resource","target","resolve","outcome","ClientPending","Handler","navigateTo","window","location","assign","console","warn","route","openDownload","link","document","createElement","href","url","filename","undefined","rel","hidden","body","append","click","remove","ActionRunnerProvider","t0","$","_c","t1","t2","t3","intl","toasts","definition","plugins","parameters","setParameters","client","setClient","details","setDetails","t4","Symbol","for","runs","setRuns","t5","Set","notified","watchers","t6","resources","t7","count","find","candidate","id","subjectOf","toastKey","_temp","finish","follow","resource_1","target_1","queued","t8","counts","content","action","succeeded","hasDetails","results","length","redirect","saysMore","message","current","undo","show","label","formatMessage","onAction","runUndo","key","resource_2","target_2","undo_0","declared","candidate_0","actions","undoTarget","kind","scope","selection","ids","items","runAction","values","params","then","response","run","subject","title","undoneFor","undone","catch","error","undoFailed","Error","description","tone","resource_3","target_3","filter","entry","entry_0","run_0","resource_4","target_4","has","add","action_0","subject_0","key_0","status","cancelledFor","cancelled","failedFor","failed","doneFor","done","ended","resource_5","target_5","t9","response_0","execute","resource_6","target_6","action_1","Promise","reject","name","component","Object","hasOwn","get","fields","resolve_0","run_1","t10","cancelActionRun","updated","getActionRun","current_0","map","entry_1","entry_2","candidate_1","cancelRun","t11","id_0","current_1","entry_3","dismissRun","t12","entry_4","onRunEnded","t13","active","_temp2","stopped","timer","setTimeout","all","entry_6","next","current_3","candidate_2","_temp3","clearTimeout","t14","t15","watchRuns","t16","value","ClientHandler","t17","values_0","t18","result_0","t19","t20","current_2","entry_5","resource_0","target_0","item","_c"],"sources":["../src/ActionRunnerProvider.tsx"],"sourcesContent":["import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from 'react';\n\nimport { usePanneau } from '@panneau/core';\nimport { getActionLabel } from '@panneau/intl';\nimport type { ActionResult, ActionRun, RouteReference } from '@panneau/protocol';\nimport { usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ParametersDialog } from './ParametersDialog';\nimport { ResultsDialog } from './ResultsDialog';\nimport { ActionRunnerContext, type ActionRunnerContextValue } from './context';\nimport { describeResult, describeSubject } from './describe';\nimport { messages } from './messages';\nimport { buildActionRequest, getLinkTarget, getResultCounts, isFinished } from './request';\nimport type {\n ActionAdapter,\n ActionDownload,\n ActionOutcome,\n ActionResultContext,\n ActionTarget,\n ClientActionHandler,\n FollowedRun,\n} from './types';\n\nexport interface ActionRunnerProviderProps {\n /** Runs the actions: a `DataAdapter`, or any object with its action methods. */\n adapter: ActionAdapter;\n children?: ReactNode;\n /**\n * Called with every result: of an action that finished at once, and of a queued run when it\n * finishes. Refresh what it changed here. With `@panneau/data/query`:\n * `invalidateActionResult(client, resource, result, target.selection)`.\n */\n onResult?: (result: ActionResult, context: ActionResultContext) => unknown;\n /**\n * Goes to the `redirect` of a result, or to the URL or route of a `link` action. Defaults to\n * `window.location.assign()` for URLs; routes need it.\n */\n onNavigate?: (to: string | RouteReference) => void;\n /** Opens the `download` of a result. Defaults to a link to its URL, clicked. */\n onDownload?: (download: ActionDownload) => void;\n /** Handlers of `client` actions by their `component`, over those of the plugins. */\n clientActions?: Readonly<Record<string, ClientActionHandler>>;\n /** Milliseconds between two checks of a queued run. Defaults to 2000. */\n pollInterval?: number;\n /** Locales of localized parameters. Defaults to the definition's. */\n locales?: readonly string[];\n}\n\ninterface Pending {\n resource: string;\n target: ActionTarget;\n resolve: (outcome: ActionOutcome | false) => void;\n}\n\ninterface ClientPending extends Pending {\n Handler: ClientActionHandler;\n}\n\nfunction navigateTo(to: string | RouteReference) {\n if (typeof to === 'string') {\n window.location.assign(to);\n } else {\n console.warn(\n `[panneau] An action goes to the route \"${to.route}\": give ActionRunnerProvider an onNavigate.`,\n );\n }\n}\n\nfunction openDownload(download: ActionDownload) {\n const link = document.createElement('a');\n link.href = download.url;\n if (download.filename !== undefined) {\n link.download = download.filename;\n }\n link.rel = 'noopener';\n link.hidden = true;\n document.body.append(link);\n link.click();\n link.remove();\n}\n\n/**\n * Runs the actions that lists and forms hand over ([decision 0023]): it asks for their parameters\n * in a dialog, runs them through the adapter, shows their result (a toast, and the items that\n * didn't succeed), follows queued runs until they end, refreshes through `onResult`, follows\n * redirects and opens downloads. Put it inside `PanneauRoot`, and above the router of an app, so\n * that runs are followed from page to page. `useActionRunner(resource)` runs an action.\n */\nexport function ActionRunnerProvider({\n adapter,\n children,\n onResult,\n onNavigate = navigateTo,\n onDownload = openDownload,\n clientActions,\n pollInterval = 2000,\n locales,\n}: ActionRunnerProviderProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const { definition, plugins } = usePanneau();\n const [parameters, setParameters] = useState<Pending | null>(null);\n const [client, setClient] = useState<ClientPending | null>(null);\n const [details, setDetails] = useState<{ label: string; result: ActionResult } | null>(null);\n const [runs, setRuns] = useState<readonly FollowedRun[]>([]);\n // Runs whose end was already shown, so that a late poll doesn't show it twice.\n const notified = useRef(new Set<string>());\n // How many lists of runs are on screen (the popover of the runs): their user sees a run end.\n const watchers = useRef(0);\n\n /** What the action applied to, by the item's title or the count of items. */\n const subjectOf = (resource: string, target: ActionTarget, count: number | null = null) =>\n describeSubject(\n target,\n definition?.resources.find((candidate) => candidate.id === resource),\n intl,\n count,\n );\n\n /** One toast per action and target: running it again replaces it. */\n const toastKey = (resource: string, target: ActionTarget) =>\n `panneau-action:${resource}:${target.action.id}:${target.item?.id ?? 'selection'}`;\n\n const finish = async (\n resource: string,\n target: ActionTarget,\n result: ActionResult,\n { queued = false }: { queued?: boolean } = {},\n ) => {\n await onResult?.(result, { resource, target });\n const counts = getResultCounts(result);\n const content = describeResult(\n result,\n getActionLabel(target.action, intl),\n intl,\n subjectOf(resource, target, counts.succeeded),\n );\n const hasDetails = (result.results ?? []).length > 0;\n const download = result.download ?? null;\n if (download !== null) {\n onDownload(download);\n }\n const redirect = result.redirect ?? null;\n // A queued run that ends in the open list of runs is seen there, unless its result says\n // more than its status: a message, items that didn't succeed, a download.\n const saysMore = (result.message ?? '') !== '' || hasDetails || download !== null;\n if (queued && watchers.current > 0 && !saysMore) {\n if (redirect !== null) {\n onNavigate(redirect);\n }\n return;\n }\n // \"Undo\" lives in the toast only (decision 0063): a queued run, which finished later, isn't\n // undone.\n const undo = !queued ? (result.undo ?? null) : null;\n toasts.show(\n {\n ...content,\n ...(undo !== null\n ? {\n action: {\n label: intl.formatMessage(messages.undo),\n onAction: () => void runUndo(resource, target, undo),\n },\n }\n : hasDetails\n ? {\n action: {\n label: intl.formatMessage(messages.details),\n onAction: () =>\n setDetails({\n label: getActionLabel(target.action, intl),\n result,\n }),\n },\n }\n : download !== null\n ? {\n action: {\n label: intl.formatMessage(messages.download),\n onAction: () => onDownload(download),\n },\n }\n : {}),\n },\n { key: toastKey(resource, target) },\n );\n if (redirect !== null) {\n onNavigate(redirect);\n }\n };\n\n /**\n * Runs the undo of a result: an action of the same resource, on the items it lists, as any\n * action. A short toast then says it was undone, in place of the first one.\n */\n const runUndo = async (\n resource: string,\n target: ActionTarget,\n undo: NonNullable<ActionResult['undo']>,\n ) => {\n const label = getActionLabel(target.action, intl);\n const key = { key: toastKey(resource, target) };\n const declared = definition?.resources\n .find((candidate) => candidate.id === resource)\n ?.actions?.find((action) => action.id === undo.action);\n const undoTarget: ActionTarget = {\n action: declared ?? { id: undo.action, kind: 'server', scope: ['selection'] },\n scope: 'selection',\n selection: { ids: undo.items },\n count: undo.items.length,\n };\n await adapter\n .runAction(resource, undo.action, {\n selection: { ids: undo.items },\n values: undo.params ?? {},\n })\n .then(async (response) => {\n if (response.run !== undefined) {\n follow(resource, undoTarget, response.run);\n return;\n }\n await onResult?.(response.result, { resource, target: undoTarget });\n const subject = subjectOf(resource, target, undo.items.length);\n toasts.show(\n {\n title:\n subject !== null\n ? intl.formatMessage(messages.undoneFor, {\n action: label,\n subject,\n })\n : intl.formatMessage(messages.undone, { action: label }),\n },\n key,\n );\n })\n .catch((error: unknown) => {\n toasts.show(\n {\n title: intl.formatMessage(messages.undoFailed, { action: label }),\n ...(error instanceof Error && error.message !== ''\n ? { description: error.message }\n : {}),\n tone: 'danger',\n },\n key,\n );\n });\n };\n\n // No toast when a run starts: the runs button of the shell shows it, and its popover follows\n // it. The toast comes when the run ends.\n const follow = (resource: string, target: ActionTarget, run: ActionRun) => {\n setRuns((current) => [\n ...current.filter((entry) => entry.run.id !== run.id),\n { run, resource, target },\n ]);\n };\n\n const ended = async (entry: FollowedRun) => {\n const { run, resource, target } = entry;\n if (notified.current.has(run.id)) {\n return;\n }\n notified.current.add(run.id);\n if (run.result !== undefined) {\n await finish(resource, target, run.result, { queued: true });\n return;\n }\n const action = getActionLabel(target.action, intl);\n const subject = subjectOf(resource, target);\n const key = { key: toastKey(resource, target) };\n if (run.status === 'cancelled') {\n toasts.show(\n {\n title:\n subject !== null\n ? intl.formatMessage(messages.cancelledFor, { action, subject })\n : intl.formatMessage(messages.cancelled, { action }),\n },\n key,\n );\n } else if (run.status === 'failed') {\n toasts.show(\n {\n title:\n subject !== null\n ? intl.formatMessage(messages.failedFor, { action, subject })\n : intl.formatMessage(messages.failed, { action }),\n tone: 'danger',\n },\n key,\n );\n } else if (watchers.current === 0) {\n toasts.show(\n {\n title:\n subject !== null\n ? intl.formatMessage(messages.doneFor, { action, subject })\n : intl.formatMessage(messages.done, { action }),\n tone: 'success',\n },\n key,\n );\n }\n };\n\n const execute = async (\n resource: string,\n target: ActionTarget,\n values: Record<string, unknown> = {},\n ): Promise<ActionOutcome> => {\n const response = await adapter.runAction(\n resource,\n target.action.id,\n buildActionRequest(target, values),\n );\n if (response.run !== undefined) {\n follow(resource, target, response.run);\n return { status: 'queued', run: response.run };\n }\n await finish(resource, target, response.result);\n return { status: 'done', result: response.result };\n };\n\n const run = (resource: string, target: ActionTarget): Promise<ActionOutcome | false> => {\n const { action } = target;\n if (action.kind === 'link') {\n const to = getLinkTarget(target);\n if (to === null) {\n return Promise.reject(new Error(`The action \"${action.id}\" has no URL or route.`));\n }\n onNavigate(to);\n return Promise.resolve({ status: 'navigated', to });\n }\n if (action.kind === 'client') {\n const name = action.component ?? '';\n const Handler =\n (clientActions !== undefined && Object.hasOwn(clientActions, name)\n ? clientActions[name]\n : undefined) ?? (plugins.actions.get(name) as ClientActionHandler | undefined);\n if (Handler === undefined) {\n return Promise.reject(\n new Error(`No handler for the client action \"${action.id}\" (${name}).`),\n );\n }\n return new Promise((resolve) => setClient({ resource, target, resolve, Handler }));\n }\n if ((action.fields ?? []).length > 0) {\n return new Promise((resolve) => setParameters({ resource, target, resolve }));\n }\n return execute(resource, target);\n };\n\n const cancelRun = async (id: string) => {\n if (adapter.cancelActionRun === undefined) {\n throw new Error('The adapter cannot cancel runs.');\n }\n await adapter.cancelActionRun(id);\n const updated = await adapter.getActionRun(id);\n setRuns((current) =>\n current.map((entry) => (entry.run.id === id ? { ...entry, run: updated } : entry)),\n );\n const entry = runs.find((candidate) => candidate.run.id === id);\n if (entry !== undefined && isFinished(updated.status)) {\n await ended({ ...entry, run: updated });\n }\n };\n\n const dismissRun = (id: string) =>\n setRuns((current) => current.filter((entry) => entry.run.id !== id));\n\n const onRunEnded = useEffectEvent((entry: FollowedRun) => ended(entry));\n\n // Checks the unfinished runs, one interval after the last change of the runs.\n useEffect(() => {\n const active = runs.filter((entry) => !isFinished(entry.run.status));\n if (active.length === 0) {\n return undefined;\n }\n let stopped = false;\n const timer = setTimeout(() => {\n void Promise.all(\n active.map(async (entry) => {\n try {\n const next = await adapter.getActionRun(entry.run.id);\n if (stopped) {\n return;\n }\n setRuns((current) =>\n current.map((candidate) =>\n candidate.run.id === next.id\n ? { ...candidate, run: next }\n : candidate,\n ),\n );\n if (isFinished(next.status)) {\n await onRunEnded({ ...entry, run: next });\n }\n } catch {\n // Checked again at the next interval.\n if (!stopped) {\n setRuns((current) => [...current]);\n }\n }\n }),\n );\n }, pollInterval);\n return () => {\n stopped = true;\n clearTimeout(timer);\n };\n }, [runs, adapter, pollInterval]);\n\n const watchRuns = () => {\n watchers.current += 1;\n return () => {\n watchers.current -= 1;\n };\n };\n\n const value: ActionRunnerContextValue = {\n adapter,\n run,\n runs,\n cancelRun,\n dismissRun,\n watchRuns,\n };\n\n const ClientHandler = client?.Handler;\n return (\n <ActionRunnerContext value={value}>\n {children}\n {parameters !== null ? (\n <ParametersDialog\n action={parameters.target.action}\n count={parameters.target.count}\n locales={locales}\n onSubmit={(values) => execute(parameters.resource, parameters.target, values)}\n onDone={(outcome) => {\n setParameters(null);\n parameters.resolve(outcome);\n }}\n onCancel={() => {\n setParameters(null);\n parameters.resolve(false);\n }}\n />\n ) : null}\n {client !== null && ClientHandler !== undefined ? (\n <ClientHandler\n action={client.target.action}\n resource={client.resource}\n target={client.target}\n onDone={(result) => {\n setClient(null);\n if (result === undefined) {\n client.resolve({ status: 'done', result: {} });\n return;\n }\n void finish(client.resource, client.target, result).then(() =>\n client.resolve({ status: 'done', result }),\n );\n }}\n onCancel={() => {\n setClient(null);\n client.resolve(false);\n }}\n />\n ) : null}\n {details !== null ? (\n <ResultsDialog\n label={details.label}\n result={details.result}\n onClose={() => setDetails(null)}\n />\n ) : null}\n </ActionRunnerContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA0DA,SAASoD,WAAWf,IAA6B;CAC7C,IAAI,OAAOA,OAAO,UACdgB,OAAOC,SAASC,OAAOlB,EAAE;MAEzBmB,QAAQC,KACJ,0CAA0CpB,GAAGqB,MAAK,4CACtD;AAER;AAEA,SAASC,aAAapB,UAA0B;CAC5C,MAAMqB,OAAOC,SAASC,cAAc,GAAG;CACvCF,KAAKG,OAAOxB,SAASyB;CACrB,IAAIzB,SAAS0B,aAAaC,KAAAA,GACtBN,KAAKrB,WAAWA,SAAS0B;CAE7BL,KAAKO,MAAM;CACXP,KAAKQ,SAAS;CACdP,SAASQ,KAAKC,OAAOV,IAAI;CACzBA,KAAKW,MAAM;CACXX,KAAKY,OAAO;AAChB;;;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uK;CAAA,OAAAA,MAAAvK,EAAA;CAAA,OA9CtBuK;AA8CsB;AAvYvB,SAAAb,OAAAc,WAAA;CAAA,OA2T0C,CAAA,GAAItH,SAAO;AAAC;AA3TtD,SAAA+F,OAAAwB,SAAA;CAAA,OAiSuC,CAAC9N,WAAW8I,QAAKd,IAAIwB,MAAO;AAAC;AAjSpE,SAAAlE,MAAAyI,YAAAC,UAAA;CAAA,OAiCC,kBAAkBxM,WAAQ,GAAIC,SAAMsE,OAAOZ,GAAG,GAAI1D,SAAMwM,MAAS9I,MAAf;AAAgC"}
|
package/dist/ActionRuns.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRuns.d.ts","sourceRoot":"","sources":["../src/ActionRuns.tsx"],"names":[],"mappings":"AAsBA,MAAM,WAAW,eAAe;IAC5B,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"ActionRuns.d.ts","sourceRoot":"","sources":["../src/ActionRuns.tsx"],"names":[],"mappings":"AAsBA,MAAM,WAAW,eAAe;IAC5B,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,eAAe,sCAgFjF"}
|
package/dist/ActionRuns.js
CHANGED
|
@@ -3,7 +3,7 @@ import { messages } from "./messages.js";
|
|
|
3
3
|
import { isFinished } from "./request.js";
|
|
4
4
|
import { ActionRunnerContext } from "./context.js";
|
|
5
5
|
import { c } from "react/compiler-runtime";
|
|
6
|
-
import { use } from "react";
|
|
6
|
+
import { use, useEffect } from "react";
|
|
7
7
|
import { getActionLabel } from "@panneau/intl";
|
|
8
8
|
import { Button, IconButton, usePanneauIntl } from "@panneau/ui";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -24,30 +24,43 @@ var STATUS_MESSAGES = {
|
|
|
24
24
|
* that have. For a notification area. Renders nothing without runs.
|
|
25
25
|
*/
|
|
26
26
|
function ActionRuns(t0) {
|
|
27
|
-
const $ = c(
|
|
27
|
+
const $ = c(16);
|
|
28
28
|
const { "aria-label": ariaLabel, className } = t0;
|
|
29
29
|
const intl = usePanneauIntl();
|
|
30
30
|
const context = use(ActionRunnerContext);
|
|
31
|
-
if (context === null || context.runs.length === 0) return null;
|
|
32
|
-
const canCancel = context.adapter.cancelActionRun !== void 0;
|
|
33
31
|
let t1;
|
|
34
|
-
if ($[0] !== ariaLabel || $[1] !== intl) {
|
|
35
|
-
t1 = ariaLabel ?? intl.formatMessage(messages.runs);
|
|
36
|
-
$[0] = ariaLabel;
|
|
37
|
-
$[1] = intl;
|
|
38
|
-
$[2] = t1;
|
|
39
|
-
} else t1 = $[2];
|
|
40
32
|
let t2;
|
|
41
|
-
if ($[
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
$[
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
if ($[0] !== context) {
|
|
34
|
+
t1 = () => context?.watchRuns();
|
|
35
|
+
t2 = [context];
|
|
36
|
+
$[0] = context;
|
|
37
|
+
$[1] = t1;
|
|
38
|
+
$[2] = t2;
|
|
39
|
+
} else {
|
|
40
|
+
t1 = $[1];
|
|
41
|
+
t2 = $[2];
|
|
42
|
+
}
|
|
43
|
+
useEffect(t1, t2);
|
|
44
|
+
if (context === null || context.runs.length === 0) return null;
|
|
45
|
+
const canCancel = context.adapter.cancelActionRun !== void 0;
|
|
46
|
+
let t3;
|
|
47
|
+
if ($[3] !== ariaLabel || $[4] !== intl) {
|
|
48
|
+
t3 = ariaLabel ?? intl.formatMessage(messages.runs);
|
|
49
|
+
$[3] = ariaLabel;
|
|
50
|
+
$[4] = intl;
|
|
51
|
+
$[5] = t3;
|
|
52
|
+
} else t3 = $[5];
|
|
47
53
|
let t4;
|
|
48
|
-
if ($[
|
|
49
|
-
t4 =
|
|
50
|
-
|
|
54
|
+
if ($[6] !== className) {
|
|
55
|
+
t4 = [ActionRunner_module_default.runs, className].filter(Boolean);
|
|
56
|
+
$[6] = className;
|
|
57
|
+
$[7] = t4;
|
|
58
|
+
} else t4 = $[7];
|
|
59
|
+
const t5 = t4.join(" ");
|
|
60
|
+
let t6;
|
|
61
|
+
if ($[8] !== canCancel || $[9] !== context || $[10] !== intl) {
|
|
62
|
+
t6 = context.runs.map((t7) => {
|
|
63
|
+
const { run, target } = t7;
|
|
51
64
|
const label = getActionLabel(target.action, intl);
|
|
52
65
|
const finished = isFinished(run.status);
|
|
53
66
|
const status = intl.formatMessage(STATUS_MESSAGES[run.status]);
|
|
@@ -90,24 +103,24 @@ function ActionRuns(t0) {
|
|
|
90
103
|
]
|
|
91
104
|
}, run.id);
|
|
92
105
|
});
|
|
93
|
-
$[
|
|
94
|
-
$[
|
|
95
|
-
$[
|
|
96
|
-
$[
|
|
97
|
-
} else
|
|
98
|
-
let
|
|
99
|
-
if ($[
|
|
100
|
-
|
|
101
|
-
"aria-label":
|
|
102
|
-
className:
|
|
103
|
-
children:
|
|
106
|
+
$[8] = canCancel;
|
|
107
|
+
$[9] = context;
|
|
108
|
+
$[10] = intl;
|
|
109
|
+
$[11] = t6;
|
|
110
|
+
} else t6 = $[11];
|
|
111
|
+
let t7;
|
|
112
|
+
if ($[12] !== t3 || $[13] !== t5 || $[14] !== t6) {
|
|
113
|
+
t7 = /* @__PURE__ */ jsx("ul", {
|
|
114
|
+
"aria-label": t3,
|
|
115
|
+
className: t5,
|
|
116
|
+
children: t6
|
|
104
117
|
});
|
|
105
|
-
$[
|
|
106
|
-
$[
|
|
107
|
-
$[
|
|
108
|
-
$[
|
|
109
|
-
} else
|
|
110
|
-
return
|
|
118
|
+
$[12] = t3;
|
|
119
|
+
$[13] = t5;
|
|
120
|
+
$[14] = t6;
|
|
121
|
+
$[15] = t7;
|
|
122
|
+
} else t7 = $[15];
|
|
123
|
+
return t7;
|
|
111
124
|
}
|
|
112
125
|
function _temp2(t0) {
|
|
113
126
|
const { percentage, valueText } = t0;
|
package/dist/ActionRuns.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRuns.js","names":["X","use","ProgressBar","getActionLabel","ActionRun","Button","IconButton","usePanneauIntl","styles","ActionRunnerContext","messages","isFinished","STATUS_MESSAGES","queued","runQueued","running","runRunning","succeeded","runSucceeded","partial","runPartial","failed","runFailed","cancelled","runCancelled","Record","ActionRunsProps","className","ActionRuns","t0","$","_c","ariaLabel","intl","context","runs","length","canCancel","adapter","cancelActionRun","undefined","
|
|
1
|
+
{"version":3,"file":"ActionRuns.js","names":["X","use","useEffect","ProgressBar","getActionLabel","ActionRun","Button","IconButton","usePanneauIntl","styles","ActionRunnerContext","messages","isFinished","STATUS_MESSAGES","queued","runQueued","running","runRunning","succeeded","runSucceeded","partial","runPartial","failed","runFailed","cancelled","runCancelled","Record","ActionRunsProps","className","ActionRuns","t0","$","_c","ariaLabel","intl","context","t1","t2","watchRuns","runs","length","canCancel","adapter","cancelActionRun","undefined","t3","formatMessage","t4","filter","Boolean","t5","join","t6","map","t7","run","target","label","action","finished","status","id","runLabel","dismissRun","cancelRun","catch","_temp","cancel","runStatus","progress","total","_temp2","percentage","valueText","track","fill","width","_c","styles","_Fragment"],"sources":["../src/ActionRuns.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { use, useEffect } from 'react';\nimport { ProgressBar } from 'react-aria-components';\n\nimport { getActionLabel } from '@panneau/intl';\nimport type { ActionRun } from '@panneau/protocol';\nimport { Button, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { ActionRunnerContext } from './context';\nimport { messages } from './messages';\nimport { isFinished } from './request';\n\nconst STATUS_MESSAGES = {\n queued: messages.runQueued,\n running: messages.runRunning,\n succeeded: messages.runSucceeded,\n partial: messages.runPartial,\n failed: messages.runFailed,\n cancelled: messages.runCancelled,\n} satisfies Record<ActionRun['status'], unknown>;\n\nexport interface ActionRunsProps {\n /** Accessible name of the list. Defaults to \"Actions in progress\". */\n 'aria-label'?: string;\n className?: string;\n}\n\n/**\n * The queued runs that the closest `ActionRunnerProvider` follows: their status and progress, a\n * button to cancel those that haven't finished (when the adapter can), and one to dismiss those\n * that have. For a notification area. Renders nothing without runs.\n */\nexport function ActionRuns({ 'aria-label': ariaLabel, className }: ActionRunsProps) {\n const intl = usePanneauIntl();\n const context = use(ActionRunnerContext);\n // Its user sees the runs that end here: the runner shows no toast for them.\n useEffect(() => context?.watchRuns(), [context]);\n if (context === null || context.runs.length === 0) {\n return null;\n }\n const canCancel = context.adapter.cancelActionRun !== undefined;\n return (\n <ul\n aria-label={ariaLabel ?? intl.formatMessage(messages.runs)}\n className={[styles.runs, className].filter(Boolean).join(' ')}\n >\n {context.runs.map(({ run, target }) => {\n const label = getActionLabel(target.action, intl);\n const finished = isFinished(run.status);\n const status = intl.formatMessage(STATUS_MESSAGES[run.status]);\n return (\n <li key={run.id} className={styles.run}>\n <span className={styles.runLabel}>{label}</span>\n {finished ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.dismissRun, { action: label })}\n onPress={() => context.dismissRun(run.id)}\n />\n ) : canCancel ? (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={intl.formatMessage(messages.cancelRun, {\n action: label,\n })}\n onPress={() => {\n context.cancelRun(run.id).catch(() => undefined);\n }}\n >\n {intl.formatMessage(messages.cancel)}\n </Button>\n ) : (\n <span />\n )}\n {finished ? (\n <span className={styles.runStatus}>{status}</span>\n ) : (\n <ProgressBar\n aria-label={label}\n className={styles.progress}\n value={run.progress}\n maxValue={run.total ?? undefined}\n isIndeterminate={run.total === null || run.total === 0}\n valueLabel={\n run.total !== null && run.total > 0\n ? intl.formatMessage(messages.progress, {\n progress: run.progress,\n total: run.total,\n })\n : status\n }\n >\n {({ percentage, valueText }) => (\n <>\n <span className={styles.runStatus}>{valueText}</span>\n <span className={styles.track}>\n <span\n className={styles.fill}\n style={{ width: `${percentage ?? 100}%` }}\n />\n </span>\n </>\n )}\n </ProgressBar>\n )}\n </li>\n );\n })}\n </ul>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAaA,IAAMa,kBAAkB;CACpBC,QAAQH,SAASI;CACjBC,SAASL,SAASM;CAClBC,WAAWP,SAASQ;CACpBC,SAAST,SAASU;CAClBC,QAAQX,SAASY;CACjBC,WAAWb,SAASc;AACxB;;;;;;AAaA,SAAOI,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAoB,MAAA,EAAA,cAAAC,WAAAL,cAAAE;CACvB,MAAAI,OAAa1B,eAAe;CAC5B,MAAA2B,UAAgBlC,IAAIS,mBAAmB;CAAE,IAAA0B;CAAA,IAAAC;CAAA,IAAAN,EAAA,OAAAI,SAAA;EAE/BC,WAAMD,SAAOG,UAAY;EAAGD,KAAA,CAACF,OAAO;EAACJ,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;EAAAL,EAAA,KAAAM;CAAA,OAAA;EAAAD,KAAAL,EAAA;EAAAM,KAAAN,EAAA;CAAA;CAA/C7B,UAAUkC,IAA4BC,EAAS;CAC/C,IAAIF,YAAY,QAAQA,QAAOI,KAAKC,WAAY,GAAC,OACtC;CAEX,MAAAC,YAAkBN,QAAOO,QAAQC,oBAAqBC,KAAAA;CAAU,IAAAC;CAAA,IAAAd,EAAA,OAAAE,aAAAF,EAAA,OAAAG,MAAA;EAG5CW,KAAAZ,aAAaC,KAAIY,cAAenC,SAAQ4B,IAAK;EAACR,EAAA,KAAAE;EAAAF,EAAA,KAAAG;EAAAH,EAAA,KAAAc;CAAA,OAAAA,KAAAd,EAAA;CAAA,IAAAgB;CAAA,IAAAhB,EAAA,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
|
|
|
5
5
|
runs: readonly FollowedRun[];
|
|
6
6
|
cancelRun: (id: string) => Promise<void>;
|
|
7
7
|
dismissRun: (id: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Says that a list of the runs is on screen, until the function it returns is called: a run
|
|
10
|
+
* that ends there needs no toast.
|
|
11
|
+
*/
|
|
12
|
+
watchRuns: () => () => void;
|
|
8
13
|
}
|
|
9
14
|
export declare const ActionRunnerContext: import("react").Context<ActionRunnerContextValue | null>;
|
|
10
15
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvF,MAAM,WAAW,wBAAwB;IACrC,OAAO,EAAE,aAAa,CAAC;IACvB,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;IAChF,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7B,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvF,MAAM,WAAW,wBAAwB;IACrC,OAAO,EAAE,aAAa,CAAC;IACvB,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;IAChF,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7B,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC;;;OAGG;IACH,SAAS,EAAE,MAAM,MAAM,IAAI,CAAC;CAC/B;AAED,eAAO,MAAM,mBAAmB,0DAAuD,CAAC"}
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["createContext","ActionAdapter","ActionOutcome","ActionTarget","FollowedRun","ActionRunnerContextValue","adapter","run","resource","target","Promise","runs","cancelRun","id","dismissRun","ActionRunnerContext"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\n\nimport type { ActionAdapter, ActionOutcome, ActionTarget, FollowedRun } from './types';\n\nexport interface ActionRunnerContextValue {\n adapter: ActionAdapter;\n run: (resource: string, target: ActionTarget) => Promise<ActionOutcome | false>;\n runs: readonly FollowedRun[];\n cancelRun: (id: string) => Promise<void>;\n dismissRun: (id: string) => void;\n}\n\nexport const ActionRunnerContext = createContext<ActionRunnerContextValue | null>(null);\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","ActionAdapter","ActionOutcome","ActionTarget","FollowedRun","ActionRunnerContextValue","adapter","run","resource","target","Promise","runs","cancelRun","id","dismissRun","watchRuns","ActionRunnerContext"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\n\nimport type { ActionAdapter, ActionOutcome, ActionTarget, FollowedRun } from './types';\n\nexport interface ActionRunnerContextValue {\n adapter: ActionAdapter;\n run: (resource: string, target: ActionTarget) => Promise<ActionOutcome | false>;\n runs: readonly FollowedRun[];\n cancelRun: (id: string) => Promise<void>;\n dismissRun: (id: string) => void;\n /**\n * Says that a list of the runs is on screen, until the function it returns is called: a run\n * that ends there needs no toast.\n */\n watchRuns: () => () => void;\n}\n\nexport const ActionRunnerContext = createContext<ActionRunnerContextValue | null>(null);\n"],"mappings":";;AAiBA,IAAagB,sBAAsBhB,cAA+C,IAAI"}
|
package/dist/describe.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl';
|
|
2
|
-
import type { ActionItemResult, ActionResult } from '@panneau/protocol';
|
|
2
|
+
import type { ActionItemResult, ActionResult, Item, Resource } from '@panneau/protocol';
|
|
3
3
|
import type { ToastContent } from '@panneau/ui';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import type { ActionTarget } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The title of an item: the value of the resource's `itemTitle` field, in the locale when it is
|
|
7
|
+
* localized. `null` without one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getItemTitle(item: Partial<Item> | undefined, itemTitle: string | undefined, locale: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* What an action applied to, for its toast: the item by its title ("“Spring contest”"), or the
|
|
12
|
+
* count of items with the resource's labels ("3 entries"). `null` when there is nothing to name:
|
|
13
|
+
* an item without a title, a selection without a count, or a resource the definition doesn't
|
|
14
|
+
* have.
|
|
15
|
+
*/
|
|
16
|
+
export declare function describeSubject(target: ActionTarget, resource: Pick<Resource, 'label' | 'itemTitle'> | undefined, intl: IntlShape, count?: number | null): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* The toast of a result: its message, or "done" with what it was done to (`subject`), the counts,
|
|
19
|
+
* and a tone that says how it went.
|
|
20
|
+
*/
|
|
21
|
+
export declare function describeResult(result: ActionResult, actionLabel: string, intl: IntlShape, subject?: string | null): Omit<ToastContent, 'action'>;
|
|
6
22
|
/** Why an item didn't succeed: its message, or its reason (`forbidden`, `not_found`, `unchanged`). */
|
|
7
23
|
export declare function describeItemResult(entry: ActionItemResult, intl: IntlShape): string;
|
|
8
24
|
//# sourceMappingURL=describe.d.ts.map
|
package/dist/describe.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../src/describe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../src/describe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,wBAAgB,YAAY,CACxB,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAWf;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,WAAW,CAAC,GAAG,SAAS,EAC3D,IAAI,EAAE,SAAS,EACf,KAAK,GAAE,MAAM,GAAG,IAAW,GAC5B,MAAM,GAAG,IAAI,CAoBf;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,SAAS,EACf,OAAO,GAAE,MAAM,GAAG,IAAW,GAC9B,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAqB9B;AAED,sGAAsG;AACtG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAgBnF"}
|
package/dist/describe.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
import { messages } from "./messages.js";
|
|
2
2
|
import { getResultCounts } from "./request.js";
|
|
3
3
|
//#region src/describe.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The title of an item: the value of the resource's `itemTitle` field, in the locale when it is
|
|
6
|
+
* localized. `null` without one.
|
|
7
|
+
*/
|
|
8
|
+
function getItemTitle(item, itemTitle, locale) {
|
|
9
|
+
const value = itemTitle !== void 0 ? item?.[itemTitle] : void 0;
|
|
10
|
+
if (typeof value === "string") return value;
|
|
11
|
+
if (value !== null && typeof value === "object") {
|
|
12
|
+
const first = value[locale] ?? Object.values(value)[0];
|
|
13
|
+
return typeof first === "string" ? first : null;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* What an action applied to, for its toast: the item by its title ("“Spring contest”"), or the
|
|
19
|
+
* count of items with the resource's labels ("3 entries"). `null` when there is nothing to name:
|
|
20
|
+
* an item without a title, a selection without a count, or a resource the definition doesn't
|
|
21
|
+
* have.
|
|
22
|
+
*/
|
|
23
|
+
function describeSubject(target, resource, intl, count = null) {
|
|
24
|
+
if (target.scope === "item" || target.item !== void 0) {
|
|
25
|
+
const title = getItemTitle(target.item, resource?.itemTitle, intl.locale);
|
|
26
|
+
return title !== null && title !== "" ? intl.formatMessage(messages.subjectItem, { title }) : null;
|
|
27
|
+
}
|
|
28
|
+
const total = count ?? target.count ?? null;
|
|
29
|
+
if (resource === void 0 || total === null) return null;
|
|
30
|
+
return intl.formatMessage(messages.subjectCount, {
|
|
31
|
+
count: total,
|
|
32
|
+
singular: resource.label.singular,
|
|
33
|
+
plural: resource.label.plural
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The toast of a result: its message, or "done" with what it was done to (`subject`), the counts,
|
|
38
|
+
* and a tone that says how it went.
|
|
39
|
+
*/
|
|
40
|
+
function describeResult(result, actionLabel, intl, subject = null) {
|
|
6
41
|
const { succeeded, failed, skipped } = getResultCounts(result);
|
|
7
42
|
const parts = [
|
|
8
43
|
...succeeded !== null && (failed > 0 || skipped > 0) ? [intl.formatMessage(messages.succeededCount, { count: succeeded })] : [],
|
|
@@ -11,7 +46,10 @@ function describeResult(result, actionLabel, intl) {
|
|
|
11
46
|
];
|
|
12
47
|
const tone = failed > 0 ? succeeded === 0 ? "danger" : "warning" : skipped > 0 ? "warning" : "success";
|
|
13
48
|
return {
|
|
14
|
-
title: result.message !== void 0 && result.message !== "" ? result.message : intl.formatMessage(messages.
|
|
49
|
+
title: result.message !== void 0 && result.message !== "" ? result.message : subject !== null ? intl.formatMessage(messages.doneFor, {
|
|
50
|
+
action: actionLabel,
|
|
51
|
+
subject
|
|
52
|
+
}) : intl.formatMessage(messages.done, { action: actionLabel }),
|
|
15
53
|
...parts.length > 0 ? { description: intl.formatList(parts, { type: "unit" }) } : {},
|
|
16
54
|
tone
|
|
17
55
|
};
|
|
@@ -27,6 +65,6 @@ function describeItemResult(entry, intl) {
|
|
|
27
65
|
}
|
|
28
66
|
}
|
|
29
67
|
//#endregion
|
|
30
|
-
export { describeItemResult, describeResult };
|
|
68
|
+
export { describeItemResult, describeResult, describeSubject, getItemTitle };
|
|
31
69
|
|
|
32
70
|
//# sourceMappingURL=describe.js.map
|
package/dist/describe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe.js","names":["IntlShape","ActionItemResult","ActionResult","ToastContent","messages","getResultCounts","describeResult","result","actionLabel","
|
|
1
|
+
{"version":3,"file":"describe.js","names":["IntlShape","ActionItemResult","ActionResult","Item","Resource","ToastContent","messages","getResultCounts","ActionTarget","getItemTitle","item","Partial","itemTitle","locale","value","undefined","localized","Record","first","Object","values","describeSubject","target","resource","Pick","intl","count","scope","title","formatMessage","subjectItem","total","subjectCount","singular","label","plural","describeResult","result","actionLabel","subject","Omit","succeeded","failed","skipped","parts","succeededCount","failedCount","skippedCount","tone","message","doneFor","action","done","length","description","formatList","type","describeItemResult","entry","reason","reasonForbidden","reasonNotFound","reasonUnchanged","status","statusFailed","statusSkipped"],"sources":["../src/describe.ts"],"sourcesContent":["import type { IntlShape } from 'react-intl';\n\nimport type { ActionItemResult, ActionResult, Item, Resource } from '@panneau/protocol';\nimport type { ToastContent } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getResultCounts } from './request';\nimport type { ActionTarget } from './types';\n\n/**\n * The title of an item: the value of the resource's `itemTitle` field, in the locale when it is\n * localized. `null` without one.\n */\nexport function getItemTitle(\n item: Partial<Item> | undefined,\n itemTitle: string | undefined,\n locale: string,\n): string | null {\n const value = itemTitle !== undefined ? item?.[itemTitle] : undefined;\n if (typeof value === 'string') {\n return value;\n }\n if (value !== null && typeof value === 'object') {\n const localized = (value as Record<string, unknown>)[locale];\n const first = localized ?? Object.values(value)[0];\n return typeof first === 'string' ? first : null;\n }\n return null;\n}\n\n/**\n * What an action applied to, for its toast: the item by its title (\"“Spring contest”\"), or the\n * count of items with the resource's labels (\"3 entries\"). `null` when there is nothing to name:\n * an item without a title, a selection without a count, or a resource the definition doesn't\n * have.\n */\nexport function describeSubject(\n target: ActionTarget,\n resource: Pick<Resource, 'label' | 'itemTitle'> | undefined,\n intl: IntlShape,\n count: number | null = null,\n): string | null {\n if (target.scope === 'item' || target.item !== undefined) {\n const title = getItemTitle(\n target.item as Partial<Item> | undefined,\n resource?.itemTitle,\n intl.locale,\n );\n return title !== null && title !== ''\n ? intl.formatMessage(messages.subjectItem, { title })\n : null;\n }\n const total = count ?? target.count ?? null;\n if (resource === undefined || total === null) {\n return null;\n }\n return intl.formatMessage(messages.subjectCount, {\n count: total,\n singular: resource.label.singular,\n plural: resource.label.plural,\n });\n}\n\n/**\n * The toast of a result: its message, or \"done\" with what it was done to (`subject`), the counts,\n * and a tone that says how it went.\n */\nexport function describeResult(\n result: ActionResult,\n actionLabel: string,\n intl: IntlShape,\n subject: string | null = null,\n): Omit<ToastContent, 'action'> {\n const { succeeded, failed, skipped } = getResultCounts(result);\n const parts = [\n ...(succeeded !== null && (failed > 0 || skipped > 0)\n ? [intl.formatMessage(messages.succeededCount, { count: succeeded })]\n : []),\n ...(failed > 0 ? [intl.formatMessage(messages.failedCount, { count: failed })] : []),\n ...(skipped > 0 ? [intl.formatMessage(messages.skippedCount, { count: skipped })] : []),\n ];\n const tone: ToastContent['tone'] =\n failed > 0 ? (succeeded === 0 ? 'danger' : 'warning') : skipped > 0 ? 'warning' : 'success';\n return {\n title:\n result.message !== undefined && result.message !== ''\n ? result.message\n : subject !== null\n ? intl.formatMessage(messages.doneFor, { action: actionLabel, subject })\n : intl.formatMessage(messages.done, { action: actionLabel }),\n ...(parts.length > 0 ? { description: intl.formatList(parts, { type: 'unit' }) } : {}),\n tone,\n };\n}\n\n/** Why an item didn't succeed: its message, or its reason (`forbidden`, `not_found`, `unchanged`). */\nexport function describeItemResult(entry: ActionItemResult, intl: IntlShape): string {\n if (entry.message !== undefined && entry.message !== '') {\n return entry.message;\n }\n switch (entry.reason) {\n case 'forbidden':\n return intl.formatMessage(messages.reasonForbidden);\n case 'not_found':\n return intl.formatMessage(messages.reasonNotFound);\n case 'unchanged':\n return intl.formatMessage(messages.reasonUnchanged);\n default:\n return intl.formatMessage(\n entry.status === 'failed' ? messages.statusFailed : messages.statusSkipped,\n );\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAgBS,aACZC,MACAE,WACAC,QACa;CACb,MAAMC,QAAQF,cAAcG,KAAAA,IAAYL,OAAOE,aAAaG,KAAAA;CAC5D,IAAI,OAAOD,UAAU,UACjB,OAAOA;CAEX,IAAIA,UAAU,QAAQ,OAAOA,UAAU,UAAU;EAE7C,MAAMI,QADaJ,MAAkCD,WAC1BM,OAAOC,OAAON,KAAK,CAAC,CAAC;EAChD,OAAO,OAAOI,UAAU,WAAWA,QAAQ;CAC/C;CACA,OAAO;AAC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AAaC;EAAQ,CAAC,IACrEd,KAAKI,cAAcvB,SAAS8C,MAAM,EAAED,QAAQb,YAAY,CAAC;EACrE,GAAIM,MAAMS,SAAS,IAAI,EAAEC,aAAa7B,KAAK8B,WAAWX,OAAO,EAAEY,MAAM,OAAO,CAAC,EAAE,IAAI,CAAC;EACpFR;CACJ;AACJ;;AAGA,SAAgBS,mBAAmBC,OAAyBjC,MAAyB;CACjF,IAAIiC,MAAMT,YAAYlC,KAAAA,KAAa2C,MAAMT,YAAY,IACjD,OAAOS,MAAMT;CAEjB,QAAQS,MAAMC,QAAd;EACI,KAAK,aACD,OAAOlC,KAAKI,cAAcvB,SAASsD,eAAe;EACtD,KAAK,aACD,OAAOnC,KAAKI,cAAcvB,SAASuD,cAAc;EACrD,KAAK,aACD,OAAOpC,KAAKI,cAAcvB,SAASwD,eAAe;EACtD,SACI,OAAOrC,KAAKI,cACR6B,MAAMK,WAAW,WAAWzD,SAAS0D,eAAe1D,SAAS2D,aACjE;CACR;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/actions",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.18",
|
|
4
4
|
"description": "Runs the actions of lists and forms: parameters in a dialog, the action through a data adapter, its result, and queued runs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"react-intl": "^12.0.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@panneau/core": "5.0.0-alpha.
|
|
41
|
-
"@panneau/data": "5.0.0-alpha.
|
|
42
|
-
"@panneau/forms": "5.0.0-alpha.
|
|
43
|
-
"@panneau/intl": "5.0.0-alpha.
|
|
44
|
-
"@panneau/protocol": "5.0.0-alpha.
|
|
45
|
-
"@panneau/ui": "5.0.0-alpha.
|
|
40
|
+
"@panneau/core": "5.0.0-alpha.18",
|
|
41
|
+
"@panneau/data": "5.0.0-alpha.18",
|
|
42
|
+
"@panneau/forms": "5.0.0-alpha.18",
|
|
43
|
+
"@panneau/intl": "5.0.0-alpha.18",
|
|
44
|
+
"@panneau/protocol": "5.0.0-alpha.18",
|
|
45
|
+
"@panneau/ui": "5.0.0-alpha.18",
|
|
46
46
|
"lucide-react": "^1.57.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@panneau/lists": "5.0.0-alpha.
|
|
49
|
+
"@panneau/lists": "5.0.0-alpha.18"
|
|
50
50
|
}
|
|
51
51
|
}
|