@quazardous/qdadm 2.48.0 → 2.50.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.
- package/dist/styles/qdadm.css +1 -1
- package/package.json +1 -1
- package/src/chain/StackHydrator.ts +82 -0
- package/src/components/dialogs/QdRevealOnce.vue +163 -0
- package/src/components/display/LogStream.vue +2 -28
- package/src/components/edit/FormPage.vue +9 -1
- package/src/components/index.ts +2 -0
- package/src/components/layout/EntityItemLayout.vue +120 -0
- package/src/components/layout/PageNav.vue +24 -2
- package/src/composables/useEntityItemFormPage.ts +45 -1
- package/src/composables/useEntityItemFormPage.types.ts +15 -0
- package/src/composables/useLiveEntity.ts +3 -1
- package/src/composables/useNavContext.ts +13 -2
- package/src/composables/useNavigation.ts +3 -4
- package/src/entity/EntityManager.cache.ts +49 -8
- package/src/entity/EntityManager.crud.ts +48 -5
- package/src/entity/EntityManager.interface.ts +10 -0
- package/src/entity/EntityManager.ts +21 -0
- package/src/entity/EntityManager.types.ts +28 -0
- package/src/i18n/defaults/core.en.generated.ts +8 -0
- package/src/i18n/defaults/core.en.yml +8 -0
- package/src/i18n/defaults/core.fr.generated.ts +8 -0
- package/src/i18n/defaults/core.fr.yml +8 -0
- package/src/index.ts +3 -1
- package/src/kernel/Kernel.routing.ts +22 -31
- package/src/kernel/KernelContext.routing.ts +9 -0
- package/src/kernel/KernelContext.ts +3 -0
- package/src/kernel/KernelContext.types.ts +6 -0
- package/src/kernel/itemTabs.ts +99 -0
- package/src/module/moduleRegistry.ts +26 -0
- package/src/security/index.ts +1 -0
- package/src/security/routeAccess.ts +94 -0
- package/src/styles/_item-tabs.scss +52 -0
- package/src/styles/index.scss +1 -0
- package/src/tasks/taskStore.ts +92 -2
- package/src/utils/clipboard.ts +36 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tabbed item (#4963): the pages of an item become children of one frame
|
|
3
|
+
* route, whose component (EntityItemLayout) shows the item's header, a tab per
|
|
4
|
+
* page and, in its `router-view`, the page.
|
|
5
|
+
*
|
|
6
|
+
* books/:bookId (frame, no name) EntityItemLayout
|
|
7
|
+
* '' book-show the item's own page, "Details"
|
|
8
|
+
* info book-info a childPage
|
|
9
|
+
* loans loan a child crud list
|
|
10
|
+
* loans/create loan-create …and its forms
|
|
11
|
+
*
|
|
12
|
+
* Route names, full paths and every route's own meta are unchanged; the frame
|
|
13
|
+
* adds only `meta.itemTabs`, which the guard, the breadcrumb and the active
|
|
14
|
+
* stack do not read. The pages of the item are those whose `meta.parent` is the
|
|
15
|
+
* entity, under the same item path, plus the entity's show route when it sits
|
|
16
|
+
* on that path.
|
|
17
|
+
*/
|
|
18
|
+
import type { RouteRecordRaw } from 'vue-router'
|
|
19
|
+
import type { ItemTabsOptions } from '../module/moduleRegistry'
|
|
20
|
+
|
|
21
|
+
/** What the frame route carries in `meta.itemTabs` */
|
|
22
|
+
export interface ItemTabsMeta extends ItemTabsOptions {
|
|
23
|
+
entity: string
|
|
24
|
+
/** The route param carrying the item's id */
|
|
25
|
+
param: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Route = RouteRecordRaw & { meta?: Record<string, unknown>; name?: string | symbol }
|
|
29
|
+
|
|
30
|
+
const EntityItemLayout = () => import('../components/layout/EntityItemLayout.vue')
|
|
31
|
+
|
|
32
|
+
/** Nest the pages of each tabbed entity under a frame route. Routes of other entities pass through, in order. */
|
|
33
|
+
export function nestItemTabs(routes: RouteRecordRaw[], frames: Map<string, ItemTabsOptions>): RouteRecordRaw[] {
|
|
34
|
+
let result = routes as Route[]
|
|
35
|
+
for (const [entity, options] of frames) {
|
|
36
|
+
result = nestOne(result, entity, options)
|
|
37
|
+
}
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parentOf(route: Route): { entity?: string; param?: string } | undefined {
|
|
42
|
+
return route.meta?.parent as { entity?: string; param?: string } | undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function nestOne(routes: Route[], entity: string, options: ItemTabsOptions): Route[] {
|
|
46
|
+
const first = routes.find((r) => parentOf(r)?.entity === entity && parentOf(r)?.param)
|
|
47
|
+
if (!first) {
|
|
48
|
+
console.warn(`[qdadm] itemTabs('${entity}'): no page of an item of '${entity}' (childPage or child crud) — nothing to show as tabs`)
|
|
49
|
+
return routes
|
|
50
|
+
}
|
|
51
|
+
const param = parentOf(first)!.param!
|
|
52
|
+
const marker = `:${param}`
|
|
53
|
+
const at = first.path.indexOf(`/${marker}`)
|
|
54
|
+
if (at < 0) return routes
|
|
55
|
+
const framePath = first.path.slice(0, at + marker.length + 1)
|
|
56
|
+
|
|
57
|
+
const inFrame = (r: Route): boolean => {
|
|
58
|
+
if (parentOf(r)?.entity === entity) return r.path.startsWith(`${framePath}/`)
|
|
59
|
+
// The item's own page, when it sits on the frame's path
|
|
60
|
+
return r.meta?.entity === entity && r.path === framePath && typeof r.name === 'string' && /-show$/.test(r.name)
|
|
61
|
+
}
|
|
62
|
+
const pages = routes.filter(inFrame)
|
|
63
|
+
// A page of the item whose parent param differs (a child crud namespaces it,
|
|
64
|
+
// a childPage keeps the id field) cannot share the frame: say so
|
|
65
|
+
const apart = routes.filter((r) => parentOf(r)?.entity === entity && !inFrame(r)).map((r) => String(r.name ?? r.path))
|
|
66
|
+
if (apart.length) {
|
|
67
|
+
console.warn(
|
|
68
|
+
`[qdadm] itemTabs('${entity}'): ${apart.join(', ')} not in the tabs — their parent param is not ':${param}'. ` +
|
|
69
|
+
`Give them parentParam: '${param}'.`
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
const show = pages.find((r) => r.path === framePath)
|
|
73
|
+
|
|
74
|
+
const children: RouteRecordRaw[] = pages.map((r) => ({ ...r, path: r.path === framePath ? '' : r.path.slice(framePath.length + 1) }) as RouteRecordRaw)
|
|
75
|
+
if (!show) {
|
|
76
|
+
// No page of its own: the item opens on its first tab
|
|
77
|
+
const firstTab = pages.find((r) => typeof r.name === 'string' && !/-(create|edit|new|show)$/.test(r.name) && !r.path.slice(framePath.length + 1).includes(':'))
|
|
78
|
+
if (firstTab) children.unshift({ path: '', redirect: (to) => ({ name: firstTab.name as string, params: to.params }) })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const frame: Route = {
|
|
82
|
+
path: framePath,
|
|
83
|
+
component: (options.component as RouteRecordRaw['component']) ?? EntityItemLayout,
|
|
84
|
+
meta: { itemTabs: { ...options, entity, param } satisfies ItemTabsMeta },
|
|
85
|
+
children,
|
|
86
|
+
} as Route
|
|
87
|
+
|
|
88
|
+
const out: Route[] = []
|
|
89
|
+
let placed = false
|
|
90
|
+
for (const r of routes) {
|
|
91
|
+
if (!inFrame(r)) {
|
|
92
|
+
out.push(r)
|
|
93
|
+
} else if (!placed) {
|
|
94
|
+
out.push(frame)
|
|
95
|
+
placed = true
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out
|
|
99
|
+
}
|
|
@@ -169,6 +169,21 @@ const navItems: NavItemWithSection[] = []
|
|
|
169
169
|
const routeFamilies: Record<string, string[]> = {}
|
|
170
170
|
const navSections = new Map<string, NavItem[]>()
|
|
171
171
|
const entityConfigs = new Map<string, EntityConfig>()
|
|
172
|
+
/** Entities shown as a tabbed item (#4963), by entity name */
|
|
173
|
+
const itemTabs = new Map<string, ItemTabsOptions>()
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A tabbed item (#4963): the item's header, one tab per page of the item, and
|
|
177
|
+
* the page below. Declared by entity: `ctx.itemTabs('instances', { header })`.
|
|
178
|
+
*/
|
|
179
|
+
export interface ItemTabsOptions {
|
|
180
|
+
/** The header, given `{ item, manager, loading, id }`. Default: the entity's label and the item's. */
|
|
181
|
+
header?: unknown
|
|
182
|
+
/** The item's own page as the first tab: `false` to leave it out, or its label. Default: shown, "Details". */
|
|
183
|
+
details?: boolean | string
|
|
184
|
+
/** The frame itself, instead of EntityItemLayout */
|
|
185
|
+
component?: unknown
|
|
186
|
+
}
|
|
172
187
|
|
|
173
188
|
// Configurable section order (set via setSectionOrder or bootstrap)
|
|
174
189
|
let sectionOrder: string[] = []
|
|
@@ -262,6 +277,16 @@ const registry = {
|
|
|
262
277
|
addEntity(name: string, config: EntityConfig): void {
|
|
263
278
|
entityConfigs.set(name, config)
|
|
264
279
|
},
|
|
280
|
+
|
|
281
|
+
/** Show an entity's item as tabs (#4963) */
|
|
282
|
+
addItemTabs(entity: string, options: ItemTabsOptions = {}): void {
|
|
283
|
+
itemTabs.set(entity, options)
|
|
284
|
+
},
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** The entities shown as a tabbed item (#4963) */
|
|
288
|
+
export function getItemTabs(): Map<string, ItemTabsOptions> {
|
|
289
|
+
return itemTabs
|
|
265
290
|
}
|
|
266
291
|
|
|
267
292
|
/**
|
|
@@ -519,6 +544,7 @@ export function resetRegistry(): void {
|
|
|
519
544
|
Object.keys(routeFamilies).forEach((key) => delete routeFamilies[key])
|
|
520
545
|
navSections.clear()
|
|
521
546
|
entityConfigs.clear()
|
|
547
|
+
itemTabs.clear()
|
|
522
548
|
sectionOrder = []
|
|
523
549
|
alteredNavSections = null
|
|
524
550
|
alterationPromise = null
|
package/src/security/index.ts
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may open a route: one rule for the router guard, the menu and PageNav
|
|
3
|
+
* (#4962), so the three cannot drift apart.
|
|
4
|
+
*
|
|
5
|
+
* - Every matched record's `meta.permission` must be granted (#4332): a
|
|
6
|
+
* parent's covers its children.
|
|
7
|
+
* - The route's entity must allow the action it declares: `list` for a list
|
|
8
|
+
* route, `read` for anything else (#2497). The entity is `meta.entity`, or,
|
|
9
|
+
* for a child page that has none of its own, the parent's
|
|
10
|
+
* (`meta.parent.entity`): a page on an item is governed by that item.
|
|
11
|
+
*
|
|
12
|
+
* An app without a security checker checks no permission; an entity that is
|
|
13
|
+
* not registered (yet) is not checked.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The part of a resolved route this reads */
|
|
17
|
+
export interface RouteLike {
|
|
18
|
+
meta?: Record<string, unknown>
|
|
19
|
+
matched?: Array<{ meta?: Record<string, unknown> }>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface RouteAccessDeps {
|
|
23
|
+
orchestrator?: {
|
|
24
|
+
isRegistered?: (name: string) => boolean
|
|
25
|
+
get: (name: string) => unknown
|
|
26
|
+
} | null
|
|
27
|
+
checker?: { isGranted: (attribute: string, subject?: unknown) => boolean } | null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ManagerAccess {
|
|
31
|
+
canList?: () => boolean
|
|
32
|
+
canRead?: () => boolean
|
|
33
|
+
labelPlural?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Why a route is refused, or null when it may be opened */
|
|
37
|
+
export type RouteDenial =
|
|
38
|
+
| { kind: 'permission'; permission: string }
|
|
39
|
+
| { kind: 'entity'; entity: string; action: 'list' | 'read'; manager: ManagerAccess }
|
|
40
|
+
|
|
41
|
+
/** Every permission the route's matched records require */
|
|
42
|
+
export function routePermissions(route: RouteLike): string[] {
|
|
43
|
+
const records = route.matched?.length ? route.matched : [{ meta: route.meta }]
|
|
44
|
+
return records.flatMap((record) => {
|
|
45
|
+
const p = record.meta?.permission
|
|
46
|
+
return (Array.isArray(p) ? p : [p]).filter((x): x is string => typeof x === 'string' && x !== '')
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The entity governing the route: its own, else its parent item's */
|
|
51
|
+
export function routeEntity(route: RouteLike): string | undefined {
|
|
52
|
+
const own = route.meta?.entity
|
|
53
|
+
if (typeof own === 'string' && own) return own
|
|
54
|
+
const parent = (route.meta?.parent as { entity?: unknown } | undefined)?.entity
|
|
55
|
+
return typeof parent === 'string' && parent ? parent : undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The action the route performs: `list` when it declares it, `read` otherwise */
|
|
59
|
+
export function routeAction(route: RouteLike): 'list' | 'read' {
|
|
60
|
+
// A child page runs on an item: `read` of the parent, whatever it declares
|
|
61
|
+
if (!route.meta?.entity) return 'read'
|
|
62
|
+
return route.meta?.entityAction === 'list' ? 'list' : 'read'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The permission check alone: the first one missing, or null */
|
|
66
|
+
export function missingPermission(route: RouteLike, deps: RouteAccessDeps): string | null {
|
|
67
|
+
if (!deps.checker) return null
|
|
68
|
+
return routePermissions(route).find((p) => !deps.checker!.isGranted(p)) ?? null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The entity check alone: the denial, or null */
|
|
72
|
+
export function entityDenial(route: RouteLike, deps: RouteAccessDeps): Extract<RouteDenial, { kind: 'entity' }> | null {
|
|
73
|
+
const entity = routeEntity(route)
|
|
74
|
+
const orchestrator = deps.orchestrator
|
|
75
|
+
if (!entity || !orchestrator) return null
|
|
76
|
+
if (orchestrator.isRegistered && !orchestrator.isRegistered(entity)) return null
|
|
77
|
+
const manager = orchestrator.get(entity) as ManagerAccess | null | undefined
|
|
78
|
+
if (!manager) return null
|
|
79
|
+
const action = routeAction(route)
|
|
80
|
+
const allowed = action === 'list' && manager.canList ? manager.canList() : manager.canRead ? manager.canRead() : true
|
|
81
|
+
return allowed ? null : { kind: 'entity', entity, action, manager }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Why the route is refused, or null when it may be opened */
|
|
85
|
+
export function routeDenial(route: RouteLike, deps: RouteAccessDeps): RouteDenial | null {
|
|
86
|
+
const permission = missingPermission(route, deps)
|
|
87
|
+
if (permission !== null) return { kind: 'permission', permission }
|
|
88
|
+
return entityDenial(route, deps)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Whether the route may be opened */
|
|
92
|
+
export function canOpenRoute(route: RouteLike, deps: RouteAccessDeps): boolean {
|
|
93
|
+
return routeDenial(route, deps) === null
|
|
94
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tabbed item (#4963): EntityItemLayout's header and tab bar
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@use 'variables' as *;
|
|
6
|
+
|
|
7
|
+
.qd-item-tabs-header {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
gap: $space-2xs;
|
|
11
|
+
margin-bottom: $space-md;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.qd-item-tabs-entity {
|
|
15
|
+
font-size: $font-size-xs;
|
|
16
|
+
text-transform: uppercase;
|
|
17
|
+
letter-spacing: 0.04em;
|
|
18
|
+
color: var(--p-text-muted-color);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.qd-item-tabs-title {
|
|
22
|
+
margin: 0;
|
|
23
|
+
font-size: $font-size-2xl;
|
|
24
|
+
font-weight: 600;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.qd-item-tabs-bar {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-wrap: wrap;
|
|
30
|
+
gap: $space-xs;
|
|
31
|
+
margin-bottom: $space-lg;
|
|
32
|
+
border-bottom: 1px solid var(--p-content-border-color);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.qd-item-tabs-tab {
|
|
36
|
+
padding: $space-sm $space-md;
|
|
37
|
+
margin-bottom: -1px;
|
|
38
|
+
border-bottom: 2px solid transparent;
|
|
39
|
+
color: var(--p-text-muted-color);
|
|
40
|
+
text-decoration: none;
|
|
41
|
+
font-size: $font-size-sm;
|
|
42
|
+
|
|
43
|
+
&:hover {
|
|
44
|
+
color: var(--p-text-color);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&--active {
|
|
48
|
+
color: var(--p-primary-color);
|
|
49
|
+
border-bottom-color: var(--p-primary-color);
|
|
50
|
+
font-weight: 600;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/styles/index.scss
CHANGED
package/src/tasks/taskStore.ts
CHANGED
|
@@ -43,6 +43,16 @@ export interface TaskFollow {
|
|
|
43
43
|
intervalMs?: number
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* A record (or a whole entity) a task changes, read again when it ends (#4961):
|
|
48
|
+
* `id` is a value, a function of the run (or of the sequence), or absent for
|
|
49
|
+
* the whole entity.
|
|
50
|
+
*/
|
|
51
|
+
export interface TaskInvalidate<S = TaskRun> {
|
|
52
|
+
entity: string
|
|
53
|
+
id?: string | number | null | ((subject: S) => string | number | null | undefined)
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
/** What a kind of task shares, whatever starts it: registered once, it lets runs resume after a reload. */
|
|
47
57
|
export interface TaskKind {
|
|
48
58
|
label?: string
|
|
@@ -57,6 +67,18 @@ export interface TaskKind {
|
|
|
57
67
|
notify?: boolean
|
|
58
68
|
/** Called once the run ends, whatever the outcome (read `run.status`). */
|
|
59
69
|
onSettled?: (run: TaskRun) => void
|
|
70
|
+
/**
|
|
71
|
+
* What the run changes, read again when it ends, whatever the outcome
|
|
72
|
+
* (#4961). A run's own list adds to its kind's.
|
|
73
|
+
*/
|
|
74
|
+
invalidates?: TaskInvalidate<TaskRun>[]
|
|
75
|
+
/**
|
|
76
|
+
* Awaited before `invalidates` apply: for a backend that is still refreshing
|
|
77
|
+
* what the task changed once the task itself has ended.
|
|
78
|
+
*/
|
|
79
|
+
ready?: (run: TaskRun) => unknown
|
|
80
|
+
/** How long `ready` may take before the invalidation goes ahead anyway. Default 30 000 ms. */
|
|
81
|
+
readyTimeoutMs?: number
|
|
60
82
|
/** The follow dialog's window options for this kind, over the app's (#4334). */
|
|
61
83
|
dialog?: TaskDialogOptions
|
|
62
84
|
/** What the log flags as an error or a timestamp for this kind, over the app's (#4386). */
|
|
@@ -149,6 +171,12 @@ export interface SequenceOptions {
|
|
|
149
171
|
notify?: boolean
|
|
150
172
|
/** Called once the sequence ends. */
|
|
151
173
|
onSettled?: (sequence: TaskSequence) => void
|
|
174
|
+
/** What the sequence changes, read again when it ends (#4961); each step's own apply as it ends. */
|
|
175
|
+
invalidates?: TaskInvalidate<TaskSequence>[]
|
|
176
|
+
/** Awaited before the sequence's `invalidates` apply. */
|
|
177
|
+
ready?: (sequence: TaskSequence) => unknown
|
|
178
|
+
/** How long `ready` may take. Default 30 000 ms. */
|
|
179
|
+
readyTimeoutMs?: number
|
|
152
180
|
}
|
|
153
181
|
|
|
154
182
|
/** A step that has no run: waiting its turn, or never run (and why). */
|
|
@@ -185,7 +213,10 @@ interface TaskHostDeps {
|
|
|
185
213
|
get: (name: string) => unknown
|
|
186
214
|
toast?: Record<'success' | 'error' | 'warn' | 'info', (summary: string, detail?: string, options?: unknown) => void>
|
|
187
215
|
} | null
|
|
188
|
-
signals?: {
|
|
216
|
+
signals?: {
|
|
217
|
+
on: (name: string, handler: (event: { data: unknown }) => void) => () => void
|
|
218
|
+
emit?: (name: string, data?: unknown) => unknown
|
|
219
|
+
} | null
|
|
189
220
|
}
|
|
190
221
|
|
|
191
222
|
interface PendingConfirm {
|
|
@@ -195,6 +226,7 @@ interface PendingConfirm {
|
|
|
195
226
|
}
|
|
196
227
|
|
|
197
228
|
const FINAL: TaskStatus[] = ['succeeded', 'failed', 'cancelled']
|
|
229
|
+
const READY_TIMEOUT_MS = 30_000
|
|
198
230
|
const STORAGE_KEY = 'qdadm:tasks'
|
|
199
231
|
const SEQUENCES_KEY = 'qdadm:task-sequences'
|
|
200
232
|
const KEEP_FINISHED = 20
|
|
@@ -330,11 +362,65 @@ function createTaskStore() {
|
|
|
330
362
|
notifyEnd(run)
|
|
331
363
|
settles.get(id)?.(run)
|
|
332
364
|
settles.delete(id)
|
|
365
|
+
const def = defs.get(id)
|
|
333
366
|
try {
|
|
334
|
-
|
|
367
|
+
def?.onSettled?.(run)
|
|
335
368
|
} catch (err) {
|
|
336
369
|
console.error(`[qdadm] Task "${run.label}": onSettled threw`, err)
|
|
337
370
|
}
|
|
371
|
+
emit('task:settled', { run, kind: run.kind, status: run.status, meta: run.meta })
|
|
372
|
+
void applyInvalidates(def, run, `Task "${run.label}"`)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function emit(name: string, data: unknown): void {
|
|
376
|
+
try {
|
|
377
|
+
void deps.signals?.emit?.(name, data)
|
|
378
|
+
} catch (err) {
|
|
379
|
+
console.error(`[qdadm] ${name}: a listener threw`, err)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Read again what a run or a sequence changed (#4961): once `ready` settles
|
|
385
|
+
* (or times out, or fails: a view a little early beats one never refreshed),
|
|
386
|
+
* each target's manager drops it and the views showing it reload.
|
|
387
|
+
*/
|
|
388
|
+
async function applyInvalidates<S>(
|
|
389
|
+
source: { invalidates?: TaskInvalidate<S>[]; ready?: (subject: S) => unknown; readyTimeoutMs?: number } | undefined,
|
|
390
|
+
subject: S,
|
|
391
|
+
what: string
|
|
392
|
+
): Promise<void> {
|
|
393
|
+
const targets = source?.invalidates
|
|
394
|
+
if (!targets?.length) return
|
|
395
|
+
if (source!.ready) {
|
|
396
|
+
const ms = source!.readyTimeoutMs ?? READY_TIMEOUT_MS
|
|
397
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
398
|
+
try {
|
|
399
|
+
await Promise.race([
|
|
400
|
+
Promise.resolve().then(() => source!.ready!(subject)),
|
|
401
|
+
new Promise((_, reject) => {
|
|
402
|
+
timer = setTimeout(() => reject(new Error(`not ready after ${ms} ms`)), ms)
|
|
403
|
+
}),
|
|
404
|
+
])
|
|
405
|
+
} catch (err) {
|
|
406
|
+
console.warn(`[qdadm] ${what}: ready failed, invalidating anyway —`, errorText(err))
|
|
407
|
+
} finally {
|
|
408
|
+
if (timer) clearTimeout(timer)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
for (const target of targets) {
|
|
412
|
+
try {
|
|
413
|
+
const id = typeof target.id === 'function' ? target.id(subject) : target.id
|
|
414
|
+
const manager = deps.orchestrator?.get(target.entity) as { invalidate?: (id?: string | number | null) => void } | null | undefined
|
|
415
|
+
if (typeof manager?.invalidate !== 'function') {
|
|
416
|
+
console.warn(`[qdadm] ${what}: cannot invalidate "${target.entity}", no such entity`)
|
|
417
|
+
continue
|
|
418
|
+
}
|
|
419
|
+
manager.invalidate(id ?? undefined)
|
|
420
|
+
} catch (err) {
|
|
421
|
+
console.warn(`[qdadm] ${what}: invalidating "${target.entity}" failed —`, errorText(err))
|
|
422
|
+
}
|
|
423
|
+
}
|
|
338
424
|
}
|
|
339
425
|
|
|
340
426
|
function notifyEnd(run: TaskRun): void {
|
|
@@ -476,6 +562,8 @@ function createTaskStore() {
|
|
|
476
562
|
throw new Error(`TaskRunner: unknown task kind "${options.kind}"`)
|
|
477
563
|
}
|
|
478
564
|
const def: TaskKind = { ...base, ...options, task: { ...base?.task, ...options.task } } as TaskKind
|
|
565
|
+
// A run's targets add to its kind's
|
|
566
|
+
if (base?.invalidates?.length && options.invalidates?.length) def.invalidates = [...base.invalidates, ...options.invalidates]
|
|
479
567
|
const labelOf = typeof options.label === 'function' ? options.label : undefined
|
|
480
568
|
const label = labelOf ? labelOf() : (options.label as string)
|
|
481
569
|
const meta = options.meta ? { ...options.meta } : null
|
|
@@ -777,6 +865,8 @@ function createTaskStore() {
|
|
|
777
865
|
} catch (err) {
|
|
778
866
|
console.error(`[qdadm] Task sequence "${sequence.label}": onSettled threw`, err)
|
|
779
867
|
}
|
|
868
|
+
emit('task:sequence-settled', { sequence, status: sequence.status, meta: sequence.meta })
|
|
869
|
+
void applyInvalidates(internals.options, sequence, `Task sequence "${sequence.label}"`)
|
|
780
870
|
}
|
|
781
871
|
|
|
782
872
|
const MARKS: Partial<Record<SequenceStepStatus, string>> = { succeeded: '✓', failed: '✗', cancelled: '⊘', skipped: '–' }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Put text on the clipboard: `navigator.clipboard` when the page has it, a
|
|
3
|
+
* selected textarea otherwise (a page served over plain http has none).
|
|
4
|
+
* Throws when neither works.
|
|
5
|
+
*/
|
|
6
|
+
export async function copyText(text: string): Promise<void> {
|
|
7
|
+
try {
|
|
8
|
+
if (!navigator.clipboard?.writeText) throw new Error('no clipboard on this page (it needs HTTPS)')
|
|
9
|
+
await navigator.clipboard.writeText(text)
|
|
10
|
+
} catch (err) {
|
|
11
|
+
try {
|
|
12
|
+
copyByCommand(text)
|
|
13
|
+
} catch {
|
|
14
|
+
throw err
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function copyByCommand(text: string): void {
|
|
20
|
+
const area = document.createElement('textarea')
|
|
21
|
+
area.value = text
|
|
22
|
+
area.setAttribute('readonly', '')
|
|
23
|
+
area.style.position = 'fixed'
|
|
24
|
+
area.style.opacity = '0'
|
|
25
|
+
document.body.appendChild(area)
|
|
26
|
+
const focused = document.activeElement as HTMLElement | null
|
|
27
|
+
area.select()
|
|
28
|
+
try {
|
|
29
|
+
if (!document.execCommand?.('copy')) throw new Error('the browser refused to copy')
|
|
30
|
+
} finally {
|
|
31
|
+
// The textarea held the value: it goes at once
|
|
32
|
+
area.value = ''
|
|
33
|
+
area.remove()
|
|
34
|
+
focused?.focus?.()
|
|
35
|
+
}
|
|
36
|
+
}
|