@dsh-workbench/shared 1.5.3 → 1.5.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/card/ApprovalDetail.d.ts +1 -0
- package/dist/components/card/ApprovalDetail.js +16 -2
- package/dist/components/card/LongTaskRow.css +62 -0
- package/dist/components/card/LongTaskRow.d.ts +17 -6
- package/dist/components/card/LongTaskRow.js +88 -46
- package/dist/components/card/board-module.d.ts +1 -0
- package/dist/contract/long-task.d.ts +20 -0
- package/dist/contract/long-task.js +2 -0
- package/dist/contract/protocol/long-tasks.d.ts +3 -1
- package/dist/host/flow/run.js +8 -2
- package/dist/host/flow/step.d.ts +1 -1
- package/dist/host/flow/step.js +8 -5
- package/dist/host/flow/task.js +12 -6
- package/dist/host/flow/types.d.ts +3 -2
- package/dist/host/unit/long-task.d.ts +13 -1
- package/dist/host/unit/long-task.js +56 -3
- package/dist/i18n/en.js +12 -0
- package/dist/i18n/index.d.ts +13 -1
- package/dist/i18n/zh.d.ts +12 -0
- package/dist/i18n/zh.js +12 -0
- package/package.json +1 -1
- package/src/components/card/ApprovalDetail.tsx +16 -2
- package/src/components/card/LongTaskRow.css +62 -0
- package/src/components/card/LongTaskRow.tsx +203 -110
- package/src/components/card/__tests__/long-task-row.test.ts +69 -15
- package/src/components/card/board-module.ts +1 -0
- package/src/contract/long-task.ts +24 -0
- package/src/contract/protocol/long-tasks.ts +8 -1
- package/src/host/flow/__tests__/step.test.ts +20 -0
- package/src/host/flow/run.ts +8 -2
- package/src/host/flow/step.ts +9 -5
- package/src/host/flow/task.ts +13 -5
- package/src/host/flow/types.ts +3 -2
- package/src/host/unit/__tests__/long-task.test.ts +79 -0
- package/src/host/unit/long-task.ts +70 -2
- package/src/i18n/en.ts +12 -0
- package/src/i18n/zh.ts +12 -0
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { FormEvent } from 'react';
|
|
1
|
+
import type { FormEvent, ReactNode } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
LONG_TASK_LINK_MAX,
|
|
3
4
|
longTaskDot,
|
|
5
|
+
longTaskIsLive,
|
|
4
6
|
longTaskStopPress,
|
|
5
7
|
longTaskStopStage,
|
|
6
8
|
LONG_TASK_STOP_ARM_MS,
|
|
7
9
|
type LongTaskInterventionField,
|
|
8
10
|
type LongTaskStatus,
|
|
11
|
+
type LongTaskStepRow,
|
|
9
12
|
} from '../../contract/long-task.js';
|
|
10
13
|
import { Link } from '../layout/Link.js';
|
|
11
14
|
import { Fragment, h, useEffect, useState } from '../../lib/react.js';
|
|
@@ -41,6 +44,7 @@ export interface LongTaskRowStop {
|
|
|
41
44
|
readonly armedLabel?: string | undefined;
|
|
42
45
|
readonly busy?: boolean | undefined;
|
|
43
46
|
readonly failed?: string | null | undefined;
|
|
47
|
+
readonly pending?: string | undefined;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
/**
|
|
@@ -88,9 +92,14 @@ export interface LongTaskRowIntervention {
|
|
|
88
92
|
export interface LongTaskRowProps {
|
|
89
93
|
readonly status: LongTaskStatus;
|
|
90
94
|
readonly headline: string;
|
|
95
|
+
readonly step?: string | undefined;
|
|
96
|
+
readonly meta?: string | undefined;
|
|
97
|
+
readonly dot?: 'done' | 'ongoing' | 'error' | 'idle' | 'warning' | undefined;
|
|
98
|
+
readonly dotLabel?: string | undefined;
|
|
91
99
|
readonly problem?: string | undefined;
|
|
92
100
|
readonly links?: readonly LongTaskRowLink[] | undefined;
|
|
93
101
|
readonly steps?: readonly string[] | undefined;
|
|
102
|
+
readonly history?: readonly LongTaskStepRow[] | undefined;
|
|
94
103
|
readonly raw?: string | undefined;
|
|
95
104
|
readonly stepsTitle?: string | undefined;
|
|
96
105
|
readonly rawTitle?: string | undefined;
|
|
@@ -109,6 +118,58 @@ function RowLink({ href, text }: LongTaskRowLink) {
|
|
|
109
118
|
);
|
|
110
119
|
}
|
|
111
120
|
|
|
121
|
+
const STEP_DOT: Readonly<
|
|
122
|
+
Record<LongTaskStepRow['kind'], 'done' | 'ongoing' | 'error' | 'idle' | 'warning'>
|
|
123
|
+
> = {
|
|
124
|
+
start: 'ongoing',
|
|
125
|
+
succeed: 'done',
|
|
126
|
+
fail: 'error',
|
|
127
|
+
warn: 'warning',
|
|
128
|
+
info: 'idle',
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const HTTP_PATTERN = /^https?:\/\//i;
|
|
132
|
+
|
|
133
|
+
function StepRow({ row }: { readonly row: LongTaskStepRow }) {
|
|
134
|
+
const links = (row.links ?? [])
|
|
135
|
+
.filter((link) => HTTP_PATTERN.test(link.href))
|
|
136
|
+
.slice(0, LONG_TASK_LINK_MAX);
|
|
137
|
+
return (
|
|
138
|
+
<li className="wb-longTaskStepRow" data-kind={row.kind}>
|
|
139
|
+
<StateDot state={STEP_DOT[row.kind]} size={8} />
|
|
140
|
+
<span className="wb-longTaskStepText">{row.text}</span>
|
|
141
|
+
{links.map((link) => (
|
|
142
|
+
<Link className="wb-longTaskStepLink" href={link.href} key={`${link.href}@${link.text}`}>
|
|
143
|
+
{link.text}
|
|
144
|
+
</Link>
|
|
145
|
+
))}
|
|
146
|
+
</li>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function DumpBlock(props: {
|
|
151
|
+
readonly icon: ReactNode;
|
|
152
|
+
readonly title: string;
|
|
153
|
+
readonly open: boolean;
|
|
154
|
+
readonly onToggle: () => void;
|
|
155
|
+
readonly children: ReactNode;
|
|
156
|
+
}) {
|
|
157
|
+
return (
|
|
158
|
+
<DisclosureRow
|
|
159
|
+
className="wb-longTaskDump"
|
|
160
|
+
icon={props.icon}
|
|
161
|
+
title={props.title}
|
|
162
|
+
open={props.open}
|
|
163
|
+
expandable
|
|
164
|
+
expandOnRowClick
|
|
165
|
+
previewChevron
|
|
166
|
+
onToggle={props.onToggle}
|
|
167
|
+
>
|
|
168
|
+
{props.children}
|
|
169
|
+
</DisclosureRow>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
112
173
|
interface InterventionFormProps {
|
|
113
174
|
readonly fields: readonly LongTaskInterventionField[];
|
|
114
175
|
readonly submit: InterventionSubmit;
|
|
@@ -156,58 +217,131 @@ function InterventionForm({ fields, submit }: InterventionFormProps) {
|
|
|
156
217
|
);
|
|
157
218
|
}
|
|
158
219
|
|
|
220
|
+
function StopControl({ stop, onFired }: { stop: LongTaskRowStop; onFired: () => void }) {
|
|
221
|
+
const [armed, setArmed] = useState(false);
|
|
222
|
+
const busy = stop.busy === true;
|
|
223
|
+
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
if (!armed) return undefined;
|
|
226
|
+
const timer = setTimeout(() => setArmed(false), LONG_TASK_STOP_ARM_MS);
|
|
227
|
+
return () => clearTimeout(timer);
|
|
228
|
+
}, [armed]);
|
|
229
|
+
|
|
230
|
+
const onPress = (): void => {
|
|
231
|
+
const press = longTaskStopPress(longTaskStopStage({ armed, busy }));
|
|
232
|
+
if (press === 'ignore') return;
|
|
233
|
+
if (press === 'arm') {
|
|
234
|
+
setArmed(true);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
setArmed(false);
|
|
238
|
+
onFired();
|
|
239
|
+
stop.onStop();
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<button
|
|
244
|
+
type="button"
|
|
245
|
+
className={`wb-longTaskStop${armed ? ' wb-longTaskStopArmed' : ''}`}
|
|
246
|
+
data-stop-state={longTaskStopStage({ armed, busy })}
|
|
247
|
+
aria-label={armed ? stop.armedLabel ?? stop.askLabel : stop.label}
|
|
248
|
+
disabled={busy}
|
|
249
|
+
onClick={onPress}
|
|
250
|
+
onBlur={() => setArmed(false)}
|
|
251
|
+
>
|
|
252
|
+
<IconStopFillRegular size={12} />
|
|
253
|
+
{armed ? <span className="wb-longTaskStopLabel">{stop.askLabel}</span> : null}
|
|
254
|
+
</button>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function InterventionNeed({ intervention }: { intervention: LongTaskRowIntervention }) {
|
|
259
|
+
const fields = intervention.fields ?? [];
|
|
260
|
+
const submit = intervention.submit;
|
|
261
|
+
return (
|
|
262
|
+
<Fragment>
|
|
263
|
+
<p className="wb-longTaskNeed">
|
|
264
|
+
<span className="wb-longTaskNeedTitle">{intervention.title}</span>
|
|
265
|
+
{intervention.hint === undefined ? null : (
|
|
266
|
+
<span className="wb-longTaskNeedHint">{intervention.hint}</span>
|
|
267
|
+
)}
|
|
268
|
+
{(intervention.actions ?? []).map((action) => (
|
|
269
|
+
<Button
|
|
270
|
+
key={action.key}
|
|
271
|
+
type="button"
|
|
272
|
+
size="sm"
|
|
273
|
+
variant={action.primary === true ? 'primary' : 'outline'}
|
|
274
|
+
disabled={action.busy === true}
|
|
275
|
+
onClick={action.onPress}
|
|
276
|
+
>
|
|
277
|
+
{action.label}
|
|
278
|
+
</Button>
|
|
279
|
+
))}
|
|
280
|
+
</p>
|
|
281
|
+
{fields.length === 0 || submit === undefined ? null : (
|
|
282
|
+
<InterventionForm fields={fields} submit={submit} />
|
|
283
|
+
)}
|
|
284
|
+
{intervention.failed === undefined || intervention.failed === null || intervention.failed === '' ? null : (
|
|
285
|
+
<p className="wb-longTaskNeedWhy">{intervention.failed}</p>
|
|
286
|
+
)}
|
|
287
|
+
</Fragment>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
159
291
|
/**
|
|
160
|
-
*
|
|
292
|
+
* 长任务那一行:点 + 标题 + 链接,可选一行当前步骤与一行状态 · 耗时;步骤收在可展开里。
|
|
161
293
|
* 发布、扫描、迁移这类跑得久的事都用它,别自己画进度。
|
|
162
|
-
* @param props.status -
|
|
294
|
+
* @param props.status - 六态之一,决定默认的点与「失败」那一块。
|
|
163
295
|
* @param props.headline - 这一行在干什么(一句话)。
|
|
296
|
+
* @param props.step - 当前步骤;运行中 / 停止后给,不给不画。
|
|
297
|
+
* @param props.meta - 状态词 · 耗时那一行;不给不画。
|
|
298
|
+
* @param props.dot - 点的档位覆盖;不给就用 `longTaskDot(status)`。
|
|
299
|
+
* @param props.dotLabel - 点的读屏文案;不给就不挂 `aria-label`。
|
|
164
300
|
* @param props.problem - 失败原因;不给不画。
|
|
165
301
|
* @param props.links - 行尾的链接,通常指向产物或日志。
|
|
166
|
-
* @param props.steps -
|
|
167
|
-
* @param props.
|
|
302
|
+
* @param props.steps - 旧的纯文本步骤;只在没有 `history` 时作为回退画。
|
|
303
|
+
* @param props.history - 结构化步骤;有它就一行一步,每步的链接挂在行尾。
|
|
304
|
+
* @param props.raw - 原始输出;给了 `rawTitle` 才成一块可展开。
|
|
168
305
|
* @param props.stepsTitle - 步骤那块展开行的标题;`rawTitle` 同理是原始输出那块。
|
|
169
306
|
* @param props.copyLabel - 复制钮文案:给了才画复制钮;`copiedLabel` 是复制成功后那句。
|
|
170
307
|
* @param props.login - `needs-login` 时那颗「去登录」;不给不画。
|
|
171
308
|
* @param props.intervention - `needs-human` 时的「要人做什么」那一行与动作;不给不画。
|
|
172
|
-
* @param props.stop -
|
|
309
|
+
* @param props.stop - 给了才在最右边画那颗两按停止钮;**不给就一个像素都不变**。`pending` 是「已请求停止,等模块确认」那句。
|
|
173
310
|
* @returns 一行长任务。
|
|
174
311
|
*/
|
|
175
312
|
export function LongTaskRow(props: LongTaskRowProps) {
|
|
176
|
-
const [stepsOpen, setStepsOpen] = useState(
|
|
313
|
+
const [stepsOpen, setStepsOpen] = useState(props.status === 'failed');
|
|
177
314
|
const [rawOpen, setRawOpen] = useState(false);
|
|
178
|
-
const [
|
|
315
|
+
const [stopFired, setStopFired] = useState(false);
|
|
179
316
|
const failed = props.status === 'failed';
|
|
317
|
+
const live = longTaskIsLive(props.status);
|
|
318
|
+
const dot = props.dot ?? longTaskDot(props.status);
|
|
319
|
+
const step = props.step ?? '';
|
|
320
|
+
const meta = props.meta ?? '';
|
|
321
|
+
const history = props.history ?? [];
|
|
180
322
|
const problem = props.problem ?? '';
|
|
181
323
|
const raw = (props.raw ?? '').trim();
|
|
182
324
|
const steps = props.steps ?? [];
|
|
183
325
|
const stop = props.stop;
|
|
184
326
|
const busy = stop?.busy === true;
|
|
185
327
|
const stopWhy = stop?.failed ?? '';
|
|
186
|
-
const
|
|
187
|
-
|
|
328
|
+
const stopPending =
|
|
329
|
+
stopFired && live && !busy && stopWhy === '' ? stop?.pending ?? '' : '';
|
|
188
330
|
|
|
189
331
|
useEffect(() => {
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
return () => clearTimeout(timer);
|
|
193
|
-
}, [armed]);
|
|
194
|
-
|
|
195
|
-
const onStopPress = (): void => {
|
|
196
|
-
if (stop === undefined) return;
|
|
197
|
-
const press = longTaskStopPress(longTaskStopStage({ armed, busy }));
|
|
198
|
-
if (press === 'ignore') return;
|
|
199
|
-
if (press === 'arm') {
|
|
200
|
-
setArmed(true);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
setArmed(false);
|
|
204
|
-
stop.onStop();
|
|
205
|
-
};
|
|
332
|
+
if (failed) setStepsOpen(true);
|
|
333
|
+
}, [failed]);
|
|
206
334
|
|
|
207
335
|
return (
|
|
208
336
|
<div className="wb-longTask">
|
|
209
337
|
<p className="wb-longTaskHead">
|
|
210
|
-
|
|
338
|
+
{props.dotLabel === undefined ? (
|
|
339
|
+
<StateDot state={dot} size={10} />
|
|
340
|
+
) : (
|
|
341
|
+
<span role="img" aria-label={props.dotLabel}>
|
|
342
|
+
<StateDot state={dot} size={10} />
|
|
343
|
+
</span>
|
|
344
|
+
)}
|
|
211
345
|
<span className="wb-longTaskHeadline">{props.headline}</span>
|
|
212
346
|
{(props.links ?? []).map((link) => (
|
|
213
347
|
<RowLink href={link.href} key={`${link.text}@${link.href}`} text={link.text} />
|
|
@@ -217,96 +351,55 @@ export function LongTaskRow(props: LongTaskRowProps) {
|
|
|
217
351
|
{props.login.label}
|
|
218
352
|
</Button>
|
|
219
353
|
)}
|
|
220
|
-
{stop === undefined ? null : (
|
|
221
|
-
<button
|
|
222
|
-
type="button"
|
|
223
|
-
className={`wb-longTaskStop${armed ? ' wb-longTaskStopArmed' : ''}`}
|
|
224
|
-
data-stop-state={longTaskStopStage({ armed, busy })}
|
|
225
|
-
aria-label={armed ? stop.armedLabel ?? stop.askLabel : stop.label}
|
|
226
|
-
disabled={busy}
|
|
227
|
-
onClick={onStopPress}
|
|
228
|
-
onBlur={() => setArmed(false)}
|
|
229
|
-
>
|
|
230
|
-
<IconStopFillRegular size={12} />
|
|
231
|
-
{armed ? <span className="wb-longTaskStopLabel">{stop.askLabel}</span> : null}
|
|
232
|
-
</button>
|
|
233
|
-
)}
|
|
354
|
+
{stop === undefined ? null : <StopControl stop={stop} onFired={() => setStopFired(true)} />}
|
|
234
355
|
</p>
|
|
356
|
+
{step === '' ? null : <p className="wb-longTaskStep">{step}</p>}
|
|
357
|
+
{meta === '' ? null : <p className="wb-longTaskMeta">{meta}</p>}
|
|
358
|
+
{stopPending === '' ? null : <p className="wb-longTaskStopPending">{stopPending}</p>}
|
|
235
359
|
{props.intervention === undefined ? null : (
|
|
236
|
-
<
|
|
237
|
-
<p className="wb-longTaskNeed">
|
|
238
|
-
<span className="wb-longTaskNeedTitle">{props.intervention.title}</span>
|
|
239
|
-
{props.intervention.hint === undefined ? null : (
|
|
240
|
-
<span className="wb-longTaskNeedHint">{props.intervention.hint}</span>
|
|
241
|
-
)}
|
|
242
|
-
{(props.intervention.actions ?? []).map((action) => (
|
|
243
|
-
<Button
|
|
244
|
-
key={action.key}
|
|
245
|
-
type="button"
|
|
246
|
-
size="sm"
|
|
247
|
-
variant={action.primary === true ? 'primary' : 'outline'}
|
|
248
|
-
disabled={action.busy === true}
|
|
249
|
-
onClick={action.onPress}
|
|
250
|
-
>
|
|
251
|
-
{action.label}
|
|
252
|
-
</Button>
|
|
253
|
-
))}
|
|
254
|
-
</p>
|
|
255
|
-
{fields.length === 0 || submit === undefined ? null : (
|
|
256
|
-
<InterventionForm fields={fields} submit={submit} />
|
|
257
|
-
)}
|
|
258
|
-
{props.intervention.failed === undefined ||
|
|
259
|
-
props.intervention.failed === null ||
|
|
260
|
-
props.intervention.failed === '' ? null : (
|
|
261
|
-
<p className="wb-longTaskNeedWhy">{props.intervention.failed}</p>
|
|
262
|
-
)}
|
|
263
|
-
</Fragment>
|
|
360
|
+
<InterventionNeed intervention={props.intervention} />
|
|
264
361
|
)}
|
|
265
362
|
{problem === '' ? null : <p className="wb-longTaskProblem">{problem}</p>}
|
|
266
363
|
{stopWhy === '' ? null : <p className="wb-longTaskStopWhy">{stopWhy}</p>}
|
|
267
|
-
{
|
|
268
|
-
<
|
|
269
|
-
{
|
|
270
|
-
|
|
364
|
+
{props.stepsTitle === undefined || (history.length === 0 && steps.length === 0) ? null : (
|
|
365
|
+
<DumpBlock
|
|
366
|
+
icon={<IconFlatListOutlineRegular size={14} />}
|
|
367
|
+
title={props.stepsTitle}
|
|
368
|
+
open={stepsOpen}
|
|
369
|
+
onToggle={() => setStepsOpen(!stepsOpen)}
|
|
370
|
+
>
|
|
371
|
+
{history.length === 0 ? (
|
|
372
|
+
<CodeBlock
|
|
373
|
+
code={steps.join('\n')}
|
|
271
374
|
className="wb-longTaskDump"
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
className="wb-longTaskDump"
|
|
283
|
-
showHeader={props.copyLabel !== undefined}
|
|
284
|
-
copyLabel={props.copyLabel ?? ''}
|
|
285
|
-
copiedLabel={props.copiedLabel ?? ''}
|
|
286
|
-
/>
|
|
287
|
-
</DisclosureRow>
|
|
288
|
-
)}
|
|
289
|
-
{raw === '' || props.rawTitle === undefined ? null : (
|
|
290
|
-
<DisclosureRow
|
|
291
|
-
className="wb-longTaskDump"
|
|
292
|
-
icon={<IconCodeOutlineRegular size={14} />}
|
|
293
|
-
title={props.rawTitle}
|
|
294
|
-
open={rawOpen}
|
|
295
|
-
expandable
|
|
296
|
-
expandOnRowClick
|
|
297
|
-
previewChevron
|
|
298
|
-
onToggle={() => setRawOpen(!rawOpen)}
|
|
299
|
-
>
|
|
300
|
-
<CodeBlock
|
|
301
|
-
code={raw}
|
|
302
|
-
className="wb-longTaskDump"
|
|
303
|
-
showHeader={props.copyLabel !== undefined}
|
|
304
|
-
copyLabel={props.copyLabel ?? ''}
|
|
305
|
-
copiedLabel={props.copiedLabel ?? ''}
|
|
306
|
-
/>
|
|
307
|
-
</DisclosureRow>
|
|
375
|
+
showHeader={props.copyLabel !== undefined}
|
|
376
|
+
copyLabel={props.copyLabel ?? ''}
|
|
377
|
+
copiedLabel={props.copiedLabel ?? ''}
|
|
378
|
+
/>
|
|
379
|
+
) : (
|
|
380
|
+
<ul className="wb-longTaskSteps">
|
|
381
|
+
{history.map((row, index) => (
|
|
382
|
+
<StepRow key={`${String(index)}:${row.text}`} row={row} />
|
|
383
|
+
))}
|
|
384
|
+
</ul>
|
|
308
385
|
)}
|
|
309
|
-
</
|
|
386
|
+
</DumpBlock>
|
|
387
|
+
)}
|
|
388
|
+
{raw === '' || props.rawTitle === undefined ? null : (
|
|
389
|
+
<DumpBlock
|
|
390
|
+
icon={<IconCodeOutlineRegular size={14} />}
|
|
391
|
+
title={props.rawTitle}
|
|
392
|
+
open={rawOpen}
|
|
393
|
+
onToggle={() => setRawOpen(!rawOpen)}
|
|
394
|
+
>
|
|
395
|
+
<CodeBlock
|
|
396
|
+
code={raw}
|
|
397
|
+
className="wb-longTaskDump"
|
|
398
|
+
showHeader={props.copyLabel !== undefined}
|
|
399
|
+
copyLabel={props.copyLabel ?? ''}
|
|
400
|
+
copiedLabel={props.copiedLabel ?? ''}
|
|
401
|
+
/>
|
|
402
|
+
</DumpBlock>
|
|
310
403
|
)}
|
|
311
404
|
</div>
|
|
312
405
|
);
|
|
@@ -8,34 +8,32 @@ const ROW = read('LongTaskRow.tsx');
|
|
|
8
8
|
const CSS = read('LongTaskRow.css');
|
|
9
9
|
|
|
10
10
|
describe('两按停止钮:接线(这仓的组件测试是 node 环境,读源码断言)', () => {
|
|
11
|
-
it('★★ 不给 stop ⇒
|
|
12
|
-
const gate = ROW.indexOf('{stop === undefined ? null :
|
|
13
|
-
const button = ROW.indexOf('<button');
|
|
11
|
+
it('★★ 不给 stop ⇒ 那颗钮整个不出现;文件里就一颗 button', () => {
|
|
12
|
+
const gate = ROW.indexOf('{stop === undefined ? null : <StopControl');
|
|
14
13
|
|
|
15
14
|
expect(ROW).toContain('const stop = props.stop;');
|
|
16
15
|
expect(gate).toBeGreaterThan(0);
|
|
17
|
-
expect(button).
|
|
18
|
-
expect(ROW.indexOf('<button', button + 1)).toBe(-1);
|
|
16
|
+
expect(ROW.match(/<button/g)).toHaveLength(1);
|
|
19
17
|
});
|
|
20
18
|
|
|
21
19
|
it('★★ 住在 .wb-longTaskHead 里、最右边那颗(margin-left: auto)', () => {
|
|
22
20
|
const head = ROW.indexOf('className="wb-longTaskHead"');
|
|
23
|
-
const
|
|
24
|
-
const close = ROW.indexOf('</p>',
|
|
21
|
+
const gate = ROW.indexOf('{stop === undefined ? null : <StopControl');
|
|
22
|
+
const close = ROW.indexOf('</p>', gate);
|
|
25
23
|
|
|
26
24
|
expect(head).toBeGreaterThan(0);
|
|
27
|
-
expect(
|
|
28
|
-
expect(close).toBeGreaterThan(
|
|
25
|
+
expect(gate).toBeGreaterThan(head);
|
|
26
|
+
expect(close).toBeGreaterThan(gate);
|
|
29
27
|
expect(CSS).toContain('margin-left: auto');
|
|
30
28
|
});
|
|
31
29
|
|
|
32
30
|
it('★★ 两按只走 longTaskStopPress(longTaskStopStage({ armed, busy })):arm 上膛 / fire 落膛并 onStop / ignore 不动', () => {
|
|
33
31
|
expect(ROW).toContain('longTaskStopPress(longTaskStopStage({ armed, busy }))');
|
|
34
|
-
expect(ROW).toContain('onClick={
|
|
32
|
+
expect(ROW).toContain('onClick={onPress}');
|
|
35
33
|
expect(ROW).toContain("if (press === 'ignore') return;");
|
|
36
34
|
expect(ROW).toContain("if (press === 'arm') {");
|
|
37
35
|
expect(ROW).toContain('setArmed(true);');
|
|
38
|
-
expect(ROW).toMatch(/setArmed\(false\);\s*stop\.onStop\(\);/);
|
|
36
|
+
expect(ROW).toMatch(/setArmed\(false\);\s*onFired\(\);\s*stop\.onStop\(\);/);
|
|
39
37
|
});
|
|
40
38
|
|
|
41
39
|
it('★★ onBlur 落膛(焦点一走就退回没上膛)', () => {
|
|
@@ -122,8 +120,8 @@ describe('人工干预节点:结构化回执表单(fields + submit)', () =
|
|
|
122
120
|
const form = ROW.indexOf('<form className="wb-longTaskForm" onSubmit={onSubmit}>');
|
|
123
121
|
const input = ROW.indexOf('<input');
|
|
124
122
|
|
|
125
|
-
expect(ROW).toContain('const fields =
|
|
126
|
-
expect(ROW).toContain('const submit =
|
|
123
|
+
expect(ROW).toContain('const fields = intervention.fields ?? [];');
|
|
124
|
+
expect(ROW).toContain('const submit = intervention.submit;');
|
|
127
125
|
expect(gate).toBeGreaterThan(0);
|
|
128
126
|
expect(usage).toBeGreaterThan(gate);
|
|
129
127
|
expect(helper).toBeGreaterThan(0);
|
|
@@ -190,17 +188,73 @@ describe('人工干预节点(needs-human):标题 + 说明 + 动作,组
|
|
|
190
188
|
});
|
|
191
189
|
|
|
192
190
|
it('★★ 动作的 key / label / onPress 全由调用点给,primary 决定主按钮', () => {
|
|
193
|
-
expect(ROW).toContain('(
|
|
191
|
+
expect(ROW).toContain('(intervention.actions ?? []).map((action) => (');
|
|
194
192
|
expect(ROW).toContain('key={action.key}');
|
|
195
193
|
expect(ROW).toContain("variant={action.primary === true ? 'primary' : 'outline'}");
|
|
196
194
|
expect(ROW).toContain('onClick={action.onPress}');
|
|
197
195
|
});
|
|
198
196
|
|
|
199
197
|
it('★ 标题与说明是两个 span,类都在同目录 .css 里', () => {
|
|
200
|
-
expect(ROW).toContain('className="wb-longTaskNeedTitle">{
|
|
198
|
+
expect(ROW).toContain('className="wb-longTaskNeedTitle">{intervention.title}');
|
|
201
199
|
expect(ROW).toContain('className="wb-longTaskNeedHint"');
|
|
202
200
|
for (const cls of ['.wb-longTaskNeed {', '.wb-longTaskNeedTitle {', '.wb-longTaskNeedHint {']) {
|
|
203
201
|
expect(CSS).toContain(cls);
|
|
204
202
|
}
|
|
205
203
|
});
|
|
206
204
|
});
|
|
205
|
+
|
|
206
|
+
describe('行内可读:当前步骤 / 状态 · 耗时 / 结构化步骤 / 停止请求', () => {
|
|
207
|
+
it('★★ 不给 step / meta 时一行都不多,给了才画', () => {
|
|
208
|
+
expect(ROW).toContain("const step = props.step ?? '';");
|
|
209
|
+
expect(ROW).toContain("const meta = props.meta ?? '';");
|
|
210
|
+
expect(ROW).toContain('{step === \'\' ? null : <p className="wb-longTaskStep">{step}</p>}');
|
|
211
|
+
expect(ROW).toContain('{meta === \'\' ? null : <p className="wb-longTaskMeta">{meta}</p>}');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('★★ 点可以抬档(人待 warning),读屏有词', () => {
|
|
215
|
+
expect(ROW).toContain('const dot = props.dot ?? longTaskDot(props.status);');
|
|
216
|
+
expect(ROW).toContain('aria-label={props.dotLabel}');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('★★ 有 history 走结构化行:一行一步 + 链接只认 http(s)、最多 3 条', () => {
|
|
220
|
+
expect(ROW).toContain('<ul className="wb-longTaskSteps">');
|
|
221
|
+
expect(ROW).toContain('const HTTP_PATTERN = /^https?:');
|
|
222
|
+
expect(ROW).toContain('.filter((link) => HTTP_PATTERN.test(link.href))');
|
|
223
|
+
expect(ROW).toContain('.slice(0, LONG_TASK_LINK_MAX)');
|
|
224
|
+
expect(ROW).toContain('data-kind={row.kind}');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('★★ 没有 history 回退旧 CodeBlock:旧模块一个像素不变', () => {
|
|
228
|
+
expect(ROW).toContain('{history.length === 0 ? (');
|
|
229
|
+
expect(ROW).toContain('code={steps.join(');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('★★ 步骤块的展开不再绑死失败:给 stepsTitle 且有内容就画,失败默认开', () => {
|
|
233
|
+
expect(ROW).toContain("useState(props.status === 'failed')");
|
|
234
|
+
expect(ROW).toContain('if (failed) setStepsOpen(true);');
|
|
235
|
+
expect(ROW).toContain('props.stepsTitle === undefined || (history.length === 0 && steps.length === 0)');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('★★ 停止请求之后、模块确认之前,行上说一句;模块确认了就收', () => {
|
|
239
|
+
expect(ROW).toContain("stopFired && live && !busy && stopWhy === ''");
|
|
240
|
+
expect(ROW).toContain('className="wb-longTaskStopPending"');
|
|
241
|
+
expect(ROW).toContain('const [stopFired, setStopFired] = useState(false);');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('★ 新样式在同一份 .css:零注释、颜色不写字面值', () => {
|
|
245
|
+
for (const cls of [
|
|
246
|
+
'.wb-longTaskStep {',
|
|
247
|
+
'.wb-longTaskMeta {',
|
|
248
|
+
'.wb-longTaskStopPending {',
|
|
249
|
+
'.wb-longTaskSteps {',
|
|
250
|
+
'.wb-longTaskStepRow {',
|
|
251
|
+
'.wb-longTaskStepText {',
|
|
252
|
+
'.wb-longTaskStepLink {',
|
|
253
|
+
]) {
|
|
254
|
+
expect(CSS).toContain(cls);
|
|
255
|
+
}
|
|
256
|
+
expect(CSS).toContain("[data-kind='fail'] .wb-longTaskStepText");
|
|
257
|
+
expect(CSS).not.toContain('/*');
|
|
258
|
+
expect(CSS).not.toContain('#');
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -146,6 +146,7 @@ export interface CardViewRow {
|
|
|
146
146
|
readonly atTitle?: string | undefined;
|
|
147
147
|
readonly tone?: CardViewTone | undefined;
|
|
148
148
|
readonly href?: string | undefined;
|
|
149
|
+
readonly longTaskTarget?: string | undefined;
|
|
149
150
|
readonly action?:
|
|
150
151
|
| {
|
|
151
152
|
readonly labelKey: string;
|
|
@@ -12,6 +12,19 @@ export type LongTaskInterventionAction =
|
|
|
12
12
|
| { readonly kind: 'open-url'; readonly url: string; readonly label?: string | undefined }
|
|
13
13
|
| { readonly kind: 'copy'; readonly text: string; readonly label?: string | undefined };
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* 一条「去哪看」的链接:步骤行尾或行进尾部。
|
|
17
|
+
* `text` 是模块写好的字(宿主侧没有 `t`),外壳只放行 `http(s)`。
|
|
18
|
+
*/
|
|
19
|
+
export interface LongTaskLink {
|
|
20
|
+
readonly href: string;
|
|
21
|
+
readonly text: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const LONG_TASK_LINK_MAX = 3;
|
|
25
|
+
|
|
26
|
+
export const LONG_TASK_HISTORY_MAX = 20;
|
|
27
|
+
|
|
15
28
|
/**
|
|
16
29
|
* 回执字段的输入类型:`text` 明文,`secret` 密码框(值同样只回给模块)。
|
|
17
30
|
*/
|
|
@@ -49,10 +62,21 @@ export interface LongTaskIntervention {
|
|
|
49
62
|
export interface LongTaskStep {
|
|
50
63
|
readonly kind: 'start' | 'succeed' | 'fail' | 'info' | 'warn';
|
|
51
64
|
readonly text: string;
|
|
65
|
+
readonly links?: readonly LongTaskLink[] | undefined;
|
|
52
66
|
readonly intervention?: LongTaskIntervention | undefined;
|
|
53
67
|
readonly loginUrl?: string | undefined;
|
|
54
68
|
}
|
|
55
69
|
|
|
70
|
+
/**
|
|
71
|
+
* 快照里的结构化步骤行:`kind` 定颜色、`text` 是文案、`links` 是这条记录的去处。
|
|
72
|
+
* 与 `steps: string[]` 同源、同去重、同上限;旧消费者照旧读 `steps`。
|
|
73
|
+
*/
|
|
74
|
+
export interface LongTaskStepRow {
|
|
75
|
+
readonly kind: LongTaskStep['kind'];
|
|
76
|
+
readonly text: string;
|
|
77
|
+
readonly links?: readonly LongTaskLink[] | undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
56
80
|
/**
|
|
57
81
|
* 单元的长任务读口路由。
|
|
58
82
|
* @param unit 单元 id。
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
LongTaskIntervention,
|
|
3
|
+
LongTaskLink,
|
|
4
|
+
LongTaskStatus,
|
|
5
|
+
LongTaskStepRow,
|
|
6
|
+
} from '../long-task.js';
|
|
2
7
|
|
|
3
8
|
export const LONG_TASKS_ROUTE = 'long-tasks';
|
|
4
9
|
|
|
@@ -11,6 +16,8 @@ export interface ShellLongTaskRow {
|
|
|
11
16
|
readonly status: LongTaskStatus;
|
|
12
17
|
readonly step?: string | undefined;
|
|
13
18
|
readonly steps?: readonly string[] | undefined;
|
|
19
|
+
readonly history?: readonly LongTaskStepRow[] | undefined;
|
|
20
|
+
readonly links?: readonly LongTaskLink[] | undefined;
|
|
14
21
|
readonly intervention?: LongTaskIntervention | undefined;
|
|
15
22
|
readonly resumable?: boolean | undefined;
|
|
16
23
|
readonly answerable?: boolean | undefined;
|
|
@@ -60,4 +60,24 @@ describe('longTaskStepOf:流程事件 → 长任务步骤的默认映射', ()
|
|
|
60
60
|
expect(step).toEqual({ kind: 'start', text: '正在读' });
|
|
61
61
|
expect('loginUrl' in step).toBe(false);
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
it('★★ 事件带 links 时每一行都跟着带;空数组不落键(旧事件一个字段都不多)', () => {
|
|
65
|
+
const links = [{ href: 'https://example.test/x', text: '打开' }];
|
|
66
|
+
expect(longTaskStepOf(eventOf('running', { links }))).toEqual({
|
|
67
|
+
kind: 'start',
|
|
68
|
+
text: '读目录',
|
|
69
|
+
links,
|
|
70
|
+
});
|
|
71
|
+
expect(longTaskStepOf(eventOf('ok', { links }))).toEqual({
|
|
72
|
+
kind: 'succeed',
|
|
73
|
+
text: '读目录',
|
|
74
|
+
links,
|
|
75
|
+
});
|
|
76
|
+
expect(longTaskStepOf(eventOf('failed', { links }))).toEqual({
|
|
77
|
+
kind: 'fail',
|
|
78
|
+
text: '读目录',
|
|
79
|
+
links,
|
|
80
|
+
});
|
|
81
|
+
expect('links' in longTaskStepOf(eventOf('running', { links: [] }))).toBe(false);
|
|
82
|
+
});
|
|
63
83
|
});
|
package/src/host/flow/run.ts
CHANGED
|
@@ -257,8 +257,14 @@ async function runOneInner(options: RunOneOptions): Promise<unknown> {
|
|
|
257
257
|
runId,
|
|
258
258
|
workspace,
|
|
259
259
|
stepId,
|
|
260
|
-
log: (text) => {
|
|
261
|
-
emit({
|
|
260
|
+
log: (text, links) => {
|
|
261
|
+
emit({
|
|
262
|
+
stepId,
|
|
263
|
+
title,
|
|
264
|
+
status: 'running',
|
|
265
|
+
message: text,
|
|
266
|
+
...(links === undefined || links.length === 0 ? {} : { links }),
|
|
267
|
+
});
|
|
262
268
|
},
|
|
263
269
|
login: (url) => {
|
|
264
270
|
emit({ stepId, title, status: 'needs-login', loginUrl: url });
|