@burdenoff/microfe-calendar 2026.1124.1 → 2026.1124.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/generated/wspace-operations.d.ts +189 -0
  2. package/dist/generated/wspace-operations.js +63 -2
  3. package/dist/generated/wspace-operations.js.map +1 -1
  4. package/dist/generated/wspace-types.d.ts +1243 -10
  5. package/dist/hooks/useSafePermissions.js.map +1 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/providers/CalendarProvider.d.ts +3 -1
  8. package/dist/providers/CalendarProvider.js +12 -10
  9. package/dist/providers/CalendarProvider.js.map +1 -1
  10. package/dist/translations/en.d.ts +60 -1
  11. package/dist/types/index.d.ts +9 -0
  12. package/dist/v2/CalendarPageV2.js +44 -39
  13. package/dist/v2/CalendarPageV2.js.map +1 -1
  14. package/dist/v2/grid/GridParts.js +100 -94
  15. package/dist/v2/grid/GridParts.js.map +1 -1
  16. package/dist/v2/grid/TimeGrid.js +98 -89
  17. package/dist/v2/grid/TimeGrid.js.map +1 -1
  18. package/dist/v2/list/ListViewV2.d.ts +6 -2
  19. package/dist/v2/list/ListViewV2.js +50 -44
  20. package/dist/v2/list/ListViewV2.js.map +1 -1
  21. package/dist/v2/month/MonthView.js +130 -126
  22. package/dist/v2/month/MonthView.js.map +1 -1
  23. package/dist/v2/rail/CalendarRail.js +54 -80
  24. package/dist/v2/rail/CalendarRail.js.map +1 -1
  25. package/dist/v2/runs/RunPeek.d.ts +2 -0
  26. package/dist/v2/runs/RunPeek.js +382 -0
  27. package/dist/v2/runs/RunPeek.js.map +1 -0
  28. package/dist/v2/runs/RunPills.d.ts +28 -0
  29. package/dist/v2/runs/RunPills.js +179 -0
  30. package/dist/v2/runs/RunPills.js.map +1 -0
  31. package/dist/v2/runs/RunRows.d.ts +21 -0
  32. package/dist/v2/runs/RunRows.js +140 -0
  33. package/dist/v2/runs/RunRows.js.map +1 -0
  34. package/dist/v2/runs/RunsNotices.d.ts +1 -0
  35. package/dist/v2/runs/RunsNotices.js +37 -0
  36. package/dist/v2/runs/RunsNotices.js.map +1 -0
  37. package/dist/v2/runs/RunsSwitch.d.ts +1 -0
  38. package/dist/v2/runs/RunsSwitch.js +54 -0
  39. package/dist/v2/runs/RunsSwitch.js.map +1 -0
  40. package/dist/v2/runs/WorkflowRunsLayer.d.ts +4 -0
  41. package/dist/v2/runs/WorkflowRunsLayer.js +82 -0
  42. package/dist/v2/runs/WorkflowRunsLayer.js.map +1 -0
  43. package/dist/v2/runs/runAccess.d.ts +37 -0
  44. package/dist/v2/runs/runAccess.js +14 -0
  45. package/dist/v2/runs/runAccess.js.map +1 -0
  46. package/dist/v2/runs/runLayout.d.ts +76 -0
  47. package/dist/v2/runs/runLayout.js +129 -0
  48. package/dist/v2/runs/runLayout.js.map +1 -0
  49. package/dist/v2/runs/runLinks.d.ts +32 -0
  50. package/dist/v2/runs/runLinks.js +50 -0
  51. package/dist/v2/runs/runLinks.js.map +1 -0
  52. package/dist/v2/runs/runModel.d.ts +97 -0
  53. package/dist/v2/runs/runModel.js +132 -0
  54. package/dist/v2/runs/runModel.js.map +1 -0
  55. package/dist/v2/runs/runPeekState.d.ts +53 -0
  56. package/dist/v2/runs/runPeekState.js +62 -0
  57. package/dist/v2/runs/runPeekState.js.map +1 -0
  58. package/dist/v2/runs/runTypes.d.ts +60 -0
  59. package/dist/v2/runs/runWords.d.ts +23 -0
  60. package/dist/v2/runs/runWords.js +83 -0
  61. package/dist/v2/runs/runWords.js.map +1 -0
  62. package/dist/v2/runs/runsLayerContext.d.ts +26 -0
  63. package/dist/v2/runs/runsLayerContext.js +33 -0
  64. package/dist/v2/runs/runsLayerContext.js.map +1 -0
  65. package/dist/v2/runs/useRunHrefs.d.ts +10 -0
  66. package/dist/v2/runs/useRunHrefs.js +60 -0
  67. package/dist/v2/runs/useRunHrefs.js.map +1 -0
  68. package/dist/v2/runs/useRunLabels.d.ts +6 -0
  69. package/dist/v2/runs/useRunLabels.js +27 -0
  70. package/dist/v2/runs/useRunLabels.js.map +1 -0
  71. package/dist/v2/runs/useRunsAccess.d.ts +2 -0
  72. package/dist/v2/runs/useRunsAccess.js +14 -0
  73. package/dist/v2/runs/useRunsAccess.js.map +1 -0
  74. package/dist/v2/runs/useWorkflowRuns.d.ts +61 -0
  75. package/dist/v2/runs/useWorkflowRuns.js +119 -0
  76. package/dist/v2/runs/useWorkflowRuns.js.map +1 -0
  77. package/package.json +1 -1
@@ -0,0 +1,129 @@
1
+ import { instantToZoned as e } from "../time/calendarTime.js";
2
+ var t = {
3
+ succeeded: 0,
4
+ failed: 0,
5
+ retrying: 0,
6
+ running: 0,
7
+ ended: 0,
8
+ overdue: 0,
9
+ scheduled: 0
10
+ }, n = [
11
+ "failed",
12
+ "retrying",
13
+ "overdue",
14
+ "running"
15
+ ];
16
+ function r(e) {
17
+ let r = { ...t };
18
+ for (let t of e) r[t.status] += 1;
19
+ let i = n.find((e) => r[e] > 0), a;
20
+ return a = i || (r.succeeded > 0 ? "succeeded" : r.ended > 0 ? "ended" : "scheduled"), {
21
+ total: e.length,
22
+ counts: r,
23
+ status: a
24
+ };
25
+ }
26
+ function i(e) {
27
+ if (e.length < 3) return null;
28
+ let t = e.map((e) => (e.fireAt ?? e.at).getTime()).sort((e, t) => e - t), n = null;
29
+ for (let e = 1; e < t.length; e += 1) {
30
+ let r = Math.round(((t[e] ?? 0) - (t[e - 1] ?? 0)) / 6e4);
31
+ if (r <= 0 || n !== null && r !== n) return null;
32
+ n = r;
33
+ }
34
+ return n;
35
+ }
36
+ function a(t, n, a) {
37
+ let o = new Set(n), s = /* @__PURE__ */ new Map();
38
+ for (let n of t) {
39
+ let { date: t } = e(n.at, a);
40
+ if (!o.has(t)) continue;
41
+ let r = s.get(t);
42
+ r || (r = /* @__PURE__ */ new Map(), s.set(t, r));
43
+ let i = r.get(n.scheduledJobId);
44
+ i ? i.push(n) : r.set(n.scheduledJobId, [n]);
45
+ }
46
+ let c = /* @__PURE__ */ new Map();
47
+ for (let t of n) {
48
+ let n = s.get(t);
49
+ if (!n) continue;
50
+ let o = [], l = [], u = [];
51
+ for (let [s, c] of n) {
52
+ if (u.push(...c), c.length <= 4) {
53
+ l.push(...c);
54
+ continue;
55
+ }
56
+ let n = [...c].sort((e, t) => e.at.getTime() - t.at.getTime()), d = n[0], f = n[n.length - 1];
57
+ d && f && o.push({
58
+ key: `${s}|${t}`,
59
+ scheduledJobId: s,
60
+ day: t,
61
+ name: d.name,
62
+ runs: n,
63
+ everyMinutes: i(n),
64
+ firstMinute: e(d.at, a).minutes,
65
+ lastMinute: e(f.at, a).minutes,
66
+ summary: r(n)
67
+ });
68
+ }
69
+ o.sort((e, t) => e.firstMinute - t.firstMinute || e.name.localeCompare(t.name)), l.sort((e, t) => e.at.getTime() - t.at.getTime() || e.name.localeCompare(t.name)), c.set(t, {
70
+ day: t,
71
+ groups: o,
72
+ single: l,
73
+ total: u.length,
74
+ summary: r(u)
75
+ });
76
+ }
77
+ return c;
78
+ }
79
+ function o(t, n, i) {
80
+ let a = [];
81
+ for (let r of t) {
82
+ let t = e(r.at, n).minutes, o = a[a.length - 1];
83
+ o && t < o.minute + i ? o.runs.push(r) : a.push({
84
+ minute: t,
85
+ runs: [r]
86
+ });
87
+ }
88
+ return a.map((e) => ({
89
+ ...e,
90
+ summary: r(e.runs)
91
+ }));
92
+ }
93
+ function s(e, t, n) {
94
+ let r = [], i = [];
95
+ for (let t of e) {
96
+ let e = n(t);
97
+ e === null ? r.push({
98
+ kind: "event",
99
+ event: t
100
+ }) : i.push({
101
+ at: e,
102
+ rank: 0,
103
+ item: {
104
+ kind: "event",
105
+ event: t
106
+ }
107
+ });
108
+ }
109
+ for (let e of t?.groups ?? []) i.push({
110
+ at: e.runs[0]?.at.getTime() ?? 0,
111
+ rank: 1,
112
+ item: {
113
+ kind: "group",
114
+ group: e
115
+ }
116
+ });
117
+ for (let e of t?.single ?? []) i.push({
118
+ at: e.at.getTime(),
119
+ rank: 1,
120
+ item: {
121
+ kind: "run",
122
+ run: e
123
+ }
124
+ });
125
+ return i.sort((e, t) => e.at - t.at || e.rank - t.rank), [...r, ...i.map((e) => e.item)];
126
+ }
127
+ export { o as clusterRuns, s as dayItems, i as evenGapMinutes, a as runsByDay, r as summarizeRuns };
128
+
129
+ //# sourceMappingURL=runLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runLayout.js","names":["NO_COUNTS","ATTENTION","summarizeRuns","counts","run","runs","first","status","evenGapMinutes","times","a","b","gap","index","minutes","runsByDay","shown","days","byDay","instantToZoned","timeZone","date","bySchedule","list","result","day","groups","single","all","scheduledJobId","sorted","last","clusterRuns","clusters","minute","current","pillMinutes","cluster","dayItems","allDay","timed","event","events","start","startOf","group","entry"],"sources":["../../../src/v2/runs/runLayout.ts"],"sourcesContent":["/**\n * Where the workflow runs layer's runs show (BOFF-15698 B5). Pure.\n *\n * - **A busy schedule is one item a day.** A schedule that runs more than `FEW_RUNS_PER_DAY`\n * times on a day (one every 20 minutes runs 72 times) shows as one item for that day: its\n * name, how often, how many, and how they went. It opens the day's runs. Others show run by\n * run.\n * - **Pills that would overlap in the grid share one**, \"3 runs\", which opens them.\n * - **One status stands for many:** a failure first, then a retry, an overdue run, a running\n * one; else succeeded when any has run, else scheduled.\n */\nimport type { DateValue } from '@burdenoff/fe-libs/ui';\nimport { instantToZoned } from '../time/calendarTime';\nimport type { RunStatus, WorkflowRun } from './runModel';\n\n/** The most runs a schedule shows one by one on a day; more show as one item. */\nexport const FEW_RUNS_PER_DAY = 4;\n\n/** A busy schedule's runs on one day. */\nexport interface RunGroup {\n /** `<schedule>|<day>` */\n key: string;\n scheduledJobId: string;\n day: DateValue;\n name: string;\n /** In time order. */\n runs: WorkflowRun[];\n /** The minutes between its runs when they are evenly apart (every 20 minutes); else null. */\n everyMinutes: number | null;\n /** Minutes after midnight of its first and last run. */\n firstMinute: number;\n lastMinute: number;\n summary: RunSummary;\n}\n\nexport interface RunSummary {\n total: number;\n counts: Readonly<Record<RunStatus, number>>;\n /** The one status a group or a shared pill shows. */\n status: RunStatus;\n}\n\n/** One day's runs: busy schedules as groups, the rest one by one. */\nexport interface DayRuns {\n day: DateValue;\n groups: RunGroup[];\n /** In time order. */\n single: WorkflowRun[];\n /** Every run of the day, groups' included. */\n total: number;\n summary: RunSummary;\n}\n\n/** Runs that share a pill in the grid: one, or several close together. */\nexport interface RunCluster {\n /** Minutes after midnight of its first run. */\n minute: number;\n runs: WorkflowRun[];\n summary: RunSummary;\n}\n\nconst NO_COUNTS: Readonly<Record<RunStatus, number>> = {\n succeeded: 0,\n failed: 0,\n retrying: 0,\n running: 0,\n ended: 0,\n overdue: 0,\n scheduled: 0,\n};\n\n/** The order a summary's status is picked in: what needs a look first. */\nconst ATTENTION: readonly RunStatus[] = ['failed', 'retrying', 'overdue', 'running'];\n\nexport function summarizeRuns(runs: readonly WorkflowRun[]): RunSummary {\n const counts: Record<RunStatus, number> = { ...NO_COUNTS };\n for (const run of runs) counts[run.status] += 1;\n const first = ATTENTION.find((status) => counts[status] > 0);\n let status: RunStatus;\n if (first) status = first;\n else if (counts.succeeded > 0) status = 'succeeded';\n else if (counts.ended > 0) status = 'ended';\n else status = 'scheduled';\n return { total: runs.length, counts, status };\n}\n\n/**\n * The minutes between a schedule's runs when they are all the same apart (to the minute), for\n * three runs or more; else null.\n */\nexport function evenGapMinutes(runs: readonly WorkflowRun[]): number | null {\n if (runs.length < 3) return null;\n const times = runs.map((run) => (run.fireAt ?? run.at).getTime()).sort((a, b) => a - b);\n let gap: number | null = null;\n for (let index = 1; index < times.length; index += 1) {\n const minutes = Math.round(((times[index] ?? 0) - (times[index - 1] ?? 0)) / 60_000);\n if (minutes <= 0 || (gap !== null && minutes !== gap)) return null;\n gap = minutes;\n }\n return gap;\n}\n\n/**\n * The shown days' runs, by day on the clock of `timeZone`. A schedule with more than\n * `FEW_RUNS_PER_DAY` runs on a day is a group that day.\n */\nexport function runsByDay(\n runs: readonly WorkflowRun[],\n days: readonly DateValue[],\n timeZone: string\n): Map<DateValue, DayRuns> {\n const shown = new Set(days);\n const byDay = new Map<DateValue, Map<string, WorkflowRun[]>>();\n for (const run of runs) {\n const { date } = instantToZoned(run.at, timeZone);\n if (!shown.has(date)) continue;\n let bySchedule = byDay.get(date);\n if (!bySchedule) {\n bySchedule = new Map();\n byDay.set(date, bySchedule);\n }\n const list = bySchedule.get(run.scheduledJobId);\n if (list) list.push(run);\n else bySchedule.set(run.scheduledJobId, [run]);\n }\n\n const result = new Map<DateValue, DayRuns>();\n for (const day of days) {\n const bySchedule = byDay.get(day);\n if (!bySchedule) continue;\n const groups: RunGroup[] = [];\n const single: WorkflowRun[] = [];\n const all: WorkflowRun[] = [];\n for (const [scheduledJobId, list] of bySchedule) {\n all.push(...list);\n if (list.length <= FEW_RUNS_PER_DAY) {\n single.push(...list);\n continue;\n }\n const sorted = [...list].sort((a, b) => a.at.getTime() - b.at.getTime());\n const first = sorted[0];\n const last = sorted[sorted.length - 1];\n if (!first || !last) continue;\n groups.push({\n key: `${scheduledJobId}|${day}`,\n scheduledJobId,\n day,\n name: first.name,\n runs: sorted,\n everyMinutes: evenGapMinutes(sorted),\n firstMinute: instantToZoned(first.at, timeZone).minutes,\n lastMinute: instantToZoned(last.at, timeZone).minutes,\n summary: summarizeRuns(sorted),\n });\n }\n groups.sort((a, b) => a.firstMinute - b.firstMinute || a.name.localeCompare(b.name));\n single.sort((a, b) => a.at.getTime() - b.at.getTime() || a.name.localeCompare(b.name));\n result.set(day, { day, groups, single, total: all.length, summary: summarizeRuns(all) });\n }\n return result;\n}\n\n/**\n * A day's single runs as grid pills: a run within `pillMinutes` of the pill before it joins\n * that pill, so no two pills overlap.\n */\nexport function clusterRuns(\n runs: readonly WorkflowRun[],\n timeZone: string,\n pillMinutes: number\n): RunCluster[] {\n const clusters: { minute: number; runs: WorkflowRun[] }[] = [];\n for (const run of runs) {\n const minute = instantToZoned(run.at, timeZone).minutes;\n const current = clusters[clusters.length - 1];\n if (current && minute < current.minute + pillMinutes) current.runs.push(run);\n else clusters.push({ minute, runs: [run] });\n }\n return clusters.map((cluster) => ({ ...cluster, summary: summarizeRuns(cluster.runs) }));\n}\n\n/** One line of a day's list: an event, a run, or a busy schedule's day. */\nexport type DayItem<E> =\n | { kind: 'event'; event: E }\n | { kind: 'run'; run: WorkflowRun }\n | { kind: 'group'; group: RunGroup };\n\n/**\n * A day's list with its runs (the List view, phones' Month): all-day events first, then\n * timed events, runs and busy schedules by time (a busy schedule at its first run), an event\n * before a run at the same time. `startOf` is an event's start, null for an all-day one.\n */\nexport function dayItems<E>(\n events: readonly E[],\n runs: DayRuns | undefined,\n startOf: (event: E) => number | null\n): DayItem<E>[] {\n const allDay: DayItem<E>[] = [];\n const timed: { at: number; rank: number; item: DayItem<E> }[] = [];\n for (const event of events) {\n const start = startOf(event);\n if (start === null) allDay.push({ kind: 'event', event });\n else timed.push({ at: start, rank: 0, item: { kind: 'event', event } });\n }\n for (const group of runs?.groups ?? []) {\n timed.push({ at: group.runs[0]?.at.getTime() ?? 0, rank: 1, item: { kind: 'group', group } });\n }\n for (const run of runs?.single ?? []) {\n timed.push({ at: run.at.getTime(), rank: 1, item: { kind: 'run', run } });\n }\n // Stable: items at the same time keep the order they came in.\n timed.sort((a, b) => a.at - b.at || a.rank - b.rank);\n return [...allDay, ...timed.map((entry) => entry.item)];\n}\n"],"mappings":";AA6DA,IAAMA,IAAiD;CACrD,WAAW;CACX,QAAQ;CACR,UAAU;CACV,SAAS;CACT,OAAO;CACP,SAAS;CACT,WAAW;AACb,GAGMC,IAAkC;CAAC;CAAU;CAAY;CAAW;AAAS;AAEnF,SAAgBC,EAAc,GAA0C;CACtE,IAAMC,IAAoC,EAAE,GAAGH,EAAU;CACzD,KAAK,IAAMI,KAAOC,GAAM,EAAOD,EAAI,WAAW;CAC9C,IAAME,IAAQL,EAAU,MAAM,MAAWE,EAAOI,KAAU,CAAC,GACvDA;CAKJ,OAJA,AAGKA,IAHDD,MACKH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ASC,EAAQ,SAASC,IAAaD,EAAQ,KAAK,KAAK/B,CAAG,IACtE6B,EAAS,KAAK;GAAE;GAAQ,MAAM,CAAC7B,CAAG;EAAE,CAAC;CAC5C;CACA,OAAO6B,EAAS,KAAK,OAAa;EAAE,GAAGI;EAAS,SAASnC,EAAcmC,EAAQ,IAAI;CAAE,EAAE;AACzF;AAaA,SAAgBC,EACd,GACA,GACA,GACc;CACd,IAAMC,IAAuB,CAAC,GACxBC,IAA0D,CAAC;CACjE,KAAK,IAAMC,KAASC,GAAQ;EAC1B,IAAMC,IAAQC,EAAQH,CAAK;EAC3B,AAAIE,MAAU,OAAMJ,EAAO,KAAK;GAAE,MAAM;GAAS;EAAM,CAAC,IACnDC,EAAM,KAAK;GAAE,IAAIG;GAAO,MAAM;GAAG,MAAM;IAAE,MAAM;IAAS;GAAM;EAAE,CAAC;CACxE;CACA,KAAK,IAAME,KAASxC,GAAM,UAAU,CAAC,GACnC,EAAM,KAAK;EAAE,IAAIwC,EAAM,KAAK,EAAE,EAAE,GAAG,QAAQ,KAAK;EAAG,MAAM;EAAG,MAAM;GAAE,MAAM;GAAS;EAAM;CAAE,CAAC;CAE9F,KAAK,IAAMzC,KAAOC,GAAM,UAAU,CAAC,GACjC,EAAM,KAAK;EAAE,IAAID,EAAI,GAAG,QAAQ;EAAG,MAAM;EAAG,MAAM;GAAE,MAAM;GAAO;EAAI;CAAE,CAAC;CAI1E,OADAoC,EAAM,MAAM,GAAG,MAAM9B,EAAE,KAAKC,EAAE,MAAMD,EAAE,OAAOC,EAAE,IAAI,GAC5C,CAAC,GAAG4B,GAAQ,GAAGC,EAAM,KAAK,MAAUM,EAAM,IAAI,CAAC;AACxD"}
@@ -0,0 +1,32 @@
1
+ import { WorkflowRun } from './runModel';
2
+ import { CalendarRunExecutionRef, CalendarRunJobRef, CalendarRunLinks } from './runTypes';
3
+ export interface RunHrefs {
4
+ /** Where the run's workflow opens; null for no link. */
5
+ workflow: string | null;
6
+ /** Where the run itself opens; null for no link (a run still to come has none). */
7
+ run: string | null;
8
+ }
9
+ export declare const NO_HREFS: RunHrefs;
10
+ /** Whether the host gave any resolver: without one the layer asks for nothing and links nowhere. */
11
+ export declare function hasRunLinks(links: CalendarRunLinks | null | undefined): links is CalendarRunLinks;
12
+ /** A link a resolver returned, when it is one: an app path, or an http(s) address. */
13
+ export declare function safeRunHref(value: unknown): string | null;
14
+ /** Whether a link leaves the app (opens in a new tab). */
15
+ export declare function isExternalHref(href: string): boolean;
16
+ /** The schedule as the resolvers take it. */
17
+ export declare function runJobRef(job: {
18
+ id: string;
19
+ name: string | null;
20
+ timezone: string;
21
+ metadata: Record<string, unknown> | null;
22
+ }): CalendarRunJobRef;
23
+ /**
24
+ * Where a run's links go. `job`: its schedule (null when the schedule no longer exists: no
25
+ * links). `execution`: what a past run answered (null when it isn't known: no run link).
26
+ */
27
+ export declare function resolveRunHrefs(input: {
28
+ links: CalendarRunLinks;
29
+ run: WorkflowRun;
30
+ job: CalendarRunJobRef | null;
31
+ execution: CalendarRunExecutionRef | null;
32
+ }): RunHrefs;
@@ -0,0 +1,50 @@
1
+ import { parseRunSubject as e } from "./runModel.js";
2
+ // src/v2/runs/runLinks.ts
3
+ var t = {
4
+ workflow: null,
5
+ run: null
6
+ };
7
+ function n(e) {
8
+ return !!(e?.resolveSubjectHref || e?.resolveExecutionHref);
9
+ }
10
+ function r(e) {
11
+ if (typeof e != "string") return null;
12
+ let t = e.trim();
13
+ if (t.startsWith("/")) return t.startsWith("//") ? null : t;
14
+ try {
15
+ let e = new URL(t);
16
+ return e.protocol === "https:" || e.protocol === "http:" ? e.href : null;
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ function i(e) {
22
+ return !e.startsWith("/");
23
+ }
24
+ function a(e) {
25
+ try {
26
+ return r(e());
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+ function o(e) {
32
+ return {
33
+ id: e.id,
34
+ name: e.name,
35
+ timezone: e.timezone,
36
+ metadata: e.metadata
37
+ };
38
+ }
39
+ function s(n) {
40
+ let { links: r, run: i, job: o, execution: s } = n;
41
+ if (!o) return t;
42
+ let c = e(o.metadata?.subject) ?? i.subject, l = r.resolveSubjectHref, u = r.resolveExecutionHref;
43
+ return {
44
+ workflow: c && l ? a(() => l(c, o)) : null,
45
+ run: s && i.execution && u ? a(() => u(s, c, o)) : null
46
+ };
47
+ }
48
+ export { t as NO_HREFS, n as hasRunLinks, i as isExternalHref, s as resolveRunHrefs, o as runJobRef, r as safeRunHref };
49
+
50
+ //# sourceMappingURL=runLinks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runLinks.js","names":["NO_HREFS","hasRunLinks","links","safeRunHref","value","href","url","isExternalHref","attempt","resolve","runJobRef","job","resolveRunHrefs","input","subject","parseRunSubject","run","resolveSubject","resolveExecution","execution"],"sources":["../../../src/v2/runs/runLinks.ts"],"sourcesContent":["/**\n * A run's links (BOFF-15698 B5): the host's resolvers (`CalendarRunLinks`) turned into where\n * \"Open workflow\" and \"Open run\" go. Pure.\n *\n * - The workflow's link needs the run's schedule and its subject (the schedule's\n * `metadata.subject`, or for an upcoming run the subject its fire carried).\n * - The run's link needs what the run answered (its execution's `output`).\n * - A link is a path in the host app (\"/workflows/runs/…\") or an http(s) address; anything\n * else is no link, and so is a resolver that throws: a link that can't work is never shown.\n */\nimport { parseRunSubject, type WorkflowRun } from './runModel';\nimport type {\n CalendarRunExecutionRef,\n CalendarRunJobRef,\n CalendarRunLinks,\n CalendarRunSubject,\n} from './runTypes';\n\nexport interface RunHrefs {\n /** Where the run's workflow opens; null for no link. */\n workflow: string | null;\n /** Where the run itself opens; null for no link (a run still to come has none). */\n run: string | null;\n}\n\nexport const NO_HREFS: RunHrefs = { workflow: null, run: null };\n\n/** Whether the host gave any resolver: without one the layer asks for nothing and links nowhere. */\nexport function hasRunLinks(links: CalendarRunLinks | null | undefined): links is CalendarRunLinks {\n return Boolean(links?.resolveSubjectHref || links?.resolveExecutionHref);\n}\n\n/** A link a resolver returned, when it is one: an app path, or an http(s) address. */\nexport function safeRunHref(value: unknown): string | null {\n if (typeof value !== 'string') return null;\n const href = value.trim();\n if (href.startsWith('/')) return href.startsWith('//') ? null : href;\n try {\n const url = new URL(href);\n return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : null;\n } catch {\n return null;\n }\n}\n\n/** Whether a link leaves the app (opens in a new tab). */\nexport function isExternalHref(href: string): boolean {\n return !href.startsWith('/');\n}\n\nfunction attempt(resolve: () => string | null | undefined): string | null {\n try {\n return safeRunHref(resolve());\n } catch {\n // A host resolver that throws is a link that can't work: none is shown.\n return null;\n }\n}\n\n/** The schedule as the resolvers take it. */\nexport function runJobRef(job: {\n id: string;\n name: string | null;\n timezone: string;\n metadata: Record<string, unknown> | null;\n}): CalendarRunJobRef {\n return { id: job.id, name: job.name, timezone: job.timezone, metadata: job.metadata };\n}\n\n/**\n * Where a run's links go. `job`: its schedule (null when the schedule no longer exists: no\n * links). `execution`: what a past run answered (null when it isn't known: no run link).\n */\nexport function resolveRunHrefs(input: {\n links: CalendarRunLinks;\n run: WorkflowRun;\n job: CalendarRunJobRef | null;\n execution: CalendarRunExecutionRef | null;\n}): RunHrefs {\n const { links, run, job, execution } = input;\n if (!job) return NO_HREFS;\n const subject: CalendarRunSubject | null = parseRunSubject(job.metadata?.subject) ?? run.subject;\n const resolveSubject = links.resolveSubjectHref;\n const resolveExecution = links.resolveExecutionHref;\n return {\n workflow: subject && resolveSubject ? attempt(() => resolveSubject(subject, job)) : null,\n run:\n execution && run.execution && resolveExecution\n ? attempt(() => resolveExecution(execution, subject, job))\n : null,\n };\n}\n"],"mappings":";;AAyBA,IAAaA,IAAqB;CAAE,UAAU;CAAM,KAAK;AAAK;AAG9D,SAAgBC,EAAY,GAAuE;CACjG,OAAO,GAAQC,GAAO,sBAAsBA,GAAO;AACrD;AAGA,SAAgBC,EAAY,GAA+B;CACzD,IAAI,OAAOC,KAAU,UAAU,OAAO;CACtC,IAAMC,IAAOD,EAAM,KAAK;CACxB,IAAIC,EAAK,WAAW,GAAG,GAAG,OAAOA,EAAK,WAAW,IAAI,IAAI,OAAOA;CAChE,IAAI;EACF,IAAMC,IAAM,IAAI,IAAID,CAAI;EACxB,OAAOC,EAAI,aAAa,YAAYA,EAAI,aAAa,UAAUA,EAAI,OAAO;CAC5E,QAAQ;EACN,OAAO;CACT;AACF;AAGA,SAAgBC,EAAe,GAAuB;CACpD,OAAO,CAACF,EAAK,WAAW,GAAG;AAC7B;AAEA,SAASG,EAAQ,GAAyD;CACxE,IAAI;EACF,OAAOL,EAAYM,EAAQ,CAAC;CAC9B,QAAQ;EAEN,OAAO;CACT;AACF;AAGA,SAAgBC,EAAU,GAKJ;CACpB,OAAO;EAAE,IAAIC,EAAI;EAAI,MAAMA,EAAI;EAAM,UAAUA,EAAI;EAAU,UAAUA,EAAI;CAAS;AACtF;AAMA,SAAgBC,EAAgB,GAKnB;CACX,IAAM,EAAE,UAAO,QAAK,QAAK,iBAAcC;CACvC,IAAI,CAACF,GAAK,OAAOX;CACjB,IAAMc,IAAqCC,EAAgBJ,EAAI,UAAU,OAAO,KAAKK,EAAI,SACnFC,IAAiBf,EAAM,oBACvBgB,IAAmBhB,EAAM;CAC/B,OAAO;EACL,UAAUY,KAAWG,IAAiBT,QAAcS,EAAeH,GAASH,CAAG,CAAC,IAAI;EACpF,KACEQ,KAAaH,EAAI,aAAaE,IAC1BV,QAAcU,EAAiBC,GAAWL,GAASH,CAAG,CAAC,IACvD;CACR;AACF"}
@@ -0,0 +1,97 @@
1
+ import { DateValue } from '@burdenoff/fe-libs/ui';
2
+ import { CalendarV2JobExecutionsQuery, CalendarV2ScheduleOccurrencesQuery } from '../../generated/wspace-operations';
3
+ import { CalendarRunJobStatus, CalendarRunSubject } from './runTypes';
4
+ export type RawRunExecution = CalendarV2JobExecutionsQuery['workspaceJobExecutions']['executions'][number];
5
+ export type RawRunOccurrence = CalendarV2ScheduleOccurrencesQuery['scheduleOccurrences']['occurrences'][number];
6
+ /** The subject kind wspace-workflow-svc stamps on a workflow's schedule. */
7
+ export declare const WORKFLOW_SUBJECT_KIND = "workflow";
8
+ /**
9
+ * How a run went, in the Schedules screen's words, or that it is still to come:
10
+ * - `retrying`: it failed and the scheduler tries again;
11
+ * - `ended`: it stopped without succeeding or failing (cancelled before it ran);
12
+ * - `overdue`: planned before now and not run yet.
13
+ */
14
+ export type RunStatus = 'succeeded' | 'failed' | 'retrying' | 'running' | 'ended' | 'overdue' | 'scheduled';
15
+ /** What a past run did. */
16
+ export interface RunExecution {
17
+ id: string;
18
+ status: CalendarRunJobStatus;
19
+ success: boolean;
20
+ startedAt: Date;
21
+ completedAt: Date | null;
22
+ /** How long the run took, in milliseconds; null while it runs. */
23
+ durationMs: number | null;
24
+ errorMessage: string | null;
25
+ /** 0 for the first try, 1 for the first retry, … */
26
+ attempt: number;
27
+ /** Someone ran it by hand ("Run now"), outside its schedule. */
28
+ manual: boolean;
29
+ /** It made up for a fire the scheduler missed. */
30
+ catchUp: boolean;
31
+ }
32
+ export interface WorkflowRun {
33
+ /** One per fire: `<schedule>|<fire time>`, or `run:<execution>` for a run without one. */
34
+ key: string;
35
+ scheduledJobId: string;
36
+ /** The workflow's name. */
37
+ name: string;
38
+ workflowKey: string | null;
39
+ /** Where it sits on the calendar. */
40
+ at: Date;
41
+ status: RunStatus;
42
+ /** The fire it stands for; null for a run the scheduler didn't stamp with one. */
43
+ fireAt: Date | null;
44
+ /** What happened, for a run that has started; null for one still to come. */
45
+ execution: RunExecution | null;
46
+ /** An upcoming run's schedule subject (`metadata.subject`); null for past runs. */
47
+ subject: CalendarRunSubject | null;
48
+ /** An upcoming run's schedule time zone. */
49
+ timeZone: string | null;
50
+ }
51
+ /** The scheduler's job status, as the host's resolvers take it; null for a value it doesn't know. */
52
+ export declare function runJobStatus(value: unknown): CalendarRunJobStatus | null;
53
+ /**
54
+ * A job's `metadata.subject` as the host's resolvers take it: a kind and an id, its label (the
55
+ * id when it has none), and its product and details when it carries them. Null when it isn't
56
+ * one.
57
+ */
58
+ export declare function parseRunSubject(value: unknown): CalendarRunSubject | null;
59
+ /** How a past run went: the Schedules screen's rule (a failed run tried again is "retrying"). */
60
+ export declare function pastRunStatus(row: Pick<RawRunExecution, 'status' | 'success' | 'willRetry' | 'completedAt'>): RunStatus;
61
+ /**
62
+ * Past runs of workflow schedules, one per fire (the latest attempt of a retried one). Rows of
63
+ * other jobs, and rows whose start doesn't parse, are left out.
64
+ */
65
+ export declare function pastRuns(rows: readonly RawRunExecution[]): WorkflowRun[];
66
+ /**
67
+ * Upcoming runs of workflow schedules from their planned fires: overdue when planned before
68
+ * `now`. A fire listed twice (pages that meet at an instant) is kept once.
69
+ */
70
+ export declare function upcomingRuns(occurrences: readonly RawRunOccurrence[], now: Date): WorkflowRun[];
71
+ /**
72
+ * The runs in `[from, to)`, in time order: the past runs, and the upcoming ones whose fire
73
+ * hasn't run. A past run whose place falls outside the range but which started in it sits at
74
+ * its start.
75
+ */
76
+ export declare function mergeRuns(past: readonly WorkflowRun[], upcoming: readonly WorkflowRun[], range: {
77
+ from: Date;
78
+ to: Date;
79
+ }): WorkflowRun[];
80
+ /** The runs of whole days only, and from which days runs were left out. */
81
+ export interface WholeDays {
82
+ runs: WorkflowRun[];
83
+ /** Past runs before this day aren't shown; null when none were left out. */
84
+ pastFrom: DateValue | null;
85
+ /** Upcoming runs from this day on aren't shown; null when none were left out. */
86
+ upcomingUntil: DateValue | null;
87
+ }
88
+ /**
89
+ * Never a silently partial day: when the past runs stop at `pastCutoff` (the oldest start
90
+ * loaded), the past runs of its day and the days before are left out; when the upcoming ones
91
+ * stop at `upcomingCutoff` (the last fire loaded), the upcoming runs of its day and the days
92
+ * after are. Each day shown then has all of its runs, and the layer names the days without.
93
+ */
94
+ export declare function wholeDaysOnly(runs: readonly WorkflowRun[], cutoffs: {
95
+ pastCutoff: Date | null;
96
+ upcomingCutoff: Date | null;
97
+ }, timeZone: string): WholeDays;
@@ -0,0 +1,132 @@
1
+ import { instantToZoned as e } from "../time/calendarTime.js";
2
+ import { addDays as t } from "@burdenoff/fe-libs/ui";
3
+ // src/v2/runs/runModel.ts
4
+ var n = "workflow", r = [
5
+ "DRAFT",
6
+ "PENDING",
7
+ "RUNNING",
8
+ "COMPLETED",
9
+ "FAILED",
10
+ "PAUSED",
11
+ "CANCELLED",
12
+ "DISABLED",
13
+ "ARCHIVED"
14
+ ];
15
+ function i(e) {
16
+ return typeof e == "object" && !!e && !Array.isArray(e);
17
+ }
18
+ function a(e) {
19
+ return typeof e == "string" && e.trim() !== "" ? e : null;
20
+ }
21
+ function o(e) {
22
+ if (!e) return null;
23
+ let t = new Date(e);
24
+ return Number.isNaN(t.getTime()) ? null : t;
25
+ }
26
+ function s(e) {
27
+ return r.find((t) => t === e) ?? null;
28
+ }
29
+ function c(e) {
30
+ if (!i(e)) return null;
31
+ let t = a(e.kind), n = a(e.id);
32
+ if (!t || !n) return null;
33
+ let r = {
34
+ kind: t,
35
+ id: n,
36
+ label: a(e.label) ?? n
37
+ }, o = a(e.productId);
38
+ return o && (r.productId = o), i(e.ref) && (r.ref = e.ref), r;
39
+ }
40
+ function l(e) {
41
+ let t = String(e.status);
42
+ return t === "RUNNING" || t === "PENDING" ? "running" : e.success ? "succeeded" : e.willRetry ? "retrying" : t === "FAILED" || e.completedAt ? "failed" : "ended";
43
+ }
44
+ function u(e, t) {
45
+ return `${e}|${t.getTime()}`;
46
+ }
47
+ function d(e, t) {
48
+ if (e.attempt !== t.attempt) return e.attempt > t.attempt;
49
+ let n = e.startedAt.getTime(), r = t.startedAt.getTime();
50
+ return n === r ? e.id > t.id : n > r;
51
+ }
52
+ function f(e) {
53
+ let t = /* @__PURE__ */ new Map();
54
+ for (let n of e) {
55
+ let e = a(n.workflowKey), r = o(n.startedAt);
56
+ if (!e || !r) continue;
57
+ let c = o(n.scheduledTime), f = i(n.metadata) ? n.metadata : {}, p = n.duration, m = {
58
+ id: n.id,
59
+ status: s(String(n.status)) ?? "FAILED",
60
+ success: n.success,
61
+ startedAt: r,
62
+ completedAt: o(n.completedAt),
63
+ durationMs: typeof p == "number" && Number.isFinite(p) && p >= 0 ? p : null,
64
+ errorMessage: a(n.errorMessage),
65
+ attempt: Math.max(0, n.retryAttempt),
66
+ manual: f.manual === !0,
67
+ catchUp: f.catchUp === !0
68
+ }, h = c ? u(n.scheduledJobId, c) : `run:${n.id}`, g = t.get(h);
69
+ (!g?.execution || d(m, g.execution)) && t.set(h, {
70
+ key: h,
71
+ scheduledJobId: n.scheduledJobId,
72
+ name: a(n.workflowName) ?? e,
73
+ workflowKey: e,
74
+ at: m.catchUp || !c ? r : c,
75
+ status: l(n),
76
+ fireAt: c,
77
+ execution: m,
78
+ subject: null,
79
+ timeZone: null
80
+ });
81
+ }
82
+ return [...t.values()];
83
+ }
84
+ function p(e, t) {
85
+ let n = /* @__PURE__ */ new Map();
86
+ for (let r of e) {
87
+ let e = o(r.fireAt), i = c(r.subject);
88
+ if (!e || i?.kind !== "workflow") continue;
89
+ let s = u(r.scheduledJobId, e);
90
+ n.has(s) || n.set(s, {
91
+ key: s,
92
+ scheduledJobId: r.scheduledJobId,
93
+ name: i.label,
94
+ workflowKey: i.id,
95
+ at: e,
96
+ status: e.getTime() < t.getTime() ? "overdue" : "scheduled",
97
+ fireAt: e,
98
+ execution: null,
99
+ subject: i,
100
+ timeZone: a(r.timezone)
101
+ });
102
+ }
103
+ return [...n.values()];
104
+ }
105
+ function m(e, t) {
106
+ return e.at.getTime() - t.at.getTime() || e.name.localeCompare(t.name) || (e.key < t.key ? -1 : +(e.key > t.key));
107
+ }
108
+ function h(e, t, n) {
109
+ let r = n.from.getTime(), i = n.to.getTime(), a = (e) => e.getTime() >= r && e.getTime() < i, o = new Set(e.map((e) => e.key)), s = e.map((e) => !a(e.at) && e.execution && a(e.execution.startedAt) ? {
110
+ ...e,
111
+ at: e.execution.startedAt
112
+ } : e), c = t.filter((e) => !o.has(e.key));
113
+ return [...s, ...c].filter((e) => a(e.at)).sort(m);
114
+ }
115
+ function g(n, r, i) {
116
+ let a = r.pastCutoff ? t(e(r.pastCutoff, i).date, 1) : null, o = r.upcomingCutoff ? e(r.upcomingCutoff, i).date : null;
117
+ return !a && !o ? {
118
+ runs: [...n],
119
+ pastFrom: a,
120
+ upcomingUntil: o
121
+ } : {
122
+ runs: n.filter((t) => {
123
+ let n = e(t.at, i).date;
124
+ return t.execution ? !a || n >= a : !o || n < o;
125
+ }),
126
+ pastFrom: a,
127
+ upcomingUntil: o
128
+ };
129
+ }
130
+ export { n as WORKFLOW_SUBJECT_KIND, h as mergeRuns, c as parseRunSubject, l as pastRunStatus, f as pastRuns, s as runJobStatus, p as upcomingRuns, g as wholeDaysOnly };
131
+
132
+ //# sourceMappingURL=runModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runModel.js","names":["WORKFLOW_SUBJECT_KIND","JOB_STATUSES","isRecord","value","nonBlank","instant","date","runJobStatus","status","parseRunSubject","kind","id","subject","productId","pastRunStatus","row","fireKey","scheduledJobId","fireAt","laterAttempt","next","current","nextStart","currentStart","pastRuns","byKey","rows","workflowKey","startedAt","metadata","duration","execution","key","upcomingRuns","occurrence","occurrences","now","byTime","a","b","mergeRuns","fromMs","range","toMs","inRange","ran","past","run","placed","toCome","upcoming","wholeDaysOnly","pastFrom","cutoffs","addDays","instantToZoned","timeZone","upcomingUntil","runs","day"],"sources":["../../../src/v2/runs/runModel.ts"],"sourcesContent":["/**\n * The workflow runs layer's runs (BOFF-15698 B5), as the calendar shows them. Pure.\n *\n * - **Past runs** are the scheduler's executions of workflow schedules (`workflowKey` set). A\n * fire the scheduler retried has a row per attempt: it shows once, as its latest attempt.\n * - **Upcoming runs** are the schedules' planned fires (`scheduleOccurrences`). One planned\n * before now that hasn't run yet is \"overdue\": the scheduler runs it when it catches up.\n * - **A fire shows once.** A run is matched to its fire by the schedule and the fire's time\n * (the execution's `scheduledTime`, which is the fire's `fireAt`), so a fire that has run (or\n * is running) shows as the run, never also as still to come.\n * - **Where it sits:** at the fire's time; a catch-up run, at the time it ran (its fire may be\n * days earlier). A run whose fire is outside the range asked for, but which started in it,\n * sits at its start.\n */\nimport { addDays, type DateValue } from '@burdenoff/fe-libs/ui';\nimport type {\n CalendarV2JobExecutionsQuery,\n CalendarV2ScheduleOccurrencesQuery,\n} from '../../generated/wspace-operations';\nimport { instantToZoned } from '../time/calendarTime';\nimport type { CalendarRunJobStatus, CalendarRunSubject } from './runTypes';\n\nexport type RawRunExecution =\n CalendarV2JobExecutionsQuery['workspaceJobExecutions']['executions'][number];\nexport type RawRunOccurrence =\n CalendarV2ScheduleOccurrencesQuery['scheduleOccurrences']['occurrences'][number];\n\n/** The subject kind wspace-workflow-svc stamps on a workflow's schedule. */\nexport const WORKFLOW_SUBJECT_KIND = 'workflow';\n\n/**\n * How a run went, in the Schedules screen's words, or that it is still to come:\n * - `retrying`: it failed and the scheduler tries again;\n * - `ended`: it stopped without succeeding or failing (cancelled before it ran);\n * - `overdue`: planned before now and not run yet.\n */\nexport type RunStatus =\n 'succeeded' | 'failed' | 'retrying' | 'running' | 'ended' | 'overdue' | 'scheduled';\n\n/** What a past run did. */\nexport interface RunExecution {\n id: string;\n status: CalendarRunJobStatus;\n success: boolean;\n startedAt: Date;\n completedAt: Date | null;\n /** How long the run took, in milliseconds; null while it runs. */\n durationMs: number | null;\n errorMessage: string | null;\n /** 0 for the first try, 1 for the first retry, … */\n attempt: number;\n /** Someone ran it by hand (\"Run now\"), outside its schedule. */\n manual: boolean;\n /** It made up for a fire the scheduler missed. */\n catchUp: boolean;\n}\n\nexport interface WorkflowRun {\n /** One per fire: `<schedule>|<fire time>`, or `run:<execution>` for a run without one. */\n key: string;\n scheduledJobId: string;\n /** The workflow's name. */\n name: string;\n workflowKey: string | null;\n /** Where it sits on the calendar. */\n at: Date;\n status: RunStatus;\n /** The fire it stands for; null for a run the scheduler didn't stamp with one. */\n fireAt: Date | null;\n /** What happened, for a run that has started; null for one still to come. */\n execution: RunExecution | null;\n /** An upcoming run's schedule subject (`metadata.subject`); null for past runs. */\n subject: CalendarRunSubject | null;\n /** An upcoming run's schedule time zone. */\n timeZone: string | null;\n}\n\nconst JOB_STATUSES: readonly CalendarRunJobStatus[] = [\n 'DRAFT',\n 'PENDING',\n 'RUNNING',\n 'COMPLETED',\n 'FAILED',\n 'PAUSED',\n 'CANCELLED',\n 'DISABLED',\n 'ARCHIVED',\n];\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction nonBlank(value: unknown): string | null {\n return typeof value === 'string' && value.trim() !== '' ? value : null;\n}\n\n/** The instant an API time names; null when it doesn't parse. */\nfunction instant(value: string | null | undefined): Date | null {\n if (!value) return null;\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n}\n\n/** The scheduler's job status, as the host's resolvers take it; null for a value it doesn't know. */\nexport function runJobStatus(value: unknown): CalendarRunJobStatus | null {\n return JOB_STATUSES.find((status) => status === value) ?? null;\n}\n\n/**\n * A job's `metadata.subject` as the host's resolvers take it: a kind and an id, its label (the\n * id when it has none), and its product and details when it carries them. Null when it isn't\n * one.\n */\nexport function parseRunSubject(value: unknown): CalendarRunSubject | null {\n if (!isRecord(value)) return null;\n const kind = nonBlank(value.kind);\n const id = nonBlank(value.id);\n if (!kind || !id) return null;\n const subject: CalendarRunSubject = { kind, id, label: nonBlank(value.label) ?? id };\n const productId = nonBlank(value.productId);\n if (productId) subject.productId = productId;\n if (isRecord(value.ref)) subject.ref = value.ref;\n return subject;\n}\n\n/** How a past run went: the Schedules screen's rule (a failed run tried again is \"retrying\"). */\nexport function pastRunStatus(\n row: Pick<RawRunExecution, 'status' | 'success' | 'willRetry' | 'completedAt'>\n): RunStatus {\n const status = String(row.status);\n if (status === 'RUNNING' || status === 'PENDING') return 'running';\n if (row.success) return 'succeeded';\n if (row.willRetry) return 'retrying';\n if (status === 'FAILED' || row.completedAt) return 'failed';\n return 'ended';\n}\n\nfunction fireKey(scheduledJobId: string, fireAt: Date): string {\n return `${scheduledJobId}|${fireAt.getTime()}`;\n}\n\n/** Whether `next` is a later attempt at the same fire than `current`. */\nfunction laterAttempt(next: RunExecution, current: RunExecution): boolean {\n if (next.attempt !== current.attempt) return next.attempt > current.attempt;\n const nextStart = next.startedAt.getTime();\n const currentStart = current.startedAt.getTime();\n if (nextStart !== currentStart) return nextStart > currentStart;\n return next.id > current.id;\n}\n\n/**\n * Past runs of workflow schedules, one per fire (the latest attempt of a retried one). Rows of\n * other jobs, and rows whose start doesn't parse, are left out.\n */\nexport function pastRuns(rows: readonly RawRunExecution[]): WorkflowRun[] {\n const byKey = new Map<string, WorkflowRun>();\n for (const row of rows) {\n const workflowKey = nonBlank(row.workflowKey);\n const startedAt = instant(row.startedAt);\n if (!workflowKey || !startedAt) continue;\n const fireAt = instant(row.scheduledTime);\n const metadata = isRecord(row.metadata) ? row.metadata : {};\n const duration = row.duration;\n const execution: RunExecution = {\n id: row.id,\n status: runJobStatus(String(row.status)) ?? 'FAILED',\n success: row.success,\n startedAt,\n completedAt: instant(row.completedAt),\n durationMs:\n typeof duration === 'number' && Number.isFinite(duration) && duration >= 0\n ? duration\n : null,\n errorMessage: nonBlank(row.errorMessage),\n attempt: Math.max(0, row.retryAttempt),\n manual: metadata.manual === true,\n catchUp: metadata.catchUp === true,\n };\n const key = fireAt ? fireKey(row.scheduledJobId, fireAt) : `run:${row.id}`;\n const current = byKey.get(key);\n if (current?.execution && !laterAttempt(execution, current.execution)) continue;\n byKey.set(key, {\n key,\n scheduledJobId: row.scheduledJobId,\n name: nonBlank(row.workflowName) ?? workflowKey,\n workflowKey,\n at: execution.catchUp || !fireAt ? startedAt : fireAt,\n status: pastRunStatus(row),\n fireAt,\n execution,\n subject: null,\n timeZone: null,\n });\n }\n return [...byKey.values()];\n}\n\n/**\n * Upcoming runs of workflow schedules from their planned fires: overdue when planned before\n * `now`. A fire listed twice (pages that meet at an instant) is kept once.\n */\nexport function upcomingRuns(occurrences: readonly RawRunOccurrence[], now: Date): WorkflowRun[] {\n const byKey = new Map<string, WorkflowRun>();\n for (const occurrence of occurrences) {\n const fireAt = instant(occurrence.fireAt);\n const subject = parseRunSubject(occurrence.subject);\n if (!fireAt || subject?.kind !== WORKFLOW_SUBJECT_KIND) continue;\n const key = fireKey(occurrence.scheduledJobId, fireAt);\n if (byKey.has(key)) continue;\n byKey.set(key, {\n key,\n scheduledJobId: occurrence.scheduledJobId,\n name: subject.label,\n workflowKey: subject.id,\n at: fireAt,\n status: fireAt.getTime() < now.getTime() ? 'overdue' : 'scheduled',\n fireAt,\n execution: null,\n subject,\n timeZone: nonBlank(occurrence.timezone),\n });\n }\n return [...byKey.values()];\n}\n\nfunction byTime(a: WorkflowRun, b: WorkflowRun): number {\n return (\n a.at.getTime() - b.at.getTime() ||\n a.name.localeCompare(b.name) ||\n (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)\n );\n}\n\n/**\n * The runs in `[from, to)`, in time order: the past runs, and the upcoming ones whose fire\n * hasn't run. A past run whose place falls outside the range but which started in it sits at\n * its start.\n */\nexport function mergeRuns(\n past: readonly WorkflowRun[],\n upcoming: readonly WorkflowRun[],\n range: { from: Date; to: Date }\n): WorkflowRun[] {\n const fromMs = range.from.getTime();\n const toMs = range.to.getTime();\n const inRange = (date: Date) => date.getTime() >= fromMs && date.getTime() < toMs;\n const ran = new Set(past.map((run) => run.key));\n const placed = past.map((run) =>\n !inRange(run.at) && run.execution && inRange(run.execution.startedAt)\n ? { ...run, at: run.execution.startedAt }\n : run\n );\n const toCome = upcoming.filter((run) => !ran.has(run.key));\n return [...placed, ...toCome].filter((run) => inRange(run.at)).sort(byTime);\n}\n\n/** The runs of whole days only, and from which days runs were left out. */\nexport interface WholeDays {\n runs: WorkflowRun[];\n /** Past runs before this day aren't shown; null when none were left out. */\n pastFrom: DateValue | null;\n /** Upcoming runs from this day on aren't shown; null when none were left out. */\n upcomingUntil: DateValue | null;\n}\n\n/**\n * Never a silently partial day: when the past runs stop at `pastCutoff` (the oldest start\n * loaded), the past runs of its day and the days before are left out; when the upcoming ones\n * stop at `upcomingCutoff` (the last fire loaded), the upcoming runs of its day and the days\n * after are. Each day shown then has all of its runs, and the layer names the days without.\n */\nexport function wholeDaysOnly(\n runs: readonly WorkflowRun[],\n cutoffs: { pastCutoff: Date | null; upcomingCutoff: Date | null },\n timeZone: string\n): WholeDays {\n const pastFrom = cutoffs.pastCutoff\n ? addDays(instantToZoned(cutoffs.pastCutoff, timeZone).date, 1)\n : null;\n const upcomingUntil = cutoffs.upcomingCutoff\n ? instantToZoned(cutoffs.upcomingCutoff, timeZone).date\n : null;\n if (!pastFrom && !upcomingUntil) return { runs: [...runs], pastFrom, upcomingUntil };\n const kept = runs.filter((run) => {\n const day = instantToZoned(run.at, timeZone).date;\n if (run.execution) return !pastFrom || day >= pastFrom;\n return !upcomingUntil || day < upcomingUntil;\n });\n return { runs: kept, pastFrom, upcomingUntil };\n}\n"],"mappings":";;;AA4BA,IAAaA,IAAwB,YAiD/BC,IAAgD;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAASC,EAAS,GAAkD;CAClE,OAAO,OAAOC,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC5E;AAEA,SAASC,EAAS,GAA+B;CAC/C,OAAO,OAAOD,KAAU,YAAYA,EAAM,KAAK,MAAM,KAAKA,IAAQ;AACpE;AAGA,SAASE,EAAQ,GAA+C;CAC9D,IAAI,CAACF,GAAO,OAAO;CACnB,IAAMG,IAAO,IAAI,KAAKH,CAAK;CAC3B,OAAO,OAAO,MAAMG,EAAK,QAAQ,CAAC,IAAI,OAAOA;AAC/C;AAGA,SAAgBC,EAAa,GAA6C;CACxE,OAAON,EAAa,MAAM,MAAWO,MAAWL,CAAK,KAAK;AAC5D;AAOA,SAAgBM,EAAgB,GAA2C;CACzE,IAAI,CAACP,EAASC,CAAK,GAAG,OAAO;CAC7B,IAAMO,IAAON,EAASD,EAAM,IAAI,GAC1BQ,IAAKP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,CAAC;GAE7C,OADIT,EAAI,YAAkB,CAACK,KAAYO,KAAOP,IACvC,CAACK,KAAiBE,IAAMF;EACjC,CACe;EAAM;EAAU;CAAc;AAC/C"}
@@ -0,0 +1,53 @@
1
+ import { DateValue } from '@burdenoff/fe-libs/ui';
2
+ import { CalendarV2Dialog } from '../types';
3
+ import { DayRuns, RunGroup } from './runLayout';
4
+ import { WorkflowRun } from './runModel';
5
+ /** What the run peek shows: a run, a busy schedule's day, runs sharing a pill, or a day's runs. */
6
+ export type RunPeekView = {
7
+ kind: 'run';
8
+ run: WorkflowRun;
9
+ } | {
10
+ kind: 'group';
11
+ group: RunGroup;
12
+ } | {
13
+ kind: 'cluster';
14
+ day: DateValue;
15
+ runs: WorkflowRun[];
16
+ } | {
17
+ kind: 'day';
18
+ day: DayRuns;
19
+ };
20
+ export interface RunPeekState {
21
+ /** What it points at (the pill, the row); null: the middle of the window. */
22
+ anchor: HTMLElement | null;
23
+ /** The views opened, the last one showing; Back goes to the one before. */
24
+ stack: RunPeekView[];
25
+ }
26
+ /** Marks what opens the run peek: a press on another one switches the peek to it. */
27
+ export declare const RUN_OPENER = "data-run-opener";
28
+ /** What identifies the view an opener opens: its run, group, cluster or day. */
29
+ export declare function openerKey(view: RunPeekView): string;
30
+ export interface RunPeekControls {
31
+ peek: RunPeekState | null;
32
+ /** Opens the peek on a view; a second press on the same opener closes it. */
33
+ openPeek: (view: RunPeekView, anchor: HTMLElement | null) => void;
34
+ /** Shows another view in the open peek (Back returns). */
35
+ showInPeek: (view: RunPeekView) => void;
36
+ backInPeek: () => void;
37
+ closePeek: () => void;
38
+ }
39
+ /** What the peek closes on, and what it closes when it opens. */
40
+ export interface RunPeekContext {
41
+ /** The shown days: a change closes it. */
42
+ daysKey: string;
43
+ /** An event's peek is open: one opening closes it; one closing as it opens doesn't. */
44
+ eventOpen: boolean;
45
+ /** A dialog the address names: one opening closes it. */
46
+ dialog: CalendarV2Dialog | null;
47
+ /** The runs show: hiding them closes it. */
48
+ shown: boolean;
49
+ closeEventPeek: () => void;
50
+ /** Set while the quick create is open: it closes as the peek opens. */
51
+ closeQuickCreate: (() => void) | null;
52
+ }
53
+ export declare function useRunPeek(context: RunPeekContext): RunPeekControls;
@@ -0,0 +1,62 @@
1
+ import { useCallback as e, useMemo as t, useState as n } from "react";
2
+ // src/v2/runs/runPeekState.ts
3
+ var r = "data-run-opener";
4
+ function i(e) {
5
+ switch (e.kind) {
6
+ case "run": return `run|${e.run.key}`;
7
+ case "group": return `group|${e.group.key}`;
8
+ case "cluster": return `cluster|${e.day}|${e.runs[0]?.key ?? ""}`;
9
+ default: return `day|${e.day.day}`;
10
+ }
11
+ }
12
+ function a(r) {
13
+ let { daysKey: a, eventOpen: o, dialog: s, shown: c, closeEventPeek: l, closeQuickCreate: u } = r, [d, f] = n(null), p = e((e, t) => {
14
+ o && l(), u?.(), f((n) => {
15
+ let r = n?.stack[0];
16
+ return r && n.anchor === t && i(r) === i(e) ? null : {
17
+ anchor: t,
18
+ stack: [e]
19
+ };
20
+ });
21
+ }, [
22
+ l,
23
+ u,
24
+ o
25
+ ]), m = e((e) => f((t) => t && {
26
+ ...t,
27
+ stack: [...t.stack, e]
28
+ }), []), h = e(() => f((e) => e && e.stack.length > 1 ? {
29
+ ...e,
30
+ stack: e.stack.slice(0, -1)
31
+ } : e), []), g = e(() => f(null), []), [_, v] = n({
32
+ daysKey: a,
33
+ eventOpen: o,
34
+ dialog: s,
35
+ shown: c
36
+ });
37
+ if (_.daysKey !== a || _.eventOpen !== o || _.dialog !== s || _.shown !== c) {
38
+ let e = _.daysKey !== a || o && !_.eventOpen || s !== null && s !== _.dialog || !c && _.shown;
39
+ v({
40
+ daysKey: a,
41
+ eventOpen: o,
42
+ dialog: s,
43
+ shown: c
44
+ }), e && d && f(null);
45
+ }
46
+ return t(() => ({
47
+ peek: d,
48
+ openPeek: p,
49
+ showInPeek: m,
50
+ backInPeek: h,
51
+ closePeek: g
52
+ }), [
53
+ h,
54
+ g,
55
+ p,
56
+ d,
57
+ m
58
+ ]);
59
+ }
60
+ export { r as RUN_OPENER, i as openerKey, a as useRunPeek };
61
+
62
+ //# sourceMappingURL=runPeekState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runPeekState.js","names":["RUN_OPENER","openerKey","view","useRunPeek","context","peek","setPeek","useState","openPeek","useCallback","eventOpen","closeEventPeek","closeQuickCreate","first","current","anchor","showInPeek","backInPeek","closePeek","seen","setSeen","daysKey","dialog","shown","closes","useMemo"],"sources":["../../../src/v2/runs/runPeekState.ts"],"sourcesContent":["/**\n * The run peek's state (BOFF-15698 B5): what it shows and what it points at, a stack of views\n * for Back, and when it closes. One peek at a time: opening it closes an event's peek and the\n * quick create; it closes when the days change, an event's peek or a dialog opens, or the runs\n * hide; a second press on what opened it closes it, as an event's block does.\n */\nimport { useCallback, useMemo, useState } from 'react';\nimport type { DateValue } from '@burdenoff/fe-libs/ui';\nimport type { CalendarV2Dialog } from '../types';\nimport type { DayRuns, RunGroup } from './runLayout';\nimport type { WorkflowRun } from './runModel';\n\n/** What the run peek shows: a run, a busy schedule's day, runs sharing a pill, or a day's runs. */\nexport type RunPeekView =\n | { kind: 'run'; run: WorkflowRun }\n | { kind: 'group'; group: RunGroup }\n | { kind: 'cluster'; day: DateValue; runs: WorkflowRun[] }\n | { kind: 'day'; day: DayRuns };\n\nexport interface RunPeekState {\n /** What it points at (the pill, the row); null: the middle of the window. */\n anchor: HTMLElement | null;\n /** The views opened, the last one showing; Back goes to the one before. */\n stack: RunPeekView[];\n}\n\n/** Marks what opens the run peek: a press on another one switches the peek to it. */\nexport const RUN_OPENER = 'data-run-opener';\n\n/** What identifies the view an opener opens: its run, group, cluster or day. */\nexport function openerKey(view: RunPeekView): string {\n switch (view.kind) {\n case 'run':\n return `run|${view.run.key}`;\n case 'group':\n return `group|${view.group.key}`;\n case 'cluster':\n return `cluster|${view.day}|${view.runs[0]?.key ?? ''}`;\n default:\n return `day|${view.day.day}`;\n }\n}\n\nexport interface RunPeekControls {\n peek: RunPeekState | null;\n /** Opens the peek on a view; a second press on the same opener closes it. */\n openPeek: (view: RunPeekView, anchor: HTMLElement | null) => void;\n /** Shows another view in the open peek (Back returns). */\n showInPeek: (view: RunPeekView) => void;\n backInPeek: () => void;\n closePeek: () => void;\n}\n\n/** What the peek closes on, and what it closes when it opens. */\nexport interface RunPeekContext {\n /** The shown days: a change closes it. */\n daysKey: string;\n /** An event's peek is open: one opening closes it; one closing as it opens doesn't. */\n eventOpen: boolean;\n /** A dialog the address names: one opening closes it. */\n dialog: CalendarV2Dialog | null;\n /** The runs show: hiding them closes it. */\n shown: boolean;\n closeEventPeek: () => void;\n /** Set while the quick create is open: it closes as the peek opens. */\n closeQuickCreate: (() => void) | null;\n}\n\nexport function useRunPeek(context: RunPeekContext): RunPeekControls {\n const { daysKey, eventOpen, dialog, shown, closeEventPeek, closeQuickCreate } = context;\n const [peek, setPeek] = useState<RunPeekState | null>(null);\n\n const openPeek = useCallback(\n (view: RunPeekView, anchor: HTMLElement | null) => {\n if (eventOpen) closeEventPeek();\n closeQuickCreate?.();\n setPeek((current) => {\n const first = current?.stack[0];\n const again = first && current.anchor === anchor && openerKey(first) === openerKey(view);\n return again ? null : { anchor, stack: [view] };\n });\n },\n [closeEventPeek, closeQuickCreate, eventOpen]\n );\n const showInPeek = useCallback(\n (view: RunPeekView) =>\n setPeek((current) => (current ? { ...current, stack: [...current.stack, view] } : current)),\n []\n );\n const backInPeek = useCallback(\n () =>\n setPeek((current) =>\n current && current.stack.length > 1\n ? { ...current, stack: current.stack.slice(0, -1) }\n : current\n ),\n []\n );\n const closePeek = useCallback(() => setPeek(null), []);\n\n // Closes on what changed since the last render (worked out while rendering, not in an effect).\n const [seen, setSeen] = useState({ daysKey, eventOpen, dialog, shown });\n const changed =\n seen.daysKey !== daysKey ||\n seen.eventOpen !== eventOpen ||\n seen.dialog !== dialog ||\n seen.shown !== shown;\n if (changed) {\n const closes =\n seen.daysKey !== daysKey ||\n (eventOpen && !seen.eventOpen) ||\n (dialog !== null && dialog !== seen.dialog) ||\n (!shown && seen.shown);\n setSeen({ daysKey, eventOpen, dialog, shown });\n if (closes && peek) setPeek(null);\n }\n\n return useMemo(\n () => ({ peek, openPeek, showInPeek, backInPeek, closePeek }),\n [backInPeek, closePeek, openPeek, peek, showInPeek]\n );\n}\n"],"mappings":";;AA2BA,IAAaA,IAAa;AAG1B,SAAgBC,EAAU,GAA2B;CACnD,QAAQC,EAAK,MAAb;EACE,KAAK,OACH,OAAO,OAAOA,EAAK,IAAI;EACzB,KAAK,SACH,OAAO,SAASA,EAAK,MAAM;EAC7B,KAAK,WACH,OAAO,WAAWA,EAAK,IAAI,GAAGA,EAAK,KAAK,EAAE,EAAE,OAAO;EACrD,SACE,OAAO,OAAOA,EAAK,IAAI;CAC3B;AACF;AA2BA,SAAgBC,EAAW,GAA0C;CACnE,IAAM,EAAE,YAAS,cAAW,WAAQ,UAAO,mBAAgB,wBAAqBC,GAC1E,CAACC,GAAMC,KAAWC,EAA8B,IAAI,GAEpDC,IAAWC,GACd,GAAmB,MAA+B;EAGjD,AAFIC,KAAWC,EAAe,GAC9BC,IAAmB,GACnBN,GAAS,MAAY;GACnB,IAAMO,IAAQC,GAAS,MAAM;GAE7B,OADcD,KAASC,EAAQ,WAAWC,KAAUd,EAAUY,CAAK,MAAMZ,EAAUC,CAAI,IACxE,OAAO;IAAE;IAAQ,OAAO,CAACA,CAAI;GAAE;EAChD,CAAC;CACH,GACA;EAACS;EAAgBC;EAAkBF;CAAS,CAC9C,GACMM,IAAaP,GAChB,MACCH,GAAS,MAAaQ,KAAU;EAAE,GAAGA;EAAS,OAAO,CAAC,GAAGA,EAAQ,OAAOZ,CAAI;CAAE,CAAY,GAC5F,CAAC,CACH,GACMe,IAAaR,QAEfH,GAAS,MACPQ,KAAWA,EAAQ,MAAM,SAAS,IAC9B;EAAE,GAAGA;EAAS,OAAOA,EAAQ,MAAM,MAAM,GAAG,EAAE;CAAE,IAChDA,CACN,GACF,CA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