@widgetic/workflows 0.2.4 → 0.2.5

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 CHANGED
@@ -39,8 +39,14 @@ Workflows are for **Teams and partner accounts** only. On Widgetic the page is
39
39
  read-only. A banner says when the draft differs from what is live.
40
40
  - **Test run.** A visitor is played through the draft on the canvas: fire a trigger and watch the path light up. Nothing is
41
41
  stored and no real visitor is touched.
42
- - **Runs.** The _Runs_ tab shows how many visitors went through each block and each line over a range of days (counts
43
- only: what a visitor typed is never stored).
42
+ - **Runs.** The _Runs_ tab shows how far visitors came over a range of days, as a Sankey diagram used as a funnel: a bar
43
+ for each composition and a band for each way from one composition to the next, as wide as the number of visitors who
44
+ went that way. Several bands that leave one bar are the alternatives of the workflow (each rule of a condition and its
45
+ Default path is a band), a band that skips a step runs in a lane between the bars, and the hollow part of a bar is the
46
+ visitors who reached it and did not go on. Counts only: what a visitor typed is never stored. It is drawn from the
47
+ three parts in `src/lib/editor/runs*.ts` (the model, the layout in pixels, the words) and
48
+ `src/lib/components/editor/RunsFlow.svelte`, so the Widgetic site, the Shopify app and a partner's page all show the
49
+ same chart.
44
50
  - **Settings.** The time zone that scheduled triggers are told in, the embed code, and the state of the workflow: pause
45
51
  or resume it, archive or restore it, duplicate it, or delete it. A workflow can be deleted in any state, after one
46
52
  confirmation that says what goes with it (its draft, and once it was published its versions and its counts; the
@@ -49,7 +49,7 @@ export interface WorkflowVersion {
49
49
  timezone: string;
50
50
  isLive: boolean;
51
51
  }
52
- /** A published version with its graph: the read-only preview and the Runs canvas draw it. */
52
+ /** A published version with its graph: the read-only preview draws it, and the Runs chart is made from it. */
53
53
  export interface WorkflowVersionDetail extends WorkflowVersion {
54
54
  startNodeId: string;
55
55
  graph: WorkflowGraph;
@@ -1,7 +1,6 @@
1
1
  <!--
2
2
  A composition block on the canvas: the composition a visitor sees at this step (its name and picture), whether it is where
3
- the workflow starts, what is wrong with it, and, in the Runs tab, how many visitors reached it. A line comes in on the
4
- left, and the next steps leave from the right.
3
+ the workflow starts, and what is wrong with it. A line comes in on the left, and the next steps leave from the right.
5
4
 
6
5
  Nothing here can be edited: a block is changed from the side panel, so the block itself only has to be picked up and moved
7
6
  (kaykay does that for the whole block). The block follows the direction of the page for its words, while the canvas around
@@ -20,13 +19,12 @@
20
19
  } from '../../editor/flowAdapter.js';
21
20
  import { useCanvasContext } from '../../editor/canvasContext.js';
22
21
  import { useWorkflowsLanguage } from '../../i18n/language.js';
23
- import { formatCount } from '../../editor/formatCount.js';
24
22
  import Icon from '../ui/Icon.svelte';
25
23
  import HandlePoint from './HandlePoint.svelte';
26
24
 
27
25
  let { id, data }: NodeProps<WorkflowBlockData> = $props();
28
26
 
29
- const { t, locale } = useWorkflowsLanguage();
27
+ const { t } = useWorkflowsLanguage();
30
28
  const textDirection = useTextDirection();
31
29
  const readContext = useCanvasContext();
32
30
 
@@ -37,8 +35,6 @@
37
35
  );
38
36
  const marks = $derived(readContext().marks);
39
37
  const problemCount = $derived(marks.problemCountOf(id));
40
- const entryCount = $derived(marks.entryCountOf(id));
41
- const failureCount = $derived(marks.failureCountOf(id));
42
38
 
43
39
  /** The words at the top of the block: the composition's name, or what is missing. */
44
40
  const title = $derived.by(() => {
@@ -98,16 +94,6 @@
98
94
  {$t('workflows.block.problems', { count: problemCount })}
99
95
  </p>
100
96
  {/if}
101
- {#if entryCount !== null}
102
- <p class="text-xs text-ink-muted">
103
- {$t('workflows.runs.entered', { count: formatCount(entryCount, $locale) })}
104
- </p>
105
- {/if}
106
- {#if failureCount > 0}
107
- <p class="text-xs text-error">
108
- {$t('workflows.runs.failed', { count: formatCount(failureCount, $locale) })}
109
- </p>
110
- {/if}
111
97
 
112
98
  <HandlePoint
113
99
  id={INPUT_HANDLE_ID}
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  A trigger block on the canvas: what makes a visitor leave the composition before it (a visitor adds an entry, does
3
3
  something in the widget, the page sends an event, or time passes), told in one line. A line comes in from the composition
4
- on the left and leaves to the next step on the right. In the Runs tab it also says how many times it fired.
4
+ on the left and leaves to the next step on the right.
5
5
  -->
6
6
  <script lang="ts">
7
7
  import type { NodeProps } from 'kaykay';
@@ -16,14 +16,13 @@
16
16
  } from '../../editor/flowAdapter.js';
17
17
  import { TRIGGER_KIND_MESSAGE_KEYS } from '../../editor/blockLabels.js';
18
18
  import { useCanvasContext } from '../../editor/canvasContext.js';
19
- import { formatCount } from '../../editor/formatCount.js';
20
19
  import { useWorkflowsLanguage } from '../../i18n/language.js';
21
20
  import Icon from '../ui/Icon.svelte';
22
21
  import HandlePoint from './HandlePoint.svelte';
23
22
 
24
23
  let { id, data }: NodeProps<WorkflowBlockData> = $props();
25
24
 
26
- const { t, locale } = useWorkflowsLanguage();
25
+ const { t } = useWorkflowsLanguage();
27
26
  const textDirection = useTextDirection();
28
27
  const readContext = useCanvasContext();
29
28
 
@@ -32,7 +31,6 @@
32
31
  /** What the trigger waits for, as one line. `summarizeTrigger` is read from the shared context so that it speaks the page's language. */
33
32
  const summary = $derived(readContext().words.summarizeTrigger(node.trigger));
34
33
  const problemCount = $derived(marks.problemCountOf(id));
35
- const firedCount = $derived(marks.entryCountOf(id));
36
34
  </script>
37
35
 
38
36
  <div
@@ -53,11 +51,6 @@
53
51
  {$t('workflows.block.problems', { count: problemCount })}
54
52
  </p>
55
53
  {/if}
56
- {#if firedCount !== null}
57
- <p class="text-xs text-ink-muted">
58
- {$t('workflows.runs.fired', { count: formatCount(firedCount, $locale) })}
59
- </p>
60
- {/if}
61
54
 
62
55
  <HandlePoint
63
56
  id={INPUT_HANDLE_ID}
@@ -4,8 +4,9 @@
4
4
  one only draws the line (kaykay's `BaseEdge`) and says what is true of it:
5
5
 
6
6
  - a line the check found a problem with is red,
7
- - the line that is selected, or that a test visitor followed, is green and a little thicker,
8
- - in the Runs tab, the line is drawn thicker the more visitors followed it, with their number on it.
7
+ - the line that is selected, or that a test visitor followed, is green and a little thicker.
8
+
9
+ How many visitors followed a line is not drawn here: the Runs tab has a chart of its own for that (`RunsFlow`).
9
10
 
10
11
  Colours are the palette's custom properties (`--color-*`), which the page or a ui-sdk theme sets, so the line follows the
11
12
  theme like everything else on the screen.
@@ -14,18 +15,14 @@
14
15
  import { BaseEdge } from 'kaykay';
15
16
  import type { EdgeProps } from 'kaykay';
16
17
  import { useCanvasContext } from '../../editor/canvasContext.js';
17
- import { formatCount } from '../../editor/formatCount.js';
18
- import { useWorkflowsLanguage } from '../../i18n/language.js';
19
18
 
20
19
  let { edge, path, selected, label_position, onselect }: EdgeProps = $props();
21
20
 
22
- const { locale } = useWorkflowsLanguage();
23
21
  const readContext = useCanvasContext();
24
22
 
25
23
  const marks = $derived(readContext().marks);
26
24
  const hasProblem = $derived(marks.hasEdgeProblem(edge.id));
27
25
  const isTaken = $derived(marks.isEdgeTaken(edge.id));
28
- const followCount = $derived(marks.followCountOf(edge.id));
29
26
 
30
27
  const color = $derived(
31
28
  hasProblem
@@ -35,15 +32,8 @@
35
32
  : 'var(--color-ink-subtle)'
36
33
  );
37
34
 
38
- /** 2 pixels, 3 for a followed line; with counts, one more pixel for every power of ten of visitors, up to 6. */
39
- const strokeWidth = $derived.by(() => {
40
- if (followCount !== null)
41
- return followCount <= 0 ? 2 : Math.min(6, 2 + Math.log10(followCount + 1));
42
- return isTaken ? 3 : 2;
43
- });
44
- const label = $derived(
45
- followCount !== null && followCount > 0 ? formatCount(followCount, $locale) : undefined
46
- );
35
+ /** 2 pixels, 3 for a line a test visitor followed. */
36
+ const strokeWidth = $derived(isTaken ? 3 : 2);
47
37
  </script>
48
38
 
49
39
  <BaseEdge
@@ -51,8 +41,6 @@
51
41
  {selected}
52
42
  {color}
53
43
  stroke_width={strokeWidth}
54
- {label}
55
44
  {label_position}
56
- label_background={label !== undefined}
57
45
  onclick={onselect}
58
46
  />
@@ -37,10 +37,7 @@
37
37
  },
38
38
  problemCountOf: (nodeId) => editor.issuesOnCanvas.byNode.get(nodeId)?.length ?? 0,
39
39
  hasEdgeProblem: (edgeId) => editor.issuesOnCanvas.byEdge.has(edgeId),
40
- isEdgeTaken: (edgeId) => editor.testTakenEdgeIds.has(edgeId),
41
- entryCountOf: () => null,
42
- followCountOf: () => null,
43
- failureCountOf: () => 0
40
+ isEdgeTaken: (edgeId) => editor.testTakenEdgeIds.has(edgeId)
44
41
  };
45
42
 
46
43
  const context = $derived<CanvasContext>({ marks, words, readOnly: !editor.canEditCanvas });
@@ -0,0 +1,276 @@
1
+ <!--
2
+ The Runs chart: how far visitors came in a workflow, drawn as a Sankey diagram used as a funnel. Every composition is a bar,
3
+ every way from one composition to the next (a trigger, then any conditions after it) is a band between two bars, and the
4
+ wider the band, the more visitors went that way. Several bands that leave one bar are the alternatives of a workflow; the
5
+ part of a bar that is drawn hollow is the visitors who reached it and did not go on.
6
+
7
+ It shows counts only, as the Runs tab always did: never a visitor, never what a visitor typed.
8
+
9
+ What it draws is worked out in three plain parts that have their own tests: the model (`runsFlow.ts`: bars, bands, columns),
10
+ the layout (`runsFlowLayout.ts`: pixels) and the words (`runsFlowWords.ts`: names). This part only draws them and says the
11
+ same numbers in a list for a person who uses a screen reader, since a drawing says nothing to one.
12
+
13
+ The chart reads from left to right in every language, as the canvas of the editor does: the columns are the steps a visitor
14
+ takes. What is written on it follows the direction of the page.
15
+ -->
16
+ <script lang="ts">
17
+ import type { WorkflowGraph } from '@widgetic/workflows-engine';
18
+ import { useTextDirection } from '@widgetic/design-system/components/textDirection';
19
+ import { formatCount } from '../../editor/formatCount.js';
20
+ import { buildRunsFlow } from '../../editor/runsFlow.js';
21
+ import type { RunsFlow, RunsFlowStep } from '../../editor/runsFlow.js';
22
+ import { RUNS_FLOW_METRICS, layoutRunsFlow } from '../../editor/runsFlowLayout.js';
23
+ import type { PlacedLink, PlacedStep } from '../../editor/runsFlowLayout.js';
24
+ import type { RunsFlowWords } from '../../editor/runsFlowWords.js';
25
+ import type { RunCounts } from '../../editor/statsRange.js';
26
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
27
+ import { workflowsError } from '../../utils/logger.js';
28
+
29
+ interface Props {
30
+ /** The blocks of the version the counts are about. */
31
+ graph: WorkflowGraph;
32
+ counts: RunCounts;
33
+ words: RunsFlowWords;
34
+ }
35
+
36
+ let { graph, counts, words }: Props = $props();
37
+
38
+ const { t, locale } = useWorkflowsLanguage();
39
+ const textDirection = useTextDirection();
40
+
41
+ /** The width the chart is drawn in until the screen has measured the room it has. */
42
+ const WIDTH_BEFORE_MEASURING = 720;
43
+ /** The width of the place a band can be pointed at, however thin the band is. */
44
+ const LEAST_POINTING_WIDTH = 14;
45
+
46
+ // A band has one colour for each of its states; each is written whole so that the stylesheet of the page finds it.
47
+ const BAND_STATE_CLASSES = {
48
+ resting: 'stroke-primary-green/25',
49
+ lit: 'stroke-primary-green/55',
50
+ dimmed: 'stroke-primary-green/10',
51
+ // A way nobody took, in a chart that has visitors: a dashed hair.
52
+ nobody: 'stroke-grey3/60',
53
+ // A chart nobody has been counted in: every band pale and whole, the shape of the workflow and no one in it.
54
+ empty: 'stroke-grey3/20'
55
+ } as const;
56
+
57
+ /** One line of numbers under a composition's name. */
58
+ interface NumberLine {
59
+ kind: 'entered' | 'stayed' | 'failed';
60
+ text: string;
61
+ }
62
+
63
+ /** The room the screen gave the chart, in pixels; 0 until it was measured. */
64
+ let measuredWidth = $state(0);
65
+ /** What a pointer is over: a bar or a band. Its bands (or itself) are lit and the others fade. */
66
+ let pointedAt = $state.raw<{ kind: 'step' | 'link'; id: string } | null>(null);
67
+
68
+ const emptyFlow: RunsFlow = { steps: [], links: [], columnCount: 0, hasVisitors: false };
69
+
70
+ /** The model. A graph the chart cannot read draws nothing (and says why once) rather than taking the screen down. */
71
+ const flow = $derived.by((): RunsFlow => {
72
+ try {
73
+ return buildRunsFlow(graph, counts);
74
+ } catch (error) {
75
+ workflowsError('Making the chart of the runs failed.', error);
76
+ return emptyFlow;
77
+ }
78
+ });
79
+
80
+ const placed = $derived(
81
+ layoutRunsFlow(flow, { width: measuredWidth > 0 ? measuredWidth : WIDTH_BEFORE_MEASURING })
82
+ );
83
+
84
+ /** The bands that are lit while a bar or a band is pointed at; `null` when nothing is. */
85
+ const litBandIds = $derived.by((): ReadonlySet<string> | null => {
86
+ if (!pointedAt) return null;
87
+ if (pointedAt.kind === 'link') return new Set([pointedAt.id]);
88
+ const stepId = pointedAt.id;
89
+ return new Set(
90
+ placed.links
91
+ .filter((band) => band.sourceId === stepId || band.targetId === stepId)
92
+ .map((band) => band.id)
93
+ );
94
+ });
95
+
96
+ function pickBandClass(band: PlacedLink): string {
97
+ if (!flow.hasVisitors) return BAND_STATE_CLASSES.empty;
98
+ if (band.value === 0) return BAND_STATE_CLASSES.nobody;
99
+ if (litBandIds === null) return BAND_STATE_CLASSES.resting;
100
+ return litBandIds.has(band.id) ? BAND_STATE_CLASSES.lit : BAND_STATE_CLASSES.dimmed;
101
+ }
102
+
103
+ /** The lines of numbers under a composition's name: how many entered, and, when they apply, how many stopped and how many failed. */
104
+ function readNumbersOf(step: Pick<RunsFlowStep, 'entered' | 'stayed' | 'failed'>): NumberLine[] {
105
+ const lines: NumberLine[] = [
106
+ {
107
+ kind: 'entered',
108
+ text: $t('workflows.runs.entered', { count: formatCount(step.entered, $locale) })
109
+ }
110
+ ];
111
+ if (step.stayed > 0) {
112
+ lines.push({
113
+ kind: 'stayed',
114
+ text: $t('workflows.runs.stayed', { count: formatCount(step.stayed, $locale) })
115
+ });
116
+ }
117
+ if (step.failed > 0) {
118
+ lines.push({
119
+ kind: 'failed',
120
+ text: $t('workflows.runs.failed', { count: formatCount(step.failed, $locale) })
121
+ });
122
+ }
123
+ return lines;
124
+ }
125
+
126
+ /** One composition in one line, for its tooltip. */
127
+ function describeStep(step: PlacedStep): string {
128
+ return [words.nameStep(step.nodeId), ...readNumbersOf(step).map((line) => line.text)].join(
129
+ ' · '
130
+ );
131
+ }
132
+
133
+ /** One band in one line, for its tooltip: where it goes, how many went, and how a visitor gets along it. */
134
+ function describeBand(band: PlacedLink): string {
135
+ return [
136
+ words.namePath(band),
137
+ $t('workflows.list.runsCount', { count: band.value }),
138
+ ...words.describeRoute(band)
139
+ ].join(' · ');
140
+ }
141
+ </script>
142
+
143
+ {#if placed.steps.length > 0}
144
+ <div
145
+ role="group"
146
+ aria-label={$t('workflows.runs.flowLabel')}
147
+ class="flex min-h-0 flex-1 flex-col"
148
+ >
149
+ <!-- rtl-ok: the chart is a left to right island in every language, like the canvas: the columns are the steps a visitor takes. -->
150
+ <div
151
+ class="min-h-72 flex-1 overflow-auto rounded-large border border-grey2 bg-white font-sans"
152
+ dir="ltr"
153
+ bind:clientWidth={measuredWidth}
154
+ >
155
+ <!-- The drawing is for the eyes; the list below says the same numbers to a screen reader. -->
156
+ <svg
157
+ class="block max-w-none"
158
+ width={placed.width}
159
+ height={placed.height}
160
+ viewBox="0 0 {placed.width} {placed.height}"
161
+ aria-hidden="true"
162
+ focusable="false"
163
+ >
164
+ {#each placed.links as band (band.id)}
165
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
166
+ <g
167
+ onpointerenter={() => (pointedAt = { kind: 'link', id: band.id })}
168
+ onpointerleave={() => (pointedAt = null)}
169
+ >
170
+ <title>{describeBand(band)}</title>
171
+ <path
172
+ d={band.path}
173
+ fill="none"
174
+ stroke-width={band.thickness}
175
+ stroke-dasharray={flow.hasVisitors && band.value === 0 ? '4 4' : undefined}
176
+ class="{pickBandClass(band)} transition-colors motion-reduce:transition-none"
177
+ />
178
+ <!-- A band a few visitors wide is a hair: this wider, invisible line is what a pointer lands on. -->
179
+ <path
180
+ d={band.path}
181
+ fill="none"
182
+ stroke-width={Math.max(band.thickness, LEAST_POINTING_WIDTH)}
183
+ class="stroke-transparent"
184
+ />
185
+ </g>
186
+ {/each}
187
+
188
+ {#each placed.steps as step (step.nodeId)}
189
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
190
+ <g
191
+ onpointerenter={() => (pointedAt = { kind: 'step', id: step.nodeId })}
192
+ onpointerleave={() => (pointedAt = null)}
193
+ >
194
+ <title>{describeStep(step)}</title>
195
+ {#if step.size > 0}
196
+ <rect
197
+ x={step.x}
198
+ y={step.barY}
199
+ width={RUNS_FLOW_METRICS.barWidth}
200
+ height={step.barHeight}
201
+ class="fill-primary-green"
202
+ />
203
+ {#if step.stayedHeight > 0}
204
+ <!-- The visitors who reached the composition and did not go on: hollow, at the bottom of the bar. -->
205
+ <rect
206
+ x={step.x + 0.5}
207
+ y={step.stayedY}
208
+ width={RUNS_FLOW_METRICS.barWidth - 1}
209
+ height={Math.max(0, step.stayedHeight - 0.5)}
210
+ class="fill-grey1 stroke-grey3"
211
+ />
212
+ {/if}
213
+ {:else}
214
+ <!-- Nobody came: the place of the bar is shown, empty. -->
215
+ <rect
216
+ x={step.x + 0.5}
217
+ y={step.barY}
218
+ width={RUNS_FLOW_METRICS.barWidth - 1}
219
+ height={step.barHeight}
220
+ stroke-dasharray="3 3"
221
+ class="fill-none stroke-grey3"
222
+ />
223
+ {/if}
224
+ <!-- The words are HTML in the drawing, so that a long name is cut with an ellipsis and a language that reads right to left is set properly. -->
225
+ <foreignObject
226
+ x={step.x}
227
+ y={step.labelY}
228
+ width={step.labelWidth}
229
+ height={step.labelHeight}
230
+ class="overflow-visible"
231
+ >
232
+ <div class="w-fit max-w-full" dir={$textDirection}>
233
+ <p
234
+ class="truncate text-sm leading-5 font-medium text-ink-primary"
235
+ dir="auto"
236
+ title={words.nameStep(step.nodeId)}
237
+ >
238
+ {words.nameStep(step.nodeId)}
239
+ </p>
240
+ {#each readNumbersOf(step) as line (line.kind)}
241
+ <p
242
+ class="truncate text-xs leading-4 {line.kind === 'failed'
243
+ ? 'text-error'
244
+ : 'text-ink-muted'}"
245
+ >
246
+ {line.text}
247
+ </p>
248
+ {/each}
249
+ </div>
250
+ </foreignObject>
251
+ </g>
252
+ {/each}
253
+ </svg>
254
+ </div>
255
+
256
+ <ul class="sr-only">
257
+ {#each flow.steps as step (step.nodeId)}
258
+ <li>
259
+ <span>{words.nameStep(step.nodeId)}</span>
260
+ {#each readNumbersOf(step) as line (line.kind)}
261
+ <span>{line.text}</span>
262
+ {/each}
263
+ </li>
264
+ {/each}
265
+ {#each flow.links as band (band.id)}
266
+ <li>
267
+ <span>{words.namePath(band)}</span>
268
+ <span>{$t('workflows.list.runsCount', { count: band.value })}</span>
269
+ {#each words.describeRoute(band) as part, position (position)}
270
+ <span>{part}</span>
271
+ {/each}
272
+ </li>
273
+ {/each}
274
+ </ul>
275
+ </div>
276
+ {/if}
@@ -0,0 +1,13 @@
1
+ import type { WorkflowGraph } from '@widgetic/workflows-engine';
2
+ import type { RunsFlow } from '../../editor/runsFlow.js';
3
+ import type { RunsFlowWords } from '../../editor/runsFlowWords.js';
4
+ import type { RunCounts } from '../../editor/statsRange.js';
5
+ interface Props {
6
+ /** The blocks of the version the counts are about. */
7
+ graph: WorkflowGraph;
8
+ counts: RunCounts;
9
+ words: RunsFlowWords;
10
+ }
11
+ declare const RunsFlow: import("svelte").Component<Props, {}, "">;
12
+ type RunsFlow = ReturnType<typeof RunsFlow>;
13
+ export default RunsFlow;
@@ -1,8 +1,9 @@
1
1
  <!--
2
- Runs: the workflow as a read-only canvas, with the number of visitors on every composition, trigger and line, for a range of
3
- days and one version (the live one to begin with). It answers "where do visitors go?" without ever showing a visitor: the
4
- counts are numbers only (how many entered, how many followed a line, how many times a composition could not be shown), never
5
- values and never people.
2
+ Runs: how far visitors came in the workflow, drawn as a Sankey diagram used as a funnel (`RunsFlow`): a bar for every
3
+ composition and a band for every way a visitor can go on, as wide as the number of visitors who went that way, for a range of
4
+ days and one version (the live one to begin with). It answers "where do visitors go, and where do they stop?" without ever
5
+ showing a visitor: the counts are numbers only (how many entered, how many followed a path, how many times a composition could
6
+ not be shown), never values and never people.
6
7
 
7
8
  Counts are by UTC day, as the API keeps them, and say so.
8
9
  -->
@@ -12,29 +13,26 @@
12
13
  import { useWorkflowsApi } from '../../api/apiContext.js';
13
14
  import { isCancelled } from '../../api/workflowsApi.js';
14
15
  import { pickApiErrorMessage } from '../../editor/apiErrorText.js';
15
- import type { CanvasContext, CanvasMarks } from '../../editor/canvasContext.js';
16
16
  import { makeCanvasWords } from '../../editor/canvasWords.js';
17
17
  import { useEditorState } from '../../editor/editorState.svelte.js';
18
- import type { CanvasHandle } from '../../editor/editorState.svelte.js';
18
+ import { makeRunsFlowWords } from '../../editor/runsFlowWords.js';
19
19
  import { RANGE_CHOICES_IN_DAYS, makeStatsRange, readRunCounts } from '../../editor/statsRange.js';
20
20
  import type { RunCounts } from '../../editor/statsRange.js';
21
21
  import { useWorkflowsLanguage } from '../../i18n/language.js';
22
22
  import type { WorkflowsMessageKey } from '../../i18n/messages.js';
23
23
  import { workflowsError } from '../../utils/logger.js';
24
- import WorkflowCanvas from '../canvas/WorkflowCanvas.svelte';
25
24
  import ActionButton from '../ui/ActionButton.svelte';
26
- import Icon from '../ui/Icon.svelte';
27
25
  import Notice from '../ui/Notice.svelte';
28
26
  import SelectField from '../ui/SelectField.svelte';
29
27
  import type { SelectChoice } from '../ui/types.js';
28
+ import RunsFlow from './RunsFlow.svelte';
30
29
 
31
30
  const editor = useEditorState();
32
31
  const api = useWorkflowsApi();
33
32
  const { t, locale } = useWorkflowsLanguage();
34
33
 
35
- /** What the canvas shows now: the version's blocks and the counts over them. */
34
+ /** What the chart shows now: the version's blocks and the counts over them. */
36
35
  interface Shown {
37
- key: string;
38
36
  graph: WorkflowGraph;
39
37
  counts: RunCounts;
40
38
  }
@@ -45,7 +43,6 @@
45
43
  let loadState = $state<'loading' | 'ready' | 'failed'>('loading');
46
44
  let failureKey = $state.raw<WorkflowsMessageKey | null>(null);
47
45
  let shown = $state.raw<Shown | null>(null);
48
- let canvasHandle = $state.raw<CanvasHandle | null>(null);
49
46
 
50
47
  let controller: AbortController | null = null;
51
48
 
@@ -77,35 +74,22 @@
77
74
  : $t('workflows.runs.started', { count: started });
78
75
  });
79
76
 
80
- const words = $derived(
77
+ /** What the compositions and the ways between them are called on the chart, for the version that is shown. */
78
+ const flowWords = $derived(
81
79
  shown
82
- ? makeCanvasWords({
83
- graph: shown.graph,
84
- options: editor.options,
85
- timeZone: editor.timezone,
86
- locale: $locale,
80
+ ? makeRunsFlowWords({
81
+ words: makeCanvasWords({
82
+ graph: shown.graph,
83
+ options: editor.options,
84
+ timeZone: editor.timezone,
85
+ locale: $locale,
86
+ t: $t
87
+ }),
87
88
  t: $t
88
89
  })
89
90
  : null
90
91
  );
91
92
 
92
- const marks: CanvasMarks = {
93
- get startNodeId() {
94
- return (
95
- shown?.graph.nodes.find((node) => node.type === 'composition' && node.startsHere === true)
96
- ?.id ?? null
97
- );
98
- },
99
- problemCountOf: () => 0,
100
- hasEdgeProblem: () => false,
101
- isEdgeTaken: () => false,
102
- entryCountOf: (nodeId) => (shown ? (shown.counts.entered.get(nodeId) ?? 0) : null),
103
- followCountOf: (edgeId) => (shown ? (shown.counts.followed.get(edgeId) ?? 0) : null),
104
- failureCountOf: (nodeId) => shown?.counts.failed.get(nodeId) ?? 0
105
- };
106
-
107
- const context = $derived<CanvasContext | null>(words ? { marks, words, readOnly: true } : null);
108
-
109
93
  /** Reads the counts and the blocks they are about, for a range of days and a version. */
110
94
  async function load(days: number, selectedVersionId: string): Promise<void> {
111
95
  controller?.abort();
@@ -131,7 +115,7 @@
131
115
  const graph = version?.graph ?? editor.graph;
132
116
  await editor.ensureOptionsFor(graph);
133
117
  if (current.signal.aborted) return;
134
- shown = { key: `${version?.id ?? 'draft'}`, graph, counts: readRunCounts(stats) };
118
+ shown = { graph, counts: readRunCounts(stats) };
135
119
  loadState = 'ready';
136
120
  } catch (error) {
137
121
  if (isCancelled(error)) return;
@@ -200,52 +184,9 @@
200
184
  </Notice>
201
185
  {/if}
202
186
 
203
- <div class="relative min-h-80 flex-1" aria-busy={loadState === 'loading'}>
204
- {#if shown && context}
205
- {#key shown.key}
206
- <WorkflowCanvas
207
- initialGraph={shown.graph}
208
- readContext={() => context}
209
- readOnly={true}
210
- onReady={(handle) => (canvasHandle = handle)}
211
- />
212
- {/key}
213
- <div
214
- class="absolute start-3 top-3 z-20 flex items-center gap-1 rounded-large border border-grey2 bg-white p-1 shadow-sm"
215
- role="toolbar"
216
- aria-label={$t('workflows.toolbar.label')}
217
- >
218
- <ActionButton
219
- variant="ghost"
220
- size="small"
221
- iconOnly
222
- ariaLabel={$t('workflows.toolbar.zoomOut')}
223
- title={$t('workflows.toolbar.zoomOut')}
224
- onclick={() => canvasHandle?.zoomOut()}
225
- >
226
- <Icon name="zoomOut" />
227
- </ActionButton>
228
- <ActionButton
229
- variant="ghost"
230
- size="small"
231
- iconOnly
232
- ariaLabel={$t('workflows.toolbar.zoomIn')}
233
- title={$t('workflows.toolbar.zoomIn')}
234
- onclick={() => canvasHandle?.zoomIn()}
235
- >
236
- <Icon name="zoomIn" />
237
- </ActionButton>
238
- <ActionButton
239
- variant="ghost"
240
- size="small"
241
- iconOnly
242
- ariaLabel={$t('workflows.toolbar.fit')}
243
- title={$t('workflows.toolbar.fit')}
244
- onclick={() => canvasHandle?.fitView()}
245
- >
246
- <Icon name="fit" />
247
- </ActionButton>
248
- </div>
187
+ <div class="flex min-h-80 flex-1 flex-col" aria-busy={loadState === 'loading'}>
188
+ {#if shown && flowWords}
189
+ <RunsFlow graph={shown.graph} counts={shown.counts} words={flowWords} />
249
190
  {:else if loadState === 'loading'}
250
191
  <p class="py-10 text-center text-sm text-ink-muted" role="status">
251
192
  {$t('workflows.common.loading')}