@widgetic/workflows 0.2.2 → 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 +24 -15
- package/dist/api/types.d.ts +19 -0
- package/dist/api/workflowsApi.d.ts +19 -1
- package/dist/api/workflowsApi.js +78 -0
- package/dist/components/WorkflowsWorkspace.svelte +6 -1
- package/dist/components/list/WorkflowList.svelte +18 -3
- package/dist/components/list/WorkflowList.svelte.d.ts +5 -0
- package/dist/components/list/WorkflowRow.svelte +20 -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 +25 -2
- package/dist/editor/listState.svelte.js +38 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +4 -0
- package/dist/i18n/messages.js +4 -0
- package/dist/types/index.d.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,21 +111,21 @@ the screen needs, the screen scrolls inside it; it never spills over what the pa
|
|
|
111
111
|
|
|
112
112
|
### Props
|
|
113
113
|
|
|
114
|
-
| Prop | Type | Default | What it does
|
|
115
|
-
| --------------------- | ------------------------------------------- | -------------------- |
|
|
116
|
-
| `apiUrl` | `string` | **required** | The Widgetic API origin, without `/v1` (`https://api.widgetic.com`).
|
|
117
|
-
| `getAccessToken` | `AccessTokenFunction` | **required** | Gives the screen a token for the API. Called with `'initial'` and, after a refusal, `'expired'`. The screen never stores a token.
|
|
118
|
-
| `workspaceId` | `string` | **required** | `personal`, or the id of the organization whose workflows are shown. A change of it starts the screen again.
|
|
119
|
-
| `workflowId` | `string \| null` | the list | The workflow that is open. The page owns it (it is part of the page's address); left out, the screen keeps track by itself.
|
|
120
|
-
| `onOpenWorkflow` | `(workflowId: string \| null) => void` | none | The person opened a workflow, or went back to the list (`null`).
|
|
121
|
-
| `onShowEmbedCode` | `(workflowId: string) => void` | none | Shows the embed code of a workflow. The dialog is the page's (it knows how the tag is built for its Embed SDK); without it there is no button.
|
|
122
|
-
| `presence` | `boolean` | `false` | Tells who else is editing the workflow that is open,
|
|
123
|
-
| `locale` | `string \| null` | English | A BCP 47 tag (`de`, `pt-BR`): plural rules, how numbers and dates are written. Translates nothing.
|
|
124
|
-
| `messages` | `Readonly<Record<string, unknown>> \| null` | none | Your own words, by key. A key you leave out stays English.
|
|
125
|
-
| `dir` | `'ltr' \| 'rtl'` | the screen around it | Which way the screen is read. You decide it; it is not worked out from `locale`.
|
|
126
|
-
| `class` | `string` | `''` | Extra classes on the root element.
|
|
127
|
-
| `onError` | `(error: WorkflowsError) => void` | none | Called once for each failure.
|
|
128
|
-
| `fetchImplementation` | `typeof fetch` | the page's `fetch` | For tests and previews: the `fetch` the screen asks the API with.
|
|
114
|
+
| Prop | Type | Default | What it does |
|
|
115
|
+
| --------------------- | ------------------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `apiUrl` | `string` | **required** | The Widgetic API origin, without `/v1` (`https://api.widgetic.com`). |
|
|
117
|
+
| `getAccessToken` | `AccessTokenFunction` | **required** | Gives the screen a token for the API. Called with `'initial'` and, after a refusal, `'expired'`. The screen never stores a token. |
|
|
118
|
+
| `workspaceId` | `string` | **required** | `personal`, or the id of the organization whose workflows are shown. A change of it starts the screen again. |
|
|
119
|
+
| `workflowId` | `string \| null` | the list | The workflow that is open. The page owns it (it is part of the page's address); left out, the screen keeps track by itself. |
|
|
120
|
+
| `onOpenWorkflow` | `(workflowId: string \| null) => void` | none | The person opened a workflow, or went back to the list (`null`). |
|
|
121
|
+
| `onShowEmbedCode` | `(workflowId: string) => void` | none | Shows the embed code of a workflow. The dialog is the page's (it knows how the tag is built for its Embed SDK); without it there is no button. |
|
|
122
|
+
| `presence` | `boolean` | `false` | Tells who else is editing: on the rows of the list, and in the workflow that is open, where it keeps this screen from writing over them (below). Read when the list or a workflow is opened. |
|
|
123
|
+
| `locale` | `string \| null` | English | A BCP 47 tag (`de`, `pt-BR`): plural rules, how numbers and dates are written. Translates nothing. |
|
|
124
|
+
| `messages` | `Readonly<Record<string, unknown>> \| null` | none | Your own words, by key. A key you leave out stays English. |
|
|
125
|
+
| `dir` | `'ltr' \| 'rtl'` | the screen around it | Which way the screen is read. You decide it; it is not worked out from `locale`. |
|
|
126
|
+
| `class` | `string` | `''` | Extra classes on the root element. |
|
|
127
|
+
| `onError` | `(error: WorkflowsError) => void` | none | Called once for each failure. |
|
|
128
|
+
| `fetchImplementation` | `typeof fetch` | the page's `fetch` | For tests and previews: the `fetch` the screen asks the API with. |
|
|
129
129
|
|
|
130
130
|
`WorkflowsError` is `{ message: string; code: 'RENDER_FAILED' | 'REQUEST_FAILED' | 'SESSION_ENDED'; fatal: boolean }`.
|
|
131
131
|
The `message` is English, for the page's developer. It is not a sentence to show a visitor: the screen shows its own.
|
|
@@ -147,6 +147,15 @@ never a lock: what keeps a draft from being overwritten is the revision check ab
|
|
|
147
147
|
names a person only to a teammate of the same organization, so a personal workspace has nothing to show and `presence`
|
|
148
148
|
changes nothing there. The page decides whether to ask for it (the Widgetic site does for an organization's workspace).
|
|
149
149
|
|
|
150
|
+
The list says it too. With `presence` on, a row says "Anna is editing" under the name of a workflow a teammate has open
|
|
151
|
+
(or "Someone is editing" when the API gave no name). The list asks `POST /v1/edit-leases/peek` once for a whole page of rows
|
|
152
|
+
(50 at most in one call), when it opens, soon after the rows change, every 20 seconds while the tab is on the screen (the
|
|
153
|
+
API may ask for another pace, kept between 10 and 60 seconds), and when the tab comes back; never while it is hidden.
|
|
154
|
+
Looking takes and renews nothing, so a person who looks at the list does not become an editor of anything. The account's
|
|
155
|
+
own other window is not a teammate and gets no badge. A look that fails (offline, a server error, "cannot tell") leaves the
|
|
156
|
+
badges as they were and the next looks come further apart; an API that says there is no presence here, or a token that may
|
|
157
|
+
not ask, ends the looking and the list goes on without badges. A badge never shuts anything: the row opens as always.
|
|
158
|
+
|
|
150
159
|
## Look and feel
|
|
151
160
|
|
|
152
161
|
Nothing in the screen is a literal colour, font or corner. It reads the Widgetic palette, and a theme is a handful of
|
package/dist/api/types.d.ts
CHANGED
|
@@ -218,5 +218,24 @@ export interface EditLeaseAnswer {
|
|
|
218
218
|
/** Who the claim was taken from, when taking over displaced somebody. */
|
|
219
219
|
tookOverFrom?: EditLeaseHolder;
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Who is editing several workflows at once, as the list reads it (`POST /edit-leases/peek`, see `readEditLeasePeekAnswer`):
|
|
223
|
+
* the teammates only, by the id of the workflow they are editing. It takes and renews nothing, so looking never makes the
|
|
224
|
+
* person who looks an editor.
|
|
225
|
+
*/
|
|
226
|
+
export interface EditLeasePeekAnswer {
|
|
227
|
+
/**
|
|
228
|
+
* The teammates who are editing, by the id of the workflow in lower case (the API compares ids that way). A workflow that is
|
|
229
|
+
* not in the map is not being edited by a teammate: nobody is, or the API may not say (it names a person only for a team's
|
|
230
|
+
* workflow the caller may read), or the one editing is the caller's own account in another window, which is not a teammate.
|
|
231
|
+
*/
|
|
232
|
+
editors: ReadonlyMap<string, EditLeaseHolder>;
|
|
233
|
+
/** How often the API wants a list that shows presence to look again, in seconds, when it said. */
|
|
234
|
+
heartbeatSeconds: number | null;
|
|
235
|
+
/** `false` when the API could not tell for at least one workflow (`unavailable`): nothing is known for sure, keep what was shown. */
|
|
236
|
+
complete: boolean;
|
|
237
|
+
/** `true` when the API said there is no presence here for every workflow asked about (a personal workspace, or the feature is off). */
|
|
238
|
+
notApplicable: boolean;
|
|
239
|
+
}
|
|
221
240
|
/** The token function the host gives the screen (see `AccessTokenFunction` of the ui-sdk modules). */
|
|
222
241
|
export type AccessTokenFunction = (reason: 'initial' | 'expired', refusedToken?: string) => Promise<string> | string;
|
|
@@ -1,5 +1,5 @@
|
|
|
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 WorkflowPreset, 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 EditLeasePeekAnswer, 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;
|
|
@@ -119,6 +119,12 @@ export interface WorkflowsApi {
|
|
|
119
119
|
takeOverEditLease(workflowId: string, sessionId: string, options?: RequestOptions): Promise<EditLeaseAnswer>;
|
|
120
120
|
/** Who is editing, without claiming anything. */
|
|
121
121
|
peekEditLease(workflowId: string, options?: RequestOptions): Promise<EditLeaseAnswer>;
|
|
122
|
+
/**
|
|
123
|
+
* Who is editing these workflows, for the badges of the list: one call for each `EDIT_LEASE_PEEK_BATCH_SIZE` workflows (a
|
|
124
|
+
* longer list is asked in several). It takes and renews nothing, so looking never makes the person who looks an editor.
|
|
125
|
+
* Advice, like all of presence: it refuses nothing. A failure is thrown like any other, and the list keeps what it showed.
|
|
126
|
+
*/
|
|
127
|
+
peekEditLeases(workflowIds: readonly string[], options?: RequestOptions): Promise<EditLeasePeekAnswer>;
|
|
122
128
|
/** Gives this tab's claim up. */
|
|
123
129
|
releaseEditLease(workflowId: string, sessionId: string, options?: ReleaseEditLeaseOptions): Promise<void>;
|
|
124
130
|
}
|
|
@@ -146,6 +152,18 @@ export declare function readWorkflowPreset(data: unknown): WorkflowPreset;
|
|
|
146
152
|
* convenience, so the editor goes on as if it were not there rather than failing.
|
|
147
153
|
*/
|
|
148
154
|
export declare function readEditLeaseAnswer(data: unknown): EditLeaseAnswer;
|
|
155
|
+
/** The most workflows the API looks at in one call (`POST /edit-leases/peek` answers 400 above it): a longer list is asked in several. */
|
|
156
|
+
export declare const EDIT_LEASE_PEEK_BATCH_SIZE = 50;
|
|
157
|
+
/**
|
|
158
|
+
* What the API answered about a page of workflows, checked: the teammates who are editing, and whether the API could tell.
|
|
159
|
+
*
|
|
160
|
+
* A workflow counts as being edited only when the API says `held_by_other`, names a holder, and the holder is not the signed-in
|
|
161
|
+
* person's own account (`isYou`: that is another window of theirs, not a teammate, and "Anna is editing" would be untrue of
|
|
162
|
+
* oneself). Everything else is nobody, with one exception that is not "nobody": an answer of `unavailable`, or one that cannot
|
|
163
|
+
* be read, means the API could not tell, so `complete` is `false` and the list keeps what it showed. A missing badge is the
|
|
164
|
+
* safe answer, a wrong one is not.
|
|
165
|
+
*/
|
|
166
|
+
export declare function readEditLeasePeekAnswer(data: unknown): EditLeasePeekAnswer;
|
|
149
167
|
/** The query string of the list: only what was asked for. */
|
|
150
168
|
export declare function buildListQueryString(query: WorkflowListQuery | undefined): string;
|
|
151
169
|
export declare function buildCompositionOptionsQueryString(query: CompositionOptionsQuery | undefined): string;
|
package/dist/api/workflowsApi.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* POST /edit-leases/workflow/{id}/take-over take the claim from whoever holds it
|
|
23
23
|
* GET /edit-leases/workflow/{id} who is editing, without claiming
|
|
24
24
|
* DELETE /edit-leases/workflow/{id}?sessionId= give the claim up
|
|
25
|
+
* POST /edit-leases/peek who is editing several workflows at once (the badges of the list)
|
|
25
26
|
*
|
|
26
27
|
* The API never gives a refusal a sentence of ours to show: a screen reads `code` (and `details`) and says it in the person's
|
|
27
28
|
* language. What the client never does: send cookies, put a token anywhere but the `Authorization` header, or keep one.
|
|
@@ -483,6 +484,50 @@ export function readEditLeaseAnswer(data) {
|
|
|
483
484
|
answer.tookOverFrom = tookOverFrom;
|
|
484
485
|
return answer;
|
|
485
486
|
}
|
|
487
|
+
/** The most workflows the API looks at in one call (`POST /edit-leases/peek` answers 400 above it): a longer list is asked in several. */
|
|
488
|
+
export const EDIT_LEASE_PEEK_BATCH_SIZE = 50;
|
|
489
|
+
/**
|
|
490
|
+
* What the API answered about a page of workflows, checked: the teammates who are editing, and whether the API could tell.
|
|
491
|
+
*
|
|
492
|
+
* A workflow counts as being edited only when the API says `held_by_other`, names a holder, and the holder is not the signed-in
|
|
493
|
+
* person's own account (`isYou`: that is another window of theirs, not a teammate, and "Anna is editing" would be untrue of
|
|
494
|
+
* oneself). Everything else is nobody, with one exception that is not "nobody": an answer of `unavailable`, or one that cannot
|
|
495
|
+
* be read, means the API could not tell, so `complete` is `false` and the list keeps what it showed. A missing badge is the
|
|
496
|
+
* safe answer, a wrong one is not.
|
|
497
|
+
*/
|
|
498
|
+
export function readEditLeasePeekAnswer(data) {
|
|
499
|
+
const editors = new Map();
|
|
500
|
+
if (!isRecord(data) || !Array.isArray(data.items)) {
|
|
501
|
+
return { editors, heartbeatSeconds: null, complete: false, notApplicable: false };
|
|
502
|
+
}
|
|
503
|
+
let complete = true;
|
|
504
|
+
let everyItemNotApplicable = data.items.length > 0;
|
|
505
|
+
for (const item of data.items) {
|
|
506
|
+
const outcome = isRecord(item)
|
|
507
|
+
? EDIT_LEASE_OUTCOMES.find((name) => name === item.outcome)
|
|
508
|
+
: undefined;
|
|
509
|
+
if (outcome !== 'not_applicable')
|
|
510
|
+
everyItemNotApplicable = false;
|
|
511
|
+
if (outcome === undefined || outcome === 'unavailable') {
|
|
512
|
+
complete = false;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (outcome !== 'held_by_other' || !isRecord(item))
|
|
516
|
+
continue;
|
|
517
|
+
if (item.type !== 'workflow' || typeof item.id !== 'string')
|
|
518
|
+
continue;
|
|
519
|
+
const holder = readEditLeaseHolder(item.holder);
|
|
520
|
+
if (!holder || holder.isYou)
|
|
521
|
+
continue;
|
|
522
|
+
editors.set(item.id.toLowerCase(), holder);
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
editors,
|
|
526
|
+
heartbeatSeconds: isSeconds(data.heartbeatSeconds) ? data.heartbeatSeconds : null,
|
|
527
|
+
complete,
|
|
528
|
+
notApplicable: everyItemNotApplicable
|
|
529
|
+
};
|
|
530
|
+
}
|
|
486
531
|
/** The error code, sentence and details of an API error answer, when it has them. */
|
|
487
532
|
function describeFailureBody(body) {
|
|
488
533
|
if (!isRecord(body))
|
|
@@ -823,6 +868,39 @@ export function createWorkflowsApi(options) {
|
|
|
823
868
|
noStore: true
|
|
824
869
|
}));
|
|
825
870
|
},
|
|
871
|
+
async peekEditLeases(workflowIds, requestOptions = {}) {
|
|
872
|
+
// Each workflow once, by the id as the API compares it; an id that is no id is a bug of the caller, never sent.
|
|
873
|
+
const unique = [
|
|
874
|
+
...new Set(workflowIds.map((workflowId) => {
|
|
875
|
+
if (typeof workflowId !== 'string' || workflowId.trim() === '') {
|
|
876
|
+
throw new TypeError('A workflow id is needed');
|
|
877
|
+
}
|
|
878
|
+
return workflowId.toLowerCase();
|
|
879
|
+
}))
|
|
880
|
+
];
|
|
881
|
+
const editors = new Map();
|
|
882
|
+
let heartbeatSeconds = null;
|
|
883
|
+
let complete = true;
|
|
884
|
+
let notApplicable = unique.length > 0;
|
|
885
|
+
for (let start = 0; start < unique.length; start += EDIT_LEASE_PEEK_BATCH_SIZE) {
|
|
886
|
+
const batch = unique.slice(start, start + EDIT_LEASE_PEEK_BATCH_SIZE);
|
|
887
|
+
const answer = readEditLeasePeekAnswer(await request('POST', '/edit-leases/peek', {
|
|
888
|
+
body: { items: batch.map((id) => ({ type: 'workflow', id })) },
|
|
889
|
+
signal: requestOptions.signal,
|
|
890
|
+
timeoutMs: readTimeoutMs,
|
|
891
|
+
noStore: true
|
|
892
|
+
}));
|
|
893
|
+
for (const [id, holder] of answer.editors)
|
|
894
|
+
editors.set(id, holder);
|
|
895
|
+
if (answer.heartbeatSeconds !== null)
|
|
896
|
+
heartbeatSeconds = answer.heartbeatSeconds;
|
|
897
|
+
if (!answer.complete)
|
|
898
|
+
complete = false;
|
|
899
|
+
if (!answer.notApplicable)
|
|
900
|
+
notApplicable = false;
|
|
901
|
+
}
|
|
902
|
+
return { editors, heartbeatSeconds, complete, notApplicable };
|
|
903
|
+
},
|
|
826
904
|
async releaseEditLease(workflowId, sessionId, releaseOptions = {}) {
|
|
827
905
|
await request('DELETE', leasePath(workflowId, `?sessionId=${encodeURIComponent(checkedSessionId(sessionId))}`), {
|
|
828
906
|
signal: releaseOptions.signal,
|
|
@@ -85,6 +85,11 @@
|
|
|
85
85
|
</div>
|
|
86
86
|
{:else}
|
|
87
87
|
<div class="flex flex-1 flex-col p-6">
|
|
88
|
-
<WorkflowList
|
|
88
|
+
<WorkflowList
|
|
89
|
+
onopen={(id) => open(id)}
|
|
90
|
+
onerror={onError}
|
|
91
|
+
onshowembedcode={onShowEmbedCode}
|
|
92
|
+
{presence}
|
|
93
|
+
/>
|
|
89
94
|
</div>
|
|
90
95
|
{/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>;
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
brought back, and any can be copied or deleted, in whatever state it is in. Archiving and deleting ask first, and deleting
|
|
7
7
|
says what goes with the workflow (its draft, its versions and its counts, and that the compositions stay): it cannot be
|
|
8
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.
|
|
9
13
|
-->
|
|
10
14
|
<script lang="ts">
|
|
11
15
|
import type { WorkflowListItem } from '../../api/types.js';
|
|
@@ -34,6 +38,8 @@
|
|
|
34
38
|
let asking = $state<'archive' | 'delete' | null>(null);
|
|
35
39
|
|
|
36
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);
|
|
37
43
|
const wasPublished = $derived(item.firstPublishedAt !== null);
|
|
38
44
|
/** What the confirmation of a delete says goes with this workflow, by how far it got. */
|
|
39
45
|
const deleteMessage = $derived(deleteMessageOf(item));
|
|
@@ -141,6 +147,20 @@
|
|
|
141
147
|
<span class="text-xs text-ink-muted"
|
|
142
148
|
>{$t('workflows.list.compositionsCount', { count: item.compositionIds.length })}</span
|
|
143
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}
|
|
144
164
|
</div>
|
|
145
165
|
<div class="@2xl:order-none">
|
|
146
166
|
<StatusBadge status={item.status} hasUnpublishedChanges={item.unpublishedChanges} />
|
|
@@ -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
|
+
}
|