@widgetic/workflows 0.2.1 → 0.2.3
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 +40 -19
- package/dist/api/types.d.ts +41 -1
- package/dist/api/workflowsApi.d.ts +41 -1
- package/dist/api/workflowsApi.js +151 -1
- package/dist/components/WorkflowsWorkspace.svelte +6 -1
- package/dist/components/editor/SettingsTab.svelte +16 -8
- package/dist/components/list/CreateWorkflowDialog.svelte +140 -14
- package/dist/components/list/WorkflowList.svelte +18 -3
- package/dist/components/list/WorkflowList.svelte.d.ts +5 -0
- package/dist/components/list/WorkflowRow.svelte +28 -6
- package/dist/editor/apiErrorText.js +10 -0
- package/dist/editor/deleteWords.d.ts +39 -0
- package/dist/editor/deleteWords.js +28 -0
- package/dist/editor/editingWatcher.d.ts +90 -0
- package/dist/editor/editingWatcher.js +267 -0
- package/dist/editor/editorState.svelte.d.ts +2 -2
- package/dist/editor/listState.svelte.d.ts +62 -3
- package/dist/editor/listState.svelte.js +118 -1
- package/dist/editor/presetChoice.d.ts +26 -0
- package/dist/editor/presetChoice.js +32 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +26 -2
- package/dist/i18n/messages.js +29 -3
- package/dist/types/index.d.ts +5 -1
- package/package.json +1 -1
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
"New workflow": a name, and
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
<p class="text-xs text-ink-muted">{$t('workflows.create.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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}
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
The list can be longer than a page, so every change of the search, the filter or the order asks the API again; "Show more"
|
|
6
6
|
adds the next page. A page of nothing says why: nothing made yet (and offers to make one), or nothing matches what was asked.
|
|
7
|
+
|
|
8
|
+
With `presence` on, a row also says when a teammate is editing that workflow ("Anna is editing"). It is advice: the row
|
|
9
|
+
can still be opened, and the editor itself asks the person whether to take over or only look.
|
|
7
10
|
-->
|
|
8
11
|
<script lang="ts">
|
|
9
|
-
import { onDestroy, onMount } from 'svelte';
|
|
12
|
+
import { onDestroy, onMount, untrack } from 'svelte';
|
|
10
13
|
import type { WorkflowDetail } from '../../api/types.js';
|
|
11
14
|
import { WORKFLOW_STATUSES } from '../../api/types.js';
|
|
12
15
|
import type { WorkflowSortField } from '../../api/types.js';
|
|
@@ -34,14 +37,24 @@
|
|
|
34
37
|
onerror: (error: WorkflowsError) => void;
|
|
35
38
|
/** Shows the embed code of a workflow; the page that hosts the screen decides what that looks like. */
|
|
36
39
|
onshowembedcode?: (workflowId: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the page asked for presence: a row then says which teammate is editing that workflow ("Anna is editing").
|
|
42
|
+
* Off unless it asks, here too: a list that was not told about it never says anything about others. Read once.
|
|
43
|
+
*/
|
|
44
|
+
presence?: boolean;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
let { onopen, onerror, onshowembedcode }: Props = $props();
|
|
47
|
+
let { onopen, onerror, onshowembedcode, presence = false }: Props = $props();
|
|
40
48
|
|
|
41
49
|
const api = useWorkflowsApi();
|
|
42
50
|
const { t } = useWorkflowsLanguage();
|
|
43
51
|
|
|
44
|
-
const list = new WorkflowListState({
|
|
52
|
+
const list = new WorkflowListState({
|
|
53
|
+
api,
|
|
54
|
+
reportError: (error) => onerror(error),
|
|
55
|
+
// Read once, like the list: presence belongs to this opening of it.
|
|
56
|
+
presence: untrack(() => presence)
|
|
57
|
+
});
|
|
45
58
|
provideListState(list);
|
|
46
59
|
|
|
47
60
|
let isCreating = $state(false);
|
|
@@ -84,6 +97,8 @@
|
|
|
84
97
|
|
|
85
98
|
onMount(() => {
|
|
86
99
|
void list.load();
|
|
100
|
+
// Who is editing what is asked alongside the load (it looks again once the rows are there); nothing happens without `presence`.
|
|
101
|
+
list.startPresence();
|
|
87
102
|
});
|
|
88
103
|
|
|
89
104
|
onDestroy(() => list.dispose());
|
|
@@ -6,6 +6,11 @@ interface Props {
|
|
|
6
6
|
onerror: (error: WorkflowsError) => void;
|
|
7
7
|
/** Shows the embed code of a workflow; the page that hosts the screen decides what that looks like. */
|
|
8
8
|
onshowembedcode?: (workflowId: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the page asked for presence: a row then says which teammate is editing that workflow ("Anna is editing").
|
|
11
|
+
* Off unless it asks, here too: a list that was not told about it never says anything about others. Read once.
|
|
12
|
+
*/
|
|
13
|
+
presence?: boolean;
|
|
9
14
|
}
|
|
10
15
|
declare const WorkflowList: import("svelte").Component<Props, {}, "">;
|
|
11
16
|
type WorkflowList = ReturnType<typeof WorkflowList>;
|
|
@@ -2,13 +2,19 @@
|
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
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.
|
|
9
|
+
|
|
10
|
+
When a teammate is editing the workflow (the list asks, with `presence`), the row says so under its name: "Anna is editing",
|
|
11
|
+
or "Someone is editing" when the API gave no name. It is advice and nothing is shut by it: the row opens as always, and the
|
|
12
|
+
editor itself asks the person whether to take over or only look.
|
|
8
13
|
-->
|
|
9
14
|
<script lang="ts">
|
|
10
15
|
import type { WorkflowListItem } from '../../api/types.js';
|
|
11
16
|
import { formatDay } from '../../editor/blockLabels.js';
|
|
17
|
+
import { deleteMessageOf } from '../../editor/deleteWords.js';
|
|
12
18
|
import { formatCount } from '../../editor/formatCount.js';
|
|
13
19
|
import { useListState } from '../../editor/listState.svelte.js';
|
|
14
20
|
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
@@ -32,7 +38,11 @@
|
|
|
32
38
|
let asking = $state<'archive' | 'delete' | null>(null);
|
|
33
39
|
|
|
34
40
|
const isBusy = $derived(list.busyIds.has(item.id));
|
|
41
|
+
/** The teammate editing this workflow now, as the list found out (ids are compared in lower case, as the API does). */
|
|
42
|
+
const editor = $derived(list.editing.get(item.id.toLowerCase()) ?? null);
|
|
35
43
|
const wasPublished = $derived(item.firstPublishedAt !== null);
|
|
44
|
+
/** What the confirmation of a delete says goes with this workflow, by how far it got. */
|
|
45
|
+
const deleteMessage = $derived(deleteMessageOf(item));
|
|
36
46
|
|
|
37
47
|
const groups = $derived.by<MenuGroup[]>(() => {
|
|
38
48
|
const states: MenuGroup['items'][number][] = [];
|
|
@@ -101,10 +111,8 @@
|
|
|
101
111
|
{
|
|
102
112
|
key: 'delete',
|
|
103
113
|
label: $t('workflows.settings.delete'),
|
|
104
|
-
description: wasPublished ? $t('workflows.settings.deleteBlocked') : undefined,
|
|
105
114
|
icon: 'trash',
|
|
106
115
|
tone: 'danger',
|
|
107
|
-
disabled: wasPublished,
|
|
108
116
|
onSelect: () => (asking = 'delete')
|
|
109
117
|
}
|
|
110
118
|
]
|
|
@@ -139,6 +147,20 @@
|
|
|
139
147
|
<span class="text-xs text-ink-muted"
|
|
140
148
|
>{$t('workflows.list.compositionsCount', { count: item.compositionIds.length })}</span
|
|
141
149
|
>
|
|
150
|
+
{#if editor}
|
|
151
|
+
<!-- The word carries the meaning; the dot only helps the eye. -->
|
|
152
|
+
<span
|
|
153
|
+
class="mt-1 inline-flex max-w-full items-center gap-1.5 self-start rounded-pill border border-grey2 px-2 py-0.5 text-xs text-ink-primary"
|
|
154
|
+
data-workflows-editing
|
|
155
|
+
>
|
|
156
|
+
<span class="size-1.5 shrink-0 rounded-pill bg-ink-muted" aria-hidden="true"></span>
|
|
157
|
+
<span class="truncate">
|
|
158
|
+
{editor.name
|
|
159
|
+
? $t('workflows.list.editingNamed', { name: editor.name })
|
|
160
|
+
: $t('workflows.list.editingSomeone')}
|
|
161
|
+
</span>
|
|
162
|
+
</span>
|
|
163
|
+
{/if}
|
|
142
164
|
</div>
|
|
143
165
|
<div class="@2xl:order-none">
|
|
144
166
|
<StatusBadge status={item.status} hasUnpublishedChanges={item.unpublishedChanges} />
|
|
@@ -181,7 +203,7 @@
|
|
|
181
203
|
{:else if asking === 'delete'}
|
|
182
204
|
<ConfirmDialog
|
|
183
205
|
title={$t('workflows.settings.deleteTitle')}
|
|
184
|
-
message={$t(
|
|
206
|
+
message={$t(deleteMessage.key, deleteMessage.values)}
|
|
185
207
|
confirmLabel={$t('workflows.settings.delete')}
|
|
186
208
|
tone="danger"
|
|
187
209
|
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
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is editing the workflows of the list right now: the "Anna is editing" on a row.
|
|
3
|
+
*
|
|
4
|
+
* It asks the API (`peekEditLeases`: one call for a whole page of rows) when it starts, again every few seconds while the
|
|
5
|
+
* tab is on the screen, soon after the list changes (`lookSoon`), and when the tab comes back to the screen. It does not look
|
|
6
|
+
* at all while the tab is hidden: nobody sees the badges, and every look costs the API a read. No user interface in it, and
|
|
7
|
+
* no dependency but the API's answers, so a test can drive it with a fake port, fake timers and a fake page.
|
|
8
|
+
*
|
|
9
|
+
* The same rules as the claim of one open editor (`editLeaseController.ts`): presence is advice, never a lock, and a badge is
|
|
10
|
+
* allowed to be missing but not to be wrong.
|
|
11
|
+
*
|
|
12
|
+
* - Looking takes nothing and renews nothing: a person who looks at the list does not become an editor of anything.
|
|
13
|
+
* - Looks never overlap: the next one is planned when the last one ended.
|
|
14
|
+
* - A look that could not tell (the network, a server that failed, an answer of `unavailable`) leaves the badges as they
|
|
15
|
+
* were, and the next looks come further apart each time, up to a few heartbeats, so a network that is down is not hammered.
|
|
16
|
+
* - The API saying there is no presence here (a personal workspace, or the feature is off), or refusing for good (a token that
|
|
17
|
+
* may not ask, which an embed's is; a gateway that does not have the route; a request it calls malformed), ends the
|
|
18
|
+
* looking: the list carries on without badges and asks no more.
|
|
19
|
+
* - `onChange` is told only when what the badges say really changed, so the list does not draw again every few seconds.
|
|
20
|
+
* - Only the rows the look was about, and that are still on the list, get a badge.
|
|
21
|
+
* - After `stop()` nothing more happens: no request goes out, and answers still on their way are ignored.
|
|
22
|
+
*/
|
|
23
|
+
import type { EditLeaseHolder, EditLeasePeekAnswer } from '../api/types.js';
|
|
24
|
+
import { type PresenceEnvironment, type TimerFunctions } from './editLeaseController.js';
|
|
25
|
+
/** How often to look when the API did not say (it asks the editors for the same: 20 seconds). */
|
|
26
|
+
export declare const DEFAULT_EDITING_LOOK_INTERVAL_MS = 20000;
|
|
27
|
+
/** A list never looks more often than this, whatever the API asks. */
|
|
28
|
+
export declare const MINIMUM_EDITING_LOOK_INTERVAL_MS = 10000;
|
|
29
|
+
/** ...and never less often than this, so a badge does not stay long after the editing stopped (a claim lives a minute). */
|
|
30
|
+
export declare const MAXIMUM_EDITING_LOOK_INTERVAL_MS = 60000;
|
|
31
|
+
/** Changes of the list that come close together (a page that is drawn in steps) make one look. */
|
|
32
|
+
export declare const EDITING_LOOK_DEBOUNCE_MS = 300;
|
|
33
|
+
/** The teammates who are editing a workflow on the list, by the id of the workflow in lower case. */
|
|
34
|
+
export type EditingBadges = ReadonlyMap<string, EditLeaseHolder>;
|
|
35
|
+
export interface EditingWatcherOptions {
|
|
36
|
+
/** The workflows to look at now. Asked at every look, so a list that changes is followed. */
|
|
37
|
+
getWorkflowIds: () => readonly string[];
|
|
38
|
+
/** Does one look. It gets a signal that is aborted when the watcher stops. It throws what the API client throws. */
|
|
39
|
+
peek: (workflowIds: readonly string[], signal: AbortSignal) => Promise<EditLeasePeekAnswer>;
|
|
40
|
+
/** Told when what the badges say has changed: never for a look that says what the list already shows. */
|
|
41
|
+
onChange: (editing: EditingBadges) => void;
|
|
42
|
+
timers?: TimerFunctions;
|
|
43
|
+
/** The clock, in milliseconds. Default: `Date.now`. */
|
|
44
|
+
now?: () => number;
|
|
45
|
+
/** The page the list is on. Default: the browser's own. */
|
|
46
|
+
environment?: Pick<PresenceEnvironment, 'isVisible' | 'onWake'>;
|
|
47
|
+
/** Writes the watcher's own notes (a look that failed). Default: the console. */
|
|
48
|
+
logger?: Pick<Console, 'warn'>;
|
|
49
|
+
}
|
|
50
|
+
/** The interval the API asked for (seconds), kept between the lowest and the highest this list allows. */
|
|
51
|
+
export declare function lookIntervalFor(heartbeatSeconds: number | null): number;
|
|
52
|
+
export declare class EditingWatcher {
|
|
53
|
+
private readonly getWorkflowIds;
|
|
54
|
+
private readonly peek;
|
|
55
|
+
private readonly onChange;
|
|
56
|
+
private readonly timers;
|
|
57
|
+
private readonly now;
|
|
58
|
+
private readonly environment;
|
|
59
|
+
private readonly logger;
|
|
60
|
+
private running;
|
|
61
|
+
/** The API said there is no presence here, or refused for good: no more looks. */
|
|
62
|
+
private ended;
|
|
63
|
+
private nextLookTimer;
|
|
64
|
+
private soonTimer;
|
|
65
|
+
private inFlight;
|
|
66
|
+
private lookAgainWhenDone;
|
|
67
|
+
private intervalMs;
|
|
68
|
+
private failureStreak;
|
|
69
|
+
private lastAnswerAt;
|
|
70
|
+
private removeWakeListener;
|
|
71
|
+
private shown;
|
|
72
|
+
private shownText;
|
|
73
|
+
constructor(options: EditingWatcherOptions);
|
|
74
|
+
/** Looks now and keeps looking. Starting twice is the same as once, and a watcher that ended (no presence here) does not start again. */
|
|
75
|
+
start(): void;
|
|
76
|
+
/** Stops looking and cancels the look that is on its way. Nothing is told after this. */
|
|
77
|
+
stop(): void;
|
|
78
|
+
/** The list changed: look soon (a moment is waited, in case more changes follow). */
|
|
79
|
+
lookSoon(): void;
|
|
80
|
+
private look;
|
|
81
|
+
private fail;
|
|
82
|
+
/** The API said there is no presence here (or refused for good): no badge, and no more looks. */
|
|
83
|
+
private end;
|
|
84
|
+
/** The tab came back to the screen (or the network did): look at once instead of waiting for the timer. */
|
|
85
|
+
private wake;
|
|
86
|
+
private planNextLook;
|
|
87
|
+
private clearTimers;
|
|
88
|
+
/** Tells the list what the badges say now, once, when it differs from what it was told last. */
|
|
89
|
+
private show;
|
|
90
|
+
}
|