@aglyn/plugins-workflows 1.17.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -12
- package/src/lib/components/org-automation-editor.component.d.ts +29 -6
- package/src/lib/components/org-automation-editor.component.js +105 -87
- package/src/lib/components/org-automation-editor.component.js.map +1 -1
- package/src/lib/components/org-automations-card.component.js +24 -4
- package/src/lib/components/org-automations-card.component.js.map +1 -1
- package/src/lib/components/use-org-automation-step-pickers.d.ts +6 -3
- package/src/lib/components/use-org-automation-step-pickers.js +7 -6
- package/src/lib/components/use-org-automation-step-pickers.js.map +1 -1
- package/src/lib/model/org-automations.d.ts +36 -5
- package/src/lib/model/org-automations.js +94 -7
- package/src/lib/model/org-automations.js.map +1 -1
- package/src/lib/server/org-automations-routes.d.ts +0 -6
- package/src/lib/server/org-automations-routes.js +116 -10
- package/src/lib/server/org-automations-routes.js.map +1 -1
- package/src/lib/transfer/org-automations-package.js +41 -8
- package/src/lib/transfer/org-automations-package.js.map +1 -1
- package/src/lib/transfer/org-automations-package.server.js +17 -3
- package/src/lib/transfer/org-automations-package.server.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-workflows",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.
|
|
31
|
-
"@aglyn/shared-ui-next": "1.
|
|
32
|
-
"@aglyn/shared-ui-snackstack": "1.
|
|
33
|
-
"@aglyn/shared-util-email": "1.
|
|
34
|
-
"@aglyn/shared-util-http": "1.
|
|
35
|
-
"@aglyn/shared-util-timestamp": "1.
|
|
36
|
-
"@aglyn/tenant-data-admin": "1.
|
|
37
|
-
"@aglyn/tenant-feature-instance": "1.
|
|
38
|
-
"@aglyn/tenant-runtime": "1.
|
|
28
|
+
"@aglyn/aglyn": "1.19.0",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.19.0",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.19.0",
|
|
31
|
+
"@aglyn/shared-ui-next": "1.19.0",
|
|
32
|
+
"@aglyn/shared-ui-snackstack": "1.19.0",
|
|
33
|
+
"@aglyn/shared-util-email": "1.19.0",
|
|
34
|
+
"@aglyn/shared-util-http": "1.19.0",
|
|
35
|
+
"@aglyn/shared-util-timestamp": "1.19.0",
|
|
36
|
+
"@aglyn/tenant-data-admin": "1.19.0",
|
|
37
|
+
"@aglyn/tenant-feature-instance": "1.19.0",
|
|
38
|
+
"@aglyn/tenant-runtime": "1.19.0",
|
|
39
39
|
"@swc/helpers": "0.5.23"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TriggerCombinator } from '@aglyn/aglyn';
|
|
2
|
+
import { type SiteSharingValue } from '@aglyn/shared-ui-jsx/components/site-sharing-field.component';
|
|
2
3
|
import { type OrgAutomationRow, type OrgAutomationTriggerEvent } from '../model/org-automations';
|
|
3
4
|
import { type ConditionRowDraft } from './automation-trigger-conditions.component';
|
|
4
5
|
import { type WorkflowsOrgMount } from './workflows-org-mount';
|
|
@@ -15,9 +16,11 @@ export interface OrgAutomationDraft {
|
|
|
15
16
|
conditionCombinator: TriggerCombinator;
|
|
16
17
|
steps: HostActionStep[];
|
|
17
18
|
enabled: boolean;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Where it runs: every site, the sites chosen, or every site except the
|
|
21
|
+
* ones left out (AGL-4047), as the sharing field edits it.
|
|
22
|
+
*/
|
|
23
|
+
sharing: SiteSharingValue;
|
|
21
24
|
}
|
|
22
25
|
/** A blank draft: every site, one email step, switched on. */
|
|
23
26
|
export declare function newOrgAutomationDraft(): OrgAutomationDraft;
|
|
@@ -31,9 +34,29 @@ export declare function orgAutomationDraft(row: OrgAutomationRow): OrgAutomation
|
|
|
31
34
|
* own reader.
|
|
32
35
|
*/
|
|
33
36
|
export declare function orgAutomationDraftFromProposal(proposal: OrgAutomationProposal): OrgAutomationDraft | null;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
/**
|
|
38
|
+
* What a draft's placement would store given the workspace's sites, or why it
|
|
39
|
+
* can't be: the answer the manage route gives, from `sharingFromChoice`. The
|
|
40
|
+
* sites a draft leaves out stay known here even where the list lacks them, so
|
|
41
|
+
* they aren't taken for sites that are gone.
|
|
42
|
+
*/
|
|
43
|
+
export declare function draftSharing(draft: OrgAutomationDraft, orgHostIds: readonly string[]): {
|
|
44
|
+
fields: import("@aglyn/aglyn").ScopeSharingFields;
|
|
45
|
+
problem: null;
|
|
46
|
+
} | {
|
|
47
|
+
fields: null;
|
|
48
|
+
problem: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The automation as its placement would leave it, for the pickers that offer
|
|
52
|
+
* only what reaches every site it runs on (`sharingCovers`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function draftPlacement(draft: OrgAutomationDraft, orgHostIds: readonly string[]): Readonly<Record<string, unknown>>;
|
|
55
|
+
/**
|
|
56
|
+
* The body `automations/manage` reads, from a draft: the choice, which decides
|
|
57
|
+
* (AGL-4047), and beside every site or the chosen ones the `visibleTo` it
|
|
58
|
+
* stores, as the route read it before there was a choice.
|
|
59
|
+
*/
|
|
37
60
|
export declare function orgAutomationBody(draft: OrgAutomationDraft): Record<string, unknown>;
|
|
38
61
|
export interface OrgAutomationEditorProps {
|
|
39
62
|
mount: WorkflowsOrgMount;
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
18
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
19
|
import { ACTION_MAX_STEPS, hostEventLabel, hostEventPayloadHint, triggerFilterProblem } from "@aglyn/aglyn";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import { hostScopeToken, ORG_SCOPE_TOKEN, scopeSharingOf, sharingFromChoice } from "@aglyn/aglyn/app-utils/scope-tokens";
|
|
21
|
+
import { SiteSharingField } from "@aglyn/shared-ui-jsx/components/site-sharing-field.component";
|
|
22
|
+
import { Alert, Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, MenuItem, Stack, Switch, TextField, Typography } from "@mui/material";
|
|
22
23
|
import { useMemo } from "react";
|
|
23
24
|
import { isOrgAutomationStepType, isOrgAutomationTriggerEvent, ORG_AUTOMATION_STEP_KINDS, ORG_AUTOMATION_TRIGGER_EVENTS } from "../model/org-automations.js";
|
|
24
25
|
import { AutomationStepFields, defaultStep } from "./automation-step-fields.component.js";
|
|
@@ -41,8 +42,23 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
41
42
|
defaultStep('sendEmail')
|
|
42
43
|
],
|
|
43
44
|
enabled: true,
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
sharing: {
|
|
46
|
+
mode: 'all'
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Where a stored automation runs, as the sharing field edits it. */ function sharingOfRow(row) {
|
|
51
|
+
const sharing = scopeSharingOf(row);
|
|
52
|
+
if (sharing.mode === 'all') return {
|
|
53
|
+
mode: 'all'
|
|
54
|
+
};
|
|
55
|
+
if (sharing.mode === 'allExcept') return {
|
|
56
|
+
mode: 'allExcept',
|
|
57
|
+
exceptHostIds: sharing.exceptHostIds
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
mode: 'selected',
|
|
61
|
+
hostIds: sharing.mode === 'selected' ? sharing.hostIds : []
|
|
46
62
|
};
|
|
47
63
|
}
|
|
48
64
|
/** A stored org automation as the editor opens it. */ export function orgAutomationDraft(row) {
|
|
@@ -60,8 +76,7 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
60
76
|
...(_row_steps = row.steps) != null ? _row_steps : []
|
|
61
77
|
],
|
|
62
78
|
enabled: row.enabled !== false,
|
|
63
|
-
|
|
64
|
-
siteIds: hostIdsFromScope(row.visibleTo)
|
|
79
|
+
sharing: sharingOfRow(row)
|
|
65
80
|
};
|
|
66
81
|
}
|
|
67
82
|
/**
|
|
@@ -95,13 +110,34 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
95
110
|
enabled: false
|
|
96
111
|
});
|
|
97
112
|
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
113
|
+
/**
|
|
114
|
+
* What a draft's placement would store given the workspace's sites, or why it
|
|
115
|
+
* can't be: the answer the manage route gives, from `sharingFromChoice`. The
|
|
116
|
+
* sites a draft leaves out stay known here even where the list lacks them, so
|
|
117
|
+
* they aren't taken for sites that are gone.
|
|
118
|
+
*/ export function draftSharing(draft, orgHostIds) {
|
|
119
|
+
const leftOut = draft.sharing.mode === 'allExcept' ? draft.sharing.exceptHostIds : [];
|
|
120
|
+
return sharingFromChoice(draft.sharing, [
|
|
121
|
+
...orgHostIds,
|
|
122
|
+
...leftOut
|
|
123
|
+
]);
|
|
102
124
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The automation as its placement would leave it, for the pickers that offer
|
|
127
|
+
* only what reaches every site it runs on (`sharingCovers`).
|
|
128
|
+
*/ export function draftPlacement(draft, orgHostIds) {
|
|
129
|
+
const fields = draftSharing(draft, orgHostIds).fields;
|
|
130
|
+
return fields ? _extends({}, fields) : {
|
|
131
|
+
visibleTo: []
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The body `automations/manage` reads, from a draft: the choice, which decides
|
|
136
|
+
* (AGL-4047), and beside every site or the chosen ones the `visibleTo` it
|
|
137
|
+
* stores, as the route read it before there was a choice.
|
|
138
|
+
*/ export function orgAutomationBody(draft) {
|
|
139
|
+
const { sharing } = draft;
|
|
140
|
+
return _extends({
|
|
105
141
|
name: draft.name.trim(),
|
|
106
142
|
trigger: _extends({
|
|
107
143
|
event: draft.event
|
|
@@ -109,9 +145,28 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
109
145
|
filter: draft.filter.trim()
|
|
110
146
|
} : {}, conditionsFromRows(draft.conditionRows, draft.conditionCombinator)),
|
|
111
147
|
steps: draft.steps,
|
|
112
|
-
enabled: draft.enabled
|
|
113
|
-
|
|
114
|
-
|
|
148
|
+
enabled: draft.enabled
|
|
149
|
+
}, sharing.mode === 'all' ? {
|
|
150
|
+
visibleTo: [
|
|
151
|
+
ORG_SCOPE_TOKEN
|
|
152
|
+
]
|
|
153
|
+
} : sharing.mode === 'selected' ? {
|
|
154
|
+
visibleTo: sharing.hostIds.map(hostScopeToken)
|
|
155
|
+
} : {}, {
|
|
156
|
+
sharing: sharing.mode === 'all' ? {
|
|
157
|
+
mode: 'all'
|
|
158
|
+
} : sharing.mode === 'selected' ? {
|
|
159
|
+
mode: 'selected',
|
|
160
|
+
hostIds: [
|
|
161
|
+
...sharing.hostIds
|
|
162
|
+
]
|
|
163
|
+
} : {
|
|
164
|
+
mode: 'allExcept',
|
|
165
|
+
exceptHostIds: [
|
|
166
|
+
...sharing.exceptHostIds
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
});
|
|
115
170
|
}
|
|
116
171
|
/**
|
|
117
172
|
* The org automation editor (AGL-3302): a name, a trigger an org automation
|
|
@@ -122,18 +177,28 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
122
177
|
* only what an org automation may hold. Nothing is written from here: Save
|
|
123
178
|
* hands the draft to `automations/manage`, which checks it again.
|
|
124
179
|
*/ export function OrgAutomationEditor(props) {
|
|
125
|
-
var _ref, _ref1, _ref2,
|
|
180
|
+
var _ref, _ref1, _ref2, _triggerFilterProblem, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
126
181
|
const { mount, draft, onDraft, opened, saving, onSave, onClose } = props;
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
182
|
+
const orgHostIds = useMemo(()=>mount.hosts.map((host)=>host.id), [
|
|
183
|
+
mount.hosts
|
|
184
|
+
]);
|
|
185
|
+
const placement = useMemo(()=>draft ? draftPlacement(draft, orgHostIds) : {
|
|
186
|
+
visibleTo: [
|
|
187
|
+
ORG_SCOPE_TOKEN
|
|
188
|
+
]
|
|
189
|
+
}, [
|
|
190
|
+
draft,
|
|
191
|
+
orgHostIds
|
|
131
192
|
]);
|
|
132
193
|
const { pickers, truncated } = useOrgAutomationStepPickers(mount.orgId, opened, placement);
|
|
133
|
-
const sites = useMemo(()=>orgSiteOptions(mount)
|
|
194
|
+
const sites = useMemo(()=>orgSiteOptions(mount).map((site)=>({
|
|
195
|
+
id: site.value,
|
|
196
|
+
name: site.label
|
|
197
|
+
})), [
|
|
134
198
|
mount
|
|
135
199
|
]);
|
|
136
|
-
|
|
200
|
+
// Nothing to say about leaving sites out until the sites have been read.
|
|
201
|
+
const sharingProblem = draft && (draft.sharing.mode !== 'allExcept' || mount.hostsReady) ? draftSharing(draft, orgHostIds).problem : null;
|
|
137
202
|
return /*#__PURE__*/ _jsxs(Dialog, {
|
|
138
203
|
open: Boolean(draft),
|
|
139
204
|
onClose: onClose,
|
|
@@ -162,7 +227,7 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
162
227
|
}) : null,
|
|
163
228
|
/*#__PURE__*/ _jsx(TextField, {
|
|
164
229
|
label: "Name",
|
|
165
|
-
value: (
|
|
230
|
+
value: (_ref = draft == null ? void 0 : draft.name) != null ? _ref : '',
|
|
166
231
|
onChange: (event)=>onDraft((previous)=>_extends({}, previous, {
|
|
167
232
|
name: event.target.value
|
|
168
233
|
})),
|
|
@@ -179,7 +244,7 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
179
244
|
/*#__PURE__*/ _jsx(TextField, {
|
|
180
245
|
select: true,
|
|
181
246
|
label: "Trigger event",
|
|
182
|
-
value: (
|
|
247
|
+
value: (_ref1 = draft == null ? void 0 : draft.event) != null ? _ref1 : 'formSubmission',
|
|
183
248
|
onChange: (event)=>onDraft((previous)=>_extends({}, previous, {
|
|
184
249
|
event: event.target.value
|
|
185
250
|
})),
|
|
@@ -199,8 +264,8 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
199
264
|
// filter's evaluator is arithmetic, and `source == "form"` throws
|
|
200
265
|
// on every event, so it is refused here.
|
|
201
266
|
error: Boolean(triggerFilterProblem(draft == null ? void 0 : draft.filter)),
|
|
202
|
-
helperText: (
|
|
203
|
-
value: (
|
|
267
|
+
helperText: (_ref2 = (_triggerFilterProblem = triggerFilterProblem(draft == null ? void 0 : draft.filter)) != null ? _triggerFilterProblem : hostEventPayloadHint(draft == null ? void 0 : draft.event)) != null ? _ref2 : undefined,
|
|
268
|
+
value: (_ref3 = draft == null ? void 0 : draft.filter) != null ? _ref3 : '',
|
|
204
269
|
onChange: (event)=>onDraft((previous)=>_extends({}, previous, {
|
|
205
270
|
filter: event.target.value
|
|
206
271
|
})),
|
|
@@ -212,8 +277,8 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
212
277
|
]
|
|
213
278
|
}),
|
|
214
279
|
/*#__PURE__*/ _jsx(TriggerConditionRows, {
|
|
215
|
-
rows: (
|
|
216
|
-
combinator: (
|
|
280
|
+
rows: (_ref4 = draft == null ? void 0 : draft.conditionRows) != null ? _ref4 : [],
|
|
281
|
+
combinator: (_ref5 = draft == null ? void 0 : draft.conditionCombinator) != null ? _ref5 : 'and',
|
|
217
282
|
onRowsChange: (update)=>onDraft((previous)=>_extends({}, previous, {
|
|
218
283
|
conditionRows: update(previous.conditionRows)
|
|
219
284
|
})),
|
|
@@ -221,71 +286,24 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
221
286
|
conditionCombinator: combinator
|
|
222
287
|
}))
|
|
223
288
|
}),
|
|
224
|
-
/*#__PURE__*/ _jsx(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
value: (_ref7 = draft == null ? void 0 : draft.placement) != null ? _ref7 : 'org',
|
|
232
|
-
onChange: (event)=>onDraft((previous)=>_extends({}, previous, {
|
|
233
|
-
placement: event.target.value === 'sites' ? 'sites' : 'org'
|
|
289
|
+
/*#__PURE__*/ _jsx(SiteSharingField, {
|
|
290
|
+
label: "Runs on",
|
|
291
|
+
value: (_ref6 = draft == null ? void 0 : draft.sharing) != null ? _ref6 : {
|
|
292
|
+
mode: 'all'
|
|
293
|
+
},
|
|
294
|
+
onChange: (next)=>onDraft((previous)=>_extends({}, previous, {
|
|
295
|
+
sharing: next
|
|
234
296
|
})),
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
control: /*#__PURE__*/ _jsx(Radio, {
|
|
239
|
-
size: "small"
|
|
240
|
-
}),
|
|
241
|
-
label: "Every site"
|
|
242
|
-
}),
|
|
243
|
-
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
244
|
-
value: "sites",
|
|
245
|
-
control: /*#__PURE__*/ _jsx(Radio, {
|
|
246
|
-
size: "small"
|
|
247
|
-
}),
|
|
248
|
-
label: "Chosen sites"
|
|
249
|
-
})
|
|
250
|
-
]
|
|
297
|
+
sites: sites,
|
|
298
|
+
sitesReady: mount.hostsReady,
|
|
299
|
+
problem: sharingProblem
|
|
251
300
|
}),
|
|
252
|
-
(draft == null ? void 0 : draft.placement) === 'sites' ? /*#__PURE__*/ _jsxs(FormGroup, {
|
|
253
|
-
"aria-label": "Sites it runs on",
|
|
254
|
-
children: [
|
|
255
|
-
!mount.hostsReady ? /*#__PURE__*/ _jsx(Typography, {
|
|
256
|
-
variant: "caption",
|
|
257
|
-
color: "text.secondary",
|
|
258
|
-
children: '…'
|
|
259
|
-
}) : !sites.length ? /*#__PURE__*/ _jsx(Typography, {
|
|
260
|
-
variant: "body2",
|
|
261
|
-
color: "text.secondary",
|
|
262
|
-
children: 'This organization has no sites yet.'
|
|
263
|
-
}) : sites.map((site)=>/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
264
|
-
control: /*#__PURE__*/ _jsx(Checkbox, {
|
|
265
|
-
size: "small",
|
|
266
|
-
checked: draft.siteIds.includes(site.value),
|
|
267
|
-
onChange: (event)=>onDraft((previous)=>_extends({}, previous, {
|
|
268
|
-
siteIds: event.target.checked ? [
|
|
269
|
-
...previous.siteIds,
|
|
270
|
-
site.value
|
|
271
|
-
] : previous.siteIds.filter((id)=>id !== site.value)
|
|
272
|
-
}))
|
|
273
|
-
}),
|
|
274
|
-
label: site.label
|
|
275
|
-
}, site.value)),
|
|
276
|
-
tooManySites ? /*#__PURE__*/ _jsx(Typography, {
|
|
277
|
-
variant: "caption",
|
|
278
|
-
color: "error",
|
|
279
|
-
children: `Choose ${MAX_SCOPE_HOSTS} sites or fewer, or run it on every site.`
|
|
280
|
-
}) : null
|
|
281
|
-
]
|
|
282
|
-
}) : null,
|
|
283
301
|
/*#__PURE__*/ _jsx(Typography, {
|
|
284
302
|
variant: "overline",
|
|
285
303
|
color: "text.secondary",
|
|
286
304
|
children: 'Steps (run in order)'
|
|
287
305
|
}),
|
|
288
|
-
((
|
|
306
|
+
((_ref7 = draft == null ? void 0 : draft.steps) != null ? _ref7 : []).map((step, index)=>/*#__PURE__*/ _jsx(AutomationStepFields, {
|
|
289
307
|
step: step,
|
|
290
308
|
index: index,
|
|
291
309
|
kind: step.type,
|
|
@@ -305,7 +323,7 @@ import { stepRunsAfterWait } from "../model/host-actions.js";
|
|
|
305
323
|
sx: {
|
|
306
324
|
alignSelf: 'flex-start'
|
|
307
325
|
},
|
|
308
|
-
disabled: ((
|
|
326
|
+
disabled: ((_ref8 = draft == null ? void 0 : draft.steps.length) != null ? _ref8 : 0) >= ACTION_MAX_STEPS,
|
|
309
327
|
onClick: ()=>onDraft((previous)=>_extends({}, previous, {
|
|
310
328
|
steps: [
|
|
311
329
|
...previous.steps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/workflows/src/lib/components/org-automation-editor.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n ACTION_MAX_STEPS,\n hostEventLabel,\n hostEventPayloadHint,\n type TriggerCombinator,\n triggerFilterProblem,\n} from '@aglyn/aglyn'\nimport {\n hostIdsFromScope,\n hostScopeToken,\n isOrgWideScope,\n MAX_SCOPE_HOSTS,\n ORG_SCOPE_TOKEN,\n} from '@aglyn/aglyn/app-utils/scope-tokens'\nimport {\n Alert,\n Button,\n Checkbox,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n FormGroup,\n MenuItem,\n Radio,\n RadioGroup,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useMemo } from 'react'\nimport {\n isOrgAutomationStepType,\n isOrgAutomationTriggerEvent,\n ORG_AUTOMATION_STEP_KINDS,\n ORG_AUTOMATION_TRIGGER_EVENTS,\n type OrgAutomationRow,\n type OrgAutomationTriggerEvent,\n} from '../model/org-automations'\nimport {\n AutomationStepFields,\n defaultStep,\n} from './automation-step-fields.component'\nimport {\n conditionRowsFromTrigger,\n conditionsFromRows,\n type ConditionRowDraft,\n EMPTY_CONDITION_ROW,\n TriggerConditionRows,\n} from './automation-trigger-conditions.component'\nimport { EDITOR_OPTION_CEILING } from './use-automation-step-pickers'\nimport { useOrgAutomationStepPickers } from './use-org-automation-step-pickers'\nimport { orgSiteOptions, type WorkflowsOrgMount } from './workflows-org-mount'\nimport {\n type HostActionStep,\n type HostActionStepType,\n type HostActionTriggerCondition,\n stepRunsAfterWait,\n} from '../model/host-actions'\nimport type { OrgAutomationProposal } from './workflow-zones'\n\n/** An org automation as the editor holds it. */\nexport interface OrgAutomationDraft {\n /** The stored document's id, or null for a new one. */\n id: string | null\n name: string\n event: OrgAutomationTriggerEvent\n filter: string\n conditionRows: ConditionRowDraft[]\n conditionCombinator: TriggerCombinator\n steps: HostActionStep[]\n enabled: boolean\n /** `org` runs on every site; `sites` on the ones in `siteIds`. */\n placement: 'org' | 'sites'\n siteIds: string[]\n}\n\n/** A blank draft: every site, one email step, switched on. */\nexport function newOrgAutomationDraft(): OrgAutomationDraft {\n return {\n id: null,\n name: '',\n event: 'formSubmission',\n filter: '',\n conditionRows: [EMPTY_CONDITION_ROW],\n conditionCombinator: 'and',\n steps: [defaultStep('sendEmail')],\n enabled: true,\n placement: 'org',\n siteIds: [],\n }\n}\n\n/** A stored org automation as the editor opens it. */\nexport function orgAutomationDraft(row: OrgAutomationRow): OrgAutomationDraft {\n const event = isOrgAutomationTriggerEvent(row.trigger?.event)\n ? row.trigger.event\n : 'formSubmission'\n return {\n id: row.$id,\n name: row.name ?? '',\n event,\n filter: row.trigger?.filter ?? '',\n conditionRows: conditionRowsFromTrigger(row.trigger),\n conditionCombinator: row.trigger?.combinator === 'or' ? 'or' : 'and',\n steps: [...(row.steps ?? [])],\n enabled: row.enabled !== false,\n placement: isOrgWideScope(row.visibleTo) ? 'org' : 'sites',\n siteIds: hostIdsFromScope(row.visibleTo),\n }\n}\n\n/**\n * An automation another plugin proposed (AGL-3603) as the editor opens it:\n * NEW, switched off and placed on every site until the person chooses, or\n * `null` when its trigger or a step is not one an org automation may hold.\n * Nothing is stored; the editor's Save is the write, through the route's\n * own reader.\n */\nexport function orgAutomationDraftFromProposal(\n proposal: OrgAutomationProposal,\n): OrgAutomationDraft | null {\n const event = proposal.trigger?.event\n if (!isOrgAutomationTriggerEvent(event)) return null\n const steps = proposal.steps ?? []\n if (!steps.length || !steps.every((step) => isOrgAutomationStepType(step?.type))) {\n return null\n }\n return {\n ...newOrgAutomationDraft(),\n name: String(proposal.name ?? ''),\n event,\n conditionRows: conditionRowsFromTrigger({\n conditions: (proposal.trigger.conditions ?? []).map((condition) => ({\n field: condition.field,\n op: condition.op,\n ...(condition.value !== undefined ? { value: condition.value } : {}),\n })) as HostActionTriggerCondition[],\n }),\n conditionCombinator: proposal.trigger.combinator === 'or' ? 'or' : 'and',\n steps: steps.map((step) => ({ ...step }) as unknown as HostActionStep),\n enabled: false,\n }\n}\n\n/** The placement a draft stores, as scope tokens. */\nexport function draftPlacement(draft: OrgAutomationDraft): string[] {\n return draft.placement === 'org'\n ? [ORG_SCOPE_TOKEN]\n : draft.siteIds.map(hostScopeToken)\n}\n\n/** The body `automations/manage` reads, from a draft. */\nexport function orgAutomationBody(\n draft: OrgAutomationDraft,\n): Record<string, unknown> {\n return {\n name: draft.name.trim(),\n trigger: {\n event: draft.event,\n ...(draft.filter.trim() ? { filter: draft.filter.trim() } : {}),\n ...conditionsFromRows(draft.conditionRows, draft.conditionCombinator),\n },\n steps: draft.steps,\n enabled: draft.enabled,\n visibleTo: draftPlacement(draft),\n }\n}\n\nexport interface OrgAutomationEditorProps {\n mount: WorkflowsOrgMount\n /** The draft being edited, or null when the dialog is closed. */\n draft: OrgAutomationDraft | null\n onDraft: (update: (previous: OrgAutomationDraft) => OrgAutomationDraft) => void\n /** The editor has been opened at least once: the latch the pickers read on. */\n opened: boolean\n saving: boolean\n onSave: () => void\n onClose: () => void\n}\n\n/**\n * The org automation editor (AGL-3302): a name, a trigger an org automation\n * can start on, the conditions, the steps from the org vocabulary, and the\n * sites it runs on.\n *\n * The same step rows and condition rows the actions builder uses, offered\n * only what an org automation may hold. Nothing is written from here: Save\n * hands the draft to `automations/manage`, which checks it again.\n */\nexport function OrgAutomationEditor(props: OrgAutomationEditorProps) {\n const { mount, draft, onDraft, opened, saving, onSave, onClose } = props\n const placement = useMemo(\n () => (draft ? draftPlacement(draft) : [ORG_SCOPE_TOKEN]),\n [draft],\n )\n const { pickers, truncated } = useOrgAutomationStepPickers(\n mount.orgId,\n opened,\n placement,\n )\n const sites = useMemo(() => orgSiteOptions(mount), [mount])\n const tooManySites = (draft?.siteIds.length ?? 0) > MAX_SCOPE_HOSTS\n return (\n <Dialog open={Boolean(draft)} onClose={onClose} maxWidth=\"md\" fullWidth>\n <DialogTitle>\n {draft?.id ? 'Edit org automation' : 'Add org automation'}\n </DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, pt: 1 }}\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Runs on every site you place it on, as that site: its email goes ' +\n 'from that site, its runs count on that site’s action runs, and ' +\n 'the site can pause it for itself.'}\n </Typography>\n {truncated.length > 0 ? (\n <Alert severity=\"info\">\n {`Offering the first ${EDITOR_OPTION_CEILING} rows, ordered by id, ` +\n `for: ${truncated.join(', ')}. The organization has more, so a ` +\n 'step target may not be listed below.'}\n </Alert>\n ) : null}\n <TextField\n label=\"Name\"\n value={draft?.name ?? ''}\n onChange={(event) =>\n onDraft((previous) => ({ ...previous, name: event.target.value }))\n }\n size=\"small\"\n autoFocus\n sx={{ mt: 1 }}\n />\n <Stack direction=\"row\" spacing={1}>\n <TextField\n select\n label=\"Trigger event\"\n value={draft?.event ?? 'formSubmission'}\n onChange={(event) =>\n onDraft((previous) => ({\n ...previous,\n event: event.target.value as OrgAutomationTriggerEvent,\n }))\n }\n size=\"small\"\n sx={{ minWidth: 200 }}\n >\n {ORG_AUTOMATION_TRIGGER_EVENTS.map((eventType) => (\n <MenuItem key={eventType} value={eventType}>\n {hostEventLabel(eventType)}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n label=\"Filter (optional)\"\n placeholder=\"subscribe\"\n // A comparison belongs in the conditions below (AGL-3458): the\n // filter's evaluator is arithmetic, and `source == \"form\"` throws\n // on every event, so it is refused here.\n error={Boolean(triggerFilterProblem(draft?.filter))}\n helperText={\n triggerFilterProblem(draft?.filter) ?? hostEventPayloadHint(draft?.event) ?? undefined\n }\n value={draft?.filter ?? ''}\n onChange={(event) =>\n onDraft((previous) => ({ ...previous, filter: event.target.value }))\n }\n size=\"small\"\n sx={{ flex: 1 }}\n />\n </Stack>\n <TriggerConditionRows\n rows={draft?.conditionRows ?? []}\n combinator={draft?.conditionCombinator ?? 'and'}\n onRowsChange={(update) =>\n onDraft((previous) => ({\n ...previous,\n conditionRows: update(previous.conditionRows),\n }))\n }\n onCombinatorChange={(combinator) =>\n onDraft((previous) => ({\n ...previous,\n conditionCombinator: combinator,\n }))\n }\n />\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Runs on'}\n </Typography>\n <RadioGroup\n row\n value={draft?.placement ?? 'org'}\n onChange={(event) =>\n onDraft((previous) => ({\n ...previous,\n placement: event.target.value === 'sites' ? 'sites' : 'org',\n }))\n }\n >\n <FormControlLabel\n value=\"org\"\n control={<Radio size=\"small\" />}\n label=\"Every site\"\n />\n <FormControlLabel\n value=\"sites\"\n control={<Radio size=\"small\" />}\n label=\"Chosen sites\"\n />\n </RadioGroup>\n {draft?.placement === 'sites' ? (\n <FormGroup aria-label=\"Sites it runs on\">\n {!mount.hostsReady ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'…'}\n </Typography>\n ) : !sites.length ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'This organization has no sites yet.'}\n </Typography>\n ) : (\n sites.map((site) => (\n <FormControlLabel\n key={site.value}\n control={\n <Checkbox\n size=\"small\"\n checked={draft.siteIds.includes(site.value)}\n onChange={(event) =>\n onDraft((previous) => ({\n ...previous,\n siteIds: event.target.checked\n ? [...previous.siteIds, site.value]\n : previous.siteIds.filter((id) => id !== site.value),\n }))\n }\n />\n }\n label={site.label}\n />\n ))\n )}\n {tooManySites ? (\n <Typography variant=\"caption\" color=\"error\">\n {`Choose ${MAX_SCOPE_HOSTS} sites or fewer, or run it on every site.`}\n </Typography>\n ) : null}\n </FormGroup>\n ) : null}\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Steps (run in order)'}\n </Typography>\n {(draft?.steps ?? []).map((step, index) => (\n <AutomationStepFields\n key={index}\n step={step}\n index={index}\n kind={step.type}\n kinds={ORG_AUTOMATION_STEP_KINDS}\n stepForKind={(value) => defaultStep(value as HostActionStepType)}\n pickers={pickers}\n onSteps={(update) =>\n onDraft((previous) => ({\n ...previous,\n steps: update(previous.steps),\n }))\n }\n replyContext={{\n event: draft?.event,\n afterWait: stepRunsAfterWait(draft?.steps, index),\n }}\n />\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={(draft?.steps.length ?? 0) >= ACTION_MAX_STEPS}\n onClick={() =>\n onDraft((previous) => ({\n ...previous,\n steps: [...previous.steps, defaultStep('sendEmail')],\n }))\n }\n >\n {'Add step'}\n </Button>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={draft?.enabled !== false}\n onChange={(event) =>\n onDraft((previous) => ({\n ...previous,\n enabled: event.target.checked,\n }))\n }\n />\n }\n label=\"Switched on\"\n />\n </DialogContent>\n <DialogActions>\n <Button color=\"inherit\" onClick={onClose}>\n {'Cancel'}\n </Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!draft?.name.trim() || saving}\n onClick={onSave}\n >\n {saving ? 'Saving…' : 'Save org automation'}\n </Button>\n </DialogActions>\n </Dialog>\n )\n}\nOrgAutomationEditor.displayName = 'OrgAutomationEditor'\n"],"names":["ACTION_MAX_STEPS","hostEventLabel","hostEventPayloadHint","triggerFilterProblem","hostIdsFromScope","hostScopeToken","isOrgWideScope","MAX_SCOPE_HOSTS","ORG_SCOPE_TOKEN","Alert","Button","Checkbox","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","FormGroup","MenuItem","Radio","RadioGroup","Stack","Switch","TextField","Typography","useMemo","isOrgAutomationStepType","isOrgAutomationTriggerEvent","ORG_AUTOMATION_STEP_KINDS","ORG_AUTOMATION_TRIGGER_EVENTS","AutomationStepFields","defaultStep","conditionRowsFromTrigger","conditionsFromRows","EMPTY_CONDITION_ROW","TriggerConditionRows","EDITOR_OPTION_CEILING","useOrgAutomationStepPickers","orgSiteOptions","stepRunsAfterWait","newOrgAutomationDraft","id","name","event","filter","conditionRows","conditionCombinator","steps","enabled","placement","siteIds","orgAutomationDraft","row","trigger","$id","combinator","visibleTo","orgAutomationDraftFromProposal","proposal","length","every","step","type","String","conditions","map","condition","field","op","value","undefined","draftPlacement","draft","orgAutomationBody","trim","OrgAutomationEditor","props","mount","onDraft","opened","saving","onSave","onClose","pickers","truncated","orgId","sites","tooManySites","open","Boolean","maxWidth","fullWidth","sx","display","flexDirection","gap","pt","variant","color","severity","join","label","onChange","previous","target","size","autoFocus","mt","direction","spacing","select","minWidth","eventType","placeholder","error","helperText","flex","rows","onRowsChange","update","onCombinatorChange","control","aria-label","hostsReady","site","checked","includes","index","kind","kinds","stepForKind","onSteps","replyContext","afterWait","alignSelf","disabled","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,gBAAgB,EAChBC,cAAc,EACdC,oBAAoB,EAEpBC,oBAAoB,QACf,eAAc;AACrB,SACEC,gBAAgB,EAChBC,cAAc,EACdC,cAAc,EACdC,eAAe,EACfC,eAAe,QACV,sCAAqC;AAC5C,SACEC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,SAAS,EACTC,QAAQ,EACRC,KAAK,EACLC,UAAU,EACVC,KAAK,EAC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MAAK;4BACLoB,SAASrD,CAAAA,yBAAAA,MAAOxB,OAAO,MAAK;4BAC5BsD,UAAU,CAAC3D,QACTmC,QAAQ,CAACyB,WAAc,aAClBA;wCACHvD,SAASL,MAAM6D,MAAM,CAACqB,OAAO;;;wBAKrCxB,OAAM;;;;0BAGV,MAACxF;;kCACC,KAACH;wBAAOwF,OAAM;wBAAUsC,SAAStD;kCAC9B;;kCAEH,KAACxE;wBACCuF,SAAQ;wBACRC,OAAM;wBACNqC,UAAU,EAAC/D,yBAAAA,MAAO9B,IAAI,CAACgC,IAAI,OAAMM;wBACjCwD,SAASvD;kCAERD,SAAS,YAAY;;;;;;AAKhC;AACAL,oBAAoB8D,WAAW,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/workflows/src/lib/components/org-automation-editor.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n ACTION_MAX_STEPS,\n hostEventLabel,\n hostEventPayloadHint,\n type TriggerCombinator,\n triggerFilterProblem,\n} from '@aglyn/aglyn'\nimport {\n hostScopeToken,\n ORG_SCOPE_TOKEN,\n scopeSharingOf,\n sharingFromChoice,\n} from '@aglyn/aglyn/app-utils/scope-tokens'\nimport {\n SiteSharingField,\n type SiteSharingValue,\n} from '@aglyn/shared-ui-jsx/components/site-sharing-field.component'\nimport {\n Alert,\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useMemo } from 'react'\nimport {\n isOrgAutomationStepType,\n isOrgAutomationTriggerEvent,\n ORG_AUTOMATION_STEP_KINDS,\n ORG_AUTOMATION_TRIGGER_EVENTS,\n type OrgAutomationRow,\n type OrgAutomationTriggerEvent,\n} from '../model/org-automations'\nimport {\n AutomationStepFields,\n defaultStep,\n} from './automation-step-fields.component'\nimport {\n conditionRowsFromTrigger,\n conditionsFromRows,\n type ConditionRowDraft,\n EMPTY_CONDITION_ROW,\n TriggerConditionRows,\n} from './automation-trigger-conditions.component'\nimport { EDITOR_OPTION_CEILING } from './use-automation-step-pickers'\nimport { useOrgAutomationStepPickers } from './use-org-automation-step-pickers'\nimport { orgSiteOptions, type WorkflowsOrgMount } from './workflows-org-mount'\nimport {\n type HostActionStep,\n type HostActionStepType,\n type HostActionTriggerCondition,\n stepRunsAfterWait,\n} from '../model/host-actions'\nimport type { OrgAutomationProposal } from './workflow-zones'\n\n/** An org automation as the editor holds it. */\nexport interface OrgAutomationDraft {\n /** The stored document's id, or null for a new one. */\n id: string | null\n name: string\n event: OrgAutomationTriggerEvent\n filter: string\n conditionRows: ConditionRowDraft[]\n conditionCombinator: TriggerCombinator\n steps: HostActionStep[]\n enabled: boolean\n /**\n * Where it runs: every site, the sites chosen, or every site except the\n * ones left out (AGL-4047), as the sharing field edits it.\n */\n sharing: SiteSharingValue\n}\n\n/** A blank draft: every site, one email step, switched on. */\nexport function newOrgAutomationDraft(): OrgAutomationDraft {\n return {\n id: null,\n name: '',\n event: 'formSubmission',\n filter: '',\n conditionRows: [EMPTY_CONDITION_ROW],\n conditionCombinator: 'and',\n steps: [defaultStep('sendEmail')],\n enabled: true,\n sharing: { mode: 'all' },\n }\n}\n\n/** Where a stored automation runs, as the sharing field edits it. */\nfunction sharingOfRow(row: OrgAutomationRow): SiteSharingValue {\n const sharing = scopeSharingOf(row as unknown as Record<string, unknown>)\n if (sharing.mode === 'all') return { mode: 'all' }\n if (sharing.mode === 'allExcept') return { mode: 'allExcept', exceptHostIds: sharing.exceptHostIds }\n return { mode: 'selected', hostIds: sharing.mode === 'selected' ? sharing.hostIds : [] }\n}\n\n/** A stored org automation as the editor opens it. */\nexport function orgAutomationDraft(row: OrgAutomationRow): OrgAutomationDraft {\n const event = isOrgAutomationTriggerEvent(row.trigger?.event)\n ? row.trigger.event\n : 'formSubmission'\n return {\n id: row.$id,\n name: row.name ?? '',\n event,\n filter: row.trigger?.filter ?? '',\n conditionRows: conditionRowsFromTrigger(row.trigger),\n conditionCombinator: row.trigger?.combinator === 'or' ? 'or' : 'and',\n steps: [...(row.steps ?? [])],\n enabled: row.enabled !== false,\n sharing: sharingOfRow(row),\n }\n}\n\n/**\n * An automation another plugin proposed (AGL-3603) as the editor opens it:\n * NEW, switched off and placed on every site until the person chooses, or\n * `null` when its trigger or a step is not one an org automation may hold.\n * Nothing is stored; the editor's Save is the write, through the route's\n * own reader.\n */\nexport function orgAutomationDraftFromProposal(\n proposal: OrgAutomationProposal,\n): OrgAutomationDraft | null {\n const event = proposal.trigger?.event\n if (!isOrgAutomationTriggerEvent(event)) return null\n const steps = proposal.steps ?? []\n if (!steps.length || !steps.every((step) => isOrgAutomationStepType(step?.type))) {\n return null\n }\n return {\n ...newOrgAutomationDraft(),\n name: String(proposal.name ?? ''),\n event,\n conditionRows: conditionRowsFromTrigger({\n conditions: (proposal.trigger.conditions ?? []).map((condition) => ({\n field: condition.field,\n op: condition.op,\n ...(condition.value !== undefined ? { value: condition.value } : {}),\n })) as HostActionTriggerCondition[],\n }),\n conditionCombinator: proposal.trigger.combinator === 'or' ? 'or' : 'and',\n steps: steps.map((step) => ({ ...step }) as unknown as HostActionStep),\n enabled: false,\n }\n}\n\n/**\n * What a draft's placement would store given the workspace's sites, or why it\n * can't be: the answer the manage route gives, from `sharingFromChoice`. The\n * sites a draft leaves out stay known here even where the list lacks them, so\n * they aren't taken for sites that are gone.\n */\nexport function draftSharing(draft: OrgAutomationDraft, orgHostIds: readonly string[]) {\n const leftOut = draft.sharing.mode === 'allExcept' ? draft.sharing.exceptHostIds : []\n return sharingFromChoice(draft.sharing, [...orgHostIds, ...leftOut])\n}\n\n/**\n * The automation as its placement would leave it, for the pickers that offer\n * only what reaches every site it runs on (`sharingCovers`).\n */\nexport function draftPlacement(\n draft: OrgAutomationDraft,\n orgHostIds: readonly string[],\n): Readonly<Record<string, unknown>> {\n const fields = draftSharing(draft, orgHostIds).fields\n return fields ? { ...fields } : { visibleTo: [] }\n}\n\n/**\n * The body `automations/manage` reads, from a draft: the choice, which decides\n * (AGL-4047), and beside every site or the chosen ones the `visibleTo` it\n * stores, as the route read it before there was a choice.\n */\nexport function orgAutomationBody(\n draft: OrgAutomationDraft,\n): Record<string, unknown> {\n const { sharing } = draft\n return {\n name: draft.name.trim(),\n trigger: {\n event: draft.event,\n ...(draft.filter.trim() ? { filter: draft.filter.trim() } : {}),\n ...conditionsFromRows(draft.conditionRows, draft.conditionCombinator),\n },\n steps: draft.steps,\n enabled: draft.enabled,\n ...(sharing.mode === 'all'\n ? { visibleTo: [ORG_SCOPE_TOKEN] }\n : sharing.mode === 'selected'\n ? { visibleTo: sharing.hostIds.map(hostScopeToken) }\n : {}),\n sharing:\n sharing.mode === 'all'\n ? { mode: 'all' }\n : sharing.mode === 'selected'\n ? { mode: 'selected', hostIds: [...sharing.hostIds] }\n : { mode: 'allExcept', exceptHostIds: [...sharing.exceptHostIds] },\n }\n}\n\nexport interface OrgAutomationEditorProps {\n mount: WorkflowsOrgMount\n /** The draft being edited, or null when the dialog is closed. */\n draft: OrgAutomationDraft | null\n onDraft: (update: (previous: OrgAutomationDraft) => OrgAutomationDraft) => void\n /** The editor has been opened at least once: the latch the pickers read on. */\n opened: boolean\n saving: boolean\n onSave: () => void\n onClose: () => void\n}\n\n/**\n * The org automation editor (AGL-3302): a name, a trigger an org automation\n * can start on, the conditions, the steps from the org vocabulary, and the\n * sites it runs on.\n *\n * The same step rows and condition rows the actions builder uses, offered\n * only what an org automation may hold. Nothing is written from here: Save\n * hands the draft to `automations/manage`, which checks it again.\n */\nexport function OrgAutomationEditor(props: OrgAutomationEditorProps) {\n const { mount, draft, onDraft, opened, saving, onSave, onClose } = props\n const orgHostIds = useMemo(() => mount.hosts.map((host) => host.id), [mount.hosts])\n const placement = useMemo(\n () => (draft ? draftPlacement(draft, orgHostIds) : { visibleTo: [ORG_SCOPE_TOKEN] }),\n [draft, orgHostIds],\n )\n const { pickers, truncated } = useOrgAutomationStepPickers(\n mount.orgId,\n opened,\n placement,\n )\n const sites = useMemo(\n () => orgSiteOptions(mount).map((site) => ({ id: site.value, name: site.label })),\n [mount],\n )\n // Nothing to say about leaving sites out until the sites have been read.\n const sharingProblem =\n draft && (draft.sharing.mode !== 'allExcept' || mount.hostsReady)\n ? draftSharing(draft, orgHostIds).problem\n : null\n return (\n <Dialog open={Boolean(draft)} onClose={onClose} maxWidth=\"md\" fullWidth>\n <DialogTitle>\n {draft?.id ? 'Edit org automation' : 'Add org automation'}\n </DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, pt: 1 }}\n >\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Runs on every site you place it on, as that site: its email goes ' +\n 'from that site, its runs count on that site’s action runs, and ' +\n 'the site can pause it for itself.'}\n </Typography>\n {truncated.length > 0 ? (\n <Alert severity=\"info\">\n {`Offering the first ${EDITOR_OPTION_CEILING} rows, ordered by id, ` +\n `for: ${truncated.join(', ')}. The organization has more, so a ` +\n 'step target may not be listed below.'}\n </Alert>\n ) : null}\n <TextField\n label=\"Name\"\n value={draft?.name ?? ''}\n onChange={(event) =>\n onDraft((previous) => ({ ...previous, name: event.target.value }))\n }\n size=\"small\"\n autoFocus\n sx={{ mt: 1 }}\n />\n <Stack direction=\"row\" spacing={1}>\n <TextField\n select\n label=\"Trigger event\"\n value={draft?.event ?? 'formSubmission'}\n onChange={(event) =>\n onDraft((previous) => ({\n ...previous,\n event: event.target.value as OrgAutomationTriggerEvent,\n }))\n }\n size=\"small\"\n sx={{ minWidth: 200 }}\n >\n {ORG_AUTOMATION_TRIGGER_EVENTS.map((eventType) => (\n <MenuItem key={eventType} value={eventType}>\n {hostEventLabel(eventType)}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n label=\"Filter (optional)\"\n placeholder=\"subscribe\"\n // A comparison belongs in the conditions below (AGL-3458): the\n // filter's evaluator is arithmetic, and `source == \"form\"` throws\n // on every event, so it is refused here.\n error={Boolean(triggerFilterProblem(draft?.filter))}\n helperText={\n triggerFilterProblem(draft?.filter) ?? hostEventPayloadHint(draft?.event) ?? undefined\n }\n value={draft?.filter ?? ''}\n onChange={(event) =>\n onDraft((previous) => ({ ...previous, filter: event.target.value }))\n }\n size=\"small\"\n sx={{ flex: 1 }}\n />\n </Stack>\n <TriggerConditionRows\n rows={draft?.conditionRows ?? []}\n combinator={draft?.conditionCombinator ?? 'and'}\n onRowsChange={(update) =>\n onDraft((previous) => ({\n ...previous,\n conditionRows: update(previous.conditionRows),\n }))\n }\n onCombinatorChange={(combinator) =>\n onDraft((previous) => ({\n ...previous,\n conditionCombinator: combinator,\n }))\n }\n />\n <SiteSharingField\n label=\"Runs on\"\n value={draft?.sharing ?? { mode: 'all' }}\n onChange={(next) => onDraft((previous) => ({ ...previous, sharing: next }))}\n sites={sites}\n sitesReady={mount.hostsReady}\n problem={sharingProblem}\n />\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Steps (run in order)'}\n </Typography>\n {(draft?.steps ?? []).map((step, index) => (\n <AutomationStepFields\n key={index}\n step={step}\n index={index}\n kind={step.type}\n kinds={ORG_AUTOMATION_STEP_KINDS}\n stepForKind={(value) => defaultStep(value as HostActionStepType)}\n pickers={pickers}\n onSteps={(update) =>\n onDraft((previous) => ({\n ...previous,\n steps: update(previous.steps),\n }))\n }\n replyContext={{\n event: draft?.event,\n afterWait: stepRunsAfterWait(draft?.steps, index),\n }}\n />\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={(draft?.steps.length ?? 0) >= ACTION_MAX_STEPS}\n onClick={() =>\n onDraft((previous) => ({\n ...previous,\n steps: [...previous.steps, defaultStep('sendEmail')],\n }))\n }\n >\n {'Add step'}\n </Button>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={draft?.enabled !== false}\n onChange={(event) =>\n onDraft((previous) => ({\n ...previous,\n enabled: event.target.checked,\n }))\n }\n />\n }\n label=\"Switched on\"\n />\n </DialogContent>\n <DialogActions>\n <Button color=\"inherit\" onClick={onClose}>\n {'Cancel'}\n </Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!draft?.name.trim() || saving}\n onClick={onSave}\n >\n {saving ? 'Saving…' : 'Save org automation'}\n </Button>\n </DialogActions>\n </Dialog>\n )\n}\nOrgAutomationEditor.displayName = 'OrgAutomationEditor'\n"],"names":["ACTION_MAX_STEPS","hostEventLabel","hostEventPayloadHint","triggerFilterProblem","hostScopeToken","ORG_SCOPE_TOKEN","scopeSharingOf","sharingFromChoice","SiteSharingField","Alert","Button","Dialog","DialogActions","DialogContent","DialogTitle","FormControlLabel","MenuItem","Stack","Switch","TextField","Typography","useMemo","isOrgAutomationStepType","isOrgAutomationTriggerEvent","ORG_AUTOMATION_STEP_KINDS","ORG_AUTOMATION_TRIGGER_EVENTS","AutomationStepFields","defaultStep","conditionRowsFromTrigger","conditionsFromRows","EMPTY_CONDITION_ROW","TriggerConditionRows","EDITOR_OPTION_CEILING","useOrgAutomationStepPickers","orgSiteOptions","stepRunsAfterWait","newOrgAutomationDraft","id","name","event","filter","conditionRows","conditionCombinator","steps","enabled","sharing","mode","sharingOfRow","row","exceptHostIds","hostIds","orgAutomationDraft","trigger","$id","combinator","orgAutomationDraftFromProposal","proposal","length","every","step","type","String","conditions","map","condition","field","op","value","undefined","draftSharing","draft","orgHostIds","leftOut","draftPlacement","fields","visibleTo","orgAutomationBody","trim","OrgAutomationEditor","props","mount","onDraft","opened","saving","onSave","onClose","hosts","host","placement","pickers","truncated","orgId","sites","site","label","sharingProblem","hostsReady","problem","open","Boolean","maxWidth","fullWidth","sx","display","flexDirection","gap","pt","variant","color","severity","join","onChange","previous","target","size","autoFocus","mt","direction","spacing","select","minWidth","eventType","placeholder","error","helperText","flex","rows","onRowsChange","update","onCombinatorChange","next","sitesReady","index","kind","kinds","stepForKind","onSteps","replyContext","afterWait","alignSelf","disabled","onClick","control","checked","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,gBAAgB,EAChBC,cAAc,EACdC,oBAAoB,EAEpBC,oBAAoB,QACf,eAAc;AACrB,SACEC,cAAc,EACdC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,sCAAqC;AAC5C,SACEC,gBAAgB,QAEX,+DAA8D;AACrE,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,OAAO,QAAQ,QAAO;AAC/B,SACEC,uBAAuB,EACvBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,6BAA6B,QAGxB,8BAA0B;AACjC,SACEC,oBAAoB,EACpBC,WAAW,QACN,wCAAoC;AAC3C,SACEC,wBAAwB,EACxBC,kBAAkB,EAElBC,mBAAmB,EACnBC,oBAAoB,QACf,+CAA2C;AAClD,SAASC,qBAAqB,QAAQ,mCAA+B;AACrE,SAASC,2BAA2B,QAAQ,uCAAmC;AAC/E,SAASC,cAAc,QAAgC,2BAAuB;AAC9E,SAIEC,iBAAiB,QACZ,2BAAuB;AAqB9B,4DAA4D,GAC5D,OAAO,SAASC;IACd,OAAO;QACLC,IAAI;QACJC,MAAM;QACNC,OAAO;QACPC,QAAQ;QACRC,eAAe;YAACX;SAAoB;QACpCY,qBAAqB;QACrBC,OAAO;YAAChB,YAAY;SAAa;QACjCiB,SAAS;QACTC,SAAS;YAAEC,MAAM;QAAM;IACzB;AACF;A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ERD,SAAS,YAAY;;;;;;AAKhC;AACAL,oBAAoBkE,WAAW,GAAG"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
18
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
19
19
|
import { checkEntitlement, hostEventLabel, pluginDocsHelp } from "@aglyn/aglyn";
|
|
20
|
-
import { hostIdsFromScope, isOrgWideScope } from "@aglyn/aglyn/app-utils/scope-tokens";
|
|
20
|
+
import { hostIdsFromScope, isOrgWideScope, scopeSharingOf } from "@aglyn/aglyn/app-utils/scope-tokens";
|
|
21
21
|
import { useConsoleWidgetSlot } from "@aglyn/aglyn/app-utils/console-widget-slot-context";
|
|
22
22
|
import { CardDisplay, useConfirmationContext } from "@aglyn/shared-ui-jsx";
|
|
23
23
|
import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
|
|
@@ -28,7 +28,7 @@ import { Alert, Button, Chip, Menu, MenuItem, Stack, Switch, Typography } from "
|
|
|
28
28
|
import { collection, documentId, limit, orderBy, query, where } from "firebase/firestore";
|
|
29
29
|
import { useCallback, useMemo, useState } from "react";
|
|
30
30
|
import { ORG_AUTOMATION_STEP_TYPES, ORG_AUTOMATION_TRIGGER_EVENTS, ORG_AUTOMATIONS_COLLECTION, ORG_AUTOMATIONS_MAX, orgAutomationPausedHostIds, readOrgAutomation } from "../model/org-automations.js";
|
|
31
|
-
import { newOrgAutomationDraft, OrgAutomationEditor, orgAutomationBody, orgAutomationDraft, orgAutomationDraftFromProposal } from "./org-automation-editor.component.js";
|
|
31
|
+
import { draftSharing, newOrgAutomationDraft, OrgAutomationEditor, orgAutomationBody, orgAutomationDraft, orgAutomationDraftFromProposal } from "./org-automation-editor.component.js";
|
|
32
32
|
import { ORG_AUTOMATIONS_ZONE } from "./workflow-zones.js";
|
|
33
33
|
import { useOrgAutomationsApi } from "./use-org-automations-api.js";
|
|
34
34
|
import { orgSiteName } from "./workflows-org-mount.js";
|
|
@@ -36,8 +36,17 @@ import { HOST_ACTION_STEP_LABELS } from "../model/host-actions.js";
|
|
|
36
36
|
/** The sites an automation runs on, by id: every org site for `['org']`. */ function placedSiteIds(row, mount) {
|
|
37
37
|
return isOrgWideScope(row.visibleTo) ? mount.hosts.map((host)=>host.id) : hostIdsFromScope(row.visibleTo);
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* "Runs on every site", "Runs on Shop, Blog" or, for one that runs on all
|
|
41
|
+
* sites except some (AGL-4047), "Runs on every site except Blog".
|
|
42
|
+
*/ function placementLine(row, mount) {
|
|
43
|
+
const sharing = scopeSharingOf(row);
|
|
44
|
+
if (sharing.mode === 'all') return 'Runs on every site';
|
|
45
|
+
if (sharing.mode === 'allExcept') {
|
|
46
|
+
if (!sharing.includedHostIds.length) return 'Runs on no site';
|
|
47
|
+
const leftOut = sharing.exceptHostIds.map((id)=>orgSiteName(mount, id));
|
|
48
|
+
return `Runs on every site except ${leftOut.join(', ')}`;
|
|
49
|
+
}
|
|
41
50
|
const names = hostIdsFromScope(row.visibleTo).map((id)=>orgSiteName(mount, id));
|
|
42
51
|
return names.length ? `Runs on ${names.join(', ')}` : 'Runs on no site';
|
|
43
52
|
}
|
|
@@ -154,6 +163,15 @@ import { HOST_ACTION_STEP_LABELS } from "../model/host-actions.js";
|
|
|
154
163
|
persist: false
|
|
155
164
|
});
|
|
156
165
|
}
|
|
166
|
+
// Where it runs, against the workspace's sites, as the route will ask it
|
|
167
|
+
// (AGL-4047). Leaving sites out waits for the sites; the route asks again.
|
|
168
|
+
const placement = draft.sharing.mode !== 'allExcept' || mount.hostsReady ? draftSharing(draft, mount.hosts.map((host)=>host.id)) : null;
|
|
169
|
+
if (placement == null ? void 0 : placement.problem) {
|
|
170
|
+
return void enqueueSnackbar(placement.problem, {
|
|
171
|
+
variant: 'warning',
|
|
172
|
+
persist: false
|
|
173
|
+
});
|
|
174
|
+
}
|
|
157
175
|
setSaving(true);
|
|
158
176
|
try {
|
|
159
177
|
await api('manage', _extends({
|
|
@@ -178,6 +196,8 @@ import { HOST_ACTION_STEP_LABELS } from "../model/host-actions.js";
|
|
|
178
196
|
draft,
|
|
179
197
|
api,
|
|
180
198
|
mount.orgId,
|
|
199
|
+
mount.hosts,
|
|
200
|
+
mount.hostsReady,
|
|
181
201
|
enqueueSnackbar,
|
|
182
202
|
fail
|
|
183
203
|
]);
|