@jive-sh/workflow-platform 0.3.2 → 0.4.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/README.md +64 -20
- package/dist/cpu-limit/limiter.js +5 -4
- package/dist/cpu-limit/limiter.js.map +1 -1
- package/dist/dashboard/agent-usage.js +25 -0
- package/dist/dashboard/agent-usage.js.map +1 -0
- package/dist/dashboard/drilldown.js +16 -0
- package/dist/dashboard/drilldown.js.map +1 -0
- package/dist/dashboard/queue-lines.js +44 -0
- package/dist/dashboard/queue-lines.js.map +1 -0
- package/dist/dashboard/queue-table.js +8 -0
- package/dist/dashboard/queue-table.js.map +1 -0
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/keep-running.js +1 -1
- package/dist/keep-running.js.map +1 -1
- package/dist/pick-wakes.js +4 -4
- package/dist/pick-wakes.js.map +1 -1
- package/dist/queue-counts.js +7 -9
- package/dist/queue-counts.js.map +1 -1
- package/dist/steps.js +133 -30
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +115 -40
- package/dist/storage/sqlite-store.js.map +1 -1
- package/dist/storage/task-store.js +14 -1
- package/dist/storage/task-store.js.map +1 -1
- package/dist/tasks.js +215 -267
- package/dist/tasks.js.map +1 -1
- package/dist/views/runs-now.js +2 -1
- package/dist/views/runs-now.js.map +1 -1
- package/dist/views/workflows-view.js +74 -15
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/cpu-limit/limiter.ts +8 -5
- package/src/dashboard/agent-usage-line.tsx +28 -0
- package/src/dashboard/agent-usage.ts +48 -0
- package/src/dashboard/dashboard.css +68 -29
- package/src/dashboard/drilldown.ts +44 -0
- package/src/dashboard/index.tsx +1 -0
- package/src/dashboard/machine-controls.tsx +53 -0
- package/src/dashboard/queue-bar.tsx +43 -0
- package/src/dashboard/queue-chart.tsx +89 -76
- package/src/dashboard/queue-lines.ts +87 -0
- package/src/dashboard/queue-table.ts +23 -0
- package/src/dashboard/workflow-drilldown.tsx +89 -0
- package/src/dashboard/workflows-dashboard.tsx +103 -37
- package/src/index.ts +11 -10
- package/src/keep-running.ts +3 -3
- package/src/pick-wakes.ts +14 -9
- package/src/queue-counts.ts +10 -14
- package/src/steps.ts +179 -42
- package/src/storage/sqlite-store.ts +123 -46
- package/src/storage/step-records.ts +14 -3
- package/src/storage/task-store.ts +88 -36
- package/src/tasks.ts +235 -301
- package/src/views/runs-now.ts +3 -2
- package/src/views/workflows-view.ts +102 -32
- package/dist/views/workflow-flows.js +0 -53
- package/dist/views/workflow-flows.js.map +0 -1
- package/src/dashboard/workflow-dag.tsx +0 -256
- package/src/views/workflow-flows.ts +0 -97
package/src/views/runs-now.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface WorkflowRunsNow {
|
|
|
29
29
|
readonly workflow: string;
|
|
30
30
|
/** Every unfinished run: its steps' `inStep` and `waitingAfter`, and `notStarted`. */
|
|
31
31
|
readonly runs: number;
|
|
32
|
-
/** Runs in an agent step
|
|
32
|
+
/** Runs an agent is working for now: those in an agent step that wait on nothing (a run waiting there for a free agent is on none). */
|
|
33
33
|
readonly onAgents: number;
|
|
34
34
|
/** Runs with no step record yet. */
|
|
35
35
|
readonly notStarted: number;
|
|
@@ -70,7 +70,8 @@ const workflowRunsNow = <Phase extends string>(d: Declared<Phase>, runs: Readonl
|
|
|
70
70
|
return {
|
|
71
71
|
workflow: d.name,
|
|
72
72
|
runs: runs.length,
|
|
73
|
-
|
|
73
|
+
// A run waiting at an agent step for a free agent (its record says what it waits on) is on no agent.
|
|
74
|
+
onAgents: steps.filter((s) => s.agent).reduce((n, s) => n + records.filter((r) => r.step === s.step && r.ended === null && r.waiting === null).length, 0),
|
|
74
75
|
notStarted: runs.length - records.length,
|
|
75
76
|
steps,
|
|
76
77
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A PROJECT'S WORKFLOWS AS ITS DASHBOARD SHOWS THEM, READ FROM THE RECORDS AT EACH REQUEST, in two readings:
|
|
3
3
|
*
|
|
4
|
-
* every workflow what it is, its
|
|
4
|
+
* every workflow what it is, its steps with their kinds, its limits, and its tasks by status with their history
|
|
5
5
|
* (`buildWorkflowsView`): what a page shows before a workflow is opened, a few small readings.
|
|
6
6
|
* one workflow its steps and their cost over a window, its step graph with the window's runs on it, and where its
|
|
7
7
|
* runs stopped and why (`buildWorkflowFigures`): read from its own records when a page opens it.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Built from the declarations and the stores alone, so any project's workflows read the same; a project adds its own
|
|
12
12
|
* panels beside it. Where its runs are now (`runs-now.ts`) is read at each request too.
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
14
|
+
import { stepKindOf, stepUsesAnAgent, type SourceRef, type StepDeclaration, type StepKind, type WorkflowDeclaration } from '../steps';
|
|
15
15
|
|
|
16
16
|
/** A definition's link: its file and text, and the line that text is on now; none when the text is no longer in the file. */
|
|
17
17
|
export interface SourceLink extends SourceRef {
|
|
@@ -21,11 +21,10 @@ import { Effect } from 'effect';
|
|
|
21
21
|
import type { StorageError } from '../storage/storage-error';
|
|
22
22
|
import type { EngineRecords } from '../storage/engine-records';
|
|
23
23
|
import type { FunnelStepRecord, RunCost, RunOutcomeRow, StepRecords, StepRunRow } from '../storage/step-records';
|
|
24
|
-
import {
|
|
24
|
+
import { TASK_STATUSES, type BlockedReason, type TaskStatus } from '../tasks';
|
|
25
25
|
import type { QueueCount, TaskStore } from '../storage/task-store';
|
|
26
26
|
import { stepFunnel, type StepFunnel } from './step-funnel';
|
|
27
27
|
import { workflowGraphs, type WorkflowGraph } from './step-graph';
|
|
28
|
-
import { pipelinePlaces, workflowFlows, type PipelinePlace, type WorkflowFlow } from './workflow-flows';
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* WHAT STARTS ITS RUNS, from its declaration: its queue (a list of work, its runs kept going while it has some), its inputs
|
|
@@ -144,9 +143,35 @@ export const yieldOf = (r: { readonly runs: number; readonly finished: number; r
|
|
|
144
143
|
perCompile: r.compiles === 0 ? null : r.finished / r.compiles,
|
|
145
144
|
});
|
|
146
145
|
|
|
147
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* A step as a workflow's own view lists it: its kind in words (`steps.ts` `StepKind`), and for a sub-workflow the workflow
|
|
148
|
+
* it opens.
|
|
149
|
+
*/
|
|
150
|
+
export interface StepSummary {
|
|
151
|
+
readonly name: string;
|
|
152
|
+
readonly kind: StepKind;
|
|
153
|
+
/** Whether it uses an agent: an agent step, or a sub-workflow with one anywhere under it. */
|
|
154
|
+
readonly usesAgent: boolean;
|
|
155
|
+
readonly description: string;
|
|
156
|
+
/** For a sub-workflow: the workflow it runs, by name; none for any other kind. */
|
|
157
|
+
readonly workflow: string | null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* THE TOP OF A PROJECT IS ONE WORKFLOW (Alex, 2026-11-19: "decompiling an entire game is in itself a workflow"): what a page
|
|
162
|
+
* enters at. Its steps are sub-workflows, and each opens that workflow's own view.
|
|
163
|
+
*/
|
|
164
|
+
export interface TopWorkflowView {
|
|
165
|
+
readonly name: string;
|
|
166
|
+
readonly description: string;
|
|
167
|
+
readonly steps: ReadonlyArray<StepSummary>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A workflow as a page shows it before it is opened: what it is, its steps, its limits and its queue. */
|
|
148
171
|
export interface WorkflowView {
|
|
149
172
|
readonly name: string;
|
|
173
|
+
/** Its own steps, in order, each with its kind. */
|
|
174
|
+
readonly steps: ReadonlyArray<StepSummary>;
|
|
150
175
|
readonly phase: string;
|
|
151
176
|
readonly description: string;
|
|
152
177
|
readonly source: SourceLink;
|
|
@@ -160,24 +185,19 @@ export interface WorkflowView {
|
|
|
160
185
|
* any other). None where no store is read.
|
|
161
186
|
*/
|
|
162
187
|
readonly limits: { readonly agents: number | null; readonly runs: number | null; readonly runsSet: boolean } | null;
|
|
163
|
-
/** Its tasks by
|
|
164
|
-
readonly queue: Readonly<Record<
|
|
188
|
+
/** Its tasks by status, as last counted (`queue-counts.ts`); none for a workflow with no item. */
|
|
189
|
+
readonly queue: Readonly<Record<TaskStatus, number>> | null;
|
|
165
190
|
/** What starts its runs. */
|
|
166
191
|
readonly startsOn: StartsOn;
|
|
167
|
-
/** The workflows whose results become its tasks, as declared (`fedBy`). */
|
|
168
|
-
readonly fedBy: ReadonlyArray<string>;
|
|
169
|
-
/** Its place in the pipeline: what the DAG lays it out by. */
|
|
170
|
-
readonly place: PipelinePlace;
|
|
171
192
|
}
|
|
172
193
|
|
|
173
194
|
/** Every workflow, read at the request: nothing here is stored for the page. */
|
|
174
195
|
export interface WorkflowsView {
|
|
175
196
|
/** When it was read, unix seconds. */
|
|
176
197
|
readonly at: number;
|
|
198
|
+
readonly top: TopWorkflowView;
|
|
177
199
|
readonly groups: ReadonlyArray<{ readonly phase: string; readonly workflows: ReadonlyArray<WorkflowView> }>;
|
|
178
|
-
/**
|
|
179
|
-
readonly flows: ReadonlyArray<WorkflowFlow>;
|
|
180
|
-
/** Each queue's counts over the last `QUEUE_HISTORY_DAYS`, a row where one changed, oldest first. */
|
|
200
|
+
/** Each queue's counts by status over the last `QUEUE_HISTORY_DAYS` (`historyByStatus`), a row where one changed, oldest first. */
|
|
181
201
|
readonly queueHistory: ReadonlyArray<QueueCount>;
|
|
182
202
|
}
|
|
183
203
|
|
|
@@ -197,6 +217,8 @@ export interface WorkflowFigures {
|
|
|
197
217
|
readonly runCosts: RunCosts;
|
|
198
218
|
/** What its runs gave in the window, and in the window before it: the trend. */
|
|
199
219
|
readonly yields: { readonly now: Yield; readonly before: Yield };
|
|
220
|
+
/** Why its blocked tasks are blocked now: a count for each reason, most tasks first (`tasks.ts` `blockedReasons`). */
|
|
221
|
+
readonly blocked: ReadonlyArray<BlockedReason>;
|
|
200
222
|
}
|
|
201
223
|
|
|
202
224
|
const NO_COST: StepCost = { calls: 0, failed: 0, open: 0, seconds: 0, inputTokens: 0, outputTokens: 0, cpuSeconds: 0, compiles: 0, items: 0 };
|
|
@@ -221,18 +243,57 @@ export const costOf = (rows: ReadonlyArray<StepRunRow>): StepCost | null =>
|
|
|
221
243
|
items: new Set(rows.flatMap((r) => (r.subject === null ? [] : [r.subject.toLowerCase()]))).size,
|
|
222
244
|
};
|
|
223
245
|
|
|
224
|
-
type Declared = Pick<WorkflowDeclaration<string, unknown>, 'name' | 'phase' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph' | '
|
|
246
|
+
type Declared = Pick<WorkflowDeclaration<string, unknown>, 'name' | 'phase' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph' | 'pending' | 'items' | 'inputs'> & {
|
|
225
247
|
readonly steps: () => ReadonlyArray<StepDeclaration>;
|
|
226
248
|
};
|
|
227
249
|
|
|
228
|
-
const noTasks = (): Record<
|
|
250
|
+
const noTasks = (): Record<TaskStatus, number> => Object.fromEntries(TASK_STATUSES.map((s) => [s, 0])) as Record<TaskStatus, number>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The names a count was recorded under before 2026-11-19, when a task stood in one of six buckets, and the status each is
|
|
254
|
+
* part of now. `queued` and `done` kept their names.
|
|
255
|
+
*/
|
|
256
|
+
const RECORDED_BEFORE: Readonly<Record<string, TaskStatus>> = { running: 'in progress', waiting: 'blocked', stuck: 'blocked', held: 'blocked' };
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* THE RECORDED COUNTS (`queueCountsSince`, oldest first) AS THE FOUR STATUSES: a row for each status of each workflow where
|
|
260
|
+
* its count moved. A count recorded under an older name is part of its status until the workflow has a count under the
|
|
261
|
+
* four, which replaces it; one recorded under an older name after that (by code still running as the newer began) is
|
|
262
|
+
* not read. Pure.
|
|
263
|
+
*/
|
|
264
|
+
export const historyByStatus = (recorded: ReadonlyArray<QueueCount>): ReadonlyArray<QueueCount> => {
|
|
265
|
+
const raw = new Map<string, Map<string, number>>();
|
|
266
|
+
const countedByStatus = new Set<string>();
|
|
267
|
+
const last = new Map<string, number>();
|
|
268
|
+
const out: QueueCount[] = [];
|
|
269
|
+
recorded.forEach((row, i) => {
|
|
270
|
+
const counts = raw.get(row.workflow) ?? new Map<string, number>();
|
|
271
|
+
raw.set(row.workflow, counts);
|
|
272
|
+
const olderName = RECORDED_BEFORE[row.bucket] !== undefined;
|
|
273
|
+
if (!olderName && (row.bucket === 'in progress' || row.bucket === 'blocked') && !countedByStatus.has(row.workflow)) {
|
|
274
|
+
countedByStatus.add(row.workflow);
|
|
275
|
+
for (const older of Object.keys(RECORDED_BEFORE)) counts.delete(older);
|
|
276
|
+
}
|
|
277
|
+
if (!(olderName && countedByStatus.has(row.workflow))) counts.set(row.bucket, row.tasks);
|
|
278
|
+
// Every row of one moment is one count of the workflow: its statuses are read once all of them are in.
|
|
279
|
+
const next = recorded[i + 1];
|
|
280
|
+
if (next !== undefined && next.workflow === row.workflow && next.at === row.at) return;
|
|
281
|
+
for (const status of TASK_STATUSES) {
|
|
282
|
+
const tasks = [...counts].reduce((sum, [name, n]) => sum + (name === status || RECORDED_BEFORE[name] === status ? n : 0), 0);
|
|
283
|
+
const key = `${row.workflow}\u0000${status}`;
|
|
284
|
+
if (last.get(key) !== tasks) out.push({ at: row.at, workflow: row.workflow, bucket: status, tasks });
|
|
285
|
+
last.set(key, tasks);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
return out;
|
|
289
|
+
};
|
|
229
290
|
|
|
230
|
-
/** Each queue's newest count from its history (`
|
|
231
|
-
export const queuesNow = (history: ReadonlyArray<QueueCount>): ReadonlyMap<string, Readonly<Record<
|
|
232
|
-
const queues = new Map<string, Record<
|
|
291
|
+
/** Each queue's newest count from its history by status (`historyByStatus`), a status never counted at 0. Pure. */
|
|
292
|
+
export const queuesNow = (history: ReadonlyArray<QueueCount>): ReadonlyMap<string, Readonly<Record<TaskStatus, number>>> => {
|
|
293
|
+
const queues = new Map<string, Record<TaskStatus, number>>();
|
|
233
294
|
for (const row of history) {
|
|
234
295
|
const queue = queues.get(row.workflow) ?? noTasks();
|
|
235
|
-
if ((
|
|
296
|
+
if ((TASK_STATUSES as ReadonlyArray<string>).includes(row.bucket)) queue[row.bucket as TaskStatus] = row.tasks;
|
|
236
297
|
queues.set(row.workflow, queue);
|
|
237
298
|
}
|
|
238
299
|
return queues;
|
|
@@ -240,7 +301,7 @@ export const queuesNow = (history: ReadonlyArray<QueueCount>): ReadonlyMap<strin
|
|
|
240
301
|
|
|
241
302
|
/**
|
|
242
303
|
* EVERY WORKFLOW AS A PAGE SHOWS IT BEFORE ONE IS OPENED, READ AT THE REQUEST: the declarations, the limits, each queue's
|
|
243
|
-
* counts as last counted and their history
|
|
304
|
+
* counts as last counted and their history. A few small readings of the store, so a
|
|
244
305
|
* page load needs no stored copy of it. `limitsOf` is none where no store is read.
|
|
245
306
|
*/
|
|
246
307
|
export const buildWorkflowsView = (input: {
|
|
@@ -248,30 +309,36 @@ export const buildWorkflowsView = (input: {
|
|
|
248
309
|
/** The project's phases, in the order its page shows them; a workflow of another phase follows them. */
|
|
249
310
|
readonly phases: ReadonlyArray<string>;
|
|
250
311
|
readonly now: number;
|
|
251
|
-
/** The queues' history
|
|
252
|
-
readonly taskStore: Pick<TaskStore, 'queueCountsSince'
|
|
312
|
+
/** The queues' history, from the task store. */
|
|
313
|
+
readonly taskStore: Pick<TaskStore, 'queueCountsSince'>;
|
|
253
314
|
/** The line a definition's text is on now. */
|
|
254
315
|
readonly locate: (source: SourceRef) => number | null;
|
|
255
316
|
readonly limitsOf: (workflow: string) => WorkflowView['limits'];
|
|
317
|
+
/** The project's top workflow, in its own words, until it declares one. */
|
|
318
|
+
readonly top: { readonly name: string; readonly description: string };
|
|
256
319
|
}): Effect.Effect<WorkflowsView, StorageError> => Effect.gen(function* () {
|
|
257
|
-
const
|
|
320
|
+
const stepSummary = (s: StepDeclaration): StepSummary => ({ name: s.name, kind: stepKindOf(s), usesAgent: stepUsesAnAgent(s), description: s.description, workflow: s.workflow ?? null });
|
|
321
|
+
// Until the project declares its top workflow, its steps are every workflow no other workflow uses as a step.
|
|
322
|
+
const usedAsAStep = new Set(input.declared.flatMap((d) => d.steps().flatMap((s) => (s.workflow === undefined ? [] : [s.workflow]))));
|
|
258
323
|
const phases = [...input.phases, ...[...new Set(input.declared.map((d) => d.phase))].filter((p) => !input.phases.includes(p))];
|
|
259
|
-
const
|
|
260
|
-
const queueHistory = yield* input.taskStore.queueCountsSince(input.now - QUEUE_HISTORY_DAYS * 86_400);
|
|
324
|
+
const queueHistory = historyByStatus(yield* input.taskStore.queueCountsSince(input.now - QUEUE_HISTORY_DAYS * 86_400));
|
|
261
325
|
const queues = queuesNow(queueHistory);
|
|
262
326
|
const workflowView = (d: Declared): WorkflowView => ({
|
|
263
|
-
name: d.name,
|
|
264
|
-
|
|
327
|
+
name: d.name, steps: d.steps().map(stepSummary),
|
|
328
|
+
phase: d.phase, description: d.description, source: { ...d.source, line: input.locate(d.source) }, item: d.item, finishedWord: d.finishedWord,
|
|
329
|
+
usesAgents: d.steps().some(stepUsesAnAgent),
|
|
265
330
|
limits: input.limitsOf(d.name),
|
|
266
331
|
queue: d.item === null ? null : queues.get(d.name) ?? noTasks(),
|
|
267
|
-
startsOn: d.pending !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
|
|
268
|
-
fedBy: d.fedBy ?? [],
|
|
269
|
-
place: places.get(d.name)!,
|
|
332
|
+
startsOn: d.pending !== undefined || d.items !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
|
|
270
333
|
});
|
|
334
|
+
const inPageOrder = phases.flatMap((phase) => input.declared.filter((d) => d.phase === phase));
|
|
271
335
|
return {
|
|
272
336
|
at: input.now,
|
|
337
|
+
top: {
|
|
338
|
+
...input.top,
|
|
339
|
+
steps: inPageOrder.filter((d) => !usedAsAStep.has(d.name)).map((d): StepSummary => ({ name: d.name, kind: 'sub-workflow', usesAgent: d.steps().some(stepUsesAnAgent), description: d.description, workflow: d.name })),
|
|
340
|
+
},
|
|
273
341
|
groups: phases.map((phase) => ({ phase, workflows: input.declared.filter((d) => d.phase === phase).map(workflowView) })).filter((g) => g.workflows.length > 0),
|
|
274
|
-
flows,
|
|
275
342
|
queueHistory,
|
|
276
343
|
};
|
|
277
344
|
});
|
|
@@ -287,6 +354,8 @@ export const buildWorkflowFigures = (input: {
|
|
|
287
354
|
readonly hours: number;
|
|
288
355
|
readonly records: StepRecords;
|
|
289
356
|
readonly engine: EngineRecords;
|
|
357
|
+
/** Why its blocked tasks are blocked now, read from its tasks. */
|
|
358
|
+
readonly blocked: Effect.Effect<ReadonlyArray<BlockedReason>, StorageError>;
|
|
290
359
|
/** The line a definition's text is on now. */
|
|
291
360
|
readonly locate: (source: SourceRef) => number | null;
|
|
292
361
|
}): Effect.Effect<WorkflowFigures, StorageError> => Effect.gen(function* () {
|
|
@@ -323,6 +392,7 @@ export const buildWorkflowFigures = (input: {
|
|
|
323
392
|
graph: workflowGraphs({ declared: [d], taken: moves.edges, lasts: moves.lasts, going })[0]!,
|
|
324
393
|
funnel,
|
|
325
394
|
runCosts: runCostsOf(runCosts),
|
|
395
|
+
blocked: yield* input.blocked,
|
|
326
396
|
yields: {
|
|
327
397
|
now: yieldOf({ runs: funnel.runs, finished: finished(finishedNow), tokens: costNow.inputTokens + costNow.outputTokens, compiles: costNow.compiles }),
|
|
328
398
|
before: yieldOf({
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/** Whether `to` reaches `from` through `feeds`: work goes from `to`, by way of others, to `from`. */
|
|
2
|
-
const reaches = (feeds, start, target) => {
|
|
3
|
-
const seen = new Set([start]);
|
|
4
|
-
const next = [start];
|
|
5
|
-
while (next.length > 0) {
|
|
6
|
-
const at = next.pop();
|
|
7
|
-
for (const f of feeds) {
|
|
8
|
-
if (f.from !== at || seen.has(f.to))
|
|
9
|
-
continue;
|
|
10
|
-
if (f.to === target)
|
|
11
|
-
return true;
|
|
12
|
-
seen.add(f.to);
|
|
13
|
-
next.push(f.to);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
};
|
|
18
|
-
export const workflowFlows = (input) => {
|
|
19
|
-
const names = new Set(input.declared.map((d) => d.name));
|
|
20
|
-
const recorded = (from, to) => input.newInputs.find((n) => n.from === from && n.to === to);
|
|
21
|
-
const feeds = input.declared.flatMap((d) => (d.fedBy ?? []).filter((f) => names.has(f) && f !== d.name).map((f) => ({ from: f, to: d.name })));
|
|
22
|
-
const declaredFlows = feeds.map((f) => {
|
|
23
|
-
const r = recorded(f.from, f.to);
|
|
24
|
-
return { from: f.from, to: f.to, kind: 'feeds', declared: true, notes: r?.notes ?? 0, last: r?.last ?? null, waiting: 0, why: null };
|
|
25
|
-
});
|
|
26
|
-
const recordedOnly = input.newInputs
|
|
27
|
-
.filter((n) => names.has(n.from) && names.has(n.to) && !feeds.some((f) => f.from === n.from && f.to === n.to))
|
|
28
|
-
.map((n) => ({ from: n.from, to: n.to, kind: reaches(feeds, n.to, n.from) ? 'sends back' : 'gives input', declared: false, notes: n.notes, last: n.last, waiting: 0, why: null }));
|
|
29
|
-
// A wait on the workflow that feeds it is that feed's work still to come, drawn as the feed; one on another is an edge.
|
|
30
|
-
const waitedOn = input.waits
|
|
31
|
-
.filter((w) => names.has(w.on) && w.on !== w.workflow && !feeds.some((f) => f.from === w.on && f.to === w.workflow))
|
|
32
|
-
.map((w) => ({ from: w.workflow, to: w.on, kind: 'waits on', declared: false, notes: 0, last: null, waiting: w.tasks, why: w.label }));
|
|
33
|
-
return [...declaredFlows, ...recordedOnly, ...waitedOn];
|
|
34
|
-
};
|
|
35
|
-
/** Each workflow's place: its stage by `stageOf` in `stages`' order (one not among them after them), then its depth there. */
|
|
36
|
-
export const pipelinePlaces = (input) => {
|
|
37
|
-
const stageIndex = (s) => (input.stages.includes(s) ? input.stages.indexOf(s) : input.stages.length);
|
|
38
|
-
const stageOf = new Map(input.workflows.map((w) => [w.name, stageIndex(w.stage)]));
|
|
39
|
-
// Forward work only: feeds, and input given to one not upstream. A send-back points against the pipeline.
|
|
40
|
-
const forward = input.flows.filter((f) => f.kind !== 'sends back');
|
|
41
|
-
const depth = new Map();
|
|
42
|
-
const depthOf = (name, path) => {
|
|
43
|
-
const known = depth.get(name);
|
|
44
|
-
if (known !== undefined)
|
|
45
|
-
return known;
|
|
46
|
-
const into = forward.filter((f) => f.to === name && !path.has(f.from) && stageOf.get(f.from) === stageOf.get(name));
|
|
47
|
-
const d = into.length === 0 ? 0 : Math.max(...into.map((f) => depthOf(f.from, new Set([...path, name])) + 1));
|
|
48
|
-
depth.set(name, d);
|
|
49
|
-
return d;
|
|
50
|
-
};
|
|
51
|
-
return input.workflows.map((w) => ({ workflow: w.name, stage: stageIndex(w.stage), depth: depthOf(w.name, new Set()) }));
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=workflow-flows.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-flows.js","sourceRoot":"","sources":["../../../../src/views/workflow-flows.ts"],"names":[],"mappings":"AAsCA,qGAAqG;AACrG,MAAM,OAAO,GAAG,CAAC,KAAoE,EAAE,KAAa,EAAE,MAAc,EAAW,EAAE;IAC/H,MAAM,IAAI,GAAG,IAAI,GAAG,CAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAG,CAAC;QACvB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAAE,SAAS;YAC9C,IAAI,CAAC,CAAC,EAAE,KAAK,MAAM;gBAA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AE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3H,CAAC,CAAC"}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* THE PROJECT'S WORKFLOWS AS A DAG, laid out by ELK's layered algorithm (`elkjs`, which the host page brings, as it brings
|
|
5
|
-
* React): each workflow one node, in layers in topological order of the forward edges, so every forward arrow points down;
|
|
6
|
-
* each stage's layers kept together (ELK's partitions, one per stage in the project's order) and shown as a band named in
|
|
7
|
-
* a gutter on the left that no edge enters. Edges are routed orthogonally around the nodes, each with its label beside its
|
|
8
|
-
* own line and its arrowhead at its target. A send-back, the only edge against the flow, is routed apart by ELK as a feedback
|
|
9
|
-
* edge, dashed and labelled "sends back". Workflows no work flows to or from are listed under their stages below the map.
|
|
10
|
-
*
|
|
11
|
-
* Chosen over dagre (`@dagrejs/dagre`): ELK routes edges around nodes and places labels beside their own edges, lays out
|
|
12
|
-
* partitions in order and routes feedback edges apart; dagre does none of those, and its edges and labels cross nodes.
|
|
13
|
-
*/
|
|
14
|
-
import ELK, { type ElkNode } from 'elkjs/lib/elk.bundled.js';
|
|
15
|
-
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react';
|
|
16
|
-
import type { WorkflowFlow } from '../views/workflow-flows';
|
|
17
|
-
import type { WorkflowView, WorkflowsView } from '../views/workflows-view';
|
|
18
|
-
|
|
19
|
-
/** What starts a workflow's runs, in words. */
|
|
20
|
-
const startsLine = (w: WorkflowView): string =>
|
|
21
|
-
w.startsOn.kind === 'queue' ? 'runs on its queue'
|
|
22
|
-
: w.startsOn.kind === 'inputs' ? `runs when its inputs change: ${w.startsOn.says}`
|
|
23
|
-
: 'runs on a timer or a request';
|
|
24
|
-
|
|
25
|
-
/** A queue's progress as a bar: done, running, queued and the rest, each segment lighter or darker than its neighbours. */
|
|
26
|
-
function QueueBar({ queue }: { readonly queue: NonNullable<WorkflowView['queue']> }) {
|
|
27
|
-
const rest = queue.waiting + queue.stuck + queue.held;
|
|
28
|
-
const total = Math.max(1, queue.done + queue.running + queue.queued + rest);
|
|
29
|
-
const segments = [
|
|
30
|
-
{ n: queue.done, cls: 'wp-seg-done' },
|
|
31
|
-
{ n: queue.running, cls: 'wp-seg-running' },
|
|
32
|
-
{ n: queue.queued, cls: 'wp-seg-queued' },
|
|
33
|
-
{ n: rest, cls: 'wp-seg-rest' },
|
|
34
|
-
];
|
|
35
|
-
const words = [
|
|
36
|
-
`${queue.queued.toLocaleString('en-US')} queued`,
|
|
37
|
-
`${queue.running.toLocaleString('en-US')} running`,
|
|
38
|
-
`${queue.done.toLocaleString('en-US')} done`,
|
|
39
|
-
...(['waiting', 'stuck', 'held'] as const).filter((b) => queue[b] > 0).map((b) => `${queue[b].toLocaleString('en-US')} ${b}`),
|
|
40
|
-
];
|
|
41
|
-
return (
|
|
42
|
-
<div className="wp-queue">
|
|
43
|
-
<div className="wp-bar" role="img" aria-label={words.join(', ')}>
|
|
44
|
-
{segments.map((s) => (s.n === 0 ? null : <span key={s.cls} className={s.cls} style={{ width: `${(100 * s.n) / total}%` }} />))}
|
|
45
|
-
</div>
|
|
46
|
-
<div className="wp-queue-words">{words.join(' · ')}</div>
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** An edge's label: what it is, and along a wait how many wait. */
|
|
52
|
-
const flowLabel = (f: WorkflowFlow): string => (f.kind === 'waits on' ? `${f.waiting.toLocaleString('en-US')} wait on it` : f.kind);
|
|
53
|
-
/** An edge's line: solid feeds, dashed sends back, dotted gives input, dash-dot waits on. */
|
|
54
|
-
const DASH: Readonly<Record<WorkflowFlow['kind'], string | undefined>> = { feeds: undefined, 'sends back': '7 4', 'gives input': '1.5 3.5', 'waits on': '7 3 1.5 3' };
|
|
55
|
-
|
|
56
|
-
/** The node's width; its height is measured from what it shows. */
|
|
57
|
-
const NODE_WIDTH = 250;
|
|
58
|
-
/** The left gutter the stages are named in. */
|
|
59
|
-
const GUTTER = 150;
|
|
60
|
-
const LABEL_HEIGHT = 15;
|
|
61
|
-
const labelWidth = (text: string) => Math.ceil(text.length * 6.3) + 10;
|
|
62
|
-
|
|
63
|
-
interface Laid {
|
|
64
|
-
readonly nodes: ReadonlyMap<string, { readonly x: number; readonly y: number; readonly h: number }>;
|
|
65
|
-
readonly edges: ReadonlyArray<{ readonly flow: WorkflowFlow; readonly points: ReadonlyArray<{ readonly x: number; readonly y: number }>; readonly label: { readonly x: number; readonly y: number; readonly w: number } | null }>;
|
|
66
|
-
readonly width: number;
|
|
67
|
-
readonly height: number;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const elk = new ELK();
|
|
71
|
-
|
|
72
|
-
/** The layout of the linked workflows, given each node's height. */
|
|
73
|
-
const layOut = async (input: {
|
|
74
|
-
/** In pipeline order: by stage, then by depth through forward edges within it. */
|
|
75
|
-
readonly workflows: ReadonlyArray<{ readonly name: string; readonly stage: number; readonly height: number }>;
|
|
76
|
-
readonly flows: ReadonlyArray<WorkflowFlow>;
|
|
77
|
-
}): Promise<Laid> => {
|
|
78
|
-
const asked: ElkNode = {
|
|
79
|
-
id: 'workflows',
|
|
80
|
-
layoutOptions: {
|
|
81
|
-
'elk.algorithm': 'layered',
|
|
82
|
-
'elk.direction': 'DOWN',
|
|
83
|
-
'elk.edgeRouting': 'ORTHOGONAL',
|
|
84
|
-
'elk.partitioning.activate': 'true',
|
|
85
|
-
// One layering for all, so every stage's layers come before the next stage's; laid out apart, unconnected groups sat side by side.
|
|
86
|
-
'elk.separateConnectedComponents': 'false',
|
|
87
|
-
'elk.layered.feedbackEdges': 'true',
|
|
88
|
-
// The platform's pipeline order decides which edges go against the flow: only one to a workflow earlier in it, a
|
|
89
|
-
// send-back. Left to itself, ELK kept Retry near-misses' send-back as forward and drew Decompile's feed going up.
|
|
90
|
-
'elk.layered.cycleBreaking.strategy': 'MODEL_ORDER',
|
|
91
|
-
'elk.layered.considerModelOrder.strategy': 'NODES_AND_EDGES',
|
|
92
|
-
'elk.layered.spacing.nodeNodeBetweenLayers': '64',
|
|
93
|
-
'elk.spacing.nodeNode': '36',
|
|
94
|
-
'elk.spacing.edgeNode': '18',
|
|
95
|
-
'elk.spacing.edgeEdge': '12',
|
|
96
|
-
'elk.spacing.edgeLabel': '4',
|
|
97
|
-
'elk.layered.edgeLabels.sideSelection': 'SMART_DOWN',
|
|
98
|
-
'elk.padding': `[top=34,left=${GUTTER},bottom=16,right=16]`,
|
|
99
|
-
},
|
|
100
|
-
children: input.workflows.map((w) => ({ id: w.name, width: NODE_WIDTH, height: w.height, layoutOptions: { 'elk.partitioning.partition': String(w.stage) } })),
|
|
101
|
-
edges: input.flows.map((f, i) => ({ id: `edge-${i}`, sources: [f.from], targets: [f.to], labels: [{ id: `label-${i}`, text: flowLabel(f), width: labelWidth(flowLabel(f)), height: LABEL_HEIGHT }] })),
|
|
102
|
-
};
|
|
103
|
-
const graph = await elk.layout(asked);
|
|
104
|
-
const nodes = new Map((graph.children ?? []).map((c) => [c.id, { x: c.x ?? 0, y: c.y ?? 0, h: c.height ?? 0 }]));
|
|
105
|
-
const edges = (graph.edges ?? []).map((e, i) => {
|
|
106
|
-
const s = e.sections?.[0];
|
|
107
|
-
const label = e.labels?.[0];
|
|
108
|
-
return {
|
|
109
|
-
flow: input.flows[i]!,
|
|
110
|
-
points: s === undefined ? [] : [s.startPoint, ...(s.bendPoints ?? []), s.endPoint],
|
|
111
|
-
label: label === undefined || label.x === undefined || label.y === undefined ? null : { x: label.x, y: label.y, w: label.width ?? 0 },
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
return { nodes, edges, width: graph.width ?? 0, height: graph.height ?? 0 };
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export interface WorkflowDagProps {
|
|
118
|
-
readonly view: WorkflowsView;
|
|
119
|
-
readonly phaseLabel: (phase: string) => string;
|
|
120
|
-
/** A stage's figures, beside its name. */
|
|
121
|
-
readonly phaseLine: (phase: string) => ReactNode;
|
|
122
|
-
/** A node's runs and agents now, with its limit controls. */
|
|
123
|
-
readonly nodeStatus: (w: WorkflowView) => ReactNode;
|
|
124
|
-
/** A node's link to its definition. */
|
|
125
|
-
readonly nodeHref: (w: WorkflowView) => string;
|
|
126
|
-
/** The open node's steps, graph and costs. */
|
|
127
|
-
readonly detail: (w: WorkflowView) => ReactNode;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function Node({ w, flows, open, setOpen, nodeStatus, nodeHref, style }: { readonly w: WorkflowView; readonly flows: ReadonlyArray<WorkflowFlow>; readonly open: boolean; readonly setOpen: (open: boolean) => void; readonly nodeStatus: (w: WorkflowView) => ReactNode; readonly nodeHref: (w: WorkflowView) => string; readonly style?: CSSProperties }) {
|
|
131
|
-
const into = flows.filter((f) => f.to === w.name);
|
|
132
|
-
const out = flows.filter((f) => f.from === w.name);
|
|
133
|
-
const word = (f: WorkflowFlow) => (f.kind === 'feeds' ? '' : f.kind === 'waits on' ? ` (${f.waiting.toLocaleString('en-US')} waiting)` : ` (${f.kind})`);
|
|
134
|
-
return (
|
|
135
|
-
<div data-workflow={w.name} className={open ? 'wp-node wp-node-open' : 'wp-node'} style={style}>
|
|
136
|
-
<div className="wp-node-head">
|
|
137
|
-
<button type="button" className="wp-node-name" aria-expanded={open} onClick={() => setOpen(!open)} title={w.description}>{open ? '▾' : '▸'} {w.name}</button>
|
|
138
|
-
<a className="wp-mut" href={nodeHref(w)} title="Its definition">source</a>
|
|
139
|
-
</div>
|
|
140
|
-
<div className="wp-node-what" title={w.description}>{w.description}</div>
|
|
141
|
-
<div className="wp-node-starts wp-mut" title={startsLine(w)}>{startsLine(w)}</div>
|
|
142
|
-
{into.length === 0 && out.length === 0 ? null : (
|
|
143
|
-
<div className="wp-node-flows wp-mut">
|
|
144
|
-
{into.length === 0 ? null : <span>from {into.map((f) => `${f.from}${word(f)}`).join(', ')}</span>}
|
|
145
|
-
{out.length === 0 ? null : <span>to {out.map((f) => `${f.to}${word(f)}`).join(', ')}</span>}
|
|
146
|
-
</div>
|
|
147
|
-
)}
|
|
148
|
-
{w.queue === null ? null : <QueueBar queue={w.queue} />}
|
|
149
|
-
<div className="wp-node-status">{nodeStatus(w)}</div>
|
|
150
|
-
</div>
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function WorkflowDag({ view, phaseLabel, phaseLine, nodeStatus, nodeHref, detail }: WorkflowDagProps) {
|
|
155
|
-
const [open, setOpenName] = useState<string | null>(null);
|
|
156
|
-
const all = view.groups.flatMap((g) => g.workflows);
|
|
157
|
-
const linkedNames = new Set(view.flows.flatMap((f) => [f.from, f.to]));
|
|
158
|
-
const linked = all.filter((w) => linkedNames.has(w.name));
|
|
159
|
-
const stageOf = new Map(view.groups.map((g, i) => [g.phase, i]));
|
|
160
|
-
const openWorkflow = all.find((w) => w.name === open) ?? null;
|
|
161
|
-
const panel = useRef<HTMLDivElement>(null);
|
|
162
|
-
const setOpen = (name: string) => (on: boolean) => setOpenName(on ? name : null);
|
|
163
|
-
useEffect(() => { if (open !== null) panel.current?.scrollIntoView({ block: 'nearest', behavior: 'smooth' }); }, [open]);
|
|
164
|
-
|
|
165
|
-
// Each node's height, measured as drawn, then the layout from them; laid out again whenever a height or the flows change.
|
|
166
|
-
const map = useRef<HTMLDivElement>(null);
|
|
167
|
-
const [heights, setHeights] = useState<string>('');
|
|
168
|
-
const [laid, setLaid] = useState<Laid | null>(null);
|
|
169
|
-
const [failed, setFailed] = useState<string | null>(null);
|
|
170
|
-
useLayoutEffect(() => {
|
|
171
|
-
const el = map.current;
|
|
172
|
-
if (el === null) return;
|
|
173
|
-
const measure = () => setHeights(JSON.stringify([...el.querySelectorAll('[data-workflow]')].map((n) => [n.getAttribute('data-workflow'), Math.ceil(n.getBoundingClientRect().height)])));
|
|
174
|
-
measure();
|
|
175
|
-
const watch = new ResizeObserver(measure);
|
|
176
|
-
for (const n of el.querySelectorAll('[data-workflow]')) watch.observe(n);
|
|
177
|
-
return () => watch.disconnect();
|
|
178
|
-
}, [view.at, linked.length]);
|
|
179
|
-
const flowsKey = JSON.stringify(view.flows.map((f) => [f.from, f.to, f.kind, flowLabel(f)]));
|
|
180
|
-
useEffect(() => {
|
|
181
|
-
if (heights === '') return;
|
|
182
|
-
const h = new Map(JSON.parse(heights) as Array<[string, number]>);
|
|
183
|
-
let current = true;
|
|
184
|
-
const inOrder = [...linked].sort((a, b) => a.place.stage - b.place.stage || a.place.depth - b.place.depth || a.name.localeCompare(b.name));
|
|
185
|
-
layOut({ workflows: inOrder.map((w) => ({ name: w.name, stage: stageOf.get(w.phase) ?? 0, height: h.get(w.name) ?? 120 })), flows: view.flows })
|
|
186
|
-
.then((l) => { if (current) { setLaid(l); setFailed(null); } })
|
|
187
|
-
.catch((e: unknown) => { if (current) setFailed(e instanceof Error ? e.message : String(e)); });
|
|
188
|
-
return () => { current = false; };
|
|
189
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- `linked` and `stageOf` follow `heights` and `flowsKey`.
|
|
190
|
-
}, [heights, flowsKey]);
|
|
191
|
-
|
|
192
|
-
// Each stage's band: from the top of its first node to the bottom of its last.
|
|
193
|
-
const bands = laid === null ? [] : view.groups.flatMap((g) => {
|
|
194
|
-
const ys = linked.filter((w) => w.phase === g.phase).flatMap((w) => { const n = laid.nodes.get(w.name); return n === undefined ? [] : [{ top: n.y, bottom: n.y + n.h }]; });
|
|
195
|
-
return ys.length === 0 ? [] : [{ phase: g.phase, top: Math.min(...ys.map((y) => y.top)) - 24, bottom: Math.max(...ys.map((y) => y.bottom)) + 14 }];
|
|
196
|
-
});
|
|
197
|
-
const unlinked = view.groups.map((g) => ({ phase: g.phase, workflows: g.workflows.filter((w) => !linkedNames.has(w.name)) })).filter((g) => g.workflows.length > 0);
|
|
198
|
-
|
|
199
|
-
return (
|
|
200
|
-
<div className="wp-dag-wrap">
|
|
201
|
-
<p className="wp-line wp-mut">
|
|
202
|
-
Each box is one workflow; open one for its steps. Arrows point the way work goes, down the page: a solid arrow feeds the next
|
|
203
|
-
workflow's tasks; dashed, “sends back”, returns work to an earlier one. Each stage is a band, named on the left.
|
|
204
|
-
</p>
|
|
205
|
-
{failed === null ? null : <p className="wp-line wp-bad">The map could not be laid out: {failed}</p>}
|
|
206
|
-
<div className="wp-dag-scroll">
|
|
207
|
-
<div ref={map} className="wp-dag" style={{ width: laid === null ? undefined : laid.width, height: laid === null ? undefined : laid.height }}>
|
|
208
|
-
{laid === null ? null : (
|
|
209
|
-
<svg className="wp-dag-edges" width={laid.width} height={laid.height} aria-hidden="true">
|
|
210
|
-
<defs>
|
|
211
|
-
<marker id="wp-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="11" markerHeight="11" markerUnits="userSpaceOnUse" orient="auto">
|
|
212
|
-
<path d="M0,0 L10,5 L0,10 z" fill="var(--wp-edge)" />
|
|
213
|
-
</marker>
|
|
214
|
-
</defs>
|
|
215
|
-
{bands.map((b, i) => (
|
|
216
|
-
<g key={b.phase}>
|
|
217
|
-
<rect x={0} y={b.top} width={laid.width} height={b.bottom - b.top} fill={i % 2 === 0 ? 'var(--wp-band)' : 'transparent'} />
|
|
218
|
-
<foreignObject x={6} y={b.top + 6} width={GUTTER - 16} height={Math.max(40, b.bottom - b.top - 12)}>
|
|
219
|
-
<div className="wp-band-name">{phaseLabel(b.phase)}<span className="wp-mut"> · {phaseLine(b.phase)}</span></div>
|
|
220
|
-
</foreignObject>
|
|
221
|
-
</g>
|
|
222
|
-
))}
|
|
223
|
-
{laid.edges.map(({ flow, points }) => (
|
|
224
|
-
<polyline key={`${flow.from}>${flow.to}`} points={points.map((p) => `${p.x},${p.y}`).join(' ')} fill="none" stroke="var(--wp-edge)"
|
|
225
|
-
strokeWidth={flow.kind === 'feeds' ? 1.8 : 1.5} strokeDasharray={DASH[flow.kind]} markerEnd="url(#wp-arrow)" />
|
|
226
|
-
))}
|
|
227
|
-
{laid.edges.map(({ flow, label }) => (label === null ? null : (
|
|
228
|
-
<g key={`label:${flow.from}>${flow.to}`}>
|
|
229
|
-
<rect x={label.x} y={label.y} width={label.w} height={LABEL_HEIGHT} rx={3} fill="var(--wp-bg)" stroke="var(--wp-edge)" strokeWidth="0.7" />
|
|
230
|
-
<text x={label.x + 5} y={label.y + 11} fontSize="10.5" fill="var(--wp-fg)">{flowLabel(flow)}{flow.why === null ? null : <title>{flow.why}</title>}</text>
|
|
231
|
-
</g>
|
|
232
|
-
)))}
|
|
233
|
-
</svg>
|
|
234
|
-
)}
|
|
235
|
-
{linked.map((w) => {
|
|
236
|
-
const at = laid?.nodes.get(w.name);
|
|
237
|
-
return (
|
|
238
|
-
<Node key={w.name} w={w} flows={view.flows} open={open === w.name} setOpen={setOpen(w.name)} nodeStatus={nodeStatus} nodeHref={nodeHref}
|
|
239
|
-
style={at === undefined ? { position: 'absolute', left: 0, top: 0, visibility: 'hidden' } : { position: 'absolute', left: at.x, top: at.y }} />
|
|
240
|
-
);
|
|
241
|
-
})}
|
|
242
|
-
</div>
|
|
243
|
-
</div>
|
|
244
|
-
{openWorkflow === null || !linkedNames.has(openWorkflow.name) ? null : <div ref={panel} className="wp-node-detail">{detail(openWorkflow)}</div>}
|
|
245
|
-
{unlinked.map((g) => (
|
|
246
|
-
<section key={g.phase} className="wp-stage">
|
|
247
|
-
<h2 className="wp-h2">{phaseLabel(g.phase)}: workflows no work flows to or from<span className="wp-mut"> · {phaseLine(g.phase)}</span></h2>
|
|
248
|
-
<div className="wp-nodes">
|
|
249
|
-
{g.workflows.map((w) => <Node key={w.name} w={w} flows={view.flows} open={open === w.name} setOpen={setOpen(w.name)} nodeStatus={nodeStatus} nodeHref={nodeHref} />)}
|
|
250
|
-
</div>
|
|
251
|
-
{openWorkflow !== null && openWorkflow.phase === g.phase && !linkedNames.has(openWorkflow.name) ? <div ref={panel} className="wp-node-detail">{detail(openWorkflow)}</div> : null}
|
|
252
|
-
</section>
|
|
253
|
-
))}
|
|
254
|
-
</div>
|
|
255
|
-
);
|
|
256
|
-
}
|