@widgetic/workflows 0.2.1 → 0.2.2

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
@@ -17,6 +17,15 @@ Workflows are for **Teams and partner accounts** only. On Widgetic the page is
17
17
  went through, and when it was last published. Search by name, show or hide the archived ones, order by name, date
18
18
  created, last published or visitors, and make a workflow (`New workflow`), duplicate it or delete it. The page is told
19
19
  when one is opened (`onOpenWorkflow`) so the address can follow.
20
+ - **Start from a preset.** `New workflow` starts blank (a name, and optionally the composition visitors see first) or, when
21
+ the workspace is offered presets, from one of them. A preset is a published workflow that Widgetic (or, for a partner's
22
+ customer, the partner) offers as a place to start; its card shows the widgets it chains, how many blocks it has and a
23
+ line from the offerer. Choosing one gives the person their own copy of every widget it chains and a draft workflow wired
24
+ like the preset's live version, named as they like (after the preset when they leave it empty); nothing they change
25
+ reaches the preset. The dialog asks for the presets when it opens, so a workspace that is offered none sees the dialog as
26
+ it always was, and when they cannot be read it says so and the blank start keeps working. A start copies every widget,
27
+ so it is given longer than another request, and it is sent with an `Idempotency-Key`: asking again after a timeout does
28
+ not copy twice.
20
29
  - **The editor.** A canvas of blocks joined by lines. A **Composition** block shows a composition; a **Trigger** block
21
30
  waits for something a visitor does (a value they add to a widget, an action in the widget, an event on the page, or a
22
31
  time); a **Condition** block sends the visitor on by the first rule that matches. Blocks go forward only, a workflow
@@ -33,8 +42,10 @@ Workflows are for **Teams and partner accounts** only. On Widgetic the page is
33
42
  - **Runs.** The _Runs_ tab shows how many visitors went through each block and each line over a range of days (counts
34
43
  only: what a visitor typed is never stored).
35
44
  - **Settings.** The time zone that scheduled triggers are told in, the embed code, and the state of the workflow: pause
36
- or resume it, archive or restore it, duplicate it, or delete it (only a draft that was never published: a published
37
- workflow can only be archived, because pages may still use it). The name is edited in the bar above the canvas.
45
+ or resume it, archive or restore it, duplicate it, or delete it. A workflow can be deleted in any state, after one
46
+ confirmation that says what goes with it (its draft, and once it was published its versions and its counts; the
47
+ compositions it uses stay). Archiving is the way to take a workflow out of the list and keep it. The name is edited in
48
+ the bar above the canvas.
38
49
  - Speaks the page's language (`locale`, `messages`) and turns around for right to left (`dir`).
39
50
  - Takes its colours, font and corners from CSS custom properties, so a host or a ui-sdk theme restyles it.
40
51
  - Reports what goes wrong to the page (`onError`) and shows the visitor a "Try again" in place of a part that failed.
@@ -120,7 +131,8 @@ the screen needs, the screen scrolls inside it; it never spills over what the pa
120
131
  The `message` is English, for the page's developer. It is not a sentence to show a visitor: the screen shows its own.
121
132
 
122
133
  **What the screen asks of the API.** `GET/POST /v1/workspaces/{workspaceId}/workflows` and the routes under it (a
123
- workflow, its draft, publish, discard, versions, stats, composition options), always as the person: the token is
134
+ workflow, its draft, publish, discard, versions, stats, composition options, and the presets to start from: `GET …/workflows/presets`
135
+ and `POST …/workflows/from-preset`), always as the person: the token is
124
136
  the person's, and a call the person may not make is refused by the API. The screen holds no service key (a test fails the
125
137
  build if any code of the package that runs in a browser reads one). A change is sent with an `Idempotency-Key`, and a draft
126
138
  with the revision the editor was given, so a draft changed somewhere else is told, not overwritten: the person is offered
@@ -183,7 +195,7 @@ Every word a person reads is a message in a catalog of English sentences, `WORKF
183
195
  `workflows.<where>.<what>`. A page gives its own words with `messages`; what it leaves out stays English, so a language
184
196
  can be added a screen at a time.
185
197
 
186
- The catalog has 390 messages. They are grouped by the part of the screen that says them:
198
+ The catalog's messages are grouped by the part of the screen that says them:
187
199
 
188
200
  | Group | What it says |
189
201
  | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
@@ -59,7 +59,7 @@ export interface WorkflowDetail extends WorkflowListItem {
59
59
  graph: WorkflowGraph;
60
60
  /** The version visitors get, without its graph; null before the first publish. */
61
61
  liveVersion: WorkflowVersion | null;
62
- /** Whether this workflow was ever published (it can then be archived but not deleted). */
62
+ /** Whether this workflow was ever published (it then has versions and counts, which a delete takes with it). */
63
63
  everPublished: boolean;
64
64
  }
65
65
  export interface WorkflowList {
@@ -137,6 +137,27 @@ export interface CompositionOptionList {
137
137
  limit: number;
138
138
  offset: number;
139
139
  }
140
+ /** A widget a preset shows: what a card of the preset draws for it. */
141
+ export interface WorkflowPresetWidget {
142
+ name: string;
143
+ /** An http(s) address for an `<img>`, or `null` when the widget has no picture. */
144
+ thumbnailUrl: string | null;
145
+ }
146
+ /**
147
+ * A place to start a new workflow: a published workflow that Widgetic (or, for one of a partner's customers, the partner)
148
+ * offers. Starting from it gives the person their own copy of its widgets, a composition on each copy, and a draft workflow
149
+ * wired like it. It carries nothing about who made it and no id of its own: `key` is how a start names it.
150
+ */
151
+ export interface WorkflowPreset {
152
+ key: string;
153
+ title: string;
154
+ /** What the offerer wrote about it; `null` when they wrote nothing. */
155
+ description: string | null;
156
+ /** How many blocks it has (compositions, triggers and conditions). */
157
+ blockCount: number;
158
+ /** The widgets it shows, once each, in the order they first appear. */
159
+ widgets: WorkflowPresetWidget[];
160
+ }
140
161
  /** What the list asks for. Everything is optional: nothing asked is the first page, newest first, drafts, live and paused. */
141
162
  export interface WorkflowListQuery {
142
163
  search?: string;
@@ -1,8 +1,14 @@
1
1
  import type { IssueCode, ValidationIssue, WorkflowGraph } from '@widgetic/workflows-engine';
2
- import { type AccessTokenFunction, type CompositionOption, type CompositionOptionList, type CompositionOptionsQuery, type EditLeaseAnswer, type WorkflowDetail, type WorkflowList, type WorkflowListItem, type WorkflowListQuery, type WorkflowPublishResult, type WorkflowStateAction, type WorkflowStats, type WorkflowStatsQuery, type WorkflowVersion, type WorkflowVersionDetail } from './types.js';
2
+ import { type AccessTokenFunction, type CompositionOption, type CompositionOptionList, type CompositionOptionsQuery, type EditLeaseAnswer, type WorkflowDetail, type WorkflowList, type WorkflowListItem, type WorkflowListQuery, type WorkflowPreset, type WorkflowPublishResult, type WorkflowStateAction, type WorkflowStats, type WorkflowStatsQuery, type WorkflowVersion, type WorkflowVersionDetail } from './types.js';
3
3
  /** How long a request may take before it is given up: the reads, and the writes (a publish reads every composition). */
4
4
  export declare const READ_TIMEOUT_MS = 15000;
5
5
  export declare const WRITE_TIMEOUT_MS = 30000;
6
+ /**
7
+ * A start from a preset copies every widget the preset chains, one after the other, so it is given longer than another write:
8
+ * a request that is given up while the gateway is still copying is asked again with the same `Idempotency-Key`, which replays
9
+ * the answer instead of copying twice, but a person would rather wait the seconds it takes.
10
+ */
11
+ export declare const START_FROM_PRESET_TIMEOUT_MS = 90000;
6
12
  /** What went wrong with a request, as far as the screens care. */
7
13
  export declare class WorkflowsApiError extends Error {
8
14
  /** The HTTP status; null when no answer came (offline, blocked by the page's policy, too slow, a token that could not be had). */
@@ -48,6 +54,7 @@ export interface WorkflowsApiOptions {
48
54
  /** For tests. */
49
55
  readTimeoutMs?: number;
50
56
  writeTimeoutMs?: number;
57
+ startFromPresetTimeoutMs?: number;
51
58
  }
52
59
  export interface RequestOptions {
53
60
  signal?: AbortSignal;
@@ -93,6 +100,16 @@ export interface WorkflowsApi {
93
100
  changeState(workflowId: string, action: WorkflowStateAction, options?: RequestOptions): Promise<WorkflowListItem>;
94
101
  getStats(workflowId: string, query?: WorkflowStatsQuery, options?: RequestOptions): Promise<WorkflowStats>;
95
102
  listCompositionOptions(query?: CompositionOptionsQuery, options?: RequestOptions): Promise<CompositionOptionList>;
103
+ /** The presets this workspace can start a workflow from, in the order their offerer set (an empty list when none is offered). */
104
+ listPresets(options?: RequestOptions): Promise<WorkflowPreset[]>;
105
+ /**
106
+ * Makes a workflow of the person's own from a preset: a copy of every widget it chains, a composition on each, and a draft
107
+ * wired like the preset. `name` is left out (or empty) to name it after the preset. It answers the new workflow, a draft.
108
+ */
109
+ startFromPreset(input: {
110
+ key: string;
111
+ name?: string | null;
112
+ }, options?: RetryableRequestOptions): Promise<WorkflowDetail>;
96
113
  /**
97
114
  * "This tab is editing this workflow", and the renewal of that claim. Presence, never a lock: it says who else is
98
115
  * editing and never refuses a save. An answer that cannot be read is `unavailable`.
@@ -119,6 +136,11 @@ export declare function usableImageUrl(value: unknown): string | null;
119
136
  * capability model is the API's, and an answer that left a part out is treated as "this composition cannot do that".
120
137
  */
121
138
  export declare function readCompositionOption(data: unknown): CompositionOption;
139
+ /**
140
+ * One preset a workflow can be started from. The key and the title are what a card and a start cannot do without; the
141
+ * description may be missing (a preset its offerer wrote nothing about), and a count that is not a number is refused.
142
+ */
143
+ export declare function readWorkflowPreset(data: unknown): WorkflowPreset;
122
144
  /**
123
145
  * What the API answered about an edit claim, checked. An answer the screen cannot read is `unavailable`: presence is a
124
146
  * convenience, so the editor goes on as if it were not there rather than failing.
@@ -5,9 +5,11 @@
5
5
  *
6
6
  * GET /workspaces/{workspaceId}/workflows the list
7
7
  * POST /workspaces/{workspaceId}/workflows a new workflow (Idempotency-Key)
8
+ * GET /workspaces/{workspaceId}/workflows/presets the presets a workflow can be started from
9
+ * POST /workspaces/{workspaceId}/workflows/from-preset a draft workflow of one's own from a preset (Idempotency-Key)
8
10
  * GET /workspaces/{workspaceId}/workflows/{id} one workflow with its draft
9
11
  * PUT /workspaces/{workspaceId}/workflows/{id} save the draft (the revision it started from)
10
- * DELETE /workspaces/{workspaceId}/workflows/{id} delete one that was never published
12
+ * DELETE /workspaces/{workspaceId}/workflows/{id} delete one, in any state, with its versions and counts
11
13
  * POST /workspaces/{workspaceId}/workflows/{id}/duplicate a copy (Idempotency-Key)
12
14
  * POST /workspaces/{workspaceId}/workflows/{id}/publish the draft becomes the next version (Idempotency-Key)
13
15
  * POST /workspaces/{workspaceId}/workflows/{id}/discard the draft goes back to what is live
@@ -35,6 +37,12 @@ import { WORKFLOW_STATUSES } from './types.js';
35
37
  /** How long a request may take before it is given up: the reads, and the writes (a publish reads every composition). */
36
38
  export const READ_TIMEOUT_MS = 15_000;
37
39
  export const WRITE_TIMEOUT_MS = 30_000;
40
+ /**
41
+ * A start from a preset copies every widget the preset chains, one after the other, so it is given longer than another write:
42
+ * a request that is given up while the gateway is still copying is asked again with the same `Idempotency-Key`, which replays
43
+ * the answer instead of copying twice, but a person would rather wait the seconds it takes.
44
+ */
45
+ export const START_FROM_PRESET_TIMEOUT_MS = 90_000;
38
46
  /** What went wrong with a request, as far as the screens care. */
39
47
  export class WorkflowsApiError extends Error {
40
48
  /** The HTTP status; null when no answer came (offline, blocked by the page's policy, too slow, a token that could not be had). */
@@ -378,6 +386,50 @@ function readCompositionOptionList(data) {
378
386
  offset: readWholeNumber(data, 'offset', 'the compositions')
379
387
  };
380
388
  }
389
+ /** A widget a preset shows. A name that is not text is not a widget a card can say anything about, so the answer is refused. */
390
+ function readPresetWidget(data) {
391
+ if (!isRecord(data))
392
+ throw invalidResponse('a widget of a preset');
393
+ return {
394
+ name: readText(data, 'name', 'a widget of a preset'),
395
+ thumbnailUrl: usableImageUrl(data.thumbnailUrl)
396
+ };
397
+ }
398
+ /**
399
+ * One preset a workflow can be started from. The key and the title are what a card and a start cannot do without; the
400
+ * description may be missing (a preset its offerer wrote nothing about), and a count that is not a number is refused.
401
+ */
402
+ export function readWorkflowPreset(data) {
403
+ if (!isRecord(data))
404
+ throw invalidResponse('a preset');
405
+ const presetKey = readRequiredText(data, 'key', 'a preset');
406
+ const heading = readRequiredText(data, 'title', 'a preset');
407
+ if (data.widgets !== undefined && !Array.isArray(data.widgets))
408
+ throw invalidResponse('a preset (widgets)');
409
+ return {
410
+ key: presetKey,
411
+ title: heading,
412
+ description: readPresetDescription(data),
413
+ blockCount: readWholeNumber(data, 'blockCount', 'a preset'),
414
+ widgets: (data.widgets ?? []).map(readPresetWidget)
415
+ };
416
+ }
417
+ /** A text the answer cannot do without: it has to be text, and more than spaces. */
418
+ function readRequiredText(source, key, what) {
419
+ const value = readText(source, key, what);
420
+ if (value.trim() === '')
421
+ throw invalidResponse(`${what} (${key})`);
422
+ return value;
423
+ }
424
+ /** What the offerer wrote about a preset: none when they wrote nothing, or only spaces. */
425
+ function readPresetDescription(data) {
426
+ return nonEmptyText(readNullableText(data, 'description', 'a preset'));
427
+ }
428
+ function readWorkflowPresetList(data) {
429
+ if (!isRecord(data) || !Array.isArray(data.items))
430
+ throw invalidResponse('the presets');
431
+ return data.items.map(readWorkflowPreset);
432
+ }
381
433
  /** What the API accepts as the id of an editor tab (an edit claim's `sessionId`). */
382
434
  const EDIT_LEASE_SESSION_ID_PATTERN = /^[A-Za-z0-9_-]{8,64}$/;
383
435
  /** True for a number of seconds worth believing: a positive, finite number. */
@@ -510,6 +562,7 @@ export function createWorkflowsApi(options) {
510
562
  const workspaceBase = `/workspaces/${encodeURIComponent(options.workspaceId)}/workflows`;
511
563
  const readTimeoutMs = options.readTimeoutMs ?? READ_TIMEOUT_MS;
512
564
  const writeTimeoutMs = options.writeTimeoutMs ?? WRITE_TIMEOUT_MS;
565
+ const startFromPresetTimeoutMs = options.startFromPresetTimeoutMs ?? START_FROM_PRESET_TIMEOUT_MS;
513
566
  const sendRequest = options.fetchImplementation ?? ((...parameters) => globalThis.fetch(...parameters));
514
567
  async function tokenFor(reason, refusedToken) {
515
568
  try {
@@ -726,6 +779,25 @@ export function createWorkflowsApi(options) {
726
779
  timeoutMs: readTimeoutMs
727
780
  }));
728
781
  },
782
+ async listPresets(requestOptions = {}) {
783
+ return readWorkflowPresetList(await request('GET', `${workspaceBase}/presets`, {
784
+ signal: requestOptions.signal,
785
+ timeoutMs: readTimeoutMs
786
+ }));
787
+ },
788
+ async startFromPreset(input, requestOptions = {}) {
789
+ const body = { key: input.key };
790
+ // A name that is only spaces is no name: the preset's title is used, as when none is given.
791
+ const name = input.name?.trim();
792
+ if (name)
793
+ body.name = name;
794
+ return readWorkflowDetail(await request('POST', `${workspaceBase}/from-preset`, {
795
+ body,
796
+ idempotencyKey: requestOptions.idempotencyKey ?? makeIdempotencyKey(),
797
+ signal: requestOptions.signal,
798
+ timeoutMs: startFromPresetTimeoutMs
799
+ }));
800
+ },
729
801
  // The edit claim calls wait no longer than a read does: a claim is renewed every few seconds, and a renewal that
730
802
  // takes longer than that has told what it will tell.
731
803
  async acquireEditLease(workflowId, sessionId, requestOptions = {}) {
@@ -3,10 +3,12 @@
3
3
  can be done with the workflow as a whole: pause it, archive it, copy it, delete it.
4
4
 
5
5
  Pausing is for a while: an embed of a paused workflow shows only its first composition, as a plain embed would. Archiving is
6
- for good, but not lost (it can be brought back). A workflow that was ever published cannot be deleted, because pages out there
7
- may still carry its id; it can be archived instead, and the page says so.
6
+ for good, but not lost (it can be brought back). Deleting is for good and is lost: a workflow can be deleted in any state,
7
+ after one confirmation that says what goes with it (its draft, its versions and its counts; the compositions stay), and a
8
+ page whose embed still names it shows the embed's first composition.
8
9
  -->
9
10
  <script lang="ts">
11
+ import { deleteMessageOf } from '../../editor/deleteWords.js';
10
12
  import { useEditorState } from '../../editor/editorState.svelte.js';
11
13
  import { listTimeZones } from '../../editor/zonedTime.js';
12
14
  import { useWorkflowsLanguage } from '../../i18n/language.js';
@@ -37,7 +39,15 @@
37
39
  });
38
40
 
39
41
  const isLiveOrPaused = $derived(editor.status === 'live' || editor.status === 'paused');
40
- const canDelete = $derived(!(editor.workflow?.everPublished ?? false));
42
+ /** What the confirmation of a delete says goes with this workflow, by how far it got. */
43
+ const deleteMessage = $derived(
44
+ deleteMessageOf({
45
+ name: editor.name,
46
+ status: editor.status,
47
+ firstPublishedAt: editor.workflow?.firstPublishedAt ?? null,
48
+ runsCount: editor.workflow?.runsCount ?? 0
49
+ })
50
+ );
41
51
 
42
52
  async function confirmArchive(): Promise<void> {
43
53
  await editor.changeState('archive');
@@ -145,15 +155,13 @@
145
155
  variant="danger"
146
156
  size="small"
147
157
  class="self-start"
148
- disabled={!editor.canChangeWorkflow || !canDelete}
158
+ disabled={!editor.canChangeWorkflow}
149
159
  onclick={() => (asking = 'delete')}
150
160
  >
151
161
  <Icon name="trash" />
152
162
  {$t('workflows.settings.delete')}
153
163
  </ActionButton>
154
- <p class="text-xs text-ink-muted">
155
- {canDelete ? $t('workflows.settings.deleteHelp') : $t('workflows.settings.deleteBlocked')}
156
- </p>
164
+ <p class="text-xs text-ink-muted">{$t('workflows.settings.deleteHelp')}</p>
157
165
  </div>
158
166
  </section>
159
167
  </div>
@@ -170,7 +178,7 @@
170
178
  {:else if asking === 'delete'}
171
179
  <ConfirmDialog
172
180
  title={$t('workflows.settings.deleteTitle')}
173
- message={$t('workflows.settings.deleteMessage', { name: editor.name })}
181
+ message={$t(deleteMessage.key, deleteMessage.values)}
174
182
  confirmLabel={$t('workflows.settings.delete')}
175
183
  tone="danger"
176
184
  busy={editor.busy === 'deleting'}
@@ -1,16 +1,27 @@
1
1
  <!--
2
- "New workflow": a name, and the composition visitors see first (optional: it can be chosen in the editor). Making it opens
3
- the editor straight away, with the composition already on the canvas as the start.
2
+ "New workflow": a name, and where to start from. Making it opens the editor straight away.
4
3
 
5
- The name is the only thing required, so the dialog never asks for what it could do without.
4
+ Where to start from is one of two things:
5
+ - a blank workflow: the composition visitors see first is chosen here (optional: it can be chosen in the editor), and it is
6
+ put on the canvas as the start;
7
+ - a preset: a workflow that Widgetic (or the partner whose customer this is) offers. It gives the person their own copy of
8
+ the widgets it chains and a draft workflow wired like it, so the composition is not chosen here and the name may be left
9
+ empty (the workflow is named after the preset).
10
+
11
+ The presets are asked for when the dialog opens. A workspace that is offered none (most are) sees the dialog as it always
12
+ was: the choices appear only when there is a preset to choose, and when they cannot be read the dialog says so and the blank
13
+ start keeps working. The name is the only thing a blank start requires, so the dialog never asks for what it could do without.
6
14
  -->
7
15
  <script lang="ts">
16
+ import { onMount } from 'svelte';
8
17
  import { MAX_WORKFLOW_NAME_LENGTH } from '../../api/types.js';
9
18
  import type { CompositionOption, WorkflowDetail } from '../../api/types.js';
10
19
  import { useListState } from '../../editor/listState.svelte.js';
20
+ import { canStartNow, chosenPresetOf, picturesOf } from '../../editor/presetChoice.js';
11
21
  import { useWorkflowsLanguage } from '../../i18n/language.js';
12
22
  import CompositionPicker from '../panel/CompositionPicker.svelte';
13
23
  import ActionButton from '../ui/ActionButton.svelte';
24
+ import Icon from '../ui/Icon.svelte';
14
25
  import Modal from '../ui/Modal.svelte';
15
26
  import Notice from '../ui/Notice.svelte';
16
27
  import TextField from '../ui/TextField.svelte';
@@ -25,18 +36,23 @@
25
36
 
26
37
  const list = useListState();
27
38
  const { t } = useWorkflowsLanguage();
39
+ const groupId = $props.id();
28
40
 
29
41
  let name = $state('');
30
42
  let chosen = $state.raw<CompositionOption | null>(null);
31
43
  let isCreating = $state(false);
32
44
 
33
- const canCreate = $derived(name.trim() !== '' && !isCreating);
45
+ /** The preset that is chosen and still on offer; `null` is a blank start (also when the one chosen went from the list). */
46
+ const chosenPreset = $derived(chosenPresetOf(list.presets, list.chosenPresetKey));
47
+ const canCreate = $derived(canStartNow({ preset: chosenPreset, name, isBusy: isCreating }));
34
48
 
35
49
  async function create(): Promise<void> {
36
50
  if (!canCreate) return;
37
51
  isCreating = true;
38
52
  try {
39
- const created = await list.create({ name: name.trim(), composition: chosen });
53
+ const created = chosenPreset
54
+ ? await list.startFromPreset({ key: chosenPreset.key, name })
55
+ : await list.create({ name: name.trim(), composition: chosen });
40
56
  if (created) oncreated(created);
41
57
  } finally {
42
58
  isCreating = false;
@@ -54,26 +70,136 @@
54
70
  void create();
55
71
  }
56
72
  }
73
+
74
+ onMount(() => {
75
+ // Every opening starts blank, whatever the last one chose.
76
+ list.chosenPresetKey = null;
77
+ void list.loadPresets();
78
+ });
57
79
  </script>
58
80
 
59
81
  <Modal title={$t('workflows.create.title')} size="medium" busy={isCreating} onclose={oncancel}>
60
82
  <!-- svelte-ignore a11y_no_static_element_interactions -->
61
83
  <div class="flex flex-col gap-4" onkeydown={handleKeydown}>
84
+ {#if list.presets.length > 0}
85
+ <fieldset class="flex min-w-0 flex-col gap-2" disabled={isCreating}>
86
+ <legend class="mb-2 text-xs font-medium">{$t('workflows.create.startLabel')}</legend>
87
+ <div class="flex max-h-64 flex-col gap-1 overflow-auto">
88
+ <label class="flex">
89
+ <input
90
+ type="radio"
91
+ name="{groupId}-start"
92
+ class="peer sr-only"
93
+ checked={chosenPreset === null}
94
+ onchange={() => (list.chosenPresetKey = null)}
95
+ />
96
+ <span
97
+ class="flex w-full items-center gap-3 rounded-medium border border-grey2 px-3 py-2 text-start text-sm hover:border-ink-subtle peer-checked:border-primary-green peer-focus-visible:outline-2 peer-focus-visible:outline-offset-1 peer-focus-visible:outline-primary-green"
98
+ >
99
+ <span
100
+ class="flex h-8 w-11 shrink-0 items-center justify-center rounded-small border border-grey2 text-ink-muted"
101
+ >
102
+ <Icon name="plus" />
103
+ </span>
104
+ <span class="flex min-w-0 flex-1 flex-col">
105
+ <span class="truncate font-medium">{$t('workflows.create.blankTitle')}</span>
106
+ <span class="text-xs text-ink-muted">{$t('workflows.create.blankHint')}</span>
107
+ </span>
108
+ </span>
109
+ </label>
110
+ {#each list.presets as preset (preset.key)}
111
+ {@const pictures = picturesOf(preset)}
112
+ <label class="flex">
113
+ <input
114
+ type="radio"
115
+ name="{groupId}-start"
116
+ class="peer sr-only"
117
+ checked={chosenPreset?.key === preset.key}
118
+ onchange={() => (list.chosenPresetKey = preset.key)}
119
+ />
120
+ <span
121
+ class="flex w-full items-start gap-3 rounded-medium border border-grey2 px-3 py-2 text-start text-sm hover:border-ink-subtle peer-checked:border-primary-green peer-focus-visible:outline-2 peer-focus-visible:outline-offset-1 peer-focus-visible:outline-primary-green"
122
+ >
123
+ <span class="flex shrink-0 items-center gap-1 pt-0.5">
124
+ {#each pictures.shown as widget, index (index)}
125
+ {#if widget.thumbnailUrl}
126
+ <img
127
+ src={widget.thumbnailUrl}
128
+ alt=""
129
+ loading="lazy"
130
+ draggable="false"
131
+ class="h-8 w-11 rounded-small border border-grey2 object-cover"
132
+ />
133
+ {:else}
134
+ <span
135
+ class="flex h-8 w-11 items-center justify-center rounded-small border border-grey2 text-ink-muted"
136
+ >
137
+ <Icon name="composition" />
138
+ </span>
139
+ {/if}
140
+ {/each}
141
+ {#if pictures.hiddenCount > 0}
142
+ <span class="text-xs text-ink-muted"
143
+ >{$t('workflows.create.presetMorePictures', {
144
+ count: pictures.hiddenCount
145
+ })}</span
146
+ >
147
+ {/if}
148
+ </span>
149
+ <span class="flex min-w-0 flex-1 flex-col">
150
+ <span class="truncate font-medium" dir="auto">{preset.title}</span>
151
+ {#if preset.description}
152
+ <span class="line-clamp-2 text-xs text-ink-muted" dir="auto"
153
+ >{preset.description}</span
154
+ >
155
+ {/if}
156
+ <span class="text-xs text-ink-muted"
157
+ >{$t('workflows.create.presetSummary', {
158
+ blocks: preset.blockCount,
159
+ widgets: preset.widgets.length
160
+ })}</span
161
+ >
162
+ </span>
163
+ </span>
164
+ </label>
165
+ {/each}
166
+ </div>
167
+ </fieldset>
168
+ {:else if list.presetsState === 'loading'}
169
+ <p class="text-xs text-ink-muted" role="status">{$t('workflows.create.presetsLoading')}</p>
170
+ {:else if list.presetsState === 'failed'}
171
+ <div class="flex flex-wrap items-center gap-2">
172
+ <p class="text-xs text-ink-muted" role="status">{$t('workflows.create.presetsFailed')}</p>
173
+ <ActionButton size="small" onclick={() => void list.loadPresets()}
174
+ >{$t('workflows.error.retry')}</ActionButton
175
+ >
176
+ </div>
177
+ {/if}
178
+
62
179
  <TextField
63
180
  label={$t('workflows.create.nameLabel')}
64
- placeholder={$t('workflows.create.namePlaceholder')}
181
+ placeholder={chosenPreset ? chosenPreset.title : $t('workflows.create.namePlaceholder')}
182
+ help={chosenPreset ? $t('workflows.create.presetNameHelp') : undefined}
65
183
  maxlength={MAX_WORKFLOW_NAME_LENGTH}
66
184
  autofocus
67
185
  bind:value={name}
68
186
  />
69
- <div class="flex flex-col gap-2">
70
- <p class="text-xs font-medium">{$t('workflows.create.compositionLabel')}</p>
71
- <p class="text-xs text-ink-muted">{$t('workflows.create.compositionHelp')}</p>
72
- <CompositionPicker
73
- selectedId={chosen?.id ?? null}
74
- onpick={(option) => (chosen = chosen?.id === option.id ? null : option)}
75
- />
76
- </div>
187
+
188
+ {#if chosenPreset}
189
+ <p class="text-xs text-ink-muted">{$t('workflows.create.presetHelp')}</p>
190
+ {#if isCreating}
191
+ <p class="text-xs text-ink-muted" role="status">{$t('workflows.create.settingUp')}</p>
192
+ {/if}
193
+ {:else}
194
+ <div class="flex flex-col gap-2">
195
+ <p class="text-xs font-medium">{$t('workflows.create.compositionLabel')}</p>
196
+ <p class="text-xs text-ink-muted">{$t('workflows.create.compositionHelp')}</p>
197
+ <CompositionPicker
198
+ selectedId={chosen?.id ?? null}
199
+ onpick={(option) => (chosen = chosen?.id === option.id ? null : option)}
200
+ />
201
+ </div>
202
+ {/if}
77
203
  {#if list.createFailure}
78
204
  <Notice tone="problem">{$t(list.createFailure)}</Notice>
79
205
  {/if}
@@ -2,13 +2,15 @@
2
2
  One workflow in the list: its name (which opens it), where it stands, how many compositions it uses, how many visitors
3
3
  started it, when it was last published and made, and a menu of what can be done to it from here.
4
4
 
5
- What the menu offers follows the workflow: a live one can be paused, a published one can be archived (never deleted: pages
6
- out there may carry its id), an archived one can be brought back, and any can be copied. The two that cannot be taken back
7
- ask first.
5
+ What the menu offers follows the workflow: a live one can be paused, a published one can be archived, an archived one can be
6
+ brought back, and any can be copied or deleted, in whatever state it is in. Archiving and deleting ask first, and deleting
7
+ says what goes with the workflow (its draft, its versions and its counts, and that the compositions stay): it cannot be
8
+ taken back.
8
9
  -->
9
10
  <script lang="ts">
10
11
  import type { WorkflowListItem } from '../../api/types.js';
11
12
  import { formatDay } from '../../editor/blockLabels.js';
13
+ import { deleteMessageOf } from '../../editor/deleteWords.js';
12
14
  import { formatCount } from '../../editor/formatCount.js';
13
15
  import { useListState } from '../../editor/listState.svelte.js';
14
16
  import { useWorkflowsLanguage } from '../../i18n/language.js';
@@ -33,6 +35,8 @@
33
35
 
34
36
  const isBusy = $derived(list.busyIds.has(item.id));
35
37
  const wasPublished = $derived(item.firstPublishedAt !== null);
38
+ /** What the confirmation of a delete says goes with this workflow, by how far it got. */
39
+ const deleteMessage = $derived(deleteMessageOf(item));
36
40
 
37
41
  const groups = $derived.by<MenuGroup[]>(() => {
38
42
  const states: MenuGroup['items'][number][] = [];
@@ -101,10 +105,8 @@
101
105
  {
102
106
  key: 'delete',
103
107
  label: $t('workflows.settings.delete'),
104
- description: wasPublished ? $t('workflows.settings.deleteBlocked') : undefined,
105
108
  icon: 'trash',
106
109
  tone: 'danger',
107
- disabled: wasPublished,
108
110
  onSelect: () => (asking = 'delete')
109
111
  }
110
112
  ]
@@ -181,7 +183,7 @@
181
183
  {:else if asking === 'delete'}
182
184
  <ConfirmDialog
183
185
  title={$t('workflows.settings.deleteTitle')}
184
- message={$t('workflows.settings.deleteMessage', { name: item.name })}
186
+ message={$t(deleteMessage.key, deleteMessage.values)}
185
187
  confirmLabel={$t('workflows.settings.delete')}
186
188
  tone="danger"
187
189
  busy={isBusy}
@@ -16,10 +16,16 @@ export function pickApiErrorMessage(error) {
16
16
  return 'workflows.error.sessionEnded';
17
17
  if (error.planRestricted)
18
18
  return 'workflows.error.planRestricted';
19
+ // A preset that is not offered any more (or can no longer be started) is not "this workflow", which is what a 404 says.
20
+ if (error.notFound && error.code === 'RESOURCE_WORKFLOW_PRESET_NOT_FOUND')
21
+ return 'workflows.error.presetGone';
19
22
  if (error.notFound)
20
23
  return 'workflows.error.notFound';
21
24
  if (error.revisionChanged)
22
25
  return 'workflows.error.revisionChanged';
26
+ // The same request was asked again while the first was still running (a start from a preset asks again with its own key).
27
+ if (error.status === 409 && error.code === 'CONFLICT_IDEMPOTENCY_IN_PROGRESS')
28
+ return 'workflows.error.stillWorking';
23
29
  switch (error.conflictReason) {
24
30
  case 'workflow_archived':
25
31
  return 'workflows.error.archived';
@@ -27,6 +33,7 @@ export function pickApiErrorMessage(error) {
27
33
  return 'workflows.error.nothingToPublish';
28
34
  case 'nothing_to_discard':
29
35
  return 'workflows.error.nothingToDiscard';
36
+ // Only a gateway from before a published workflow could be deleted still says this to a delete.
30
37
  case 'ever_published':
31
38
  return 'workflows.error.everPublished';
32
39
  case 'wrong_state':
@@ -37,6 +44,9 @@ export function pickApiErrorMessage(error) {
37
44
  const reason = error.details?.reason;
38
45
  if (error.status === 422 && reason === 'too_many_workflows')
39
46
  return 'workflows.error.tooManyWorkflows';
47
+ // The copy of a preset's widgets failed on the server's side; the compositions it made were taken back, so trying again is safe.
48
+ if (error.status === 503 && reason === 'preset_copy_failed')
49
+ return 'workflows.error.presetCopyFailed';
40
50
  if (error.status === 422)
41
51
  return 'workflows.error.publishBlocked';
42
52
  if (error.status === 400)
@@ -0,0 +1,39 @@
1
+ /**
2
+ * What the confirmation of a delete says. A workflow can be deleted in any state, and what goes with it depends on how far
3
+ * it got: a workflow that was never published has only its draft; one that was published also has versions and counts; and
4
+ * a live one is being followed by visitors this very moment, so its embeds change from then on. The confirmation says
5
+ * which, once, for the row of the list and for the settings of the open workflow, so the two never tell it differently.
6
+ *
7
+ * The compositions a workflow chains are never part of it: they are the person's own and stay as they are, and every
8
+ * message says so.
9
+ */
10
+ import type { WorkflowStatus } from '../api/types.js';
11
+ import type { WorkflowsMessageKey } from '../i18n/messages.js';
12
+ /** The four things a delete can be about. */
13
+ export type DeleteCase = 'draft' | 'live' | 'paused' | 'archived';
14
+ /** The message of each case; an archived draft is told as a draft, because it has nothing but its draft. */
15
+ export declare const DELETE_MESSAGE_KEYS: {
16
+ readonly draft: "workflows.settings.deleteMessageDraft";
17
+ readonly live: "workflows.settings.deleteMessageLive";
18
+ readonly paused: "workflows.settings.deleteMessagePaused";
19
+ readonly archived: "workflows.settings.deleteMessageArchived";
20
+ };
21
+ /** What the confirmation needs of a workflow: both a row of the list and the open workflow have it. */
22
+ export interface DeletableWorkflow {
23
+ name: string;
24
+ status: WorkflowStatus;
25
+ /** Null for a workflow that was never published. */
26
+ firstPublishedAt: string | null;
27
+ /** Visitors who started it, over its whole life. */
28
+ runsCount: number;
29
+ }
30
+ /** Which of the four it is: how far the workflow got decides what goes with it. */
31
+ export declare function deleteCaseOf(workflow: Pick<DeletableWorkflow, 'status' | 'firstPublishedAt'>): DeleteCase;
32
+ /** The message to show and the values it is told with (a message that has no use for a value simply does not name it). */
33
+ export declare function deleteMessageOf(workflow: DeletableWorkflow): {
34
+ key: WorkflowsMessageKey;
35
+ values: {
36
+ name: string;
37
+ count: number;
38
+ };
39
+ };