@panneau/actions 5.0.0-alpha.1 → 5.0.0-alpha.3
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 +13 -4
- package/dist/ActionRunner.css +14 -14
- package/dist/ActionRunner.module.js +13 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/preview.d.ts +21 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +30 -0
- package/dist/preview.js.map +1 -0
- package/dist/useActionRunner.d.ts +10 -0
- package/dist/useActionRunner.d.ts.map +1 -1
- package/dist/useActionRunner.js +15 -1
- package/dist/useActionRunner.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -5,7 +5,12 @@ Runs the actions of lists and forms: parameters in a dialog, the action through
|
|
|
5
5
|
```tsx
|
|
6
6
|
import { useQueryClient } from '@tanstack/react-query';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ActionRunnerProvider,
|
|
10
|
+
ActionRuns,
|
|
11
|
+
useActionPreview,
|
|
12
|
+
useActionRunner,
|
|
13
|
+
} from '@panneau/actions';
|
|
9
14
|
import { createRestAdapter } from '@panneau/data';
|
|
10
15
|
import { invalidateActionResult } from '@panneau/data/query';
|
|
11
16
|
import { ListView } from '@panneau/lists';
|
|
@@ -33,6 +38,7 @@ function App() {
|
|
|
33
38
|
|
|
34
39
|
function Pages() {
|
|
35
40
|
const runAction = useActionRunner('pages');
|
|
41
|
+
const previewAction = useActionPreview('pages');
|
|
36
42
|
return (
|
|
37
43
|
<ListView
|
|
38
44
|
list={list}
|
|
@@ -40,14 +46,15 @@ function Pages() {
|
|
|
40
46
|
columns={columns}
|
|
41
47
|
actions={actions}
|
|
42
48
|
onAction={runAction}
|
|
49
|
+
previewAction={previewAction}
|
|
43
50
|
/>
|
|
44
51
|
);
|
|
45
52
|
}
|
|
46
53
|
```
|
|
47
54
|
|
|
48
|
-
| Export | Content
|
|
49
|
-
| ------------------ |
|
|
50
|
-
| `@panneau/actions` | `ActionRunnerProvider`, `useActionRunner()`, `ActionRuns` and `useActionRuns()`, the dialogs (`ParametersDialog`, `ResultsDialog`), and their helpers |
|
|
55
|
+
| Export | Content |
|
|
56
|
+
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
57
|
+
| `@panneau/actions` | `ActionRunnerProvider`, `useActionRunner()`, `useActionPreview()`, `ActionRuns` and `useActionRuns()`, the dialogs (`ParametersDialog`, `ResultsDialog`), and their helpers |
|
|
51
58
|
|
|
52
59
|
## What the runner does
|
|
53
60
|
|
|
@@ -62,6 +69,8 @@ function Pages() {
|
|
|
62
69
|
- **`link` actions** go to their `url` (with `{id}`) or `route`, through `onNavigate`.
|
|
63
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()`.
|
|
64
71
|
|
|
72
|
+
**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
|
+
|
|
65
74
|
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).
|
|
66
75
|
|
|
67
76
|
## The adapter
|
package/dist/ActionRunner.css
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
.panneau-parameters
|
|
1
|
+
.panneau-action-runner-parameters {
|
|
2
2
|
margin: 0;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
.panneau-summary
|
|
5
|
+
.panneau-action-runner-summary {
|
|
6
6
|
margin: 0 0 var(--panneau-space-3);
|
|
7
7
|
color: var(--panneau-color-text-muted);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.panneau-results
|
|
10
|
+
.panneau-action-runner-results {
|
|
11
11
|
display: grid;
|
|
12
12
|
gap: var(--panneau-space-2);
|
|
13
13
|
margin: 0;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
list-style: none;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
.panneau-result
|
|
18
|
+
.panneau-action-runner-result {
|
|
19
19
|
display: flex;
|
|
20
20
|
flex-wrap: wrap;
|
|
21
21
|
align-items: center;
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
border-bottom: var(--panneau-border-width) solid var(--panneau-color-border);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
.panneau-
|
|
27
|
+
.panneau-action-runner-result-item {
|
|
28
28
|
font-weight: var(--panneau-font-weight-medium);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
.panneau-
|
|
31
|
+
.panneau-action-runner-result-reason {
|
|
32
32
|
flex: 1 1 12rem;
|
|
33
33
|
color: var(--panneau-color-text-muted);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
.panneau-runs
|
|
36
|
+
.panneau-action-runner-runs {
|
|
37
37
|
display: grid;
|
|
38
38
|
gap: var(--panneau-space-3);
|
|
39
39
|
margin: 0;
|
|
@@ -41,36 +41,36 @@
|
|
|
41
41
|
list-style: none;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
.panneau-run
|
|
44
|
+
.panneau-action-runner-run {
|
|
45
45
|
display: grid;
|
|
46
46
|
grid-template-columns: 1fr auto;
|
|
47
47
|
align-items: center;
|
|
48
48
|
gap: var(--panneau-space-1) var(--panneau-space-2);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
.panneau-
|
|
51
|
+
.panneau-action-runner-run-label {
|
|
52
52
|
font-weight: var(--panneau-font-weight-medium);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
.panneau-
|
|
55
|
+
.panneau-action-runner-run-status {
|
|
56
56
|
font-size: var(--panneau-font-size-sm);
|
|
57
57
|
color: var(--panneau-color-text-muted);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
.panneau-progress
|
|
60
|
+
.panneau-action-runner-progress {
|
|
61
61
|
grid-column: 1 / -1;
|
|
62
62
|
display: grid;
|
|
63
63
|
gap: var(--panneau-space-1);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
.panneau-track
|
|
66
|
+
.panneau-action-runner-track {
|
|
67
67
|
height: 0.375rem;
|
|
68
68
|
overflow: hidden;
|
|
69
69
|
background: var(--panneau-color-surface-sunken);
|
|
70
70
|
border-radius: var(--panneau-radius-full);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
.panneau-fill
|
|
73
|
+
.panneau-action-runner-fill {
|
|
74
74
|
height: 100%;
|
|
75
75
|
background: var(--panneau-color-accent);
|
|
76
76
|
border-radius: inherit;
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
@media (prefers-reduced-motion: reduce) {
|
|
81
|
-
.panneau-fill
|
|
81
|
+
.panneau-action-runner-fill {
|
|
82
82
|
transition: none;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import "./ActionRunner.css";
|
|
2
2
|
//#region src/ActionRunner.module.css
|
|
3
|
-
var parameters = "panneau-parameters
|
|
4
|
-
var summary = "panneau-summary
|
|
5
|
-
var results = "panneau-results
|
|
6
|
-
var result = "panneau-result
|
|
7
|
-
var resultItem = "panneau-
|
|
8
|
-
var resultReason = "panneau-
|
|
9
|
-
var runs = "panneau-runs
|
|
10
|
-
var run = "panneau-run
|
|
11
|
-
var runLabel = "panneau-
|
|
12
|
-
var runStatus = "panneau-
|
|
13
|
-
var progress = "panneau-progress
|
|
14
|
-
var track = "panneau-track
|
|
15
|
-
var fill = "panneau-fill
|
|
3
|
+
var parameters = "panneau-action-runner-parameters";
|
|
4
|
+
var summary = "panneau-action-runner-summary";
|
|
5
|
+
var results = "panneau-action-runner-results";
|
|
6
|
+
var result = "panneau-action-runner-result";
|
|
7
|
+
var resultItem = "panneau-action-runner-result-item";
|
|
8
|
+
var resultReason = "panneau-action-runner-result-reason";
|
|
9
|
+
var runs = "panneau-action-runner-runs";
|
|
10
|
+
var run = "panneau-action-runner-run";
|
|
11
|
+
var runLabel = "panneau-action-runner-run-label";
|
|
12
|
+
var runStatus = "panneau-action-runner-run-status";
|
|
13
|
+
var progress = "panneau-action-runner-progress";
|
|
14
|
+
var track = "panneau-action-runner-track";
|
|
15
|
+
var fill = "panneau-action-runner-fill";
|
|
16
16
|
var ActionRunner_module_default = {
|
|
17
17
|
parameters,
|
|
18
18
|
summary,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export { ActionRuns, type ActionRunsProps } from './ActionRuns';
|
|
|
3
3
|
export { ParametersDialog, type ParametersDialogProps } from './ParametersDialog';
|
|
4
4
|
export { ResultsDialog, type ResultsDialogProps } from './ResultsDialog';
|
|
5
5
|
export { describeItemResult, describeResult } from './describe';
|
|
6
|
+
export { type ActionPreview, canPreviewAction, previewAction } from './preview';
|
|
6
7
|
export { buildActionRequest, getLinkTarget, getResultCounts } from './request';
|
|
7
8
|
export type { ActionAdapter, ActionDownload, ActionOutcome, ActionResultContext, ActionTarget, ClientActionHandler, ClientActionProps, FollowedRun, } from './types';
|
|
8
|
-
export { useActionRunner, useActionRuns } from './useActionRunner';
|
|
9
|
+
export { useActionPreview, useActionRunner, useActionRuns } from './useActionRunner';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,KAAK,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,5 +4,6 @@ import { describeItemResult, describeResult } from "./describe.js";
|
|
|
4
4
|
import { ResultsDialog } from "./ResultsDialog.js";
|
|
5
5
|
import { ActionRunnerProvider } from "./ActionRunnerProvider.js";
|
|
6
6
|
import { ActionRuns } from "./ActionRuns.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { canPreviewAction, previewAction } from "./preview.js";
|
|
8
|
+
import { useActionPreview, useActionRunner, useActionRuns } from "./useActionRunner.js";
|
|
9
|
+
export { ActionRunnerProvider, ActionRuns, ParametersDialog, ResultsDialog, buildActionRequest, canPreviewAction, describeItemResult, describeResult, getLinkTarget, getResultCounts, previewAction, useActionPreview, useActionRunner, useActionRuns };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActionAdapter, ActionTarget } from './types';
|
|
2
|
+
/** What a dry run of an action told: how many items it would apply to, and skip. */
|
|
3
|
+
export interface ActionPreview {
|
|
4
|
+
succeeded: number;
|
|
5
|
+
skipped: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Whether the backend can say what an action would do before it runs: a `server` action with
|
|
9
|
+
* `dryRun`, on every item matching a query. Selected ids need no dry run, since the list knows
|
|
10
|
+
* their abilities.
|
|
11
|
+
*/
|
|
12
|
+
export declare function canPreviewAction(target: ActionTarget): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Asks the backend what an action would do on a query selection, without running it (a dry run,
|
|
15
|
+
* `"dryRun": true` in the request), and resolves with the counts of its summary, or with `null`
|
|
16
|
+
* for an action that can't be previewed (`canPreviewAction()`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function previewAction(adapter: Pick<ActionAdapter, 'runAction'>, resource: string, target: ActionTarget, options?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<ActionPreview | null>;
|
|
21
|
+
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAQ9D;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAC/B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,EACzC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACvC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAc/B"}
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/preview.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether the backend can say what an action would do before it runs: a `server` action with
|
|
4
|
+
* `dryRun`, on every item matching a query. Selected ids need no dry run, since the list knows
|
|
5
|
+
* their abilities.
|
|
6
|
+
*/
|
|
7
|
+
function canPreviewAction(target) {
|
|
8
|
+
const { action, selection } = target;
|
|
9
|
+
return action.dryRun === true && action.kind === "server" && selection !== void 0 && "query" in selection;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Asks the backend what an action would do on a query selection, without running it (a dry run,
|
|
13
|
+
* `"dryRun": true` in the request), and resolves with the counts of its summary, or with `null`
|
|
14
|
+
* for an action that can't be previewed (`canPreviewAction()`).
|
|
15
|
+
*/
|
|
16
|
+
async function previewAction(adapter, resource, target, options = {}) {
|
|
17
|
+
if (!canPreviewAction(target)) return null;
|
|
18
|
+
const summary = (await adapter.runAction(resource, target.action.id, {
|
|
19
|
+
selection: target.selection,
|
|
20
|
+
dryRun: true
|
|
21
|
+
}, options)).result?.summary;
|
|
22
|
+
return summary !== void 0 ? {
|
|
23
|
+
succeeded: summary.succeeded,
|
|
24
|
+
skipped: summary.skipped
|
|
25
|
+
} : null;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { canPreviewAction, previewAction };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","names":[],"sources":["../src/preview.ts"],"sourcesContent":["import type { ActionAdapter, ActionTarget } from './types';\n\n/** What a dry run of an action told: how many items it would apply to, and skip. */\nexport interface ActionPreview {\n succeeded: number;\n skipped: number;\n}\n\n/**\n * Whether the backend can say what an action would do before it runs: a `server` action with\n * `dryRun`, on every item matching a query. Selected ids need no dry run, since the list knows\n * their abilities.\n */\nexport function canPreviewAction(target: ActionTarget): boolean {\n const { action, selection } = target;\n return (\n action.dryRun === true &&\n action.kind === 'server' &&\n selection !== undefined &&\n 'query' in selection\n );\n}\n\n/**\n * Asks the backend what an action would do on a query selection, without running it (a dry run,\n * `\"dryRun\": true` in the request), and resolves with the counts of its summary, or with `null`\n * for an action that can't be previewed (`canPreviewAction()`).\n */\nexport async function previewAction(\n adapter: Pick<ActionAdapter, 'runAction'>,\n resource: string,\n target: ActionTarget,\n options: { signal?: AbortSignal } = {},\n): Promise<ActionPreview | null> {\n if (!canPreviewAction(target)) {\n return null;\n }\n const response = await adapter.runAction(\n resource,\n target.action.id,\n { selection: target.selection, dryRun: true },\n options,\n );\n const summary = response.result?.summary;\n return summary !== undefined\n ? { succeeded: summary.succeeded, skipped: summary.skipped }\n : null;\n}\n"],"mappings":";;;;;;AAaA,SAAgB,iBAAiB,QAA+B;CAC5D,MAAM,EAAE,QAAQ,cAAc;CAC9B,OACI,OAAO,WAAW,QAClB,OAAO,SAAS,YAChB,cAAc,KAAA,KACd,WAAW;AAEnB;;;;;;AAOA,eAAsB,cAClB,SACA,UACA,QACA,UAAoC,CAAC,GACR;CAC7B,IAAI,CAAC,iBAAiB,MAAM,GACxB,OAAO;CAQX,MAAM,WAAU,MANO,QAAQ,UAC3B,UACA,OAAO,OAAO,IACd;EAAE,WAAW,OAAO;EAAW,QAAQ;CAAK,GAC5C,OACJ,EAAA,CACyB,QAAQ;CACjC,OAAO,YAAY,KAAA,IACb;EAAE,WAAW,QAAQ;EAAW,SAAS,QAAQ;CAAQ,IACzD;AACV"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ActionPreview } from './preview';
|
|
1
2
|
import type { ActionOutcome, ActionTarget, FollowedRun } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a
|
|
@@ -12,6 +13,15 @@ import type { ActionOutcome, ActionTarget, FollowedRun } from './types';
|
|
|
12
13
|
* user cancelled its parameters (a list then keeps its selection), and rejects when it failed.
|
|
13
14
|
*/
|
|
14
15
|
export declare function useActionRunner(resource: string): (target: ActionTarget) => Promise<ActionOutcome | false>;
|
|
16
|
+
/**
|
|
17
|
+
* Asks the backend how many items of a query selection an action would skip, before the list
|
|
18
|
+
* confirms it (a dry run, for actions with `dryRun`). It is the `previewAction` of a list:
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <ListView onAction={useActionRunner('pages')} previewAction={useActionPreview('pages')} … />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useActionPreview(resource: string): (target: ActionTarget) => Promise<ActionPreview | null>;
|
|
15
25
|
/** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */
|
|
16
26
|
export declare function useActionRuns(): {
|
|
17
27
|
runs: readonly FollowedRun[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActionRunner.d.ts","sourceRoot":"","sources":["../src/useActionRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,MAAM,GACjB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAM1D;AAED,wFAAwF;AACxF,wBAAgB,aAAa,IAAI;IAC7B,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAMA"}
|
|
1
|
+
{"version":3,"file":"useActionRunner.d.ts","sourceRoot":"","sources":["../src/useActionRunner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,MAAM,GACjB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAM1D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC5B,QAAQ,EAAE,MAAM,GACjB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAMzD;AAED,wFAAwF;AACxF,wBAAgB,aAAa,IAAI;IAC7B,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAMA"}
|
package/dist/useActionRunner.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActionRunnerContext } from "./context.js";
|
|
2
|
+
import { previewAction } from "./preview.js";
|
|
2
3
|
import { use } from "react";
|
|
3
4
|
//#region src/useActionRunner.ts
|
|
4
5
|
/**
|
|
@@ -18,6 +19,19 @@ function useActionRunner(resource) {
|
|
|
18
19
|
if (context === null) throw new Error("useActionRunner() must be used inside <ActionRunnerProvider>.");
|
|
19
20
|
return (target) => context.run(resource, target);
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Asks the backend how many items of a query selection an action would skip, before the list
|
|
24
|
+
* confirms it (a dry run, for actions with `dryRun`). It is the `previewAction` of a list:
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <ListView onAction={useActionRunner('pages')} previewAction={useActionPreview('pages')} … />
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function useActionPreview(resource) {
|
|
31
|
+
const context = use(ActionRunnerContext);
|
|
32
|
+
if (context === null) throw new Error("useActionPreview() must be used inside <ActionRunnerProvider>.");
|
|
33
|
+
return (target) => previewAction(context.adapter, resource, target);
|
|
34
|
+
}
|
|
21
35
|
/** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */
|
|
22
36
|
function useActionRuns() {
|
|
23
37
|
const context = use(ActionRunnerContext);
|
|
@@ -29,6 +43,6 @@ function useActionRuns() {
|
|
|
29
43
|
};
|
|
30
44
|
}
|
|
31
45
|
//#endregion
|
|
32
|
-
export { useActionRunner, useActionRuns };
|
|
46
|
+
export { useActionPreview, useActionRunner, useActionRuns };
|
|
33
47
|
|
|
34
48
|
//# sourceMappingURL=useActionRunner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActionRunner.js","names":[],"sources":["../src/useActionRunner.ts"],"sourcesContent":["import { use } from 'react';\n\nimport { ActionRunnerContext } from './context';\nimport type { ActionOutcome, ActionTarget, FollowedRun } from './types';\n\n/**\n * Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a\n * list's `ListActionEvent`, so it is the `onAction` of a list:\n *\n * ```tsx\n * const runAction = useActionRunner('pages');\n * <ListView list={list} items={items} actions={actions} onAction={runAction} />\n * ```\n *\n * It resolves once the action has run, has been queued or has navigated, with `false` when the\n * user cancelled its parameters (a list then keeps its selection), and rejects when it failed.\n */\nexport function useActionRunner(\n resource: string,\n): (target: ActionTarget) => Promise<ActionOutcome | false> {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRunner() must be used inside <ActionRunnerProvider>.');\n }\n return (target) => context.run(resource, target);\n}\n\n/** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */\nexport function useActionRuns(): {\n runs: readonly FollowedRun[];\n cancel: (id: string) => Promise<void>;\n dismiss: (id: string) => void;\n} {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRuns() must be used inside <ActionRunnerProvider>.');\n }\n return { runs: context.runs, cancel: context.cancelRun, dismiss: context.dismissRun };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useActionRunner.js","names":[],"sources":["../src/useActionRunner.ts"],"sourcesContent":["import { use } from 'react';\n\nimport { ActionRunnerContext } from './context';\nimport { type ActionPreview, previewAction } from './preview';\nimport type { ActionOutcome, ActionTarget, FollowedRun } from './types';\n\n/**\n * Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a\n * list's `ListActionEvent`, so it is the `onAction` of a list:\n *\n * ```tsx\n * const runAction = useActionRunner('pages');\n * <ListView list={list} items={items} actions={actions} onAction={runAction} />\n * ```\n *\n * It resolves once the action has run, has been queued or has navigated, with `false` when the\n * user cancelled its parameters (a list then keeps its selection), and rejects when it failed.\n */\nexport function useActionRunner(\n resource: string,\n): (target: ActionTarget) => Promise<ActionOutcome | false> {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRunner() must be used inside <ActionRunnerProvider>.');\n }\n return (target) => context.run(resource, target);\n}\n\n/**\n * Asks the backend how many items of a query selection an action would skip, before the list\n * confirms it (a dry run, for actions with `dryRun`). It is the `previewAction` of a list:\n *\n * ```tsx\n * <ListView onAction={useActionRunner('pages')} previewAction={useActionPreview('pages')} … />\n * ```\n */\nexport function useActionPreview(\n resource: string,\n): (target: ActionTarget) => Promise<ActionPreview | null> {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionPreview() must be used inside <ActionRunnerProvider>.');\n }\n return (target) => previewAction(context.adapter, resource, target);\n}\n\n/** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */\nexport function useActionRuns(): {\n runs: readonly FollowedRun[];\n cancel: (id: string) => Promise<void>;\n dismiss: (id: string) => void;\n} {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRuns() must be used inside <ActionRunnerProvider>.');\n }\n return { runs: context.runs, cancel: context.cancelRun, dismiss: context.dismissRun };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,gBACZ,UACwD;CACxD,MAAM,UAAU,IAAI,mBAAmB;CACvC,IAAI,YAAY,MACZ,MAAM,IAAI,MAAM,+DAA+D;CAEnF,QAAQ,WAAW,QAAQ,IAAI,UAAU,MAAM;AACnD;;;;;;;;;AAUA,SAAgB,iBACZ,UACuD;CACvD,MAAM,UAAU,IAAI,mBAAmB;CACvC,IAAI,YAAY,MACZ,MAAM,IAAI,MAAM,gEAAgE;CAEpF,QAAQ,WAAW,cAAc,QAAQ,SAAS,UAAU,MAAM;AACtE;;AAGA,SAAgB,gBAId;CACE,MAAM,UAAU,IAAI,mBAAmB;CACvC,IAAI,YAAY,MACZ,MAAM,IAAI,MAAM,6DAA6D;CAEjF,OAAO;EAAE,MAAM,QAAQ;EAAM,QAAQ,QAAQ;EAAW,SAAS,QAAQ;CAAW;AACxF"}
|
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.3",
|
|
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.3",
|
|
41
|
+
"@panneau/data": "5.0.0-alpha.3",
|
|
42
|
+
"@panneau/forms": "5.0.0-alpha.3",
|
|
43
|
+
"@panneau/intl": "5.0.0-alpha.3",
|
|
44
|
+
"@panneau/protocol": "5.0.0-alpha.3",
|
|
45
|
+
"@panneau/ui": "5.0.0-alpha.3",
|
|
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.3"
|
|
50
50
|
}
|
|
51
51
|
}
|