@quazardous/qdadm 2.47.0 → 2.49.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.
Files changed (35) hide show
  1. package/dist/styles/qdadm.css +1 -1
  2. package/package.json +1 -1
  3. package/src/chain/StackHydrator.ts +82 -0
  4. package/src/components/index.ts +3 -0
  5. package/src/components/layout/EntityItemLayout.vue +120 -0
  6. package/src/components/layout/PageNav.vue +24 -2
  7. package/src/components/tasks/TaskDialog.vue +13 -157
  8. package/src/components/tasks/TaskHost.vue +15 -2
  9. package/src/components/tasks/TaskRunView.vue +197 -0
  10. package/src/components/tasks/TaskSequenceDialog.vue +157 -0
  11. package/src/components/tasks/TaskTray.vue +33 -13
  12. package/src/composables/useLiveEntity.ts +3 -1
  13. package/src/composables/useNavigation.ts +3 -4
  14. package/src/entity/EntityManager.cache.ts +49 -8
  15. package/src/entity/EntityManager.interface.ts +6 -0
  16. package/src/entity/EntityManager.ts +8 -0
  17. package/src/i18n/defaults/core.en.generated.ts +13 -0
  18. package/src/i18n/defaults/core.en.yml +13 -0
  19. package/src/i18n/defaults/core.fr.generated.ts +13 -0
  20. package/src/i18n/defaults/core.fr.yml +13 -0
  21. package/src/index.ts +7 -0
  22. package/src/kernel/Kernel.routing.ts +22 -31
  23. package/src/kernel/KernelContext.routing.ts +9 -0
  24. package/src/kernel/KernelContext.ts +3 -0
  25. package/src/kernel/KernelContext.types.ts +6 -0
  26. package/src/kernel/itemTabs.ts +99 -0
  27. package/src/module/moduleRegistry.ts +26 -0
  28. package/src/security/index.ts +1 -0
  29. package/src/security/routeAccess.ts +94 -0
  30. package/src/styles/_item-tabs.scss +52 -0
  31. package/src/styles/_tasks.scss +102 -0
  32. package/src/styles/index.scss +1 -0
  33. package/src/tasks/taskStore.ts +503 -14
  34. package/src/tasks/useTaskNotifications.ts +6 -2
  35. package/src/tasks/useTaskRunner.ts +15 -1
@@ -0,0 +1,120 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * EntityItemLayout - a tabbed item (#4963)
4
+ *
5
+ * The frame of `ctx.itemTabs(entity)`: the item's header, one tab per page of
6
+ * the item (its own page as "Details", its child pages and child lists, in
7
+ * declaration order, those the user may open), and the page in a
8
+ * `router-view`. A tab switch changes only the page: the header stays, and the
9
+ * item comes from the active stack, which reads it again when it is
10
+ * invalidated (#4960).
11
+ *
12
+ * Inside it, `<PageNav/>` stays silent: the tabs are the navigation.
13
+ */
14
+ import { computed, inject, provide, type Component } from 'vue'
15
+ import { RouterLink, RouterView, useRoute, useRouter, type RouteRecordNormalized, type RouteRecordRaw } from 'vue-router'
16
+ import { useStackHydrator } from '../../chain/useStackHydrator'
17
+ import { useI18n } from '../../i18n/useI18n'
18
+ import { canOpenRoute, type RouteAccessDeps } from '../../security/routeAccess'
19
+ import type { ItemTabsMeta } from '../../kernel/itemTabs'
20
+
21
+ interface ManagerView {
22
+ label?: string
23
+ labelPlural?: string
24
+ getEntityLabel?: (item: unknown) => string | null
25
+ }
26
+
27
+ const route = useRoute()
28
+ const router = useRouter()
29
+ const { tOr } = useI18n()
30
+ const hydrator = useStackHydrator()
31
+ const orchestrator = inject<(RouteAccessDeps['orchestrator'] & { get: (name: string) => unknown }) | null>('qdadmOrchestrator', null)
32
+ const checker = inject<RouteAccessDeps['checker']>('qdadmSecurityChecker', null)
33
+
34
+ provide('qdadmItemTabs', true)
35
+
36
+ /** This frame's record: the innermost matched record carrying meta.itemTabs */
37
+ const frame = computed<RouteRecordNormalized | undefined>(() => [...route.matched].reverse().find((r) => r.meta?.itemTabs))
38
+ const config = computed(() => frame.value?.meta.itemTabs as ItemTabsMeta | undefined)
39
+ const manager = computed(() => (config.value ? (orchestrator?.get(config.value.entity) as ManagerView | null) : null))
40
+ const id = computed(() => (config.value ? (route.params[config.value.param] as string | undefined) ?? null : null))
41
+
42
+ // Read through the levels array each time: the stack replaces it on every
43
+ // hydration, while a level object keeps its identity as its data changes
44
+ const findLevel = () =>
45
+ hydrator.levels.value.find((l) => l.entity === config.value?.entity && String(l.id) === String(id.value)) ?? null
46
+ const item = computed(() => findLevel()?.data ?? null)
47
+ const loading = computed(() => !findLevel()?.hydrated)
48
+ const title = computed(() => (item.value ? manager.value?.getEntityLabel?.(item.value) : null) ?? id.value ?? '')
49
+
50
+ interface Tab {
51
+ name: string
52
+ label: string
53
+ href: string
54
+ exact: boolean
55
+ }
56
+
57
+ function tabLabel(child: RouteRecordRaw): string {
58
+ if (child.path === '') {
59
+ const details = config.value?.details
60
+ return typeof details === 'string' ? details : tOr('breadcrumb.details', 'Details')
61
+ }
62
+ const meta = (child.meta ?? {}) as { navLabel?: string; entity?: string }
63
+ if (meta.navLabel) return meta.navLabel
64
+ const childManager = meta.entity ? (orchestrator?.get(meta.entity) as ManagerView | null) : null
65
+ return childManager?.labelPlural || String(child.name)
66
+ }
67
+
68
+ const tabs = computed<Tab[]>(() => {
69
+ const children = (frame.value?.children ?? []) as RouteRecordRaw[]
70
+ const out: Tab[] = []
71
+ for (const child of children) {
72
+ if (typeof child.name !== 'string' || child.redirect) continue
73
+ // Forms and a child's own record are not tabs: they open from the tab's page
74
+ if (/-(create|edit|new|show)$/.test(child.name) && child.path !== '') continue
75
+ if (child.path.includes(':')) continue
76
+ if (child.path === '' && config.value?.details === false) continue
77
+ let resolved
78
+ try {
79
+ resolved = router.resolve({ name: child.name, params: route.params })
80
+ } catch {
81
+ continue
82
+ }
83
+ if (!canOpenRoute(resolved, { orchestrator, checker })) continue
84
+ out.push({ name: child.name, label: tabLabel(child), href: resolved.path, exact: child.path === '' })
85
+ }
86
+ return out
87
+ })
88
+
89
+ const isActive = (tab: Tab): boolean =>
90
+ tab.exact ? route.path === tab.href : route.path === tab.href || route.path.startsWith(`${tab.href}/`)
91
+
92
+ const header = computed(() => config.value?.header as Component | undefined)
93
+ </script>
94
+
95
+ <template>
96
+ <div class="qd-item-tabs">
97
+ <header class="qd-item-tabs-header">
98
+ <component :is="header" v-if="header" :item="item" :manager="manager" :loading="loading" :id="id" />
99
+ <template v-else>
100
+ <span v-if="manager?.label" class="qd-item-tabs-entity">{{ manager.label }}</span>
101
+ <h1 class="qd-item-tabs-title">{{ title }}</h1>
102
+ </template>
103
+ </header>
104
+ <nav v-if="tabs.length > 1" class="qd-item-tabs-bar" :aria-label="title">
105
+ <RouterLink
106
+ v-for="tab in tabs"
107
+ :key="tab.name"
108
+ :to="tab.href"
109
+ class="qd-item-tabs-tab"
110
+ :class="{ 'qd-item-tabs-tab--active': isActive(tab) }"
111
+ :aria-current="isActive(tab) ? 'page' : undefined"
112
+ >
113
+ {{ tab.label }}
114
+ </RouterLink>
115
+ </nav>
116
+ <div class="qd-item-tabs-page">
117
+ <RouterView />
118
+ </div>
119
+ </div>
120
+ </template>
@@ -12,6 +12,9 @@
12
12
  * Auto-detects from current route:
13
13
  * - Navlinks: sibling routes (same parent entity + param) or children routes
14
14
  *
15
+ * Links the user cannot open are left out (#4962): the same rule as the
16
+ * router guard and the menu (security/routeAccess).
17
+ *
15
18
  * Props:
16
19
  * - showDetailsLink: Show "Details" link in navlinks (default: false)
17
20
  */
@@ -20,6 +23,7 @@ import { useRoute, useRouter } from 'vue-router'
20
23
  import { getSiblingRoutes, getChildRoutes, routeParamsSatisfied, type ModuleRoute, type ParentConfig } from '../../module/moduleRegistry'
21
24
  import { useOrchestrator } from '../../orchestrator/useOrchestrator.js'
22
25
  import { useI18n } from '../../i18n/useI18n'
26
+ import { canOpenRoute, type RouteAccessDeps } from '../../security/routeAccess'
23
27
  import type { EntityManager } from '../../entity/EntityManager'
24
28
  import type { EntityRecord } from '../../types'
25
29
 
@@ -41,6 +45,18 @@ const route = useRoute()
41
45
  const router = useRouter()
42
46
  const { getManager } = useOrchestrator()
43
47
  const { tOr } = useI18n()
48
+ // null without security: every link shows, as in the menu
49
+ const securityChecker = inject<RouteAccessDeps['checker']>('qdadmSecurityChecker', null)
50
+ const accessOrchestrator = inject<RouteAccessDeps['orchestrator']>('qdadmOrchestrator', null)
51
+
52
+ /** Whether the user may open the link's route (unresolvable: shown, the router decides) */
53
+ function canOpen(link: NavLink): boolean {
54
+ try {
55
+ return canOpenRoute(router.resolve(link.to as never), { orchestrator: accessOrchestrator, checker: securityChecker })
56
+ } catch {
57
+ return true
58
+ }
59
+ }
44
60
 
45
61
  // Parent config from route meta
46
62
  const parentConfig = computed<ParentConfig | undefined>(() => route.meta?.parent as ParentConfig | undefined)
@@ -186,10 +202,16 @@ const allNavlinks = computed<NavLink[]>(() => {
186
202
  return []
187
203
  })
188
204
 
205
+ // Only what the user may open
206
+ const visibleNavlinks = computed<NavLink[]>(() => allNavlinks.value.filter(canOpen))
207
+
208
+ // Inside a tabbed item (#4963) the tabs are the navigation: no links twice
209
+ const inItemTabs = inject<boolean>('qdadmItemTabs', false)
210
+
189
211
  // Sync navlinks to AppLayout via provide/inject
190
- watch([allNavlinks, () => route.fullPath], ([links]) => {
212
+ watch([visibleNavlinks, () => route.fullPath], ([links]) => {
191
213
  if (navlinksOverride) {
192
- navlinksOverride.value = links as NavLink[]
214
+ navlinksOverride.value = inItemTabs ? [] : (links as NavLink[])
193
215
  }
194
216
  }, { immediate: true })
195
217
  </script>
@@ -15,20 +15,17 @@
15
15
  * `actions` and `result` get `{ run, kind, final }`.
16
16
  *
17
17
  * A kind with `phases` gets a frieze above the log (#4655), read at the log's
18
- * pace while the run lasts; picking a step shows only its lines.
18
+ * pace while the run lasts; picking a step shows only its lines. The body is
19
+ * TaskRunView (#4934).
19
20
  */
20
21
  import { computed, inject, onBeforeUnmount, onMounted, ref, useSlots, watch, type Component } from 'vue'
21
22
  import { RouterLink } from 'vue-router'
22
23
  import Dialog from 'primevue/dialog'
23
- import ProgressBar from 'primevue/progressbar'
24
24
  import QdButton from '../base/QdButton.vue'
25
- import LogStream from '../display/LogStream.vue'
26
- import TaskPhases from './TaskPhases.vue'
27
- import JsonViewer from '../editors/JsonViewer.vue'
25
+ import TaskRunView from './TaskRunView.vue'
28
26
  import { useI18n } from '../../i18n/useI18n'
29
27
  import { getTaskStore } from '../../tasks/taskStore'
30
28
  import { resolveTaskUi, type TaskDialogOptions, type TaskDialogSlotName } from '../../tasks/taskUi'
31
- import { phaseLabel, phasesMarkedIn, phaseSteps, type TaskPhase } from '../../tasks/taskPhases'
32
29
 
33
30
  interface Props {
34
31
  runId: string | null
@@ -42,125 +39,26 @@ const props = withDefaults(defineProps<Props>(), { options: null, width: undefin
42
39
  const emit = defineEmits<{ close: [] }>()
43
40
  const slots = useSlots()
44
41
 
45
- const { t, tOr } = useI18n()
42
+ const { t } = useI18n()
46
43
  const store = getTaskStore()
47
44
  const appConfig = inject<{ name?: string }>('qdadmApp', {})
48
45
 
49
46
  const run = computed(() => (props.runId ? store.state.runs.find((r) => r.id === props.runId) ?? null : null))
50
47
  const def = computed(() => (props.runId ? store.definition(props.runId) : undefined))
51
48
  const final = computed(() => (run.value ? store.isFinal(run.value.status) : false))
52
- const logSource = computed(() => (run.value?.taskId != null && def.value?.log ? def.value.log(run.value.taskId) : null))
53
- /** The log's download name: the kind and the task, e.g. "deploy-42.log" */
54
- const logFilename = computed(() => {
55
- const r = run.value
56
- const name = `${r?.kind ?? 'task'}-${r?.taskId ?? r?.id ?? 'log'}`.replace(/[^\w.-]+/g, '_')
57
- return `${name}.log`
58
- })
59
49
  const link = computed(() => (run.value?.taskId != null && def.value?.to ? def.value.to(run.value.taskId) : null))
60
50
  const canCancel = computed(() => !!def.value?.cancel && !final.value && run.value?.taskId != null)
61
- const resultIsObject = computed(() => run.value?.result !== null && typeof run.value?.result === 'object')
62
51
 
63
- const ui = computed(() => resolveTaskUi(def.value, { ...props.options, ...(props.width ? { width: props.width } : {}) }))
52
+ const pageOptions = computed(() => ({ ...props.options, ...(props.width ? { width: props.width } : {}) }))
53
+ const ui = computed(() => resolveTaskUi(def.value, pageOptions.value))
54
+ /** The page's slots the body takes */
55
+ const bodySlots = computed(() => (['before-log', 'after-log', 'result'] as const).filter((name) => !!slots[name]))
64
56
  const opts = computed(() => ui.value.dialog)
65
57
  const slotProps = computed(() => ({ run: run.value, kind: run.value?.kind ?? null, final: final.value }))
66
58
  /** A page's slot, else the component the app or the kind gave for it */
67
59
  const slotComponent = (name: TaskDialogSlotName): Component | null => (slots[name] ? null : (ui.value.slots[name] ?? null))
68
60
  const has = (name: TaskDialogSlotName) => !!slots[name] || !!ui.value.slots[name]
69
61
 
70
- // ── The phases (#4655) ────────────────────────────────────────────────────
71
- const phases = ref<TaskPhase[] | null>(null)
72
- const selectedPhase = ref<string | null>(null)
73
- const logView = ref<InstanceType<typeof LogStream> | null>(null)
74
- /** The sub-phases the log has markers for: the only ones it can be filtered on */
75
- const markedSubs = computed(() => {
76
- const marked = phasesMarkedIn(logView.value?.log.lines.value ?? [])
77
- return (phases.value ?? []).flatMap((s) => s.subs ?? []).map((s) => s.name).filter((name) => marked.has(name))
78
- })
79
- const selectedLabel = computed(() => {
80
- const name = selectedPhase.value
81
- if (!name) return ''
82
- const isSub = !(phases.value ?? []).some((s) => s.name === name)
83
- return phaseLabel(tOr, name, isSub)
84
- })
85
- /** The log's pace, else the task's */
86
- const phasesInterval = computed(() => {
87
- const src = logSource.value as { intervalMs?: number } | null
88
- return src?.intervalMs ?? def.value?.task?.intervalMs ?? 2000
89
- })
90
-
91
- let phasesTimer: ReturnType<typeof setTimeout> | null = null
92
- let phasesRead = 0
93
-
94
- async function readPhases(): Promise<void> {
95
- const source = def.value?.phases
96
- if (!source) {
97
- phases.value = null
98
- return
99
- }
100
- if (typeof source !== 'function') {
101
- phases.value = phaseSteps(source)
102
- return
103
- }
104
- const taskId = run.value?.taskId
105
- if (taskId === null || taskId === undefined) return
106
- const current = phasesRead
107
- try {
108
- const read = phaseSteps(await source(taskId))
109
- if (current === phasesRead) phases.value = read
110
- } catch {
111
- // Kept as they were: the next read may do better
112
- }
113
- }
114
-
115
- function stopPhases(): void {
116
- phasesRead++
117
- if (phasesTimer) clearTimeout(phasesTimer)
118
- phasesTimer = null
119
- }
120
-
121
- // Read now, then at the log's pace until the run ends, then once more
122
- function followPhases(): void {
123
- stopPhases()
124
- const current = phasesRead
125
- const tick = async () => {
126
- await readPhases()
127
- if (current !== phasesRead || final.value || typeof def.value?.phases !== 'function') return
128
- phasesTimer = setTimeout(tick, phasesInterval.value)
129
- }
130
- void tick()
131
- }
132
-
133
- watch(
134
- () => [run.value?.id, run.value?.taskId] as const,
135
- ([id], previous) => {
136
- const previousId = previous?.[0]
137
- if (id !== previousId) {
138
- phases.value = null
139
- selectedPhase.value = null
140
- }
141
- if (id) followPhases()
142
- else stopPhases()
143
- },
144
- { immediate: true }
145
- )
146
-
147
- watch(final, (done, was) => {
148
- if (done && !was && run.value) {
149
- stopPhases()
150
- void readPhases()
151
- }
152
- })
153
-
154
- const now = ref(Date.now())
155
- const ticker = setInterval(() => (now.value = Date.now()), 1000)
156
-
157
- const elapsed = computed(() => {
158
- if (!run.value) return ''
159
- const ms = (run.value.endedAt ?? now.value) - run.value.startedAt
160
- const s = Math.round(ms / 1000)
161
- return s < 60 ? `${s} s` : `${Math.floor(s / 60)} min ${s % 60} s`
162
- })
163
-
164
62
  // ── The window (#4334) ────────────────────────────────────────────────────
165
63
  const narrowQuery = typeof window !== 'undefined' && window.matchMedia ? window.matchMedia('(max-width: 640px)') : null
166
64
  const narrow = ref(!!narrowQuery?.matches)
@@ -279,8 +177,6 @@ watch(
279
177
  )
280
178
 
281
179
  onBeforeUnmount(() => {
282
- clearInterval(ticker)
283
- stopPhases()
284
180
  narrowQuery?.removeEventListener?.('change', onNarrow)
285
181
  window.removeEventListener('pointerup', onPointerUp)
286
182
  window.removeEventListener('keydown', onKeyDown)
@@ -314,51 +210,11 @@ onBeforeUnmount(() => {
314
210
  </slot>
315
211
  </div>
316
212
  </template>
317
- <template v-if="run">
318
- <div class="qd-task-head">
319
- <span class="qd-task-status" :class="`qd-task-status--${run.status}`">
320
- <i v-if="!final" class="pi pi-spin pi-spinner" />
321
- <i v-else-if="run.status === 'succeeded'" class="pi pi-check-circle" />
322
- <i v-else-if="run.status === 'failed'" class="pi pi-times-circle" />
323
- <i v-else class="pi pi-ban" />
324
- {{ t(`core.task.status.${run.status}`) }}
325
- </span>
326
- <span class="qd-task-elapsed">{{ elapsed }}</span>
327
- <span v-if="run.taskId !== null" class="qd-task-id">#{{ run.taskId }}</span>
328
- </div>
329
- <ProgressBar v-if="!final" class="qd-task-progress" :mode="run.progress === null ? 'indeterminate' : 'determinate'"
330
- :value="Math.round(run.progress ?? 0)" :show-value="run.progress !== null" />
331
- <div v-if="run.step" class="qd-task-step">{{ run.step }}</div>
332
- <TaskPhases v-if="phases?.length" v-model:selected="selectedPhase" class="qd-task-phases-frieze" :phases="phases"
333
- :selectable="!!logSource" :selectable-subs="markedSubs" :icons="ui.phaseIcons" />
334
- <div v-if="selectedPhase && logSource" class="qd-task-phase-filter">
335
- <span>{{ t('core.task.phase.filter', { name: selectedLabel }) }}</span>
336
- <button type="button" class="qd-task-phase-filter-clear" :aria-label="t('core.task.phase.showAll')"
337
- v-tooltip.top="t('core.task.phase.showAll')" @click="selectedPhase = null"><i class="pi pi-times" /></button>
338
- </div>
339
- <div v-if="has('before-log')" class="qd-task-before-log">
340
- <slot name="before-log" v-bind="slotProps">
341
- <component :is="slotComponent('before-log')!" v-bind="slotProps" />
342
- </slot>
343
- </div>
344
- <LogStream v-if="logSource" ref="logView" :key="run.id" class="qd-task-log" :source="logSource" :filename="logFilename" height="16rem"
345
- :phase="selectedPhase"
346
- :error-pattern="ui.logPatterns.errorPattern" :timestamp-pattern="ui.logPatterns.timestampPattern" @done="store.poke(run.id)" />
347
- <div v-if="has('after-log')" class="qd-task-after-log">
348
- <slot name="after-log" v-bind="slotProps">
349
- <component :is="slotComponent('after-log')!" v-bind="slotProps" />
350
- </slot>
351
- </div>
352
- <div v-if="run.status === 'failed' && run.error" class="qd-task-error"><i class="pi pi-exclamation-triangle" /> {{ run.error }}</div>
353
- <div v-else-if="!final && run.error" class="qd-task-warning">{{ t('core.task.readError', { error: run.error }) }}</div>
354
- <div v-if="run.status === 'succeeded' && run.result !== null" class="qd-task-result">
355
- <slot name="result" v-bind="slotProps">
356
- <component :is="slotComponent('result')!" v-if="slotComponent('result')" v-bind="slotProps" />
357
- <JsonViewer v-else-if="resultIsObject" :model-value="(run.result as never)" height="12rem" />
358
- <span v-else>{{ run.result }}</span>
359
- </slot>
360
- </div>
361
- </template>
213
+ <TaskRunView v-if="run" :run-id="runId" :options="pageOptions">
214
+ <template v-for="name in bodySlots" :key="name" #[name]="p">
215
+ <slot :name="name" v-bind="p" />
216
+ </template>
217
+ </TaskRunView>
362
218
  <template #footer>
363
219
  <RouterLink v-if="link" :to="(link as never)" class="qd-task-link" @click="emit('close')">
364
220
  <i class="pi pi-external-link" /> {{ t('core.task.open') }}
@@ -9,13 +9,15 @@
9
9
  *
10
10
  * The follow dialog is TaskDialog, or the `component` the run's kind or the
11
11
  * app gives (#4334), with props `{ runId, options }` and a `close` event. The
12
- * host's slots go to TaskDialog.
12
+ * host's slots go to TaskDialog. A sequence's id opens TaskSequenceDialog
13
+ * (#4934), which gets the same slots for a step's detail.
13
14
  */
14
15
  import { computed, onBeforeUnmount, ref, watch } from 'vue'
15
16
  import { useRoute } from 'vue-router'
16
17
  import InputText from 'primevue/inputtext'
17
18
  import SimpleDialog from '../dialogs/SimpleDialog.vue'
18
19
  import TaskDialog from './TaskDialog.vue'
20
+ import TaskSequenceDialog from './TaskSequenceDialog.vue'
19
21
  import { useI18n } from '../../i18n/useI18n'
20
22
  import { useTaskRunner } from '../../tasks/useTaskRunner'
21
23
  import { getTaskStore } from '../../tasks/taskStore'
@@ -31,6 +33,12 @@ const { t } = useI18n()
31
33
  store.state.hosts++
32
34
  onBeforeUnmount(() => store.state.hosts--)
33
35
 
36
+ // The open id is a sequence's: its window, not a run's (#4934)
37
+ const openSequence = computed(() => {
38
+ const id = store.state.openId
39
+ return id && store.state.sequences.some((s) => s.id === id) ? id : null
40
+ })
41
+
34
42
  // The open run's dialog: a replacement from its kind or the app, else TaskDialog
35
43
  const dialogComponent = computed(() => {
36
44
  const id = store.state.openId
@@ -58,11 +66,16 @@ const severity = computed(() => pending.value?.confirm.severity ?? (expected.val
58
66
  </script>
59
67
 
60
68
  <template>
61
- <component :is="dialogComponent" :run-id="store.state.openId" :options="null" @close="store.open(null)">
69
+ <component :is="dialogComponent" :run-id="openSequence ? null : store.state.openId" :options="null" @close="store.open(null)">
62
70
  <template v-for="(_, name) in $slots" #[name]="slotProps">
63
71
  <slot :name="name" v-bind="slotProps ?? {}" />
64
72
  </template>
65
73
  </component>
74
+ <TaskSequenceDialog :sequence-id="openSequence" @close="store.open(null)">
75
+ <template v-for="(_, name) in $slots" #[name]="slotProps">
76
+ <slot :name="name" v-bind="slotProps ?? {}" />
77
+ </template>
78
+ </TaskSequenceDialog>
66
79
  <SimpleDialog :visible="!!pending" :title="pending?.label ?? ''" :confirm-label="pending?.confirm.accept ?? t('core.task.start')"
67
80
  :confirm-severity="severity" :confirm-disabled="!confirmable" :cancel-label="t('core.task.dontStart')"
68
81
  @confirm="store.answerConfirm(true)" @cancel="store.answerConfirm(false)"
@@ -0,0 +1,197 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * TaskRunView - one run followed, without its window (#4934)
4
+ *
5
+ * The body of TaskDialog: status, elapsed time, progress, current step, the
6
+ * phases frieze (#4655), the live log, then the error or the result. The
7
+ * sequence window shows it for the step picked in its list. Slots
8
+ * `before-log`, `after-log` and `result` get `{ run, kind, final }`; without
9
+ * one, the app's or the kind's component for it.
10
+ */
11
+ import { computed, onBeforeUnmount, ref, useSlots, watch, type Component } from 'vue'
12
+ import ProgressBar from 'primevue/progressbar'
13
+ import LogStream from '../display/LogStream.vue'
14
+ import TaskPhases from './TaskPhases.vue'
15
+ import JsonViewer from '../editors/JsonViewer.vue'
16
+ import { useI18n } from '../../i18n/useI18n'
17
+ import { getTaskStore } from '../../tasks/taskStore'
18
+ import { resolveTaskUi, type TaskDialogOptions, type TaskDialogSlotName } from '../../tasks/taskUi'
19
+ import { phaseLabel, phasesMarkedIn, phaseSteps, type TaskPhase } from '../../tasks/taskPhases'
20
+
21
+ interface Props {
22
+ runId: string | null
23
+ /** Options over the app's and the kind's (the log's patterns, the phases' icons come from the kind) */
24
+ options?: TaskDialogOptions | null
25
+ }
26
+
27
+ const props = withDefaults(defineProps<Props>(), { options: null })
28
+ const slots = useSlots()
29
+
30
+ const { t, tOr } = useI18n()
31
+ const store = getTaskStore()
32
+
33
+ const run = computed(() => (props.runId ? store.state.runs.find((r) => r.id === props.runId) ?? null : null))
34
+ const def = computed(() => (props.runId ? store.definition(props.runId) : undefined))
35
+ const final = computed(() => (run.value ? store.isFinal(run.value.status) : false))
36
+ const logSource = computed(() => (run.value?.taskId != null && def.value?.log ? def.value.log(run.value.taskId) : null))
37
+ /** The log's download name: the kind and the task, e.g. "deploy-42.log" */
38
+ const logFilename = computed(() => {
39
+ const r = run.value
40
+ const name = `${r?.kind ?? 'task'}-${r?.taskId ?? r?.id ?? 'log'}`.replace(/[^\w.-]+/g, '_')
41
+ return `${name}.log`
42
+ })
43
+ const resultIsObject = computed(() => run.value?.result !== null && typeof run.value?.result === 'object')
44
+
45
+ const ui = computed(() => resolveTaskUi(def.value, props.options))
46
+ const slotProps = computed(() => ({ run: run.value, kind: run.value?.kind ?? null, final: final.value }))
47
+ /** A page's slot, else the component the app or the kind gave for it */
48
+ const slotComponent = (name: TaskDialogSlotName): Component | null => (slots[name] ? null : (ui.value.slots[name] ?? null))
49
+ const has = (name: TaskDialogSlotName) => !!slots[name] || !!ui.value.slots[name]
50
+
51
+ // ── The phases (#4655) ────────────────────────────────────────────────────
52
+ const phases = ref<TaskPhase[] | null>(null)
53
+ const selectedPhase = ref<string | null>(null)
54
+ const logView = ref<InstanceType<typeof LogStream> | null>(null)
55
+ /** The sub-phases the log has markers for: the only ones it can be filtered on */
56
+ const markedSubs = computed(() => {
57
+ const marked = phasesMarkedIn(logView.value?.log.lines.value ?? [])
58
+ return (phases.value ?? []).flatMap((s) => s.subs ?? []).map((s) => s.name).filter((name) => marked.has(name))
59
+ })
60
+ const selectedLabel = computed(() => {
61
+ const name = selectedPhase.value
62
+ if (!name) return ''
63
+ const isSub = !(phases.value ?? []).some((s) => s.name === name)
64
+ return phaseLabel(tOr, name, isSub)
65
+ })
66
+ /** The log's pace, else the task's */
67
+ const phasesInterval = computed(() => {
68
+ const src = logSource.value as { intervalMs?: number } | null
69
+ return src?.intervalMs ?? def.value?.task?.intervalMs ?? 2000
70
+ })
71
+
72
+ let phasesTimer: ReturnType<typeof setTimeout> | null = null
73
+ let phasesRead = 0
74
+
75
+ async function readPhases(): Promise<void> {
76
+ const source = def.value?.phases
77
+ if (!source) {
78
+ phases.value = null
79
+ return
80
+ }
81
+ if (typeof source !== 'function') {
82
+ phases.value = phaseSteps(source)
83
+ return
84
+ }
85
+ const taskId = run.value?.taskId
86
+ if (taskId === null || taskId === undefined) return
87
+ const current = phasesRead
88
+ try {
89
+ const read = phaseSteps(await source(taskId))
90
+ if (current === phasesRead) phases.value = read
91
+ } catch {
92
+ // Kept as they were: the next read may do better
93
+ }
94
+ }
95
+
96
+ function stopPhases(): void {
97
+ phasesRead++
98
+ if (phasesTimer) clearTimeout(phasesTimer)
99
+ phasesTimer = null
100
+ }
101
+
102
+ // Read now, then at the log's pace until the run ends, then once more
103
+ function followPhases(): void {
104
+ stopPhases()
105
+ const current = phasesRead
106
+ const tick = async () => {
107
+ await readPhases()
108
+ if (current !== phasesRead || final.value || typeof def.value?.phases !== 'function') return
109
+ phasesTimer = setTimeout(tick, phasesInterval.value)
110
+ }
111
+ void tick()
112
+ }
113
+
114
+ watch(
115
+ () => [run.value?.id, run.value?.taskId] as const,
116
+ ([id], previous) => {
117
+ const previousId = previous?.[0]
118
+ if (id !== previousId) {
119
+ phases.value = null
120
+ selectedPhase.value = null
121
+ }
122
+ if (id) followPhases()
123
+ else stopPhases()
124
+ },
125
+ { immediate: true }
126
+ )
127
+
128
+ watch(final, (done, was) => {
129
+ if (done && !was && run.value) {
130
+ stopPhases()
131
+ void readPhases()
132
+ }
133
+ })
134
+
135
+ const now = ref(Date.now())
136
+ const ticker = setInterval(() => (now.value = Date.now()), 1000)
137
+
138
+ const elapsed = computed(() => {
139
+ if (!run.value) return ''
140
+ const ms = (run.value.endedAt ?? now.value) - run.value.startedAt
141
+ const s = Math.round(ms / 1000)
142
+ return s < 60 ? `${s} s` : `${Math.floor(s / 60)} min ${s % 60} s`
143
+ })
144
+
145
+ onBeforeUnmount(() => {
146
+ clearInterval(ticker)
147
+ stopPhases()
148
+ })
149
+ </script>
150
+
151
+ <template>
152
+ <div v-if="run" class="qd-task-run-view">
153
+ <div class="qd-task-head">
154
+ <span class="qd-task-status" :class="`qd-task-status--${run.status}`">
155
+ <i v-if="!final" class="pi pi-spin pi-spinner" />
156
+ <i v-else-if="run.status === 'succeeded'" class="pi pi-check-circle" />
157
+ <i v-else-if="run.status === 'failed'" class="pi pi-times-circle" />
158
+ <i v-else class="pi pi-ban" />
159
+ {{ t(`core.task.status.${run.status}`) }}
160
+ </span>
161
+ <span class="qd-task-elapsed">{{ elapsed }}</span>
162
+ <span v-if="run.taskId !== null" class="qd-task-id">#{{ run.taskId }}</span>
163
+ </div>
164
+ <ProgressBar v-if="!final" class="qd-task-progress" :mode="run.progress === null ? 'indeterminate' : 'determinate'"
165
+ :value="Math.round(run.progress ?? 0)" :show-value="run.progress !== null" />
166
+ <div v-if="run.step" class="qd-task-step">{{ run.step }}</div>
167
+ <TaskPhases v-if="phases?.length" v-model:selected="selectedPhase" class="qd-task-phases-frieze" :phases="phases"
168
+ :selectable="!!logSource" :selectable-subs="markedSubs" :icons="ui.phaseIcons" />
169
+ <div v-if="selectedPhase && logSource" class="qd-task-phase-filter">
170
+ <span>{{ t('core.task.phase.filter', { name: selectedLabel }) }}</span>
171
+ <button type="button" class="qd-task-phase-filter-clear" :aria-label="t('core.task.phase.showAll')"
172
+ v-tooltip.top="t('core.task.phase.showAll')" @click="selectedPhase = null"><i class="pi pi-times" /></button>
173
+ </div>
174
+ <div v-if="has('before-log')" class="qd-task-before-log">
175
+ <slot name="before-log" v-bind="slotProps">
176
+ <component :is="slotComponent('before-log')!" v-bind="slotProps" />
177
+ </slot>
178
+ </div>
179
+ <LogStream v-if="logSource" ref="logView" :key="run.id" class="qd-task-log" :source="logSource" :filename="logFilename" height="16rem"
180
+ :phase="selectedPhase"
181
+ :error-pattern="ui.logPatterns.errorPattern" :timestamp-pattern="ui.logPatterns.timestampPattern" @done="store.poke(run.id)" />
182
+ <div v-if="has('after-log')" class="qd-task-after-log">
183
+ <slot name="after-log" v-bind="slotProps">
184
+ <component :is="slotComponent('after-log')!" v-bind="slotProps" />
185
+ </slot>
186
+ </div>
187
+ <div v-if="run.status === 'failed' && run.error" class="qd-task-error"><i class="pi pi-exclamation-triangle" /> {{ run.error }}</div>
188
+ <div v-else-if="!final && run.error" class="qd-task-warning">{{ t('core.task.readError', { error: run.error }) }}</div>
189
+ <div v-if="run.status === 'succeeded' && run.result !== null" class="qd-task-result">
190
+ <slot name="result" v-bind="slotProps">
191
+ <component :is="slotComponent('result')!" v-if="slotComponent('result')" v-bind="slotProps" />
192
+ <JsonViewer v-else-if="resultIsObject" :model-value="(run.result as never)" height="12rem" />
193
+ <span v-else>{{ run.result }}</span>
194
+ </slot>
195
+ </div>
196
+ </div>
197
+ </template>