@quazardous/qdadm 2.46.0 → 2.48.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 (51) hide show
  1. package/dist/styles/qdadm.css +1 -1
  2. package/package.json +1 -1
  3. package/src/components/SeverityTag.vue +15 -1
  4. package/src/components/display/QdPending.vue +58 -0
  5. package/src/components/display/QdPendingZone.vue +104 -0
  6. package/src/components/index.ts +5 -0
  7. package/src/components/lists/ListPage.vue +33 -4
  8. package/src/components/show/ShowDisplay.vue +13 -2
  9. package/src/components/show/ShowPage.vue +6 -6
  10. package/src/components/tasks/TaskDialog.vue +13 -157
  11. package/src/components/tasks/TaskHost.vue +28 -2
  12. package/src/components/tasks/TaskRunStatus.vue +63 -0
  13. package/src/components/tasks/TaskRunView.vue +197 -0
  14. package/src/components/tasks/TaskSequenceDialog.vue +157 -0
  15. package/src/components/tasks/TaskTray.vue +33 -13
  16. package/src/composables/index.ts +6 -0
  17. package/src/composables/useAsyncRead.ts +109 -0
  18. package/src/composables/useEntityItemFormPage.ts +13 -6
  19. package/src/composables/useEntityItemFormPage.types.ts +4 -1
  20. package/src/composables/useEntityItemShowPage.ts +18 -7
  21. package/src/composables/useFieldManager.ts +11 -2
  22. package/src/composables/useListPage.filters.ts +21 -1
  23. package/src/composables/useListPage.ts +68 -9
  24. package/src/composables/useListPage.types.ts +4 -1
  25. package/src/composables/useNavContext.ts +5 -4
  26. package/src/entity/EntityManager.ts +17 -0
  27. package/src/entity/EntityManager.types.ts +2 -0
  28. package/src/entity/storage/MockApiStorage.ts +31 -7
  29. package/src/i18n/defaults/core.en.generated.ts +32 -0
  30. package/src/i18n/defaults/core.en.yml +32 -0
  31. package/src/i18n/defaults/core.fr.generated.ts +32 -0
  32. package/src/i18n/defaults/core.fr.yml +32 -0
  33. package/src/i18n/optionLabels.ts +35 -0
  34. package/src/i18n/types.ts +5 -0
  35. package/src/index.ts +11 -0
  36. package/src/kernel/Kernel.i18n.ts +36 -3
  37. package/src/kernel/Kernel.registries.ts +11 -7
  38. package/src/kernel/Kernel.ts +2 -0
  39. package/src/kernel/KernelContext.permissions.ts +11 -0
  40. package/src/kernel/KernelContext.ts +6 -0
  41. package/src/kernel/KernelContext.types.ts +2 -0
  42. package/src/orchestrator/Orchestrator.ts +3 -0
  43. package/src/security/PersistableRolesProvider.ts +61 -3
  44. package/src/security/StaticRolesProvider.ts +6 -0
  45. package/src/styles/_pending.scss +125 -0
  46. package/src/styles/_tasks.scss +126 -0
  47. package/src/styles/index.scss +1 -0
  48. package/src/tasks/taskStore.ts +449 -14
  49. package/src/tasks/taskUi.ts +6 -0
  50. package/src/tasks/useTaskNotifications.ts +6 -2
  51. package/src/tasks/useTaskRunner.ts +24 -0
@@ -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>
@@ -0,0 +1,157 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * TaskSequenceDialog - tasks chained in one window (#4934)
4
+ *
5
+ * The list: one line per step, with its state (waiting, running, done,
6
+ * failed, not run), its duration and a recap (the kind's `summary`, else the
7
+ * error, else the step reached); the running step is highlighted. A click on
8
+ * a step shows its detail, the body of TaskDialog (TaskRunView); "Back to the
9
+ * list" returns. Closing does not stop anything: the sequence goes on in the
10
+ * tray. TaskHost renders it when the open id is a sequence's.
11
+ *
12
+ * Slots `before-log`, `after-log` and `result` reach the step's detail.
13
+ */
14
+ import { computed, onBeforeUnmount, ref, useSlots, watch } from 'vue'
15
+ import Dialog from 'primevue/dialog'
16
+ import ProgressBar from 'primevue/progressbar'
17
+ import QdButton from '../base/QdButton.vue'
18
+ import TaskRunView from './TaskRunView.vue'
19
+ import { useI18n } from '../../i18n/useI18n'
20
+ import { getTaskStore, type SequenceStepStatus, type TaskSequenceStep } from '../../tasks/taskStore'
21
+ import { resolveTaskUi, type TaskDialogOptions } from '../../tasks/taskUi'
22
+ import { formatPhaseDuration } from '../../tasks/taskPhases'
23
+
24
+ interface Props {
25
+ sequenceId: string | null
26
+ /** Window options over the app's */
27
+ options?: TaskDialogOptions | null
28
+ }
29
+
30
+ const props = withDefaults(defineProps<Props>(), { options: null })
31
+ const emit = defineEmits<{ close: [] }>()
32
+ const slots = useSlots()
33
+ const { t } = useI18n()
34
+ const store = getTaskStore()
35
+
36
+ const sequence = computed(() => (props.sequenceId ? store.state.sequences.find((s) => s.id === props.sequenceId) ?? null : null))
37
+ const running = computed(() => store.isActive(sequence.value))
38
+ const opts = computed(() => resolveTaskUi(null, props.options).dialog)
39
+ const bodySlots = computed(() => (['before-log', 'after-log', 'result'] as const).filter((name) => !!slots[name]))
40
+
41
+ /** The run shown in detail, or null for the list */
42
+ const detailId = ref<string | null>(null)
43
+ watch(() => props.sequenceId, () => (detailId.value = null))
44
+ const detailStep = computed(() => (detailId.value ? sequence.value?.steps.find((s) => s.runId === detailId.value) ?? null : null))
45
+ const detailIndex = computed(() => (detailStep.value ? sequence.value!.steps.indexOf(detailStep.value) : -1))
46
+ const detailDef = computed(() => (detailId.value ? store.definition(detailId.value) : undefined))
47
+ const detailRun = computed(() => (detailId.value ? store.state.runs.find((r) => r.id === detailId.value) ?? null : null))
48
+ const canCancelStep = computed(() => !!detailDef.value?.cancel && !!detailRun.value && store.isActive(detailRun.value) && detailRun.value.taskId != null)
49
+
50
+ const done = computed(() => sequence.value?.steps.filter((s) => store.isFinal(store.stepStatus(s)) && store.stepStatus(s) !== 'skipped').length ?? 0)
51
+ const total = computed(() => sequence.value?.steps.length ?? 0)
52
+
53
+ const now = ref(Date.now())
54
+ const ticker = setInterval(() => (now.value = Date.now()), 1000)
55
+ onBeforeUnmount(() => clearInterval(ticker))
56
+
57
+ const stepLabel = (step: TaskSequenceStep, i: number) => step.label || t('core.task.sequence.step', { n: i + 1 })
58
+ const runOf = (step: TaskSequenceStep) => (step.runId ? store.state.runs.find((r) => r.id === step.runId) ?? null : null)
59
+
60
+ function stateText(status: SequenceStepStatus): string {
61
+ if (status === 'pending') return t('core.task.sequence.pending')
62
+ if (status === 'skipped') return t('core.task.sequence.skipped')
63
+ return t(`core.task.status.${status}`)
64
+ }
65
+
66
+ function icon(status: SequenceStepStatus): string {
67
+ if (status === 'pending') return 'pi pi-circle'
68
+ if (status === 'skipped') return 'pi pi-minus-circle'
69
+ if (status === 'succeeded') return 'pi pi-check-circle'
70
+ if (status === 'failed') return 'pi pi-times-circle'
71
+ if (status === 'cancelled') return 'pi pi-ban'
72
+ return 'pi pi-spin pi-spinner'
73
+ }
74
+
75
+ function duration(step: TaskSequenceStep): string {
76
+ const run = runOf(step)
77
+ if (!run) return ''
78
+ return formatPhaseDuration(((run.endedAt ?? now.value) - run.startedAt) / 1000)
79
+ }
80
+
81
+ function recap(step: TaskSequenceStep): string | null {
82
+ if (step.skipped) return t(`core.task.sequence.why.${step.skipped}`)
83
+ return store.stepSummary(step)
84
+ }
85
+
86
+ const isCurrent = (i: number) => running.value && sequence.value?.current === i
87
+ </script>
88
+
89
+ <template>
90
+ <Dialog
91
+ :visible="!!sequence"
92
+ :modal="opts.modal"
93
+ :style="{ width: opts.width }"
94
+ :breakpoints="{ '640px': '96vw' }"
95
+ :draggable="opts.draggable"
96
+ :position="opts.position"
97
+ class="qd-task-dialog qd-task-sequence-dialog"
98
+ :class="opts.class"
99
+ @update:visible="(v: boolean) => !v && emit('close')"
100
+ >
101
+ <template #header>
102
+ <div v-if="sequence" class="qd-task-header qd-task-sequence-header">
103
+ <span class="p-dialog-title">{{ sequence.label }}</span>
104
+ <span class="qd-task-status" :class="`qd-task-status--${sequence.status}`">
105
+ <i :class="icon(sequence.status)" aria-hidden="true" />
106
+ {{ t('core.task.sequence.progress', { done, total }) }}
107
+ </span>
108
+ </div>
109
+ </template>
110
+
111
+ <template v-if="sequence">
112
+ <ol v-if="!detailStep" class="qd-task-sequence-list">
113
+ <li v-for="(step, i) in sequence.steps" :key="i">
114
+ <button type="button" class="qd-task-sequence-step"
115
+ :class="[`qd-task-sequence-step--${store.stepStatus(step)}`, { 'qd-task-sequence-step--current': isCurrent(i) }]"
116
+ :disabled="!step.runId" :aria-current="isCurrent(i) ? 'step' : undefined"
117
+ :aria-label="step.runId ? `${stepLabel(step, i)} — ${t('core.task.sequence.details')}` : undefined"
118
+ @click="detailId = step.runId">
119
+ <i class="qd-task-sequence-icon" :class="icon(store.stepStatus(step))" aria-hidden="true" />
120
+ <span class="qd-task-sequence-main">
121
+ <span class="qd-task-sequence-label">{{ stepLabel(step, i) }}</span>
122
+ <span v-if="recap(step)" class="qd-task-sequence-recap">{{ recap(step) }}</span>
123
+ <ProgressBar v-if="isCurrent(i) && runOf(step)" class="qd-task-sequence-progress"
124
+ :mode="runOf(step)!.progress === null ? 'indeterminate' : 'determinate'"
125
+ :value="Math.round(runOf(step)!.progress ?? 0)" :show-value="false" />
126
+ </span>
127
+ <span class="qd-task-sequence-state">{{ stateText(store.stepStatus(step)) }}</span>
128
+ <span class="qd-task-sequence-duration">{{ duration(step) }}</span>
129
+ <i v-if="step.runId" class="pi pi-angle-right qd-task-sequence-open" aria-hidden="true" />
130
+ </button>
131
+ </li>
132
+ </ol>
133
+ <template v-else>
134
+ <div class="qd-task-sequence-detail-title">
135
+ <span class="qd-task-sequence-detail-index">{{ detailIndex + 1 }}/{{ total }}</span>
136
+ {{ stepLabel(detailStep, detailIndex) }}
137
+ </div>
138
+ <TaskRunView :run-id="detailId" :options="options">
139
+ <template v-for="name in bodySlots" :key="name" #[name]="p">
140
+ <slot :name="name" v-bind="p" />
141
+ </template>
142
+ </TaskRunView>
143
+ </template>
144
+ </template>
145
+
146
+ <template #footer>
147
+ <QdButton v-if="detailStep" class="qd-task-sequence-back" icon="pi pi-arrow-left" text
148
+ :label="t('core.task.sequence.back')" @click="detailId = null" />
149
+ <span class="qd-task-spacer" />
150
+ <QdButton v-if="detailStep && canCancelStep" severity="danger" text :loading="detailRun?.cancelling" icon="pi pi-stop-circle"
151
+ :label="t('core.task.cancel')" @click="detailRun && store.cancel(detailRun.id)" />
152
+ <QdButton v-else-if="!detailStep && running" severity="danger" text :loading="sequence?.cancelling" icon="pi pi-stop-circle"
153
+ :label="t('core.task.sequence.cancel')" @click="sequence && store.cancelSequence(sequence.id)" />
154
+ <QdButton :label="running ? t('core.task.background') : t('core.task.close')" severity="secondary" @click="emit('close')" />
155
+ </template>
156
+ </Dialog>
157
+ </template>
@@ -4,13 +4,14 @@
4
4
  *
5
5
  * Shown while there is a run to show. Each run reopens its dialog; finished
6
6
  * ones can be cleared. A row's content can be replaced (#4334): the `item`
7
- * slot, or `configureTasks({ tray: { item } })`, gets `{ run }`.
7
+ * slot, or `configureTasks({ tray: { item } })`, gets `{ run }`. A sequence
8
+ * (#4934) is one row, "Verify · 1/2", which opens its window.
8
9
  */
9
10
  import { computed, ref } from 'vue'
10
11
  import Popover from 'primevue/popover'
11
12
  import QdButton from '../base/QdButton.vue'
12
13
  import { useI18n } from '../../i18n/useI18n'
13
- import { getTaskStore } from '../../tasks/taskStore'
14
+ import { getTaskStore, type TaskRun, type TaskSequence } from '../../tasks/taskStore'
14
15
  import { getTaskUi } from '../../tasks/taskUi'
15
16
  import { useTaskTrayVisible } from '../../tasks/useTaskNotifications'
16
17
 
@@ -21,9 +22,20 @@ const visible = useTaskTrayVisible()
21
22
  const { t } = useI18n()
22
23
  const popover = ref<InstanceType<typeof Popover> | null>(null)
23
24
 
24
- const runs = computed(() => store.state.runs)
25
- const activeCount = computed(() => store.active.value.length)
26
- const hasFinished = computed(() => runs.value.some((r) => store.isFinal(r.status)))
25
+ // A sequence's steps show as the sequence's row
26
+ const runs = computed(() => store.state.runs.filter((r) => !r.sequenceId || !store.state.sequences.some((s) => s.id === r.sequenceId)))
27
+ const sequences = computed(() => store.state.sequences)
28
+ type Row = { id: string; startedAt: number; run: TaskRun | null; sequence: TaskSequence | null }
29
+ const rows = computed<Row[]>(() =>
30
+ [
31
+ ...runs.value.map((run) => ({ id: run.id, startedAt: run.startedAt, run, sequence: null })),
32
+ ...sequences.value.map((sequence) => ({ id: sequence.id, startedAt: sequence.startedAt, run: null, sequence })),
33
+ ].sort((a, b) => b.startedAt - a.startedAt)
34
+ )
35
+ const activeCount = computed(() => runs.value.filter((r) => store.isActive(r)).length + sequences.value.filter((s) => store.isActive(s)).length)
36
+ const hasFinished = computed(() => runs.value.some((r) => store.isFinal(r.status)) || sequences.value.some((s) => !store.isActive(s)))
37
+ const stepsDone = (sequence: TaskSequence) =>
38
+ sequence.steps.filter((st) => ['succeeded', 'failed', 'cancelled'].includes(store.stepStatus(st))).length
27
39
 
28
40
  function openRun(id: string): void {
29
41
  store.open(id)
@@ -35,7 +47,7 @@ const icon = (status: string) =>
35
47
  </script>
36
48
 
37
49
  <template>
38
- <div v-if="visible && runs.length" class="qd-task-tray">
50
+ <div v-if="visible && rows.length" class="qd-task-tray">
39
51
  <button type="button" class="qd-task-tray-button" :class="{ 'qd-task-tray-button--busy': activeCount > 0 }"
40
52
  :aria-label="t('core.task.tray', { count: activeCount })" @click="popover?.toggle($event)">
41
53
  <i :class="activeCount ? 'pi pi-spin pi-cog' : 'pi pi-check'" />
@@ -44,15 +56,23 @@ const icon = (status: string) =>
44
56
  </button>
45
57
  <Popover ref="popover" class="qd-task-popover">
46
58
  <ul class="qd-task-list">
47
- <li v-for="r in runs" :key="r.id">
48
- <button type="button" class="qd-task-item" :class="`qd-task-item--${r.status}`" @click="openRun(r.id)">
49
- <slot name="item" :run="r">
50
- <component :is="taskUi.tray.item" v-if="taskUi.tray?.item" :run="r" />
59
+ <li v-for="row in rows" :key="row.id">
60
+ <button v-if="row.sequence" type="button" class="qd-task-item qd-task-item--sequence"
61
+ :class="`qd-task-item--${row.sequence.status}`" @click="openRun(row.sequence.id)">
62
+ <i :class="icon(row.sequence.status)" />
63
+ <span class="qd-task-item-label">{{ row.sequence.label }}</span>
64
+ <span class="qd-task-item-state">
65
+ {{ t('core.task.sequence.progress', { done: stepsDone(row.sequence), total: row.sequence.steps.length }) }}
66
+ </span>
67
+ </button>
68
+ <button v-else-if="row.run" type="button" class="qd-task-item" :class="`qd-task-item--${row.run.status}`" @click="openRun(row.run.id)">
69
+ <slot name="item" :run="row.run">
70
+ <component :is="taskUi.tray.item" v-if="taskUi.tray?.item" :run="row.run" />
51
71
  <template v-else>
52
- <i :class="icon(r.status)" />
53
- <span class="qd-task-item-label">{{ r.label }}</span>
72
+ <i :class="icon(row.run.status)" />
73
+ <span class="qd-task-item-label">{{ row.run.label }}</span>
54
74
  <span class="qd-task-item-state">
55
- {{ r.progress !== null && !store.isFinal(r.status) ? `${Math.round(r.progress)} %` : t(`core.task.status.${r.status}`) }}
75
+ {{ row.run.progress !== null && !store.isFinal(row.run.status) ? `${Math.round(row.run.progress)} %` : t(`core.task.status.${row.run.status}`) }}
56
76
  </span>
57
77
  </template>
58
78
  </slot>
@@ -124,6 +124,12 @@ export {
124
124
  type UseLogStreamOptions,
125
125
  type UseLogStreamReturn,
126
126
  } from './useLogStream'
127
+ export {
128
+ useAsyncRead,
129
+ readErrorMessage,
130
+ type UseAsyncReadOptions,
131
+ type UseAsyncReadReturn,
132
+ } from './useAsyncRead'
127
133
  export { useTaskRunner, taskAction } from '../tasks/useTaskRunner'
128
134
  export {
129
135
  useDeferred,
@@ -0,0 +1,109 @@
1
+ /**
2
+ * useAsyncRead - one asynchronous read of a page, and its waiting state (#4665)
3
+ *
4
+ * A page reads several things at once (the server's state, the refs, the
5
+ * builds). Until a read arrives, it must show that it is waiting, not an empty
6
+ * zone, and never a false state such as "no backup" in red.
7
+ *
8
+ * ```ts
9
+ * const backups = useAsyncRead(() => api.get('/backups').then((r) => r.data))
10
+ * // backups.data.value: undefined until the first answer, then the answer, null and [] included
11
+ * // backups.ready.value: true after the first success, for good
12
+ * // backups.pending.value: loading or not ready yet, for :disabled on a gesture that needs it
13
+ * // backups.load(): read again (a retry after an error, a refresh)
14
+ * ```
15
+ *
16
+ * - `loading` is true from creation when the read starts at once: the first
17
+ * render already shows the wait.
18
+ * - The latest call wins: an earlier answer arriving late is dropped.
19
+ * - A failure stops `loading`, sets `error` (a readable message) and keeps the
20
+ * last good `data`.
21
+ * - `key`: what the read is about; a new key reads again from scratch.
22
+ * `useAsyncRead(() => api.leadTime(id.value), { key: () => id.value })`
23
+ *
24
+ * QdPending (a badge) and QdPendingZone (an area) take it as `:read`.
25
+ */
26
+
27
+ import { computed, ref, shallowRef, watch, type ComputedRef, type Ref, type ShallowRef, type WatchSource } from 'vue'
28
+
29
+ export interface UseAsyncReadOptions {
30
+ /** Read at once, from setup. Default true. */
31
+ immediate?: boolean
32
+ /**
33
+ * What the read is about (an id, a route param): when it changes, the read
34
+ * starts over, not ready, so the previous record's answer never shows
35
+ * under the next one (#4687).
36
+ */
37
+ key?: WatchSource<unknown>
38
+ }
39
+
40
+ export interface UseAsyncReadReturn<T> {
41
+ /** `undefined` until the first answer; then the last good answer. */
42
+ data: ShallowRef<T | undefined>
43
+ /** Why the last read failed, or null. */
44
+ error: Ref<string | null>
45
+ /** A read is in flight. */
46
+ loading: Ref<boolean>
47
+ /** At least one read succeeded: `data` is an answer, even null or empty. */
48
+ ready: Ref<boolean>
49
+ /** Loading, or nothing read yet: a gesture that needs the data waits. */
50
+ pending: ComputedRef<boolean>
51
+ /** Read (again); resolves with the answer, or undefined when it failed or a newer read took over. */
52
+ load: () => Promise<T | undefined>
53
+ }
54
+
55
+ /** A readable message from whatever a loader threw. */
56
+ export function readErrorMessage(err: unknown): string {
57
+ if (err instanceof Error) return err.message || err.name
58
+ if (typeof err === 'string') return err
59
+ const message = (err as { message?: unknown } | null)?.message
60
+ if (typeof message === 'string' && message) return message
61
+ try {
62
+ return JSON.stringify(err) ?? String(err)
63
+ } catch {
64
+ return String(err)
65
+ }
66
+ }
67
+
68
+ export function useAsyncRead<T>(loader: () => Promise<T> | T, options: UseAsyncReadOptions = {}): UseAsyncReadReturn<T> {
69
+ const { immediate = true, key } = options
70
+
71
+ const data = shallowRef<T | undefined>(undefined)
72
+ const error = ref<string | null>(null)
73
+ const loading = ref(false)
74
+ const ready = ref(false)
75
+ const pending = computed(() => loading.value || !ready.value)
76
+
77
+ let latest = 0
78
+
79
+ async function load(): Promise<T | undefined> {
80
+ const call = ++latest
81
+ loading.value = true
82
+ try {
83
+ const answer = await loader()
84
+ if (call !== latest) return undefined
85
+ data.value = answer
86
+ error.value = null
87
+ ready.value = true
88
+ return answer
89
+ } catch (err) {
90
+ if (call === latest) error.value = readErrorMessage(err)
91
+ return undefined
92
+ } finally {
93
+ if (call === latest) loading.value = false
94
+ }
95
+ }
96
+
97
+ if (key) {
98
+ watch(key, () => {
99
+ data.value = undefined
100
+ error.value = null
101
+ ready.value = false
102
+ void load()
103
+ })
104
+ }
105
+
106
+ if (immediate) void load()
107
+
108
+ return { data, error, loading, ready, pending, load }
109
+ }
@@ -730,6 +730,7 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
730
730
  if (action.visible && !action.visible({ isEdit: isEdit.value, dirty: dirty.value })) return null
731
731
  return {
732
732
  ...action,
733
+ label: typeof action.label === 'function' ? action.label() : action._label ? action._label() : action.label,
733
734
  isLoading: action.loading ? action.loading() : false,
734
735
  isDisabled: action.disabled
735
736
  ? action.disabled({ dirty: dirty.value, saving: saving.value })
@@ -754,10 +755,14 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
754
755
 
755
756
  function addSaveAction(options: AddSaveActionOptions = {}): void {
756
757
  const { label, andClose = true } = options
757
- const actionLabel = label || (andClose ? 'Save & Close' : 'Save')
758
+ // The catalogue's, by mode: Create / Update, and & Close (#4686)
759
+ const saveLabel = () =>
760
+ andClose
761
+ ? isEdit.value ? tOr('core.actions.updateAndClose', 'Save & Close') : tOr('core.actions.createAndClose', 'Save & Close')
762
+ : tOr('core.actions.save', 'Save')
758
763
 
759
764
  addAction('save', {
760
- label: actionLabel,
765
+ ...(label ? { label } : { label: saveLabel(), _label: saveLabel }),
761
766
  icon: andClose ? 'pi pi-check-circle' : 'pi pi-check',
762
767
  severity: andClose ? 'success' : 'primary',
763
768
  onClick: async () => { await submit(andClose) },
@@ -768,10 +773,11 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
768
773
  }
769
774
 
770
775
  function addDeleteAction(options: AddDeleteActionOptions = {}): void {
771
- const { label = tOr('core.actions.delete', 'Delete') } = options
776
+ const { label } = options
777
+ const deleteLabel = () => tOr('core.actions.delete', 'Delete')
772
778
 
773
779
  addAction('delete', {
774
- label,
780
+ ...(label ? { label } : { label: deleteLabel(), _label: deleteLabel }),
775
781
  icon: 'pi pi-trash',
776
782
  severity: 'danger',
777
783
  onClick: confirmDelete,
@@ -780,10 +786,11 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
780
786
  }
781
787
 
782
788
  function addCancelAction(options: AddCancelActionOptions = {}): void {
783
- const { label = 'Cancel' } = options
789
+ const { label } = options
790
+ const cancelLabel = () => tOr('core.actions.cancel', 'Cancel')
784
791
 
785
792
  addAction('cancel', {
786
- label,
793
+ ...(label ? { label } : { label: cancelLabel(), _label: cancelLabel }),
787
794
  icon: 'pi pi-times',
788
795
  severity: 'secondary',
789
796
  onClick: cancel,
@@ -69,7 +69,8 @@ export interface ToastHelper {
69
69
  */
70
70
  export interface ActionConfig {
71
71
  name: string
72
- label: string
72
+ /** A string, or a function read at each render, so it follows the locale (#4692) */
73
+ label: string | (() => string)
73
74
  icon?: string
74
75
  severity?: string
75
76
  size?: string
@@ -77,6 +78,8 @@ export interface ActionConfig {
77
78
  visible?: (ctx: { isEdit: boolean; dirty: boolean }) => boolean
78
79
  disabled?: (ctx: { dirty: boolean; saving: boolean }) => boolean
79
80
  loading?: () => boolean
81
+ /** A default label, read again at each render so it follows the locale (#4686) */
82
+ _label?: () => string
80
83
  }
81
84
 
82
85
  /**