@widgetic/workflows 0.2.0 → 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.
Files changed (36) hide show
  1. package/README.md +28 -5
  2. package/dist/api/types.d.ts +55 -1
  3. package/dist/api/workflowsApi.d.ts +47 -1
  4. package/dist/api/workflowsApi.js +179 -1
  5. package/dist/components/Workflows.svelte +2 -0
  6. package/dist/components/WorkflowsWorkspace.svelte +3 -0
  7. package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
  8. package/dist/components/editor/ConflictBanner.svelte +78 -0
  9. package/dist/components/editor/ConflictBanner.svelte.d.ts +3 -0
  10. package/dist/components/editor/EditorBanners.svelte +9 -11
  11. package/dist/components/editor/PresenceBanner.svelte +126 -0
  12. package/dist/components/editor/PresenceBanner.svelte.d.ts +3 -0
  13. package/dist/components/editor/SettingsTab.svelte +19 -11
  14. package/dist/components/editor/WorkflowEditor.svelte +14 -1
  15. package/dist/components/editor/WorkflowEditor.svelte.d.ts +2 -0
  16. package/dist/components/list/CreateWorkflowDialog.svelte +140 -14
  17. package/dist/components/list/WorkflowRow.svelte +8 -6
  18. package/dist/components/panel/VersionHistory.svelte +1 -1
  19. package/dist/editor/apiErrorText.js +10 -0
  20. package/dist/editor/deleteWords.d.ts +39 -0
  21. package/dist/editor/deleteWords.js +28 -0
  22. package/dist/editor/editLeaseController.d.ts +162 -0
  23. package/dist/editor/editLeaseController.js +459 -0
  24. package/dist/editor/editorState.svelte.d.ts +62 -5
  25. package/dist/editor/editorState.svelte.js +155 -6
  26. package/dist/editor/keepCopy.d.ts +41 -0
  27. package/dist/editor/keepCopy.js +52 -0
  28. package/dist/editor/listState.svelte.d.ts +39 -3
  29. package/dist/editor/listState.svelte.js +80 -1
  30. package/dist/editor/presetChoice.d.ts +26 -0
  31. package/dist/editor/presetChoice.js +32 -0
  32. package/dist/i18n/language.d.ts +3 -3
  33. package/dist/i18n/messages.d.ts +55 -2
  34. package/dist/i18n/messages.js +60 -3
  35. package/dist/types/index.d.ts +10 -0
  36. package/package.json +1 -1
@@ -0,0 +1,126 @@
1
+ <!--
2
+ What a person is told when a teammate is editing the workflow they opened, and what they can do about it.
3
+
4
+ - `blocked`: a choice is waiting. Take the editing over (the teammate's editing pauses, and what they saved stays), or
5
+ only look. It says who, in the person's own words: a named teammate, "you" in another window, or "someone". A person
6
+ whose own editing was taken is told so, which is not what a person who arrived to find it held is told.
7
+ - `readOnly`: the person chose to look. One line, with the way back: take over, or start editing once nobody is.
8
+ - anything else: nothing at all.
9
+
10
+ It shows what `editor.presence` says and reports the person's choices to the editor, which decides what they do (the
11
+ claim on editing, what is still allowed while it is held by another). Every word is in the catalog (`presence.*`).
12
+ -->
13
+ <script lang="ts">
14
+ import { useEditorState } from '../../editor/editorState.svelte.js';
15
+ import { useWorkflowsLanguage } from '../../i18n/language.js';
16
+ import ActionButton from '../ui/ActionButton.svelte';
17
+
18
+ const editor = useEditorState();
19
+ const { t } = useWorkflowsLanguage();
20
+
21
+ const presence = $derived(editor.presence);
22
+
23
+ // Who holds the editing, as the person is to read it: their own other window ("you"), a named teammate, or nobody named.
24
+ const holderIsYou = $derived(presence.holder?.isYou === true);
25
+ const holderName = $derived(presence.holder?.name ?? null);
26
+ </script>
27
+
28
+ {#if presence.phase === 'blocked'}
29
+ <!-- A choice is waiting: the screen only looks until the person makes it. -->
30
+ <div
31
+ role="alert"
32
+ data-workflows-presence="blocked"
33
+ class="flex flex-wrap items-start justify-between gap-x-4 gap-y-3 rounded-medium border border-grey2 bg-white px-3 py-2 text-start text-sm text-ink-primary"
34
+ >
35
+ <div class="flex min-w-0 flex-1 basis-60 flex-col gap-1">
36
+ <p class="font-medium break-words">
37
+ <!-- The heading: a claim that was this tab's and was taken says so; a tab that arrived to find it held does not. -->
38
+ {#if presence.lostIt}
39
+ {#if holderIsYou}
40
+ {$t('workflows.presence.lostTitleYou')}
41
+ {:else if holderName}
42
+ {$t('workflows.presence.lostTitleNamed', { name: holderName })}
43
+ {:else}
44
+ {$t('workflows.presence.lostTitle')}
45
+ {/if}
46
+ {:else if holderIsYou}
47
+ {$t('workflows.presence.blockedTitleYou')}
48
+ {:else if holderName}
49
+ {$t('workflows.presence.blockedTitleNamed', { name: holderName })}
50
+ {:else}
51
+ {$t('workflows.presence.blockedTitle')}
52
+ {/if}
53
+ </p>
54
+ <p class="text-xs text-ink-muted">
55
+ {presence.lostIt ? $t('workflows.presence.lostBody') : $t('workflows.presence.blockedBody')}
56
+ </p>
57
+ {#if presence.actionFailed}
58
+ <p class="text-xs text-error">{$t('workflows.presence.actionFailed')}</p>
59
+ {/if}
60
+ {#if presence.working}
61
+ <p class="text-xs text-ink-muted" role="status">{$t('workflows.presence.working')}</p>
62
+ {/if}
63
+ </div>
64
+ <div class="flex flex-wrap items-start gap-3">
65
+ <div class="flex max-w-48 flex-col items-start gap-1">
66
+ <ActionButton
67
+ variant="primary"
68
+ size="small"
69
+ disabled={presence.working}
70
+ onclick={() => editor.takeOverEditing()}
71
+ >
72
+ {$t('workflows.presence.takeOver')}
73
+ </ActionButton>
74
+ <span class="text-xs text-ink-muted">{$t('workflows.presence.takeOverHint')}</span>
75
+ </div>
76
+ <div class="flex max-w-48 flex-col items-start gap-1">
77
+ <ActionButton size="small" disabled={presence.working} onclick={() => editor.lookOnly()}>
78
+ {$t('workflows.presence.lookOnly')}
79
+ </ActionButton>
80
+ <span class="text-xs text-ink-muted">{$t('workflows.presence.lookOnlyHint')}</span>
81
+ </div>
82
+ </div>
83
+ </div>
84
+ {:else if presence.phase === 'readOnly'}
85
+ <div
86
+ role="status"
87
+ data-workflows-presence="readOnly"
88
+ class="flex flex-wrap items-center gap-x-3 gap-y-2 rounded-medium border border-grey2 bg-white px-3 py-2 text-start text-sm text-ink-primary"
89
+ >
90
+ <span class="min-w-0 flex-1 basis-60 break-words">
91
+ {#if presence.nobodyIsEditing}
92
+ {$t('workflows.presence.readOnlyFree')}
93
+ {:else if holderIsYou}
94
+ {$t('workflows.presence.readOnlyYou')}
95
+ {:else if holderName}
96
+ {$t('workflows.presence.readOnlyNamed', { name: holderName })}
97
+ {:else}
98
+ {$t('workflows.presence.readOnly')}
99
+ {/if}
100
+ </span>
101
+ {#if presence.actionFailed}
102
+ <span class="text-xs text-error">{$t('workflows.presence.actionFailed')}</span>
103
+ {/if}
104
+ {#if presence.working}
105
+ <span class="text-xs text-ink-muted">{$t('workflows.presence.working')}</span>
106
+ {/if}
107
+ {#if presence.nobodyIsEditing}
108
+ <ActionButton
109
+ variant="primary"
110
+ size="small"
111
+ disabled={presence.working}
112
+ onclick={() => editor.startEditing()}
113
+ >
114
+ {$t('workflows.presence.startEditing')}
115
+ </ActionButton>
116
+ {:else}
117
+ <ActionButton
118
+ size="small"
119
+ disabled={presence.working}
120
+ onclick={() => editor.takeOverEditing()}
121
+ >
122
+ {$t('workflows.presence.takeOver')}
123
+ </ActionButton>
124
+ {/if}
125
+ </div>
126
+ {/if}
@@ -0,0 +1,3 @@
1
+ declare const PresenceBanner: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type PresenceBanner = ReturnType<typeof PresenceBanner>;
3
+ export default PresenceBanner;
@@ -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');
@@ -88,7 +98,7 @@
88
98
  <ActionButton
89
99
  size="small"
90
100
  class="self-start"
91
- disabled={editor.busy !== null}
101
+ disabled={!editor.canChangeWorkflow}
92
102
  onclick={() => void editor.changeState(editor.status === 'paused' ? 'resume' : 'pause')}
93
103
  >
94
104
  {editor.status === 'paused'
@@ -108,7 +118,7 @@
108
118
  <ActionButton
109
119
  size="small"
110
120
  class="self-start"
111
- disabled={editor.busy !== null}
121
+ disabled={!editor.canChangeWorkflow}
112
122
  onclick={() => void editor.changeState('unarchive')}
113
123
  >
114
124
  {$t('workflows.settings.unarchive')}
@@ -118,7 +128,7 @@
118
128
  <ActionButton
119
129
  size="small"
120
130
  class="self-start"
121
- disabled={editor.busy !== null}
131
+ disabled={!editor.canChangeWorkflow}
122
132
  onclick={() => (asking = 'archive')}
123
133
  >
124
134
  {$t('workflows.settings.archive')}
@@ -145,15 +155,13 @@
145
155
  variant="danger"
146
156
  size="small"
147
157
  class="self-start"
148
- disabled={editor.busy !== null || !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'}
@@ -35,9 +35,18 @@
35
35
  onerror: (error: WorkflowsError) => void;
36
36
  /** Shows the embed code of the workflow; the page that hosts the screen decides what that looks like. */
37
37
  onshowembedcode?: (workflowId: string) => void;
38
+ /** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
39
+ presence?: boolean;
38
40
  }
39
41
 
40
- let { workflowId, onback, onopenworkflow, onerror, onshowembedcode }: Props = $props();
42
+ let {
43
+ workflowId,
44
+ onback,
45
+ onopenworkflow,
46
+ onerror,
47
+ onshowembedcode,
48
+ presence = false
49
+ }: Props = $props();
41
50
 
42
51
  const api = useWorkflowsApi();
43
52
  const { t } = useWorkflowsLanguage();
@@ -47,6 +56,8 @@
47
56
  const editor = new WorkflowEditorState({
48
57
  api,
49
58
  workflowId: untrack(() => workflowId),
59
+ // Read once, like the workflow: presence belongs to this opening of it.
60
+ presence: untrack(() => presence),
50
61
  reportError: (error) => onerror(error),
51
62
  leave: () => onback(),
52
63
  openWorkflow: (openedId) => onopenworkflow(openedId)
@@ -86,6 +97,8 @@
86
97
 
87
98
  onMount(() => {
88
99
  void editor.load();
100
+ // Who else is editing is asked alongside the load (it needs only the workflow's id); nothing happens without `presence`.
101
+ editor.startPresence();
89
102
 
90
103
  // A finger cannot draw a line between two small points: on a touch screen the canvas only shows (the panel edits).
91
104
  const touchQuery = window.matchMedia('(pointer: coarse)');
@@ -9,6 +9,8 @@ interface Props {
9
9
  onerror: (error: WorkflowsError) => void;
10
10
  /** Shows the embed code of the workflow; the page that hosts the screen decides what that looks like. */
11
11
  onshowembedcode?: (workflowId: string) => void;
12
+ /** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
13
+ presence?: boolean;
12
14
  }
13
15
  declare const WorkflowEditor: import("svelte").Component<Props, {}, "">;
14
16
  type WorkflowEditor = ReturnType<typeof WorkflowEditor>;
@@ -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}
@@ -50,7 +50,7 @@
50
50
  <ActionButton
51
51
  variant="primary"
52
52
  size="small"
53
- disabled={editor.busy !== null || editor.status === 'archived'}
53
+ disabled={!editor.canChangeWorkflow || editor.status === 'archived'}
54
54
  onclick={() => (isAskingToRestore = true)}
55
55
  >
56
56
  {$t('workflows.history.restore')}
@@ -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
+ };
@@ -0,0 +1,28 @@
1
+ /** The message of each case; an archived draft is told as a draft, because it has nothing but its draft. */
2
+ export const DELETE_MESSAGE_KEYS = {
3
+ draft: 'workflows.settings.deleteMessageDraft',
4
+ live: 'workflows.settings.deleteMessageLive',
5
+ paused: 'workflows.settings.deleteMessagePaused',
6
+ archived: 'workflows.settings.deleteMessageArchived'
7
+ };
8
+ /** Which of the four it is: how far the workflow got decides what goes with it. */
9
+ export function deleteCaseOf(workflow) {
10
+ // Never published: no versions, no counts, whatever state it was put in (a draft can be archived).
11
+ if (workflow.firstPublishedAt === null)
12
+ return 'draft';
13
+ if (workflow.status === 'live')
14
+ return 'live';
15
+ if (workflow.status === 'paused')
16
+ return 'paused';
17
+ return 'archived';
18
+ }
19
+ /** 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). */
20
+ export function deleteMessageOf(workflow) {
21
+ const runsCount = Number.isFinite(workflow.runsCount)
22
+ ? Math.max(0, Math.trunc(workflow.runsCount))
23
+ : 0;
24
+ return {
25
+ key: DELETE_MESSAGE_KEYS[deleteCaseOf(workflow)],
26
+ values: { name: workflow.name, count: runsCount }
27
+ };
28
+ }