@widgetic/workflows 0.1.1 → 0.2.1
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 +118 -46
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +201 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +133 -0
- package/dist/api/workflowsApi.js +763 -0
- package/dist/components/Workflows.svelte +43 -17
- package/dist/components/WorkflowsEmptyState.svelte +16 -5
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +5 -16
- package/dist/components/WorkflowsHeader.svelte +2 -2
- package/dist/components/WorkflowsWorkspace.svelte +90 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +15 -0
- package/dist/components/canvas/AddBlockMenu.svelte +101 -0
- package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasToolbar.svelte +95 -0
- package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
- package/dist/components/canvas/CompositionNodeView.svelte +125 -0
- package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/ConditionNodeView.svelte +95 -0
- package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/HandlePoint.svelte +32 -0
- package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
- package/dist/components/canvas/TriggerNodeView.svelte +75 -0
- package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
- package/dist/components/editor/ConflictBanner.svelte +78 -0
- package/dist/components/editor/ConflictBanner.svelte.d.ts +3 -0
- package/dist/components/editor/EditorBanners.svelte +141 -0
- package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
- package/dist/components/editor/EditorCanvasArea.svelte +85 -0
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
- package/dist/components/editor/EditorTabs.svelte +81 -0
- package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +132 -0
- package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
- package/dist/components/editor/PresenceBanner.svelte +126 -0
- package/dist/components/editor/PresenceBanner.svelte.d.ts +3 -0
- package/dist/components/editor/RunsTab.svelte +256 -0
- package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
- package/dist/components/editor/SettingsTab.svelte +180 -0
- package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
- package/dist/components/editor/WorkflowEditor.svelte +198 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +17 -0
- package/dist/components/index.d.ts +0 -2
- package/dist/components/index.js +0 -2
- package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
- package/dist/components/list/WorkflowList.svelte +204 -0
- package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
- package/dist/components/list/WorkflowRow.svelte +191 -0
- package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
- package/dist/components/panel/BlockProblems.svelte +47 -0
- package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
- package/dist/components/panel/CompositionForm.svelte +127 -0
- package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
- package/dist/components/panel/CompositionPicker.svelte +179 -0
- package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
- package/dist/components/panel/ConditionForm.svelte +105 -0
- package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
- package/dist/components/panel/EventValueRow.svelte +85 -0
- package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
- package/dist/components/panel/NextStepSelect.svelte +70 -0
- package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
- package/dist/components/panel/ProblemsList.svelte +101 -0
- package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
- package/dist/components/panel/RuleCard.svelte +191 -0
- package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
- package/dist/components/panel/SidePanel.svelte +82 -0
- package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestRow.svelte +150 -0
- package/dist/components/panel/TestRow.svelte.d.ts +15 -0
- package/dist/components/panel/TestRunPanel.svelte +85 -0
- package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestTriggerCard.svelte +121 -0
- package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
- package/dist/components/panel/TriggerForm.svelte +385 -0
- package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
- package/dist/components/panel/VersionHistory.svelte +123 -0
- package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
- package/dist/components/ui/ActionButton.svelte +85 -0
- package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
- package/dist/components/ui/ConfirmDialog.svelte +52 -0
- package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
- package/dist/components/ui/Icon.svelte +32 -0
- package/dist/components/ui/Icon.svelte.d.ts +9 -0
- package/dist/components/ui/Menu.svelte +211 -0
- package/dist/components/ui/Menu.svelte.d.ts +21 -0
- package/dist/components/ui/Modal.svelte +129 -0
- package/dist/components/ui/Modal.svelte.d.ts +13 -0
- package/dist/components/ui/Notice.svelte +36 -0
- package/dist/components/ui/Notice.svelte.d.ts +11 -0
- package/dist/components/ui/SelectField.svelte +74 -0
- package/dist/components/ui/SelectField.svelte.d.ts +16 -0
- package/dist/components/ui/StatusBadge.svelte +41 -0
- package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TextField.svelte +97 -0
- package/dist/components/ui/TextField.svelte.d.ts +29 -0
- package/dist/components/ui/icons.d.ts +34 -0
- package/dist/components/ui/icons.js +54 -0
- package/dist/components/ui/types.d.ts +26 -0
- package/dist/components/ui/types.js +1 -0
- package/dist/editor/apiErrorText.d.ts +10 -0
- package/dist/editor/apiErrorText.js +53 -0
- package/dist/editor/autosave.d.ts +47 -0
- package/dist/editor/autosave.js +119 -0
- package/dist/editor/blockLabels.d.ts +91 -0
- package/dist/editor/blockLabels.js +196 -0
- package/dist/editor/canvasContext.d.ts +52 -0
- package/dist/editor/canvasContext.js +37 -0
- package/dist/editor/canvasWords.d.ts +24 -0
- package/dist/editor/canvasWords.js +40 -0
- package/dist/editor/capabilityModel.d.ts +46 -0
- package/dist/editor/capabilityModel.js +113 -0
- package/dist/editor/editLeaseController.d.ts +162 -0
- package/dist/editor/editLeaseController.js +459 -0
- package/dist/editor/editorState.svelte.d.ts +277 -0
- package/dist/editor/editorState.svelte.js +862 -0
- package/dist/editor/flowAdapter.d.ts +59 -0
- package/dist/editor/flowAdapter.js +166 -0
- package/dist/editor/formatCount.d.ts +5 -0
- package/dist/editor/formatCount.js +15 -0
- package/dist/editor/graphDiff.d.ts +27 -0
- package/dist/editor/graphDiff.js +64 -0
- package/dist/editor/graphModel.d.ts +154 -0
- package/dist/editor/graphModel.js +457 -0
- package/dist/editor/issueText.d.ts +64 -0
- package/dist/editor/issueText.js +101 -0
- package/dist/editor/keepCopy.d.ts +41 -0
- package/dist/editor/keepCopy.js +52 -0
- package/dist/editor/listState.svelte.d.ts +82 -0
- package/dist/editor/listState.svelte.js +250 -0
- package/dist/editor/statsRange.d.ts +26 -0
- package/dist/editor/statsRange.js +41 -0
- package/dist/editor/testRun.d.ts +36 -0
- package/dist/editor/testRun.js +74 -0
- package/dist/editor/zonedTime.d.ts +20 -0
- package/dist/editor/zonedTime.js +134 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +429 -4
- package/dist/i18n/messages.js +456 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +41 -3
- package/package.json +5 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MAX_WORKFLOW_NAME_LENGTH } from '../api/types.js';
|
|
2
|
+
import { workflowsWarn } from '../utils/logger.js';
|
|
3
|
+
const ELLIPSIS = '…';
|
|
4
|
+
/** Whether a text is short enough for the API, which counts what a script counts (UTF-16 units, not letters). */
|
|
5
|
+
function fitsIn(text, max) {
|
|
6
|
+
return text.length <= max;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The name of a copy: the person's own words around the name of the workflow (`wording` puts them there, in the person's
|
|
10
|
+
* language: "{name} (my changes)"), cut so that the whole is at most what the API accepts. It is the workflow's name that
|
|
11
|
+
* gives way, with an ellipsis, never the words around it; a letter is never cut in two (an emoji is one letter here).
|
|
12
|
+
*/
|
|
13
|
+
export function nameForCopy(name, wording, max = MAX_WORKFLOW_NAME_LENGTH) {
|
|
14
|
+
const whole = Array.from(name.trim());
|
|
15
|
+
const uncut = wording(whole.join('')).trim();
|
|
16
|
+
if (fitsIn(uncut, max))
|
|
17
|
+
return uncut;
|
|
18
|
+
// One letter fewer at a time, down to none: "…" alone, between the words, is the shortest the name can be.
|
|
19
|
+
for (let kept = whole.length - 1; kept >= 0; kept -= 1) {
|
|
20
|
+
const shown = `${whole.slice(0, kept).join('').trimEnd()}${ELLIPSIS}`;
|
|
21
|
+
const candidate = wording(shown).trim();
|
|
22
|
+
if (fitsIn(candidate, max))
|
|
23
|
+
return candidate;
|
|
24
|
+
}
|
|
25
|
+
// The words around the name are too long on their own (no catalog does that): cut them, a letter at a time.
|
|
26
|
+
const letters = Array.from(wording('').trim());
|
|
27
|
+
while (letters.length > 0 && !fitsIn(letters.join(''), max))
|
|
28
|
+
letters.pop();
|
|
29
|
+
return letters.join('');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Makes a new workflow that holds the draft on the person's screen, and answers it. If the draft cannot be saved into it,
|
|
33
|
+
* the new workflow is deleted again and the failure is thrown. `signal` cancels the requests of the copy (the screen was
|
|
34
|
+
* left); the clean-up after a failure is made anyway.
|
|
35
|
+
*/
|
|
36
|
+
export async function keepCopyOfDraft(api, input, signal) {
|
|
37
|
+
const made = await api.createWorkflow({ name: input.name, timezone: input.timezone }, { signal });
|
|
38
|
+
try {
|
|
39
|
+
await api.saveDraft(made.id, { revision: made.revision, graph: input.graph }, { signal });
|
|
40
|
+
}
|
|
41
|
+
catch (failure) {
|
|
42
|
+
try {
|
|
43
|
+
await api.deleteWorkflow(made.id);
|
|
44
|
+
}
|
|
45
|
+
catch (cleanupFailure) {
|
|
46
|
+
// The copy stays, empty. The person is told the copy failed; the console tells the page's developer why it is there.
|
|
47
|
+
workflowsWarn(`An empty workflow (${made.id}) was left behind: the draft could not be saved into it and it could not be deleted.`, cleanupFailure);
|
|
48
|
+
}
|
|
49
|
+
throw failure;
|
|
50
|
+
}
|
|
51
|
+
return { id: made.id, name: made.name };
|
|
52
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type WorkflowsApi } from '../api/workflowsApi.js';
|
|
2
|
+
import type { CompositionOption, SortDirection, WorkflowDetail, WorkflowListItem, WorkflowSortField, WorkflowStateAction, WorkflowStatus } from '../api/types.js';
|
|
3
|
+
import type { WorkflowsMessageKey } from '../i18n/messages.js';
|
|
4
|
+
import type { WorkflowsError } from '../types/index.js';
|
|
5
|
+
/** What the list is filtered by. Empty is "not archived" (drafts, live and paused), which is what the API lists by default. */
|
|
6
|
+
export type ListStatusFilter = '' | WorkflowStatus | 'all';
|
|
7
|
+
/** One page of the list is this many workflows; "Show more" reads the next. */
|
|
8
|
+
export declare const LIST_PAGE_SIZE = 25;
|
|
9
|
+
/** How long the list waits after the last letter typed in the search before it asks. */
|
|
10
|
+
export declare const SEARCH_DELAY_MILLISECONDS = 300;
|
|
11
|
+
export interface WorkflowListOptions {
|
|
12
|
+
api: WorkflowsApi;
|
|
13
|
+
reportError: (error: WorkflowsError) => void;
|
|
14
|
+
/** For tests. */
|
|
15
|
+
searchDelayMilliseconds?: number;
|
|
16
|
+
/** For tests. */
|
|
17
|
+
pageSize?: number;
|
|
18
|
+
}
|
|
19
|
+
/** What the person is told after something they did in the list. */
|
|
20
|
+
export interface ListNotice {
|
|
21
|
+
tone: 'info' | 'problem';
|
|
22
|
+
messageKey: WorkflowsMessageKey;
|
|
23
|
+
values?: Record<string, string | number>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The list of workflows: what is shown, how it is searched, filtered and ordered, and the things done to a workflow from
|
|
27
|
+
* its row (create, duplicate, pause, archive, delete). It asks the API for every change of the search or the order (the list
|
|
28
|
+
* can be longer than a page), and keeps the answer of the newest question only.
|
|
29
|
+
*/
|
|
30
|
+
export declare class WorkflowListState {
|
|
31
|
+
items: readonly WorkflowListItem[];
|
|
32
|
+
total: number;
|
|
33
|
+
loadState: "loading" | "ready" | "failed";
|
|
34
|
+
loadingMore: boolean;
|
|
35
|
+
failure: "workflows.region.label" | "workflows.header.title" | "workflows.header.subtitle" | "workflows.common.cancel" | "workflows.common.close" | "workflows.common.dismiss" | "workflows.common.loading" | "workflows.empty.title" | "workflows.empty.hint" | "workflows.error.title" | "workflows.error.hint" | "workflows.error.retry" | "workflows.error.generic" | "workflows.error.network" | "workflows.error.timeout" | "workflows.error.server" | "workflows.error.sessionEnded" | "workflows.error.planRestricted" | "workflows.error.notFound" | "workflows.error.revisionChanged" | "workflows.error.archived" | "workflows.error.nothingToPublish" | "workflows.error.nothingToDiscard" | "workflows.error.everPublished" | "workflows.error.wrongState" | "workflows.error.tooManyWorkflows" | "workflows.error.publishBlocked" | "workflows.error.invalidGraph" | "workflows.error.tooManyRequests" | "workflows.list.label" | "workflows.list.newWorkflow" | "workflows.list.searchLabel" | "workflows.list.searchPlaceholder" | "workflows.list.filterLabel" | "workflows.list.filterActive" | "workflows.list.filterAll" | "workflows.list.sortLabel" | "workflows.list.sortCreated" | "workflows.list.sortPublished" | "workflows.list.sortRuns" | "workflows.list.sortName" | "workflows.list.sortAscending" | "workflows.list.sortDescending" | "workflows.list.columnName" | "workflows.list.columnStatus" | "workflows.list.columnRuns" | "workflows.list.columnPublished" | "workflows.list.columnCreated" | "workflows.list.compositionsCount" | "workflows.list.runsCount" | "workflows.list.publishedOn" | "workflows.list.neverPublished" | "workflows.list.never" | "workflows.list.open" | "workflows.list.rowMenu" | "workflows.list.showMore" | "workflows.list.noMatches" | "workflows.list.duplicated" | "workflows.list.deleted" | "workflows.create.title" | "workflows.create.nameLabel" | "workflows.create.namePlaceholder" | "workflows.create.compositionLabel" | "workflows.create.compositionHelp" | "workflows.create.create" | "workflows.create.creating" | "workflows.status.draft" | "workflows.status.live" | "workflows.status.paused" | "workflows.status.archived" | "workflows.status.unpublishedChanges" | "workflows.top.back" | "workflows.top.nameLabel" | "workflows.top.testRun" | "workflows.top.history" | "workflows.top.embedCode" | "workflows.top.publish" | "workflows.top.publishChanges" | "workflows.top.publishing" | "workflows.save.saved" | "workflows.save.saving" | "workflows.save.pending" | "workflows.save.failed" | "workflows.save.conflict" | "workflows.tabs.label" | "workflows.tabs.editor" | "workflows.tabs.runs" | "workflows.tabs.settings" | "workflows.banner.unpublishedChanges" | "workflows.banner.publishChanges" | "workflows.banner.discard" | "workflows.banner.discardTitle" | "workflows.banner.discardMessage" | "workflows.banner.neverPublished" | "workflows.banner.paused" | "workflows.banner.archived" | "workflows.banner.conflict" | "workflows.banner.reload" | "workflows.banner.touchOnly" | "workflows.conflict.keepCopy" | "workflows.conflict.keepingCopy" | "workflows.conflict.copyName" | "workflows.conflict.copyKept" | "workflows.conflict.openCopy" | "workflows.conflict.loadTitle" | "workflows.conflict.loadMessage" | "workflows.presence.blockedTitleNamed" | "workflows.presence.blockedTitleYou" | "workflows.presence.blockedTitle" | "workflows.presence.blockedBody" | "workflows.presence.lostTitleNamed" | "workflows.presence.lostTitleYou" | "workflows.presence.lostTitle" | "workflows.presence.lostBody" | "workflows.presence.takeOver" | "workflows.presence.takeOverHint" | "workflows.presence.lookOnly" | "workflows.presence.lookOnlyHint" | "workflows.presence.working" | "workflows.presence.actionFailed" | "workflows.presence.readOnlyNamed" | "workflows.presence.readOnlyYou" | "workflows.presence.readOnly" | "workflows.presence.readOnlyFree" | "workflows.presence.startEditing" | "workflows.editor.published" | "workflows.editor.discarded" | "workflows.editor.restored" | "workflows.editor.reloaded" | "workflows.editor.paused" | "workflows.editor.resumed" | "workflows.editor.archived" | "workflows.editor.unarchived" | "workflows.editor.saveFirst" | "workflows.editor.fixProblems" | "workflows.editor.blockLimit" | "workflows.publish.firstTitle" | "workflows.publish.firstMessage" | "workflows.publish.changesTitle" | "workflows.publish.changesMessage" | "workflows.leave.title" | "workflows.leave.message" | "workflows.leave.confirm" | "workflows.canvas.label" | "workflows.canvas.pointIn" | "workflows.canvas.pointOut" | "workflows.toolbar.label" | "workflows.toolbar.addBlock" | "workflows.toolbar.undo" | "workflows.toolbar.redo" | "workflows.toolbar.zoomIn" | "workflows.toolbar.zoomOut" | "workflows.toolbar.fit" | "workflows.addBlock.composition" | "workflows.addBlock.helpComposition" | "workflows.addBlock.condition" | "workflows.addBlock.helpCondition" | "workflows.addBlock.triggerHeading" | "workflows.addBlock.helpInput" | "workflows.addBlock.helpAction" | "workflows.addBlock.helpPageEvent" | "workflows.addBlock.helpScheduled" | "workflows.block.startsHere" | "workflows.block.trigger" | "workflows.block.condition" | "workflows.block.unknown" | "workflows.block.compositionNotChosen" | "workflows.block.compositionLoading" | "workflows.block.compositionUnavailable" | "workflows.block.notPublished" | "workflows.block.numbered" | "workflows.block.problems" | "workflows.panel.label" | "workflows.panel.overviewHeading" | "workflows.panel.overviewHelp" | "workflows.panel.problemsHeading" | "workflows.panel.problemsLabel" | "workflows.panel.noProblems" | "workflows.panel.manyBlocksSelected" | "workflows.panel.connectionSelected" | "workflows.panel.removeBlock" | "workflows.panel.removeBlocks" | "workflows.panel.removeConnection" | "workflows.composition.heading" | "workflows.composition.help" | "workflows.composition.searchLabel" | "workflows.composition.searchPlaceholder" | "workflows.composition.none" | "workflows.composition.alreadyUsed" | "workflows.composition.isStart" | "workflows.composition.makeStart" | "workflows.composition.capabilitiesHeading" | "workflows.composition.capabilityInput" | "workflows.composition.capabilityAction" | "workflows.composition.capabilityWebsites" | "workflows.composition.inputTables" | "workflows.composition.actionCount" | "workflows.trigger.heading" | "workflows.trigger.help" | "workflows.trigger.kindLabel" | "workflows.trigger.kindInput" | "workflows.trigger.kindAction" | "workflows.trigger.kindPageEvent" | "workflows.trigger.kindScheduled" | "workflows.trigger.unavailable" | "workflows.trigger.tableLabel" | "workflows.trigger.tableHelp" | "workflows.trigger.actionLabel" | "workflows.trigger.actionHelp" | "workflows.trigger.chooseOne" | "workflows.trigger.notFound" | "workflows.trigger.readableValues" | "workflows.trigger.noReadableValues" | "workflows.trigger.nextLabel" | "workflows.trigger.nextHelp" | "workflows.trigger.nextNone" | "workflows.trigger.summaryInput" | "workflows.trigger.summaryAction" | "workflows.trigger.summaryPageEvent" | "workflows.trigger.summaryAt" | "workflows.trigger.summaryUnfinished" | "workflows.reason.widgetKeepsNoData" | "workflows.reason.widgetReportsNoActions" | "workflows.reason.widgetNotPublished" | "workflows.schedule.modeLabel" | "workflows.schedule.modeAfter" | "workflows.schedule.modeAt" | "workflows.schedule.afterHelp" | "workflows.schedule.amountLabel" | "workflows.schedule.unitLabel" | "workflows.schedule.unitSeconds" | "workflows.schedule.unitMinutes" | "workflows.schedule.unitHours" | "workflows.schedule.unitDays" | "workflows.schedule.unitWeeks" | "workflows.schedule.waitSeconds" | "workflows.schedule.waitMinutes" | "workflows.schedule.waitHours" | "workflows.schedule.waitDays" | "workflows.schedule.waitWeeks" | "workflows.schedule.momentLabel" | "workflows.schedule.momentHelp" | "workflows.schedule.invalidMoment" | "workflows.event.nameLabel" | "workflows.event.namePlaceholder" | "workflows.event.nameHelp" | "workflows.event.nameInvalid" | "workflows.event.howToSend" | "workflows.event.valuesHeading" | "workflows.event.valuesHelp" | "workflows.event.addValue" | "workflows.event.valueName" | "workflows.event.valueNamePlaceholder" | "workflows.event.valueNameInvalid" | "workflows.event.valueType" | "workflows.event.removeValue" | "workflows.fieldType.text" | "workflows.fieldType.number" | "workflows.fieldType.boolean" | "workflows.value.yes" | "workflows.value.no" | "workflows.condition.heading" | "workflows.condition.help" | "workflows.condition.noTrigger" | "workflows.condition.noValues" | "workflows.condition.addRule" | "workflows.condition.ruleLimit" | "workflows.condition.defaultName" | "workflows.condition.defaultLabel" | "workflows.condition.defaultStay" | "workflows.condition.defaultHelp" | "workflows.condition.defaultHint" | "workflows.condition.defaultStays" | "workflows.rule.defaultName" | "workflows.rule.nameLabel" | "workflows.rule.moveUp" | "workflows.rule.moveDown" | "workflows.rule.remove" | "workflows.rule.matchLabel" | "workflows.rule.matchAll" | "workflows.rule.matchAny" | "workflows.rule.noTests" | "workflows.rule.addTest" | "workflows.rule.testLimit" | "workflows.rule.thenGoTo" | "workflows.rule.testWithValue" | "workflows.rule.testWithoutValue" | "workflows.rule.testAndMore" | "workflows.test.field" | "workflows.test.operator" | "workflows.test.value" | "workflows.test.valuePlaceholder" | "workflows.test.remove" | "workflows.operator.is" | "workflows.operator.isNot" | "workflows.operator.contains" | "workflows.operator.doesNotContain" | "workflows.operator.startsWith" | "workflows.operator.endsWith" | "workflows.operator.greaterThan" | "workflows.operator.atLeast" | "workflows.operator.lessThan" | "workflows.operator.atMost" | "workflows.operator.isEmpty" | "workflows.operator.isNotEmpty" | "workflows.test.heading" | "workflows.test.help" | "workflows.test.close" | "workflows.test.start" | "workflows.test.restart" | "workflows.test.ended" | "workflows.test.noStart" | "workflows.test.noTriggers" | "workflows.test.visitorIsOn" | "workflows.test.fire" | "workflows.test.resultMoved" | "workflows.test.resultStayed" | "workflows.test.resultIgnored" | "workflows.history.heading" | "workflows.history.help" | "workflows.history.close" | "workflows.history.none" | "workflows.history.failed" | "workflows.history.version" | "workflows.history.live" | "workflows.history.by" | "workflows.history.view" | "workflows.history.viewing" | "workflows.history.backToDraft" | "workflows.history.restore" | "workflows.history.restoreTitle" | "workflows.history.restoreMessage" | "workflows.runs.help" | "workflows.runs.rangeLabel" | "workflows.runs.lastDays" | "workflows.runs.versionLabel" | "workflows.runs.allVersions" | "workflows.runs.versionLive" | "workflows.runs.started" | "workflows.runs.entered" | "workflows.runs.fired" | "workflows.runs.failed" | "workflows.runs.none" | "workflows.runs.neverPublished" | "workflows.settings.zoneHeading" | "workflows.settings.zoneLabel" | "workflows.settings.zoneHelp" | "workflows.settings.embedHeading" | "workflows.settings.embedHelp" | "workflows.settings.stateHeading" | "workflows.settings.pause" | "workflows.settings.pauseHelp" | "workflows.settings.resume" | "workflows.settings.resumeHelp" | "workflows.settings.archive" | "workflows.settings.archiveHelp" | "workflows.settings.archiveTitle" | "workflows.settings.archiveMessage" | "workflows.settings.unarchive" | "workflows.settings.unarchiveHelp" | "workflows.settings.duplicate" | "workflows.settings.duplicateHelp" | "workflows.settings.delete" | "workflows.settings.deleteHelp" | "workflows.settings.deleteBlocked" | "workflows.settings.deleteTitle" | "workflows.settings.deleteMessage" | "workflows.issue.unknown" | "workflows.issue.malformed" | "workflows.issue.schemaVersion" | "workflows.issue.graphTooLarge" | "workflows.issue.unknownNodeType" | "workflows.issue.unknownTriggerKind" | "workflows.issue.badId" | "workflows.issue.duplicateId" | "workflows.issue.tooManyBlocks" | "workflows.issue.tooManyEdges" | "workflows.issue.noComposition" | "workflows.issue.noStart" | "workflows.issue.manyStarts" | "workflows.issue.compositionMissingId" | "workflows.issue.duplicateComposition" | "workflows.issue.compositionNotAvailable" | "workflows.issue.compositionWebsiteMismatch" | "workflows.issue.unreachableBlock" | "workflows.issue.edgeUnknownNode" | "workflows.issue.edgeBadPort" | "workflows.issue.edgeInvalidConnection" | "workflows.issue.portManyTargets" | "workflows.issue.cycle" | "workflows.issue.triggerNoSource" | "workflows.issue.triggerManySources" | "workflows.issue.triggerNoTarget" | "workflows.issue.triggerConfigIncomplete" | "workflows.issue.triggerNeedsTable" | "workflows.issue.triggerNeedsAction" | "workflows.issue.triggerNeedsName" | "workflows.issue.scheduleInvalid" | "workflows.issue.eventValueInvalid" | "workflows.issue.eventTooManyValues" | "workflows.issue.triggerCapabilityMissing" | "workflows.issue.triggerInputMissing" | "workflows.issue.triggerActionMissing" | "workflows.issue.conditionNoSource" | "workflows.issue.conditionManySources" | "workflows.issue.conditionNoCases" | "workflows.issue.conditionTooManyCases" | "workflows.issue.caseBadId" | "workflows.issue.caseDuplicateId" | "workflows.issue.caseNoTests" | "workflows.issue.caseTooManyTests" | "workflows.issue.caseNoTarget" | "workflows.issue.testBadField" | "workflows.issue.testBadOperator" | "workflows.issue.testMissingValue" | "workflows.issue.fieldUnknown" | null;
|
|
36
|
+
search: string;
|
|
37
|
+
statusFilter: ListStatusFilter;
|
|
38
|
+
sortField: WorkflowSortField;
|
|
39
|
+
sortDirection: SortDirection;
|
|
40
|
+
/** Workflows something is being done to (a duplicate on its way, a state change). */
|
|
41
|
+
busyIds: ReadonlySet<string>;
|
|
42
|
+
notice: ListNotice | null;
|
|
43
|
+
/** Whether there is more of the list than is shown. */
|
|
44
|
+
hasMore: boolean;
|
|
45
|
+
/** Whether the person asked for anything that narrows the list (so "nothing" means "nothing matches", not "nothing yet"). */
|
|
46
|
+
isNarrowed: boolean;
|
|
47
|
+
private readonly api;
|
|
48
|
+
private readonly reportError;
|
|
49
|
+
private readonly searchDelay;
|
|
50
|
+
private readonly pageSize;
|
|
51
|
+
private controller;
|
|
52
|
+
private searchTimer;
|
|
53
|
+
private disposed;
|
|
54
|
+
constructor(options: WorkflowListOptions);
|
|
55
|
+
dispose(): void;
|
|
56
|
+
private buildQuery;
|
|
57
|
+
/** Reads the first page again with the search, the filter and the order as they are now. */
|
|
58
|
+
load(): Promise<void>;
|
|
59
|
+
/** Reads the next page and adds it to the end. */
|
|
60
|
+
loadMore(): Promise<void>;
|
|
61
|
+
/** The person typed in the search: ask again once they stop. */
|
|
62
|
+
setSearch(text: string): void;
|
|
63
|
+
setStatusFilter(filter: ListStatusFilter): void;
|
|
64
|
+
setSort(field: WorkflowSortField): void;
|
|
65
|
+
toggleSortDirection(): void;
|
|
66
|
+
private setBusy;
|
|
67
|
+
private runFor;
|
|
68
|
+
/** Makes a workflow (the dialog asked). Resolves to it, or to `undefined` with the reason in `createFailure`. */
|
|
69
|
+
createFailure: "workflows.region.label" | "workflows.header.title" | "workflows.header.subtitle" | "workflows.common.cancel" | "workflows.common.close" | "workflows.common.dismiss" | "workflows.common.loading" | "workflows.empty.title" | "workflows.empty.hint" | "workflows.error.title" | "workflows.error.hint" | "workflows.error.retry" | "workflows.error.generic" | "workflows.error.network" | "workflows.error.timeout" | "workflows.error.server" | "workflows.error.sessionEnded" | "workflows.error.planRestricted" | "workflows.error.notFound" | "workflows.error.revisionChanged" | "workflows.error.archived" | "workflows.error.nothingToPublish" | "workflows.error.nothingToDiscard" | "workflows.error.everPublished" | "workflows.error.wrongState" | "workflows.error.tooManyWorkflows" | "workflows.error.publishBlocked" | "workflows.error.invalidGraph" | "workflows.error.tooManyRequests" | "workflows.list.label" | "workflows.list.newWorkflow" | "workflows.list.searchLabel" | "workflows.list.searchPlaceholder" | "workflows.list.filterLabel" | "workflows.list.filterActive" | "workflows.list.filterAll" | "workflows.list.sortLabel" | "workflows.list.sortCreated" | "workflows.list.sortPublished" | "workflows.list.sortRuns" | "workflows.list.sortName" | "workflows.list.sortAscending" | "workflows.list.sortDescending" | "workflows.list.columnName" | "workflows.list.columnStatus" | "workflows.list.columnRuns" | "workflows.list.columnPublished" | "workflows.list.columnCreated" | "workflows.list.compositionsCount" | "workflows.list.runsCount" | "workflows.list.publishedOn" | "workflows.list.neverPublished" | "workflows.list.never" | "workflows.list.open" | "workflows.list.rowMenu" | "workflows.list.showMore" | "workflows.list.noMatches" | "workflows.list.duplicated" | "workflows.list.deleted" | "workflows.create.title" | "workflows.create.nameLabel" | "workflows.create.namePlaceholder" | "workflows.create.compositionLabel" | "workflows.create.compositionHelp" | "workflows.create.create" | "workflows.create.creating" | "workflows.status.draft" | "workflows.status.live" | "workflows.status.paused" | "workflows.status.archived" | "workflows.status.unpublishedChanges" | "workflows.top.back" | "workflows.top.nameLabel" | "workflows.top.testRun" | "workflows.top.history" | "workflows.top.embedCode" | "workflows.top.publish" | "workflows.top.publishChanges" | "workflows.top.publishing" | "workflows.save.saved" | "workflows.save.saving" | "workflows.save.pending" | "workflows.save.failed" | "workflows.save.conflict" | "workflows.tabs.label" | "workflows.tabs.editor" | "workflows.tabs.runs" | "workflows.tabs.settings" | "workflows.banner.unpublishedChanges" | "workflows.banner.publishChanges" | "workflows.banner.discard" | "workflows.banner.discardTitle" | "workflows.banner.discardMessage" | "workflows.banner.neverPublished" | "workflows.banner.paused" | "workflows.banner.archived" | "workflows.banner.conflict" | "workflows.banner.reload" | "workflows.banner.touchOnly" | "workflows.conflict.keepCopy" | "workflows.conflict.keepingCopy" | "workflows.conflict.copyName" | "workflows.conflict.copyKept" | "workflows.conflict.openCopy" | "workflows.conflict.loadTitle" | "workflows.conflict.loadMessage" | "workflows.presence.blockedTitleNamed" | "workflows.presence.blockedTitleYou" | "workflows.presence.blockedTitle" | "workflows.presence.blockedBody" | "workflows.presence.lostTitleNamed" | "workflows.presence.lostTitleYou" | "workflows.presence.lostTitle" | "workflows.presence.lostBody" | "workflows.presence.takeOver" | "workflows.presence.takeOverHint" | "workflows.presence.lookOnly" | "workflows.presence.lookOnlyHint" | "workflows.presence.working" | "workflows.presence.actionFailed" | "workflows.presence.readOnlyNamed" | "workflows.presence.readOnlyYou" | "workflows.presence.readOnly" | "workflows.presence.readOnlyFree" | "workflows.presence.startEditing" | "workflows.editor.published" | "workflows.editor.discarded" | "workflows.editor.restored" | "workflows.editor.reloaded" | "workflows.editor.paused" | "workflows.editor.resumed" | "workflows.editor.archived" | "workflows.editor.unarchived" | "workflows.editor.saveFirst" | "workflows.editor.fixProblems" | "workflows.editor.blockLimit" | "workflows.publish.firstTitle" | "workflows.publish.firstMessage" | "workflows.publish.changesTitle" | "workflows.publish.changesMessage" | "workflows.leave.title" | "workflows.leave.message" | "workflows.leave.confirm" | "workflows.canvas.label" | "workflows.canvas.pointIn" | "workflows.canvas.pointOut" | "workflows.toolbar.label" | "workflows.toolbar.addBlock" | "workflows.toolbar.undo" | "workflows.toolbar.redo" | "workflows.toolbar.zoomIn" | "workflows.toolbar.zoomOut" | "workflows.toolbar.fit" | "workflows.addBlock.composition" | "workflows.addBlock.helpComposition" | "workflows.addBlock.condition" | "workflows.addBlock.helpCondition" | "workflows.addBlock.triggerHeading" | "workflows.addBlock.helpInput" | "workflows.addBlock.helpAction" | "workflows.addBlock.helpPageEvent" | "workflows.addBlock.helpScheduled" | "workflows.block.startsHere" | "workflows.block.trigger" | "workflows.block.condition" | "workflows.block.unknown" | "workflows.block.compositionNotChosen" | "workflows.block.compositionLoading" | "workflows.block.compositionUnavailable" | "workflows.block.notPublished" | "workflows.block.numbered" | "workflows.block.problems" | "workflows.panel.label" | "workflows.panel.overviewHeading" | "workflows.panel.overviewHelp" | "workflows.panel.problemsHeading" | "workflows.panel.problemsLabel" | "workflows.panel.noProblems" | "workflows.panel.manyBlocksSelected" | "workflows.panel.connectionSelected" | "workflows.panel.removeBlock" | "workflows.panel.removeBlocks" | "workflows.panel.removeConnection" | "workflows.composition.heading" | "workflows.composition.help" | "workflows.composition.searchLabel" | "workflows.composition.searchPlaceholder" | "workflows.composition.none" | "workflows.composition.alreadyUsed" | "workflows.composition.isStart" | "workflows.composition.makeStart" | "workflows.composition.capabilitiesHeading" | "workflows.composition.capabilityInput" | "workflows.composition.capabilityAction" | "workflows.composition.capabilityWebsites" | "workflows.composition.inputTables" | "workflows.composition.actionCount" | "workflows.trigger.heading" | "workflows.trigger.help" | "workflows.trigger.kindLabel" | "workflows.trigger.kindInput" | "workflows.trigger.kindAction" | "workflows.trigger.kindPageEvent" | "workflows.trigger.kindScheduled" | "workflows.trigger.unavailable" | "workflows.trigger.tableLabel" | "workflows.trigger.tableHelp" | "workflows.trigger.actionLabel" | "workflows.trigger.actionHelp" | "workflows.trigger.chooseOne" | "workflows.trigger.notFound" | "workflows.trigger.readableValues" | "workflows.trigger.noReadableValues" | "workflows.trigger.nextLabel" | "workflows.trigger.nextHelp" | "workflows.trigger.nextNone" | "workflows.trigger.summaryInput" | "workflows.trigger.summaryAction" | "workflows.trigger.summaryPageEvent" | "workflows.trigger.summaryAt" | "workflows.trigger.summaryUnfinished" | "workflows.reason.widgetKeepsNoData" | "workflows.reason.widgetReportsNoActions" | "workflows.reason.widgetNotPublished" | "workflows.schedule.modeLabel" | "workflows.schedule.modeAfter" | "workflows.schedule.modeAt" | "workflows.schedule.afterHelp" | "workflows.schedule.amountLabel" | "workflows.schedule.unitLabel" | "workflows.schedule.unitSeconds" | "workflows.schedule.unitMinutes" | "workflows.schedule.unitHours" | "workflows.schedule.unitDays" | "workflows.schedule.unitWeeks" | "workflows.schedule.waitSeconds" | "workflows.schedule.waitMinutes" | "workflows.schedule.waitHours" | "workflows.schedule.waitDays" | "workflows.schedule.waitWeeks" | "workflows.schedule.momentLabel" | "workflows.schedule.momentHelp" | "workflows.schedule.invalidMoment" | "workflows.event.nameLabel" | "workflows.event.namePlaceholder" | "workflows.event.nameHelp" | "workflows.event.nameInvalid" | "workflows.event.howToSend" | "workflows.event.valuesHeading" | "workflows.event.valuesHelp" | "workflows.event.addValue" | "workflows.event.valueName" | "workflows.event.valueNamePlaceholder" | "workflows.event.valueNameInvalid" | "workflows.event.valueType" | "workflows.event.removeValue" | "workflows.fieldType.text" | "workflows.fieldType.number" | "workflows.fieldType.boolean" | "workflows.value.yes" | "workflows.value.no" | "workflows.condition.heading" | "workflows.condition.help" | "workflows.condition.noTrigger" | "workflows.condition.noValues" | "workflows.condition.addRule" | "workflows.condition.ruleLimit" | "workflows.condition.defaultName" | "workflows.condition.defaultLabel" | "workflows.condition.defaultStay" | "workflows.condition.defaultHelp" | "workflows.condition.defaultHint" | "workflows.condition.defaultStays" | "workflows.rule.defaultName" | "workflows.rule.nameLabel" | "workflows.rule.moveUp" | "workflows.rule.moveDown" | "workflows.rule.remove" | "workflows.rule.matchLabel" | "workflows.rule.matchAll" | "workflows.rule.matchAny" | "workflows.rule.noTests" | "workflows.rule.addTest" | "workflows.rule.testLimit" | "workflows.rule.thenGoTo" | "workflows.rule.testWithValue" | "workflows.rule.testWithoutValue" | "workflows.rule.testAndMore" | "workflows.test.field" | "workflows.test.operator" | "workflows.test.value" | "workflows.test.valuePlaceholder" | "workflows.test.remove" | "workflows.operator.is" | "workflows.operator.isNot" | "workflows.operator.contains" | "workflows.operator.doesNotContain" | "workflows.operator.startsWith" | "workflows.operator.endsWith" | "workflows.operator.greaterThan" | "workflows.operator.atLeast" | "workflows.operator.lessThan" | "workflows.operator.atMost" | "workflows.operator.isEmpty" | "workflows.operator.isNotEmpty" | "workflows.test.heading" | "workflows.test.help" | "workflows.test.close" | "workflows.test.start" | "workflows.test.restart" | "workflows.test.ended" | "workflows.test.noStart" | "workflows.test.noTriggers" | "workflows.test.visitorIsOn" | "workflows.test.fire" | "workflows.test.resultMoved" | "workflows.test.resultStayed" | "workflows.test.resultIgnored" | "workflows.history.heading" | "workflows.history.help" | "workflows.history.close" | "workflows.history.none" | "workflows.history.failed" | "workflows.history.version" | "workflows.history.live" | "workflows.history.by" | "workflows.history.view" | "workflows.history.viewing" | "workflows.history.backToDraft" | "workflows.history.restore" | "workflows.history.restoreTitle" | "workflows.history.restoreMessage" | "workflows.runs.help" | "workflows.runs.rangeLabel" | "workflows.runs.lastDays" | "workflows.runs.versionLabel" | "workflows.runs.allVersions" | "workflows.runs.versionLive" | "workflows.runs.started" | "workflows.runs.entered" | "workflows.runs.fired" | "workflows.runs.failed" | "workflows.runs.none" | "workflows.runs.neverPublished" | "workflows.settings.zoneHeading" | "workflows.settings.zoneLabel" | "workflows.settings.zoneHelp" | "workflows.settings.embedHeading" | "workflows.settings.embedHelp" | "workflows.settings.stateHeading" | "workflows.settings.pause" | "workflows.settings.pauseHelp" | "workflows.settings.resume" | "workflows.settings.resumeHelp" | "workflows.settings.archive" | "workflows.settings.archiveHelp" | "workflows.settings.archiveTitle" | "workflows.settings.archiveMessage" | "workflows.settings.unarchive" | "workflows.settings.unarchiveHelp" | "workflows.settings.duplicate" | "workflows.settings.duplicateHelp" | "workflows.settings.delete" | "workflows.settings.deleteHelp" | "workflows.settings.deleteBlocked" | "workflows.settings.deleteTitle" | "workflows.settings.deleteMessage" | "workflows.issue.unknown" | "workflows.issue.malformed" | "workflows.issue.schemaVersion" | "workflows.issue.graphTooLarge" | "workflows.issue.unknownNodeType" | "workflows.issue.unknownTriggerKind" | "workflows.issue.badId" | "workflows.issue.duplicateId" | "workflows.issue.tooManyBlocks" | "workflows.issue.tooManyEdges" | "workflows.issue.noComposition" | "workflows.issue.noStart" | "workflows.issue.manyStarts" | "workflows.issue.compositionMissingId" | "workflows.issue.duplicateComposition" | "workflows.issue.compositionNotAvailable" | "workflows.issue.compositionWebsiteMismatch" | "workflows.issue.unreachableBlock" | "workflows.issue.edgeUnknownNode" | "workflows.issue.edgeBadPort" | "workflows.issue.edgeInvalidConnection" | "workflows.issue.portManyTargets" | "workflows.issue.cycle" | "workflows.issue.triggerNoSource" | "workflows.issue.triggerManySources" | "workflows.issue.triggerNoTarget" | "workflows.issue.triggerConfigIncomplete" | "workflows.issue.triggerNeedsTable" | "workflows.issue.triggerNeedsAction" | "workflows.issue.triggerNeedsName" | "workflows.issue.scheduleInvalid" | "workflows.issue.eventValueInvalid" | "workflows.issue.eventTooManyValues" | "workflows.issue.triggerCapabilityMissing" | "workflows.issue.triggerInputMissing" | "workflows.issue.triggerActionMissing" | "workflows.issue.conditionNoSource" | "workflows.issue.conditionManySources" | "workflows.issue.conditionNoCases" | "workflows.issue.conditionTooManyCases" | "workflows.issue.caseBadId" | "workflows.issue.caseDuplicateId" | "workflows.issue.caseNoTests" | "workflows.issue.caseTooManyTests" | "workflows.issue.caseNoTarget" | "workflows.issue.testBadField" | "workflows.issue.testBadOperator" | "workflows.issue.testMissingValue" | "workflows.issue.fieldUnknown" | null;
|
|
70
|
+
create(input: {
|
|
71
|
+
name: string;
|
|
72
|
+
composition: CompositionOption | null;
|
|
73
|
+
}): Promise<WorkflowDetail | undefined>;
|
|
74
|
+
duplicate(workflowId: string): Promise<WorkflowDetail | undefined>;
|
|
75
|
+
changeState(workflowId: string, action: WorkflowStateAction): Promise<void>;
|
|
76
|
+
remove(workflowId: string): Promise<boolean>;
|
|
77
|
+
showNotice(tone: ListNotice['tone'], messageKey: WorkflowsMessageKey, values?: Record<string, string | number>): void;
|
|
78
|
+
dismissNotice(): void;
|
|
79
|
+
private noteFailure;
|
|
80
|
+
}
|
|
81
|
+
export declare function provideListState(state: WorkflowListState): WorkflowListState;
|
|
82
|
+
export declare function useListState(): WorkflowListState;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { WorkflowsApiError, isCancelled } from '../api/workflowsApi.js';
|
|
3
|
+
import { workflowsError, workflowsWarn } from '../utils/logger.js';
|
|
4
|
+
import { pickApiErrorMessage } from './apiErrorText.js';
|
|
5
|
+
import { detectBrowserTimeZone } from './zonedTime.js';
|
|
6
|
+
/** One page of the list is this many workflows; "Show more" reads the next. */
|
|
7
|
+
export const LIST_PAGE_SIZE = 25;
|
|
8
|
+
/** How long the list waits after the last letter typed in the search before it asks. */
|
|
9
|
+
export const SEARCH_DELAY_MILLISECONDS = 300;
|
|
10
|
+
/**
|
|
11
|
+
* The list of workflows: what is shown, how it is searched, filtered and ordered, and the things done to a workflow from
|
|
12
|
+
* its row (create, duplicate, pause, archive, delete). It asks the API for every change of the search or the order (the list
|
|
13
|
+
* can be longer than a page), and keeps the answer of the newest question only.
|
|
14
|
+
*/
|
|
15
|
+
export class WorkflowListState {
|
|
16
|
+
items = $state.raw([]);
|
|
17
|
+
total = $state(0);
|
|
18
|
+
loadState = $state('loading');
|
|
19
|
+
loadingMore = $state(false);
|
|
20
|
+
failure = $state.raw(null);
|
|
21
|
+
search = $state('');
|
|
22
|
+
statusFilter = $state('');
|
|
23
|
+
sortField = $state('createdAt');
|
|
24
|
+
sortDirection = $state('desc');
|
|
25
|
+
/** Workflows something is being done to (a duplicate on its way, a state change). */
|
|
26
|
+
// Replaced as a whole (see setBusy), never changed in place, which is what `$state.raw` watches
|
|
27
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
28
|
+
busyIds = $state.raw(new Set());
|
|
29
|
+
notice = $state.raw(null);
|
|
30
|
+
/** Whether there is more of the list than is shown. */
|
|
31
|
+
hasMore = $derived(this.items.length < this.total);
|
|
32
|
+
/** Whether the person asked for anything that narrows the list (so "nothing" means "nothing matches", not "nothing yet"). */
|
|
33
|
+
isNarrowed = $derived(this.search.trim() !== '' || this.statusFilter !== '');
|
|
34
|
+
api;
|
|
35
|
+
reportError;
|
|
36
|
+
searchDelay;
|
|
37
|
+
pageSize;
|
|
38
|
+
controller = null;
|
|
39
|
+
searchTimer = null;
|
|
40
|
+
disposed = false;
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.api = options.api;
|
|
43
|
+
this.reportError = options.reportError;
|
|
44
|
+
this.searchDelay = options.searchDelayMilliseconds ?? SEARCH_DELAY_MILLISECONDS;
|
|
45
|
+
this.pageSize = options.pageSize ?? LIST_PAGE_SIZE;
|
|
46
|
+
}
|
|
47
|
+
dispose() {
|
|
48
|
+
this.disposed = true;
|
|
49
|
+
this.controller?.abort();
|
|
50
|
+
if (this.searchTimer !== null)
|
|
51
|
+
clearTimeout(this.searchTimer);
|
|
52
|
+
this.searchTimer = null;
|
|
53
|
+
}
|
|
54
|
+
buildQuery(offset) {
|
|
55
|
+
const search = this.search.trim();
|
|
56
|
+
return {
|
|
57
|
+
...(search === '' ? {} : { search }),
|
|
58
|
+
...(this.statusFilter === '' ? {} : { status: this.statusFilter }),
|
|
59
|
+
sort: { field: this.sortField, direction: this.sortDirection },
|
|
60
|
+
limit: this.pageSize,
|
|
61
|
+
offset
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Reads the first page again with the search, the filter and the order as they are now. */
|
|
65
|
+
async load() {
|
|
66
|
+
this.controller?.abort();
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
this.controller = controller;
|
|
69
|
+
this.loadState = this.items.length === 0 ? 'loading' : this.loadState;
|
|
70
|
+
this.failure = null;
|
|
71
|
+
try {
|
|
72
|
+
const page = await this.api.listWorkflows(this.buildQuery(0), { signal: controller.signal });
|
|
73
|
+
if (controller.signal.aborted || this.disposed)
|
|
74
|
+
return;
|
|
75
|
+
this.items = page.items;
|
|
76
|
+
this.total = page.total;
|
|
77
|
+
this.loadState = 'ready';
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (isCancelled(error) || this.disposed)
|
|
81
|
+
return;
|
|
82
|
+
this.loadState = 'failed';
|
|
83
|
+
this.failure = pickApiErrorMessage(error) ?? 'workflows.error.generic';
|
|
84
|
+
this.noteFailure('Reading the list of workflows failed', error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Reads the next page and adds it to the end. */
|
|
88
|
+
async loadMore() {
|
|
89
|
+
if (this.loadingMore || !this.hasMore || this.loadState !== 'ready')
|
|
90
|
+
return;
|
|
91
|
+
this.loadingMore = true;
|
|
92
|
+
const controller = new AbortController();
|
|
93
|
+
this.controller?.abort();
|
|
94
|
+
this.controller = controller;
|
|
95
|
+
try {
|
|
96
|
+
const page = await this.api.listWorkflows(this.buildQuery(this.items.length), {
|
|
97
|
+
signal: controller.signal
|
|
98
|
+
});
|
|
99
|
+
if (controller.signal.aborted || this.disposed)
|
|
100
|
+
return;
|
|
101
|
+
// A local lookup for leaving out what the list already has, not state
|
|
102
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
103
|
+
const known = new Set(this.items.map((item) => item.id));
|
|
104
|
+
this.items = [...this.items, ...page.items.filter((item) => !known.has(item.id))];
|
|
105
|
+
this.total = page.total;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (isCancelled(error) || this.disposed)
|
|
109
|
+
return;
|
|
110
|
+
this.showNotice('problem', pickApiErrorMessage(error) ?? 'workflows.error.generic');
|
|
111
|
+
this.noteFailure('Reading more workflows failed', error);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
this.loadingMore = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** The person typed in the search: ask again once they stop. */
|
|
118
|
+
setSearch(text) {
|
|
119
|
+
this.search = text;
|
|
120
|
+
if (this.searchTimer !== null)
|
|
121
|
+
clearTimeout(this.searchTimer);
|
|
122
|
+
this.searchTimer = setTimeout(() => {
|
|
123
|
+
this.searchTimer = null;
|
|
124
|
+
void this.load();
|
|
125
|
+
}, this.searchDelay);
|
|
126
|
+
}
|
|
127
|
+
setStatusFilter(filter) {
|
|
128
|
+
if (filter === this.statusFilter)
|
|
129
|
+
return;
|
|
130
|
+
this.statusFilter = filter;
|
|
131
|
+
void this.load();
|
|
132
|
+
}
|
|
133
|
+
setSort(field) {
|
|
134
|
+
this.sortField = field;
|
|
135
|
+
void this.load();
|
|
136
|
+
}
|
|
137
|
+
toggleSortDirection() {
|
|
138
|
+
this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
|
|
139
|
+
void this.load();
|
|
140
|
+
}
|
|
141
|
+
// ---- things done to a workflow -------------------------------------------------------------------------------
|
|
142
|
+
setBusy(workflowId, isBusy) {
|
|
143
|
+
// A copy that is changed and then handed over whole: the old set is never touched
|
|
144
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
145
|
+
const next = new Set(this.busyIds);
|
|
146
|
+
if (isBusy)
|
|
147
|
+
next.add(workflowId);
|
|
148
|
+
else
|
|
149
|
+
next.delete(workflowId);
|
|
150
|
+
this.busyIds = next;
|
|
151
|
+
}
|
|
152
|
+
async runFor(workflowId, action, whatFailed) {
|
|
153
|
+
if (this.busyIds.has(workflowId))
|
|
154
|
+
return undefined;
|
|
155
|
+
this.setBusy(workflowId, true);
|
|
156
|
+
try {
|
|
157
|
+
return await action();
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (isCancelled(error))
|
|
161
|
+
return undefined;
|
|
162
|
+
this.showNotice('problem', pickApiErrorMessage(error) ?? 'workflows.error.generic');
|
|
163
|
+
this.noteFailure(whatFailed, error);
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
this.setBusy(workflowId, false);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** Makes a workflow (the dialog asked). Resolves to it, or to `undefined` with the reason in `createFailure`. */
|
|
171
|
+
createFailure = $state.raw(null);
|
|
172
|
+
async create(input) {
|
|
173
|
+
this.createFailure = null;
|
|
174
|
+
try {
|
|
175
|
+
const created = await this.api.createWorkflow({
|
|
176
|
+
name: input.name,
|
|
177
|
+
compositionId: input.composition?.id ?? null,
|
|
178
|
+
timezone: detectBrowserTimeZone()
|
|
179
|
+
});
|
|
180
|
+
return created;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (isCancelled(error))
|
|
184
|
+
return undefined;
|
|
185
|
+
this.createFailure = pickApiErrorMessage(error) ?? 'workflows.error.generic';
|
|
186
|
+
this.noteFailure('Creating the workflow failed', error);
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async duplicate(workflowId) {
|
|
191
|
+
const copy = await this.runFor(workflowId, () => this.api.duplicateWorkflow(workflowId), 'Duplicating failed');
|
|
192
|
+
if (copy) {
|
|
193
|
+
this.showNotice('info', 'workflows.list.duplicated');
|
|
194
|
+
await this.load();
|
|
195
|
+
}
|
|
196
|
+
return copy;
|
|
197
|
+
}
|
|
198
|
+
async changeState(workflowId, action) {
|
|
199
|
+
const updated = await this.runFor(workflowId, () => this.api.changeState(workflowId, action), 'Changing the state failed');
|
|
200
|
+
if (!updated)
|
|
201
|
+
return;
|
|
202
|
+
// Archived workflows leave the default list, and a restored one joins it, so read the list again.
|
|
203
|
+
await this.load();
|
|
204
|
+
}
|
|
205
|
+
async remove(workflowId) {
|
|
206
|
+
const done = await this.runFor(workflowId, async () => {
|
|
207
|
+
await this.api.deleteWorkflow(workflowId);
|
|
208
|
+
return true;
|
|
209
|
+
}, 'Deleting failed');
|
|
210
|
+
if (!done)
|
|
211
|
+
return false;
|
|
212
|
+
this.items = this.items.filter((item) => item.id !== workflowId);
|
|
213
|
+
this.total = Math.max(0, this.total - 1);
|
|
214
|
+
this.showNotice('info', 'workflows.list.deleted');
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
showNotice(tone, messageKey, values) {
|
|
218
|
+
this.notice = { tone, messageKey, values };
|
|
219
|
+
}
|
|
220
|
+
dismissNotice() {
|
|
221
|
+
this.notice = null;
|
|
222
|
+
}
|
|
223
|
+
noteFailure(what, error) {
|
|
224
|
+
if (isCancelled(error))
|
|
225
|
+
return;
|
|
226
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
227
|
+
workflowsError(`${what}: ${detail}`, error);
|
|
228
|
+
const sessionEnded = error instanceof WorkflowsApiError && error.sessionEnded;
|
|
229
|
+
try {
|
|
230
|
+
this.reportError({
|
|
231
|
+
message: `${what}: ${detail}`,
|
|
232
|
+
code: sessionEnded ? 'SESSION_ENDED' : 'REQUEST_FAILED',
|
|
233
|
+
fatal: false
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (handlerError) {
|
|
237
|
+
workflowsWarn('The onError handler of the page threw.', handlerError);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const LIST_STATE_KEY = Symbol('workflows-list-state');
|
|
242
|
+
export function provideListState(state) {
|
|
243
|
+
return setContext(LIST_STATE_KEY, state);
|
|
244
|
+
}
|
|
245
|
+
export function useListState() {
|
|
246
|
+
const state = getContext(LIST_STATE_KEY);
|
|
247
|
+
if (!state)
|
|
248
|
+
throw new Error('[Workflows] A part of the list was drawn outside the list.');
|
|
249
|
+
return state;
|
|
250
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { WorkflowStats } from '../api/types.js';
|
|
2
|
+
/** The longest range the API answers for: a year and a day (a leap year's days). */
|
|
3
|
+
export declare const MAX_RANGE_DAYS = 366;
|
|
4
|
+
/** The ranges the Runs tab offers, in days. */
|
|
5
|
+
export declare const RANGE_CHOICES_IN_DAYS: readonly number[];
|
|
6
|
+
/**
|
|
7
|
+
* The days a stats request covers: the last `days` days with today included, written `YYYY-MM-DD` as the API wants them.
|
|
8
|
+
* The API counts in UTC days, so the range is in UTC days too: what the person sees as "today" can be a day behind or ahead
|
|
9
|
+
* of it for a few hours, which the counts' own wording ("days (UTC)") tells.
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeStatsRange(days: number, now?: Date): {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
};
|
|
15
|
+
/** What the Runs canvas shows: a number for every block and line by its id. A block nobody entered is 0, not missing. */
|
|
16
|
+
export interface RunCounts {
|
|
17
|
+
/** Visitors who started the workflow in the range, or `null` when the counts cover every version. */
|
|
18
|
+
started: number | null;
|
|
19
|
+
entered: ReadonlyMap<string, number>;
|
|
20
|
+
followed: ReadonlyMap<string, number>;
|
|
21
|
+
failed: ReadonlyMap<string, number>;
|
|
22
|
+
/** The most visitors that reached any one block: the busiest block sets the scale of the story. */
|
|
23
|
+
busiest: number;
|
|
24
|
+
}
|
|
25
|
+
/** Turns the API's lists (ids are values, never keys) into lookups the blocks and lines ask by id. */
|
|
26
|
+
export declare function readRunCounts(stats: WorkflowStats): RunCounts;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const ONE_DAY_MILLISECONDS = 24 * 60 * 60 * 1000;
|
|
2
|
+
/** The longest range the API answers for: a year and a day (a leap year's days). */
|
|
3
|
+
export const MAX_RANGE_DAYS = 366;
|
|
4
|
+
/** The ranges the Runs tab offers, in days. */
|
|
5
|
+
export const RANGE_CHOICES_IN_DAYS = [7, 30, 90, 365];
|
|
6
|
+
/**
|
|
7
|
+
* The days a stats request covers: the last `days` days with today included, written `YYYY-MM-DD` as the API wants them.
|
|
8
|
+
* The API counts in UTC days, so the range is in UTC days too: what the person sees as "today" can be a day behind or ahead
|
|
9
|
+
* of it for a few hours, which the counts' own wording ("days (UTC)") tells.
|
|
10
|
+
*/
|
|
11
|
+
export function makeStatsRange(days, now = new Date()) {
|
|
12
|
+
const wholeDays = Number.isFinite(days)
|
|
13
|
+
? Math.min(MAX_RANGE_DAYS, Math.max(1, Math.floor(days)))
|
|
14
|
+
: 30;
|
|
15
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
16
|
+
const first = today - (wholeDays - 1) * ONE_DAY_MILLISECONDS;
|
|
17
|
+
return {
|
|
18
|
+
from: new Date(first).toISOString().slice(0, 10),
|
|
19
|
+
to: new Date(today).toISOString().slice(0, 10)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function toLookup(items) {
|
|
23
|
+
const lookup = new Map();
|
|
24
|
+
for (const item of items)
|
|
25
|
+
lookup.set(item.id, (lookup.get(item.id) ?? 0) + item.total);
|
|
26
|
+
return lookup;
|
|
27
|
+
}
|
|
28
|
+
/** Turns the API's lists (ids are values, never keys) into lookups the blocks and lines ask by id. */
|
|
29
|
+
export function readRunCounts(stats) {
|
|
30
|
+
const entered = toLookup(stats.nodes);
|
|
31
|
+
let busiest = 0;
|
|
32
|
+
for (const total of entered.values())
|
|
33
|
+
busiest = Math.max(busiest, total);
|
|
34
|
+
return {
|
|
35
|
+
started: stats.started,
|
|
36
|
+
entered,
|
|
37
|
+
followed: toLookup(stats.edges),
|
|
38
|
+
failed: toLookup(stats.failed),
|
|
39
|
+
busiest
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CompositionNode, FieldValue, Signal, TriggerNode, WorkflowGraph } from '@widgetic/workflows-engine';
|
|
2
|
+
/** Where the test visitor is, and the trail they left. */
|
|
3
|
+
export interface TestRunState {
|
|
4
|
+
/** The composition block the visitor is on; `null` when the workflow has no start to begin from. */
|
|
5
|
+
currentNodeId: string | null;
|
|
6
|
+
/** Every composition the visitor was on, in order, the start included. */
|
|
7
|
+
visitedNodeIds: string[];
|
|
8
|
+
/** Every block and connection the visitor passed, for the highlight on the canvas. */
|
|
9
|
+
passedNodeIds: string[];
|
|
10
|
+
takenEdgeIds: string[];
|
|
11
|
+
/** What the last trigger did, for the line under the list of triggers; `null` before any. */
|
|
12
|
+
lastResult: TestRunResult | null;
|
|
13
|
+
}
|
|
14
|
+
/** What firing a trigger did, in terms a screen can say. */
|
|
15
|
+
export type TestRunResult = {
|
|
16
|
+
outcome: 'moved';
|
|
17
|
+
fromNodeId: string;
|
|
18
|
+
toNodeId: string;
|
|
19
|
+
} | {
|
|
20
|
+
outcome: 'stayed';
|
|
21
|
+
} | {
|
|
22
|
+
outcome: 'ignored';
|
|
23
|
+
};
|
|
24
|
+
/** Begins a test at the start composition. */
|
|
25
|
+
export declare function startTestRun(graph: WorkflowGraph): TestRunState;
|
|
26
|
+
/** The triggers hanging off the composition the test visitor is on. */
|
|
27
|
+
export declare function listTriggersOfCurrent(graph: WorkflowGraph, state: TestRunState): TriggerNode[];
|
|
28
|
+
/**
|
|
29
|
+
* What the visitor's browser would tell the workflow when this trigger fires: a new row for an Input added trigger (with the
|
|
30
|
+
* values the person typed for the test), a goal for an Action, the page's event, the clock for a Scheduled one.
|
|
31
|
+
*/
|
|
32
|
+
export declare function makeSignalFor(trigger: TriggerNode, values: Record<string, FieldValue>): Signal;
|
|
33
|
+
/** Fires one trigger for the test visitor and returns where they are after it. The state that came in is not changed. */
|
|
34
|
+
export declare function fireTestTrigger(graph: WorkflowGraph, state: TestRunState, trigger: TriggerNode, values?: Record<string, FieldValue>): TestRunState;
|
|
35
|
+
/** The composition blocks of the graph by id, for the screen that names where the visitor is. */
|
|
36
|
+
export declare function findCompositionBlock(graph: WorkflowGraph, nodeId: string | null): CompositionNode | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor's Test run: a person plays a visitor on the draft, fires a trigger, and sees where the visitor goes. Nothing is
|
|
3
|
+
* recorded and nothing leaves the screen. It is the engine's own `advance` (the very function the embed runs), so what the
|
|
4
|
+
* test shows is what a visitor gets.
|
|
5
|
+
*/
|
|
6
|
+
import { advance, buildGraphIndex, findStartNode, listTriggersOf } from '@widgetic/workflows-engine';
|
|
7
|
+
/** Begins a test at the start composition. */
|
|
8
|
+
export function startTestRun(graph) {
|
|
9
|
+
const start = findStartNode(graph);
|
|
10
|
+
return {
|
|
11
|
+
currentNodeId: start?.id ?? null,
|
|
12
|
+
visitedNodeIds: start ? [start.id] : [],
|
|
13
|
+
passedNodeIds: [],
|
|
14
|
+
takenEdgeIds: [],
|
|
15
|
+
lastResult: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The triggers hanging off the composition the test visitor is on. */
|
|
19
|
+
export function listTriggersOfCurrent(graph, state) {
|
|
20
|
+
if (state.currentNodeId === null)
|
|
21
|
+
return [];
|
|
22
|
+
return listTriggersOf(buildGraphIndex(graph), state.currentNodeId);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What the visitor's browser would tell the workflow when this trigger fires: a new row for an Input added trigger (with the
|
|
26
|
+
* values the person typed for the test), a goal for an Action, the page's event, the clock for a Scheduled one.
|
|
27
|
+
*/
|
|
28
|
+
export function makeSignalFor(trigger, values) {
|
|
29
|
+
const config = trigger.trigger;
|
|
30
|
+
switch (config.kind) {
|
|
31
|
+
case 'input':
|
|
32
|
+
return { type: 'input', table: config.table, values };
|
|
33
|
+
case 'action':
|
|
34
|
+
return { type: 'action', actionId: config.actionId };
|
|
35
|
+
case 'pageEvent':
|
|
36
|
+
return { type: 'pageEvent', name: config.name, values };
|
|
37
|
+
case 'scheduled':
|
|
38
|
+
return { type: 'scheduled', triggerId: trigger.id };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function describe(result, fromNodeId) {
|
|
42
|
+
if (result.outcome === 'moved')
|
|
43
|
+
return { outcome: 'moved', fromNodeId, toNodeId: result.position.nodeId };
|
|
44
|
+
return result.outcome === 'stayed' ? { outcome: 'stayed' } : { outcome: 'ignored' };
|
|
45
|
+
}
|
|
46
|
+
/** Fires one trigger for the test visitor and returns where they are after it. The state that came in is not changed. */
|
|
47
|
+
export function fireTestTrigger(graph, state, trigger, values = {}) {
|
|
48
|
+
if (state.currentNodeId === null)
|
|
49
|
+
return state;
|
|
50
|
+
const result = advance(graph, { nodeId: state.currentNodeId }, makeSignalFor(trigger, values));
|
|
51
|
+
const lastResult = describe(result, state.currentNodeId);
|
|
52
|
+
if (result.outcome !== 'moved')
|
|
53
|
+
return { ...state, lastResult };
|
|
54
|
+
// The engine reports the connections from the trigger on; the one that led from the composition to the trigger comes first.
|
|
55
|
+
const edgeIntoTrigger = graph.edges.find((edge) => edge.source === state.currentNodeId && edge.target === result.firedTriggerId);
|
|
56
|
+
return {
|
|
57
|
+
currentNodeId: result.position.nodeId,
|
|
58
|
+
visitedNodeIds: [...state.visitedNodeIds, result.position.nodeId],
|
|
59
|
+
passedNodeIds: [...state.passedNodeIds, ...result.passedNodeIds],
|
|
60
|
+
takenEdgeIds: [
|
|
61
|
+
...state.takenEdgeIds,
|
|
62
|
+
...(edgeIntoTrigger ? [edgeIntoTrigger.id] : []),
|
|
63
|
+
...result.takenEdgeIds
|
|
64
|
+
],
|
|
65
|
+
lastResult
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** The composition blocks of the graph by id, for the screen that names where the visitor is. */
|
|
69
|
+
export function findCompositionBlock(graph, nodeId) {
|
|
70
|
+
if (nodeId === null)
|
|
71
|
+
return undefined;
|
|
72
|
+
const node = graph.nodes.find((candidate) => candidate.id === nodeId);
|
|
73
|
+
return node?.type === 'composition' ? node : undefined;
|
|
74
|
+
}
|