@quazardous/qdadm 2.44.0 → 2.45.0

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.
@@ -0,0 +1,111 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * TaskPhases - a task's phases as a frieze (#4655)
4
+ *
5
+ * One item per step: its state (icon and colour), its duration, or the time
6
+ * since it started while it runs. Sub-phases fold out under their step; a
7
+ * failed step stands out and opens its sub-phases. A row across, or a column
8
+ * when its container is narrow. TaskDialog shows it above the log; a page may
9
+ * use it alone.
10
+ *
11
+ * Usage:
12
+ * <TaskPhases :phases="phases" />
13
+ * <TaskPhases v-model:selected="phase" :phases="phases" selectable :selectable-subs="['deploy.wait-crons']" />
14
+ *
15
+ * Labels: `phase.<name>` in the app's catalogue, else the name. Icons: the
16
+ * app's per phase name, else the state's.
17
+ */
18
+ import { computed, onBeforeUnmount, ref } from 'vue'
19
+ import { useI18n } from '../../i18n/useI18n'
20
+ import {
21
+ formatPhaseDuration,
22
+ phaseLabel,
23
+ phaseSteps,
24
+ TASK_PHASE_STATE_ICONS,
25
+ type TaskPhase,
26
+ type TaskPhasesData,
27
+ } from '../../tasks/taskPhases'
28
+
29
+ interface Props {
30
+ phases: TaskPhasesData | TaskPhase[] | null
31
+ /** The phase whose lines the log shows (v-model:selected) */
32
+ selected?: string | null
33
+ /** The steps can be picked */
34
+ selectable?: boolean
35
+ /** The sub-phases that can be picked: those the log has markers for */
36
+ selectableSubs?: string[] | null
37
+ /** An icon class per phase name */
38
+ icons?: Record<string, string> | null
39
+ }
40
+
41
+ const props = withDefaults(defineProps<Props>(), { selected: null, selectable: false, selectableSubs: null, icons: null })
42
+ const emit = defineEmits<{ 'update:selected': [name: string | null] }>()
43
+
44
+ const { t, tOr } = useI18n()
45
+
46
+ const steps = computed(() => phaseSteps(props.phases))
47
+
48
+ const now = ref(Date.now())
49
+ const ticker = setInterval(() => (now.value = Date.now()), 1000)
50
+ onBeforeUnmount(() => clearInterval(ticker))
51
+
52
+ /** Folded or not, as the user left it; a failed step opens by itself */
53
+ const opened = ref<Record<string, boolean>>({})
54
+ const hasFailure = (step: TaskPhase) => step.state === 'failed' || (step.subs ?? []).some((s) => s.state === 'failed')
55
+ const isOpen = (step: TaskPhase) => opened.value[step.name] ?? hasFailure(step)
56
+ const toggle = (step: TaskPhase) => (opened.value = { ...opened.value, [step.name]: !isOpen(step) })
57
+
58
+ const icon = (phase: TaskPhase) => props.icons?.[phase.name] ?? TASK_PHASE_STATE_ICONS[phase.state] ?? TASK_PHASE_STATE_ICONS.pending
59
+ const label = (phase: TaskPhase, sub = false) => phaseLabel(tOr, phase.name, sub)
60
+ const stateLabel = (phase: TaskPhase) => t(`core.task.phase.${phase.state}`)
61
+
62
+ /** Its duration once ended, the time since it started while it runs */
63
+ function time(phase: TaskPhase): string {
64
+ if (phase.dur !== null && phase.dur !== undefined) return formatPhaseDuration(phase.dur)
65
+ if (!phase.started) return ''
66
+ const start = Date.parse(phase.started)
67
+ if (Number.isNaN(start)) return ''
68
+ const end = phase.ended ? Date.parse(phase.ended) : now.value
69
+ return formatPhaseDuration(Math.max(0, (end - start) / 1000))
70
+ }
71
+
72
+ const canPick = (phase: TaskPhase, sub: boolean) => (sub ? !!props.selectableSubs?.includes(phase.name) : props.selectable)
73
+
74
+ function pick(phase: TaskPhase, sub: boolean): void {
75
+ if (!canPick(phase, sub)) return
76
+ emit('update:selected', props.selected === phase.name ? null : phase.name)
77
+ }
78
+ </script>
79
+
80
+ <template>
81
+ <div v-if="steps.length" class="qd-task-phases">
82
+ <ol class="qd-task-phases-list">
83
+ <li v-for="step in steps" :key="step.name" class="qd-task-phase" :class="[`qd-task-phase--${step.state}`, { 'qd-task-phase--selected': selected === step.name }]">
84
+ <div class="qd-task-phase-head">
85
+ <button type="button" class="qd-task-phase-main" :disabled="!canPick(step, false)" :aria-pressed="canPick(step, false) ? selected === step.name : undefined"
86
+ :title="`${label(step)} · ${stateLabel(step)}`" :aria-label="`${label(step)}, ${stateLabel(step)} ${time(step)}`.trim()" @click="pick(step, false)">
87
+ <i class="qd-task-phase-icon" :class="icon(step)" aria-hidden="true" />
88
+ <span class="qd-task-phase-label">{{ label(step) }}</span>
89
+ <span class="qd-task-phase-time">{{ time(step) }}</span>
90
+ </button>
91
+ <button v-if="step.subs?.length" type="button" class="qd-task-phase-toggle" :aria-expanded="isOpen(step)"
92
+ :aria-label="t('core.task.phase.subs', { count: step.subs.length })" @click="toggle(step)">
93
+ <i class="pi" :class="isOpen(step) ? 'pi-chevron-up' : 'pi-chevron-down'" />
94
+ <span class="qd-task-phase-count">{{ step.subs.length }}</span>
95
+ </button>
96
+ </div>
97
+ <ol v-if="step.subs?.length && isOpen(step)" class="qd-task-phase-subs">
98
+ <li v-for="sub in step.subs" :key="sub.name" class="qd-task-phase qd-task-phase--sub"
99
+ :class="[`qd-task-phase--${sub.state}`, { 'qd-task-phase--selected': selected === sub.name }]">
100
+ <button type="button" class="qd-task-phase-main" :disabled="!canPick(sub, true)" :aria-pressed="canPick(sub, true) ? selected === sub.name : undefined"
101
+ :title="`${label(sub, true)} · ${stateLabel(sub)}`" :aria-label="`${label(sub, true)}, ${stateLabel(sub)} ${time(sub)}`.trim()" @click="pick(sub, true)">
102
+ <i class="qd-task-phase-icon" :class="icon(sub)" aria-hidden="true" />
103
+ <span class="qd-task-phase-label">{{ label(sub, true) }}</span>
104
+ <span class="qd-task-phase-time">{{ time(sub) }}</span>
105
+ </button>
106
+ </li>
107
+ </ol>
108
+ </li>
109
+ </ol>
110
+ </div>
111
+ </template>
@@ -116,6 +116,8 @@ export {
116
116
  useLogStream,
117
117
  type LogSource,
118
118
  type LogLine,
119
+ type LogEntry,
120
+ type LogChunkLine,
119
121
  type LogPollResult,
120
122
  type LogPushApi,
121
123
  type LogStreamStatus,
@@ -18,13 +18,27 @@
18
18
  * // A finished log
19
19
  * useLogStream({ lines: text.split('\n') })
20
20
  * ```
21
+ *
22
+ * A line may also come as an object, `{ text, step, phase }`: the step it
23
+ * belongs to, and on a phase's first and last lines the marker (#4655). The
24
+ * follow dialog filters the log by phase with them.
21
25
  */
22
26
 
23
27
  import { shallowRef, ref, onScopeDispose, getCurrentScope, type Ref, type ShallowRef } from 'vue'
24
28
  import { parseAnsiLine, stripAnsi, type AnsiSegment, type AnsiStyle } from '../utils/ansi'
25
29
 
30
+ /** A line with what it belongs to (#4655): its step, and a phase's start or end marker. */
31
+ export interface LogEntry {
32
+ text: string
33
+ step?: string | null
34
+ phase?: { event: 'start' | 'end'; name: string } | null
35
+ }
36
+
37
+ /** A line as a source gives it: plain text, or an entry. */
38
+ export type LogChunkLine = string | LogEntry
39
+
26
40
  export interface LogPollResult {
27
- lines: string[]
41
+ lines: LogChunkLine[]
28
42
  /** Offset to ask for next. Defaults to the previous one plus the lines received. */
29
43
  next?: number
30
44
  /** True once the log is complete: polling stops. */
@@ -32,7 +46,7 @@ export interface LogPollResult {
32
46
  }
33
47
 
34
48
  export interface LogPushApi {
35
- push: (lines: string | string[]) => void
49
+ push: (lines: LogChunkLine | LogChunkLine[]) => void
36
50
  end: () => void
37
51
  fail: (error: unknown) => void
38
52
  }
@@ -46,10 +60,10 @@ export type LogSource =
46
60
  /** Event that closes the log. Default `end`. */
47
61
  endEvent?: string
48
62
  /** Turn a message's data into lines. Default: JSON `{ lines, done }` or plain text split on newlines. */
49
- parse?: (data: string) => string[] | LogPollResult
63
+ parse?: (data: string) => LogChunkLine[] | LogPollResult
50
64
  }
51
65
  | { subscribe: (api: LogPushApi) => (() => void) | void }
52
- | { lines: string[] }
66
+ | { lines: LogChunkLine[] }
53
67
 
54
68
  export interface LogLine {
55
69
  /** 1-based number in the whole log, kept when old lines are dropped. */
@@ -59,6 +73,10 @@ export interface LogLine {
59
73
  text: string
60
74
  segments: AnsiSegment[]
61
75
  error: boolean
76
+ /** The step it belongs to, when the source says (#4655). */
77
+ step?: string
78
+ /** On a phase's first and last lines: the marker. */
79
+ phase?: { event: 'start' | 'end'; name: string }
62
80
  }
63
81
 
64
82
  export type LogStreamStatus = 'idle' | 'streaming' | 'done' | 'error'
@@ -83,7 +101,7 @@ export interface UseLogStreamReturn {
83
101
  /** Empty the buffer and read the source again from its start. */
84
102
  restart: () => void
85
103
  /** Add lines by hand (used by the push sources, open to the app). */
86
- append: (lines: string | string[]) => void
104
+ append: (lines: LogChunkLine | LogChunkLine[]) => void
87
105
  }
88
106
 
89
107
  const MAX_BACKOFF_MS = 30_000
@@ -95,9 +113,21 @@ function toRegExp(pattern: RegExp | string | null | undefined): RegExp | null {
95
113
  return new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ''))
96
114
  }
97
115
 
98
- function splitLines(chunk: string | string[]): string[] {
116
+ type Incoming = { raw: string; step?: string; phase?: LogLine['phase'] }
117
+
118
+ // An entry spanning several lines keeps its step on each, its marker on the first
119
+ function splitLines(chunk: LogChunkLine | LogChunkLine[]): Incoming[] {
99
120
  const list = Array.isArray(chunk) ? chunk : [chunk]
100
- return list.flatMap((l) => String(l).replace(/\r\n?/g, '\n').split('\n'))
121
+ return list.flatMap((l) => {
122
+ const entry = l !== null && typeof l === 'object' ? l : null
123
+ const raws = String(entry ? entry.text : l).replace(/\r\n?/g, '\n').split('\n')
124
+ if (!entry) return raws.map((raw) => ({ raw }))
125
+ return raws.map((raw, i) => ({
126
+ raw,
127
+ ...(entry.step ? { step: entry.step } : {}),
128
+ ...(i === 0 && entry.phase ? { phase: { event: entry.phase.event, name: entry.phase.name } } : {}),
129
+ }))
130
+ })
101
131
  }
102
132
 
103
133
  function defaultParse(data: string): string[] | LogPollResult {
@@ -110,7 +140,7 @@ function defaultParse(data: string): string[] | LogPollResult {
110
140
  // not JSON: a line that happens to start with a brace
111
141
  }
112
142
  }
113
- return splitLines(data)
143
+ return splitLines(data).map((l) => l.raw)
114
144
  }
115
145
 
116
146
  export function useLogStream(source: LogSource, options: UseLogStreamOptions = {}): UseLogStreamReturn {
@@ -128,14 +158,17 @@ export function useLogStream(source: LogSource, options: UseLogStreamOptions = {
128
158
  // A restart must not let a poll answer from the previous run append.
129
159
  let run = 0
130
160
 
131
- function append(chunk: string | string[]): void {
161
+ function append(chunk: LogChunkLine | LogChunkLine[]): void {
132
162
  const incoming = splitLines(chunk)
133
163
  if (incoming.length === 0) return
134
- const parsed: LogLine[] = incoming.map((raw) => {
164
+ const parsed: LogLine[] = incoming.map(({ raw, step, phase }) => {
135
165
  const { segments, state } = parseAnsiLine(raw, ansiState)
136
166
  ansiState = state
137
167
  const text = stripAnsi(raw)
138
- return { n: ++counter, raw, text, segments, error: errorRe ? errorRe.test(text) : false }
168
+ const line: LogLine = { n: ++counter, raw, text, segments, error: errorRe ? errorRe.test(text) : false }
169
+ if (step) line.step = step
170
+ if (phase) line.phase = phase
171
+ return line
139
172
  })
140
173
  let next = lines.value.concat(parsed)
141
174
  if (next.length > maxLines) {
@@ -165,6 +165,17 @@ export default `core:
165
165
  tray: "{count} running task | {count} running tasks"
166
166
  trayDone: Recent tasks
167
167
  clear: Clear finished
168
+ # The phases frieze (#4655)
169
+ phase:
170
+ pending: To do
171
+ running: Running
172
+ done: Done
173
+ failed: Failed
174
+ cancelled: Cancelled
175
+ skipped: Skipped
176
+ subs: "{count} sub-phase | {count} sub-phases"
177
+ filter: "Phase: {name}"
178
+ showAll: Show the whole log
168
179
  # LoginPage (#4168)
169
180
  login:
170
181
  username: Username
@@ -163,6 +163,17 @@ core:
163
163
  tray: "{count} running task | {count} running tasks"
164
164
  trayDone: Recent tasks
165
165
  clear: Clear finished
166
+ # The phases frieze (#4655)
167
+ phase:
168
+ pending: To do
169
+ running: Running
170
+ done: Done
171
+ failed: Failed
172
+ cancelled: Cancelled
173
+ skipped: Skipped
174
+ subs: "{count} sub-phase | {count} sub-phases"
175
+ filter: "Phase: {name}"
176
+ showAll: Show the whole log
166
177
  # LoginPage (#4168)
167
178
  login:
168
179
  username: Username
@@ -165,6 +165,17 @@ export default `core:
165
165
  tray: "{count} tâche en cours | {count} tâches en cours"
166
166
  trayDone: Tâches récentes
167
167
  clear: Effacer les terminées
168
+ # The phases frieze (#4655)
169
+ phase:
170
+ pending: À venir
171
+ running: En cours
172
+ done: Faite
173
+ failed: En échec
174
+ cancelled: Annulée
175
+ skipped: Sautée
176
+ subs: "{count} sous-phase | {count} sous-phases"
177
+ filter: "Phase : {name}"
178
+ showAll: Voir tout le journal
168
179
  # LoginPage (#4168)
169
180
  login:
170
181
  username: Identifiant
@@ -163,6 +163,17 @@ core:
163
163
  tray: "{count} tâche en cours | {count} tâches en cours"
164
164
  trayDone: Tâches récentes
165
165
  clear: Effacer les terminées
166
+ # The phases frieze (#4655)
167
+ phase:
168
+ pending: À venir
169
+ running: En cours
170
+ done: Faite
171
+ failed: En échec
172
+ cancelled: Annulée
173
+ skipped: Sautée
174
+ subs: "{count} sous-phase | {count} sous-phases"
175
+ filter: "Phase : {name}"
176
+ showAll: Voir tout le journal
166
177
  # LoginPage (#4168)
167
178
  login:
168
179
  username: Identifiant
package/src/index.ts CHANGED
@@ -333,6 +333,8 @@ export {
333
333
  useLogStream,
334
334
  type LogSource,
335
335
  type LogLine,
336
+ type LogEntry,
337
+ type LogChunkLine,
336
338
  type LogPollResult,
337
339
  type LogPushApi,
338
340
  type LogStreamStatus,
@@ -474,6 +476,18 @@ export {
474
476
  type TaskConfirm,
475
477
  type RunOptions,
476
478
  } from './tasks/taskStore'
479
+ export {
480
+ TASK_PHASE_STATE_ICONS,
481
+ formatPhaseDuration,
482
+ linesOfPhase,
483
+ phaseLabel,
484
+ phasesMarkedIn,
485
+ phaseSteps,
486
+ type TaskPhase,
487
+ type TaskPhasesData,
488
+ type TaskPhaseState,
489
+ type TaskPhasesSource,
490
+ } from './tasks/taskPhases'
477
491
 
478
492
  // ════════════════════════════════════════════════════════════════════════════
479
493
  // MODULE SYSTEM (excluding types that conflict)
@@ -253,3 +253,179 @@
253
253
  display: none;
254
254
  }
255
255
  }
256
+
257
+ // ── The phases frieze (#4655): a row across, a column when narrow ──────────
258
+ .qd-task-phases {
259
+ container-type: inline-size;
260
+ margin-top: 0.75rem;
261
+ }
262
+
263
+ .qd-task-phases-list,
264
+ .qd-task-phase-subs {
265
+ list-style: none;
266
+ margin: 0;
267
+ padding: 0;
268
+ }
269
+
270
+ .qd-task-phases-list {
271
+ display: flex;
272
+ align-items: flex-start;
273
+ gap: 0.25rem;
274
+ }
275
+
276
+ .qd-task-phases-list > .qd-task-phase {
277
+ flex: 1 1 0;
278
+ min-width: 0;
279
+ border-top: 3px solid var(--qd-phase-color);
280
+ padding-top: 0.25rem;
281
+ }
282
+
283
+ @container (max-width: 36rem) {
284
+ .qd-task-phases-list {
285
+ flex-direction: column;
286
+ align-items: stretch;
287
+ }
288
+
289
+ .qd-task-phases-list > .qd-task-phase {
290
+ border-top: none;
291
+ border-left: 3px solid var(--qd-phase-color);
292
+ padding: 0 0 0 0.375rem;
293
+ }
294
+ }
295
+
296
+ .qd-task-phase {
297
+ --qd-phase-color: var(--p-surface-300);
298
+ color: var(--p-text-muted-color);
299
+
300
+ &--running {
301
+ --qd-phase-color: var(--p-primary-color);
302
+ color: var(--p-text-color);
303
+ }
304
+
305
+ &--done {
306
+ --qd-phase-color: var(--p-green-500);
307
+ color: var(--p-text-color);
308
+
309
+ .qd-task-phase-icon {
310
+ color: var(--p-green-600);
311
+ }
312
+ }
313
+
314
+ &--failed {
315
+ --qd-phase-color: var(--p-red-500);
316
+ color: var(--p-red-700);
317
+ background: var(--p-red-50);
318
+ border-radius: $radius-sm;
319
+ font-weight: 600;
320
+ }
321
+
322
+ &--cancelled {
323
+ --qd-phase-color: var(--p-surface-400);
324
+
325
+ .qd-task-phase-label {
326
+ text-decoration: line-through;
327
+ }
328
+ }
329
+
330
+ &--skipped {
331
+ --qd-phase-color: var(--p-surface-200);
332
+ opacity: 0.7;
333
+ }
334
+
335
+ &--running > .qd-task-phase-head .qd-task-phase-icon,
336
+ &--running > .qd-task-phase-main .qd-task-phase-icon {
337
+ color: var(--p-primary-color);
338
+ }
339
+ }
340
+
341
+ .qd-task-phase-head {
342
+ display: flex;
343
+ align-items: flex-start;
344
+ }
345
+
346
+ .qd-task-phase-main,
347
+ .qd-task-phase-toggle,
348
+ .qd-task-phase-filter-clear {
349
+ border: none;
350
+ background: none;
351
+ color: inherit;
352
+ font: inherit;
353
+ cursor: pointer;
354
+
355
+ &:disabled {
356
+ cursor: default;
357
+ }
358
+ }
359
+
360
+ .qd-task-phase-main {
361
+ flex: 1 1 auto;
362
+ min-width: 0;
363
+ display: grid;
364
+ grid-template-columns: auto 1fr;
365
+ column-gap: 0.375rem;
366
+ align-items: center;
367
+ padding: 0.25rem 0.375rem;
368
+ border-radius: $radius-sm;
369
+ text-align: left;
370
+ font-size: $font-size-sm;
371
+
372
+ &:not(:disabled):hover {
373
+ background: var(--p-content-hover-background);
374
+ }
375
+ }
376
+
377
+ .qd-task-phase-label {
378
+ overflow: hidden;
379
+ text-overflow: ellipsis;
380
+ white-space: nowrap;
381
+ }
382
+
383
+ .qd-task-phase-time {
384
+ grid-column: 2;
385
+ font-size: $font-size-xs;
386
+ font-variant-numeric: tabular-nums;
387
+ color: var(--p-text-muted-color);
388
+
389
+ &:empty {
390
+ display: none;
391
+ }
392
+ }
393
+
394
+ .qd-task-phase--selected > .qd-task-phase-head > .qd-task-phase-main,
395
+ .qd-task-phase--selected > .qd-task-phase-main {
396
+ background: var(--p-highlight-background);
397
+ color: var(--p-highlight-color);
398
+ }
399
+
400
+ .qd-task-phase-toggle {
401
+ display: inline-flex;
402
+ align-items: center;
403
+ gap: 0.125rem;
404
+ padding: 0.25rem;
405
+ font-size: $font-size-xs;
406
+ color: var(--p-text-muted-color);
407
+ }
408
+
409
+ .qd-task-phase-subs {
410
+ margin: 0.125rem 0 0.25rem 0.75rem;
411
+ border-left: 1px dashed var(--p-content-border-color);
412
+ }
413
+
414
+ .qd-task-phase-filter {
415
+ display: inline-flex;
416
+ align-items: center;
417
+ align-self: flex-start;
418
+ gap: 0.25rem;
419
+ margin-top: 0.5rem;
420
+ padding: 0.125rem 0.25rem 0.125rem 0.625rem;
421
+ border-radius: 1rem;
422
+ background: var(--p-highlight-background);
423
+ color: var(--p-highlight-color);
424
+ font-size: $font-size-sm;
425
+ }
426
+
427
+ .qd-task-phase-filter-clear {
428
+ display: inline-flex;
429
+ padding: 0.25rem;
430
+ border-radius: 50%;
431
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * A task's phases (#4655): the steps a worker goes through (status, preview,
3
+ * wait for the crons, deliver, back up), each with its state and timing,
4
+ * shown as a frieze above the follow dialog's log.
5
+ *
6
+ * The shape is the one a worker reports, e.g. `GET /v1/tasks/{id}/phases`:
7
+ *
8
+ * { state: 'running', steps: [
9
+ * { name: 'status', state: 'done', started: '…', ended: '…', dur: 1.2, subs: [] },
10
+ * { name: 'deploy', state: 'running', started: '…', ended: null, dur: null,
11
+ * subs: [{ name: 'deploy.wait-crons', state: 'done', started: '…', ended: '…', dur: 63 }] },
12
+ * { name: 'backup-after', state: 'pending', started: null, ended: null, dur: null, subs: [] },
13
+ * ] }
14
+ *
15
+ * registerTaskKind('deliver', { task, log, phases: (id) => api.get(`/v1/tasks/${id}/phases`).then((r) => r.data) })
16
+ */
17
+ import type { LogLine } from '../composables/useLogStream'
18
+
19
+ export type TaskPhaseState = 'pending' | 'running' | 'done' | 'failed' | 'cancelled' | 'skipped'
20
+
21
+ export interface TaskPhase {
22
+ /** The step's name; a sub-phase's is usually prefixed by its step's (`deploy.wait-crons`). */
23
+ name: string
24
+ state: TaskPhaseState
25
+ /** ISO times */
26
+ started?: string | null
27
+ ended?: string | null
28
+ /** Duration in seconds, once ended */
29
+ dur?: number | null
30
+ subs?: TaskPhase[]
31
+ }
32
+
33
+ export interface TaskPhasesData {
34
+ state?: string
35
+ result?: unknown
36
+ steps: TaskPhase[]
37
+ }
38
+
39
+ /** The phases of a kind or a run: fixed, or read from the backend while the run lasts. */
40
+ export type TaskPhasesSource =
41
+ | TaskPhasesData
42
+ | TaskPhase[]
43
+ | ((taskId: string | number) => Promise<TaskPhasesData | TaskPhase[]> | TaskPhasesData | TaskPhase[])
44
+
45
+ /** The icon of each state, when the app gives none for the phase. */
46
+ export const TASK_PHASE_STATE_ICONS: Record<TaskPhaseState, string> = {
47
+ pending: 'pi pi-circle',
48
+ running: 'pi pi-spin pi-spinner',
49
+ done: 'pi pi-check-circle',
50
+ failed: 'pi pi-times-circle',
51
+ cancelled: 'pi pi-ban',
52
+ skipped: 'pi pi-minus-circle',
53
+ }
54
+
55
+ /** The steps, from either shape. */
56
+ export function phaseSteps(phases: TaskPhasesData | TaskPhase[] | null | undefined): TaskPhase[] {
57
+ if (!phases) return []
58
+ return Array.isArray(phases) ? phases : (phases.steps ?? [])
59
+ }
60
+
61
+ /**
62
+ * A phase's label: `phase.<name>` in the app's catalogue, else the name. A
63
+ * sub-phase also tries its last segment (`phase.wait-crons`), and falls back
64
+ * to that segment.
65
+ */
66
+ export function phaseLabel(tOr: (key: string, fallback: string) => string, name: string, sub = false): string {
67
+ if (!sub) return tOr(`phase.${name}`, name)
68
+ const last = name.slice(name.lastIndexOf('.') + 1)
69
+ return tOr(`phase.${name}`, last === name ? name : tOr(`phase.${last}`, last))
70
+ }
71
+
72
+ /** A duration in seconds, short: "1.2 s", "12 s", "1 min 3 s", "1 h 2 min". */
73
+ export function formatPhaseDuration(seconds: number | null | undefined): string {
74
+ if (seconds === null || seconds === undefined || !Number.isFinite(seconds) || seconds < 0) return ''
75
+ if (seconds < 10) return `${Math.round(seconds * 10) / 10} s`
76
+ const s = Math.round(seconds)
77
+ if (s < 60) return `${s} s`
78
+ if (s < 3600) return `${Math.floor(s / 60)} min ${s % 60} s`
79
+ return `${Math.floor(s / 3600)} h ${Math.floor((s % 3600) / 60)} min`
80
+ }
81
+
82
+ /**
83
+ * The log lines of a phase. A step's lines carry its name in `step`. A
84
+ * sub-phase's lines carry their step's: they are the ones from its start
85
+ * marker (`phase: { event: 'start', name }`) through its end marker, or up to
86
+ * the last line while it runs.
87
+ */
88
+ export function linesOfPhase(lines: LogLine[], name: string): LogLine[] {
89
+ const prefix = `${name}.`
90
+ const ofStep = lines.filter((l) => l.step === name || (l.step?.startsWith(prefix) ?? false))
91
+ if (ofStep.length) return ofStep
92
+ const out: LogLine[] = []
93
+ let inside = false
94
+ for (const line of lines) {
95
+ if (line.phase?.name === name && line.phase.event === 'start') inside = true
96
+ if (inside) out.push(line)
97
+ if (line.phase?.name === name && line.phase.event === 'end') inside = false
98
+ }
99
+ return out
100
+ }
101
+
102
+ /** The phases a log has start markers for: the sub-phases it can be filtered on. */
103
+ export function phasesMarkedIn(lines: LogLine[]): Set<string> {
104
+ const out = new Set<string>()
105
+ for (const line of lines) if (line.phase?.event === 'start') out.add(line.phase.name)
106
+ return out
107
+ }
@@ -15,6 +15,7 @@
15
15
  import type { TaskDialogOptions, TaskLogPatterns, TaskUiOptions } from './taskUi'
16
16
  import { reactive, computed, type ComputedRef } from 'vue'
17
17
  import type { LogSource } from '../composables/useLogStream'
18
+ import type { TaskPhasesSource } from './taskPhases'
18
19
 
19
20
  export type TaskStatus = 'starting' | 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled'
20
21
 
@@ -60,6 +61,13 @@ export interface TaskKind {
60
61
  dialog?: TaskDialogOptions
61
62
  /** What the log flags as an error or a timestamp for this kind, over the app's (#4386). */
62
63
  logPatterns?: TaskLogPatterns
64
+ /**
65
+ * The task's phases, shown as a frieze above the log (#4655): fixed, or read
66
+ * from the backend at the log's pace while the run lasts, then once at its end.
67
+ */
68
+ phases?: TaskPhasesSource
69
+ /** An icon class per phase name, over the app's. */
70
+ phaseIcons?: Record<string, string>
63
71
  /** Slot components for this kind's dialog, over the app's. */
64
72
  slots?: TaskUiOptions['slots']
65
73
  /** A dialog of its own for this kind, instead of TaskDialog. */