@prenta/admin 2.7.0 → 2.9.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 (211) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/design-system/tokens.css +17 -0
  3. package/design-system/tokens.json +35 -1
  4. package/design-system/tokens.scss +15 -0
  5. package/design-system/tokens.tailwind.cjs +14 -0
  6. package/dist/AdminRoot.d.ts.map +1 -1
  7. package/dist/AdminRoot.js +7 -7
  8. package/dist/AdminRoot.js.map +1 -1
  9. package/dist/__tests__/components/batch-ai-actions.test.js +4 -0
  10. package/dist/__tests__/components/batch-ai-actions.test.js.map +1 -1
  11. package/dist/__tests__/lib/batch-wizard.test.d.ts +2 -0
  12. package/dist/__tests__/lib/batch-wizard.test.d.ts.map +1 -0
  13. package/dist/__tests__/lib/batch-wizard.test.js +227 -0
  14. package/dist/__tests__/lib/batch-wizard.test.js.map +1 -0
  15. package/dist/__tests__/lib/job-drawer.test.js +2 -0
  16. package/dist/__tests__/lib/job-drawer.test.js.map +1 -1
  17. package/dist/__tests__/lib/job-view.test.js +100 -3
  18. package/dist/__tests__/lib/job-view.test.js.map +1 -1
  19. package/dist/__tests__/lib/jobs-service.test.js +74 -2
  20. package/dist/__tests__/lib/jobs-service.test.js.map +1 -1
  21. package/dist/__tests__/views/appearance-chrome.render.test.d.ts +2 -0
  22. package/dist/__tests__/views/appearance-chrome.render.test.d.ts.map +1 -0
  23. package/dist/__tests__/views/appearance-chrome.render.test.js +688 -0
  24. package/dist/__tests__/views/appearance-chrome.render.test.js.map +1 -0
  25. package/dist/__tests__/views/header-footer-form.test.d.ts +2 -0
  26. package/dist/__tests__/views/header-footer-form.test.d.ts.map +1 -0
  27. package/dist/__tests__/views/header-footer-form.test.js +266 -0
  28. package/dist/__tests__/views/header-footer-form.test.js.map +1 -0
  29. package/dist/__tests__/views/jobs-drawer.render.test.js +442 -2
  30. package/dist/__tests__/views/jobs-drawer.render.test.js.map +1 -1
  31. package/dist/__tests__/views/jobs-list.render.test.js +7 -5
  32. package/dist/__tests__/views/jobs-list.render.test.js.map +1 -1
  33. package/dist/__tests__/views/jobs-wizard.render.test.d.ts +2 -0
  34. package/dist/__tests__/views/jobs-wizard.render.test.d.ts.map +1 -0
  35. package/dist/__tests__/views/jobs-wizard.render.test.js +588 -0
  36. package/dist/__tests__/views/jobs-wizard.render.test.js.map +1 -0
  37. package/dist/__tests__/views/run-with-ai.render.test.d.ts +2 -0
  38. package/dist/__tests__/views/run-with-ai.render.test.d.ts.map +1 -0
  39. package/dist/__tests__/views/run-with-ai.render.test.js +689 -0
  40. package/dist/__tests__/views/run-with-ai.render.test.js.map +1 -0
  41. package/dist/components/BatchAiActions.d.ts +8 -1
  42. package/dist/components/BatchAiActions.d.ts.map +1 -1
  43. package/dist/components/BatchAiActions.js +3 -2
  44. package/dist/components/BatchAiActions.js.map +1 -1
  45. package/dist/lib/api.d.ts +2 -0
  46. package/dist/lib/api.d.ts.map +1 -1
  47. package/dist/lib/api.js +8 -1
  48. package/dist/lib/api.js.map +1 -1
  49. package/dist/lib/batch-wizard.d.ts +118 -0
  50. package/dist/lib/batch-wizard.d.ts.map +1 -0
  51. package/dist/lib/batch-wizard.js +216 -0
  52. package/dist/lib/batch-wizard.js.map +1 -0
  53. package/dist/lib/chrome-service.d.ts +69 -0
  54. package/dist/lib/chrome-service.d.ts.map +1 -0
  55. package/dist/lib/chrome-service.js +108 -0
  56. package/dist/lib/chrome-service.js.map +1 -0
  57. package/dist/lib/job-view.d.ts +43 -0
  58. package/dist/lib/job-view.d.ts.map +1 -1
  59. package/dist/lib/job-view.js +57 -1
  60. package/dist/lib/job-view.js.map +1 -1
  61. package/dist/lib/jobs-service.d.ts +48 -1
  62. package/dist/lib/jobs-service.d.ts.map +1 -1
  63. package/dist/lib/jobs-service.js +50 -0
  64. package/dist/lib/jobs-service.js.map +1 -1
  65. package/dist/prenta-admin.css +1 -1
  66. package/dist/views/AppearanceChrome.d.ts +22 -4
  67. package/dist/views/AppearanceChrome.d.ts.map +1 -1
  68. package/dist/views/AppearanceChrome.js +451 -15
  69. package/dist/views/AppearanceChrome.js.map +1 -1
  70. package/dist/views/CollectionList.d.ts +3 -1
  71. package/dist/views/CollectionList.d.ts.map +1 -1
  72. package/dist/views/CollectionList.js +5 -2
  73. package/dist/views/CollectionList.js.map +1 -1
  74. package/dist/views/Jobs/CancelJobDialog.d.ts +7 -1
  75. package/dist/views/Jobs/CancelJobDialog.d.ts.map +1 -1
  76. package/dist/views/Jobs/CancelJobDialog.js +13 -3
  77. package/dist/views/Jobs/CancelJobDialog.js.map +1 -1
  78. package/dist/views/Jobs/DrawerOverview.d.ts +6 -2
  79. package/dist/views/Jobs/DrawerOverview.d.ts.map +1 -1
  80. package/dist/views/Jobs/DrawerOverview.js +6 -3
  81. package/dist/views/Jobs/DrawerOverview.js.map +1 -1
  82. package/dist/views/Jobs/DrawerResults.d.ts +13 -3
  83. package/dist/views/Jobs/DrawerResults.d.ts.map +1 -1
  84. package/dist/views/Jobs/DrawerResults.js +37 -3
  85. package/dist/views/Jobs/DrawerResults.js.map +1 -1
  86. package/dist/views/Jobs/DrawerReview.d.ts +7 -0
  87. package/dist/views/Jobs/DrawerReview.d.ts.map +1 -1
  88. package/dist/views/Jobs/DrawerReview.js +1 -1
  89. package/dist/views/Jobs/DrawerReview.js.map +1 -1
  90. package/dist/views/Jobs/JobDrawer.d.ts +26 -3
  91. package/dist/views/Jobs/JobDrawer.d.ts.map +1 -1
  92. package/dist/views/Jobs/JobDrawer.js +30 -5
  93. package/dist/views/Jobs/JobDrawer.js.map +1 -1
  94. package/dist/views/Jobs/JobsTable.d.ts +4 -2
  95. package/dist/views/Jobs/JobsTable.d.ts.map +1 -1
  96. package/dist/views/Jobs/JobsTable.js +6 -5
  97. package/dist/views/Jobs/JobsTable.js.map +1 -1
  98. package/dist/views/Jobs/NewBatchJob.d.ts +34 -0
  99. package/dist/views/Jobs/NewBatchJob.d.ts.map +1 -0
  100. package/dist/views/Jobs/NewBatchJob.js +282 -0
  101. package/dist/views/Jobs/NewBatchJob.js.map +1 -0
  102. package/dist/views/Jobs/RunWithAi.d.ts +25 -0
  103. package/dist/views/Jobs/RunWithAi.d.ts.map +1 -0
  104. package/dist/views/Jobs/RunWithAi.js +46 -0
  105. package/dist/views/Jobs/RunWithAi.js.map +1 -0
  106. package/dist/views/Jobs/WorkerStrip.d.ts +3 -1
  107. package/dist/views/Jobs/WorkerStrip.d.ts.map +1 -1
  108. package/dist/views/Jobs/WorkerStrip.js +2 -2
  109. package/dist/views/Jobs/WorkerStrip.js.map +1 -1
  110. package/dist/views/Jobs/focus.d.ts +6 -0
  111. package/dist/views/Jobs/focus.d.ts.map +1 -1
  112. package/dist/views/Jobs/focus.js +10 -0
  113. package/dist/views/Jobs/focus.js.map +1 -1
  114. package/dist/views/Jobs.d.ts +14 -3
  115. package/dist/views/Jobs.d.ts.map +1 -1
  116. package/dist/views/Jobs.js +144 -32
  117. package/dist/views/Jobs.js.map +1 -1
  118. package/dist/views/MediaBrowser.d.ts +5 -1
  119. package/dist/views/MediaBrowser.d.ts.map +1 -1
  120. package/dist/views/MediaBrowser.js +6 -2
  121. package/dist/views/MediaBrowser.js.map +1 -1
  122. package/dist/views/Pages/PagesListView.d.ts +5 -1
  123. package/dist/views/Pages/PagesListView.d.ts.map +1 -1
  124. package/dist/views/Pages/PagesListView.js +7 -4
  125. package/dist/views/Pages/PagesListView.js.map +1 -1
  126. package/dist/views/Posts/PostsListView.d.ts +5 -1
  127. package/dist/views/Posts/PostsListView.d.ts.map +1 -1
  128. package/dist/views/Posts/PostsListView.js +7 -4
  129. package/dist/views/Posts/PostsListView.js.map +1 -1
  130. package/dist/views/header-footer/AnnouncementTab.d.ts +15 -0
  131. package/dist/views/header-footer/AnnouncementTab.d.ts.map +1 -0
  132. package/dist/views/header-footer/AnnouncementTab.js +43 -0
  133. package/dist/views/header-footer/AnnouncementTab.js.map +1 -0
  134. package/dist/views/header-footer/ChromeField.d.ts +25 -0
  135. package/dist/views/header-footer/ChromeField.d.ts.map +1 -0
  136. package/dist/views/header-footer/ChromeField.js +99 -0
  137. package/dist/views/header-footer/ChromeField.js.map +1 -0
  138. package/dist/views/header-footer/ChromePreview.d.ts +31 -0
  139. package/dist/views/header-footer/ChromePreview.d.ts.map +1 -0
  140. package/dist/views/header-footer/ChromePreview.js +195 -0
  141. package/dist/views/header-footer/ChromePreview.js.map +1 -0
  142. package/dist/views/header-footer/DeveloperTab.d.ts +17 -0
  143. package/dist/views/header-footer/DeveloperTab.d.ts.map +1 -0
  144. package/dist/views/header-footer/DeveloperTab.js +98 -0
  145. package/dist/views/header-footer/DeveloperTab.js.map +1 -0
  146. package/dist/views/header-footer/RegionTab.d.ts +27 -0
  147. package/dist/views/header-footer/RegionTab.d.ts.map +1 -0
  148. package/dist/views/header-footer/RegionTab.js +80 -0
  149. package/dist/views/header-footer/RegionTab.js.map +1 -0
  150. package/dist/views/header-footer/chrome-form.d.ts +137 -0
  151. package/dist/views/header-footer/chrome-form.d.ts.map +1 -0
  152. package/dist/views/header-footer/chrome-form.js +518 -0
  153. package/dist/views/header-footer/chrome-form.js.map +1 -0
  154. package/dist/views/header-footer/code-samples.d.ts +30 -0
  155. package/dist/views/header-footer/code-samples.d.ts.map +1 -0
  156. package/dist/views/header-footer/code-samples.js +127 -0
  157. package/dist/views/header-footer/code-samples.js.map +1 -0
  158. package/dist/views/header-footer/controls.d.ts +57 -0
  159. package/dist/views/header-footer/controls.d.ts.map +1 -0
  160. package/dist/views/header-footer/controls.js +43 -0
  161. package/dist/views/header-footer/controls.js.map +1 -0
  162. package/package.json +3 -3
  163. package/src/AdminRoot.tsx +36 -6
  164. package/src/__tests__/components/batch-ai-actions.test.tsx +10 -0
  165. package/src/__tests__/lib/batch-wizard.test.ts +325 -0
  166. package/src/__tests__/lib/job-drawer.test.ts +2 -0
  167. package/src/__tests__/lib/job-view.test.ts +123 -2
  168. package/src/__tests__/lib/jobs-service.test.ts +92 -3
  169. package/src/__tests__/views/appearance-chrome.render.test.tsx +818 -0
  170. package/src/__tests__/views/header-footer-form.test.ts +333 -0
  171. package/src/__tests__/views/jobs-drawer.render.test.tsx +508 -2
  172. package/src/__tests__/views/jobs-list.render.test.tsx +8 -5
  173. package/src/__tests__/views/jobs-wizard.render.test.tsx +707 -0
  174. package/src/__tests__/views/run-with-ai.render.test.tsx +807 -0
  175. package/src/components/BatchAiActions.tsx +15 -2
  176. package/src/lib/api.ts +12 -1
  177. package/src/lib/batch-wizard.ts +313 -0
  178. package/src/lib/chrome-service.ts +200 -0
  179. package/src/lib/job-view.ts +95 -1
  180. package/src/lib/jobs-service.ts +92 -1
  181. package/src/styles/prenta-tokens.css +17 -0
  182. package/src/styles/theme.css +15 -0
  183. package/src/views/AppearanceChrome.tsx +704 -46
  184. package/src/views/CollectionList.tsx +20 -1
  185. package/src/views/Jobs/CancelJobDialog.tsx +20 -2
  186. package/src/views/Jobs/DrawerOverview.tsx +16 -3
  187. package/src/views/Jobs/DrawerResults.tsx +71 -2
  188. package/src/views/Jobs/DrawerReview.tsx +1 -1
  189. package/src/views/Jobs/JobDrawer.tsx +88 -4
  190. package/src/views/Jobs/JobsTable.tsx +11 -4
  191. package/src/views/Jobs/NewBatchJob.tsx +857 -0
  192. package/src/views/Jobs/RunWithAi.tsx +89 -0
  193. package/src/views/Jobs/WorkerStrip.tsx +16 -11
  194. package/src/views/Jobs/focus.ts +11 -0
  195. package/src/views/Jobs.tsx +212 -50
  196. package/src/views/MediaBrowser.tsx +20 -1
  197. package/src/views/Pages/PagesListView.tsx +28 -3
  198. package/src/views/Posts/PostsListView.tsx +26 -3
  199. package/src/views/header-footer/AnnouncementTab.tsx +231 -0
  200. package/src/views/header-footer/ChromeField.tsx +358 -0
  201. package/src/views/header-footer/ChromePreview.tsx +497 -0
  202. package/src/views/header-footer/DeveloperTab.tsx +331 -0
  203. package/src/views/header-footer/RegionTab.tsx +398 -0
  204. package/src/views/header-footer/chrome-form.ts +603 -0
  205. package/src/views/header-footer/code-samples.ts +146 -0
  206. package/src/views/header-footer/controls.tsx +166 -0
  207. package/dist/views/Jobs/placeholders.d.ts +0 -6
  208. package/dist/views/Jobs/placeholders.d.ts.map +0 -1
  209. package/dist/views/Jobs/placeholders.js +0 -20
  210. package/dist/views/Jobs/placeholders.js.map +0 -1
  211. package/src/views/Jobs/placeholders.tsx +0 -66
@@ -14,6 +14,7 @@ import { useState, useMemo, useCallback, useEffect, useRef } from 'react'
14
14
  import { toast } from 'sonner'
15
15
  import { BatchAiActions } from '../components/BatchAiActions.js'
16
16
  import { cmsApi } from '../lib/api.js'
17
+ import { pickedDocuments } from '../lib/batch-wizard.js'
17
18
  import { useApiData } from '../lib/useApiData.js'
18
19
  import { useVirtualWindow, VirtualTablePadding } from '../components/virtual-window.js'
19
20
  import { editPathForDoc, newPathForCollection } from '../lib/collection-routes.js'
@@ -28,11 +29,14 @@ import {
28
29
  import { TIER_MEDIA, useMediaQuery } from '../lib/tiers.js'
29
30
  import { CardListControls, type CardSortOption } from '../components/ui/CardListControls.js'
30
31
  import { EntryDetailPane } from '../components/collections/EntryDetailPane.js'
32
+ import { RunWithAi } from './Jobs/RunWithAi.js'
31
33
 
32
34
  export interface CollectionListProps {
33
35
  collectionSlug: string
34
36
  config: any
35
37
  onNavigate: (path: string) => void
38
+ /** The signed-in user's role: "Run with AI…" shows to the roles that may queue jobs. */
39
+ role?: string | null
36
40
  }
37
41
 
38
42
  type SortField = 'title' | 'status' | 'updatedAt'
@@ -200,7 +204,7 @@ function formatDate(d: string | undefined): string {
200
204
  })
201
205
  }
202
206
 
203
- export function CollectionList({ collectionSlug, config, onNavigate }: CollectionListProps) {
207
+ export function CollectionList({ collectionSlug, config, onNavigate, role }: CollectionListProps) {
204
208
  const labels = useMemo(() => resolveLabel(config, collectionSlug), [config, collectionSlug])
205
209
  const facets = useMemo(() => facetFieldsFor(config, collectionSlug), [config, collectionSlug])
206
210
  // Post-type and Pages collections open in dedicated editors — never the
@@ -210,6 +214,7 @@ export function CollectionList({ collectionSlug, config, onNavigate }: Collectio
210
214
  () => resolveCollection(config, collectionSlug),
211
215
  [config, collectionSlug],
212
216
  )
217
+ const runsBatchAi = collectionDef?.type === 'page' || collectionDef?.type === 'post'
213
218
  const editPath = useCallback(
214
219
  (id: string | number) => editPathForDoc(collectionDef, collectionSlug, String(id)),
215
220
  [collectionDef, collectionSlug],
@@ -515,10 +520,24 @@ export function CollectionList({ collectionSlug, config, onNavigate }: Collectio
515
520
  >
516
521
  Unpublish
517
522
  </button>
523
+ {/* The batch wizard runs on page and post collections (P-21). Like
524
+ Posts and Pages, they keep only Alt text of the old buttons. */}
525
+ {runsBatchAi ? (
526
+ <RunWithAi
527
+ pick={pickedDocuments(
528
+ [...selected].map((id) => ({ collection: collectionSlug, id })),
529
+ )}
530
+ role={role}
531
+ config={config}
532
+ onNavigate={onNavigate}
533
+ className="rounded-lg px-3 py-1.5 text-sm"
534
+ />
535
+ ) : null}
518
536
  <BatchAiActions
519
537
  documents={[...selected].map((id) => ({ collection: collectionSlug, id }))}
520
538
  onQueued={() => setSelected(new Set())}
521
539
  buttonClassName="rounded-lg px-3 py-1.5 text-sm"
540
+ operations={runsBatchAi ? ['alt-text'] : undefined}
522
541
  />
523
542
  <button
524
543
  onClick={() => bulkAction('delete')}
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
 
3
- import { useState } from 'react'
3
+ import { useRef, useState } from 'react'
4
4
  import * as Dialog from '@radix-ui/react-dialog'
5
5
  import { Button } from '../../components/ui/Button.js'
6
6
  import { jobType, type JobRow } from '../../lib/job-view.js'
@@ -51,19 +51,28 @@ export interface CancelJobDialogProps {
51
51
  * as it is once a cancel goes through, or never had focus.
52
52
  */
53
53
  onFocusFallback: () => void
54
+ /**
55
+ * The dialog has gone and focus is back. A cancel's outcome is reported
56
+ * from here: while the dialog is open, screen readers are kept inside it.
57
+ */
58
+ onClosed?: () => void
54
59
  }
55
60
 
56
61
  /**
57
62
  * The cancel confirmation (jobs-view.jsx `CancelDlg`, JOBS.md "Cancel
58
63
  * dialog"): 460px, radius 14, padding 20. Radix traps focus and closes on Esc.
64
+ * It opens from a row or over the drawer; Esc and the backdrop close only it.
59
65
  */
60
66
  export function CancelJobDialog({
61
67
  job,
62
68
  onClose,
63
69
  onConfirm,
64
70
  onFocusFallback,
71
+ onClosed,
65
72
  }: CancelJobDialogProps) {
66
73
  const [busy, setBusy] = useState(false)
74
+ /** Set before the first await, so a second click can't post a second cancel. */
75
+ const sending = useRef(false)
67
76
  const returnFocus = useReturnFocus(onFocusFallback)
68
77
 
69
78
  return (
@@ -77,11 +86,17 @@ export function CancelJobDialog({
77
86
  <Dialog.Overlay className="bg-scrim fixed inset-0 z-[var(--z-modal)]" />
78
87
  <Dialog.Content
79
88
  {...returnFocus}
89
+ onCloseAutoFocus={(event) => {
90
+ returnFocus.onCloseAutoFocus(event)
91
+ onClosed?.()
92
+ }}
93
+ // Radix makes the rest of the page inert but doesn't say so on the dialog.
94
+ aria-modal="true"
80
95
  className="bg-card border-bdr rounded-14 shadow-shd2 fixed top-1/2 left-1/2 z-[var(--z-modal)] flex w-[min(460px,calc(100%-32px))] -translate-x-1/2 -translate-y-1/2 flex-col gap-3 border p-5 leading-[normal]"
81
96
  >
82
97
  {job ? (
83
98
  <>
84
- <Dialog.Title className="text-txt m-0 text-[length:var(--fs-drawer)] font-bold">
99
+ <Dialog.Title className="text-txt m-0 text-[length:var(--fs-drawer)] leading-[normal] font-bold">
85
100
  Cancel “{job.title}”?
86
101
  </Dialog.Title>
87
102
  <Dialog.Description className="text-body text-sub m-0 leading-[1.55] text-pretty">
@@ -106,10 +121,13 @@ export function CancelJobDialog({
106
121
  busy={busy}
107
122
  leftIcon={<JobIcons.stop size={12} />}
108
123
  onClick={async () => {
124
+ if (sending.current) return
125
+ sending.current = true
109
126
  setBusy(true)
110
127
  try {
111
128
  await onConfirm(job)
112
129
  } finally {
130
+ sending.current = false
113
131
  setBusy(false)
114
132
  }
115
133
  onClose()
@@ -16,10 +16,23 @@ export function DrawerSection({ children }: { children: ReactNode }) {
16
16
  )
17
17
  }
18
18
 
19
- /** `.jd-ai`: an AI note ("What happened", "AI summary") on the accent tint. */
20
- export function AiNote({ label, children }: { label: string; children: ReactNode }) {
19
+ /**
20
+ * `.jd-ai`: an AI note ("What happened", "AI summary") on the accent tint, or
21
+ * on `--bg` (`plain`) for the results' "Fix with AI".
22
+ */
23
+ export function AiNote({
24
+ label,
25
+ plain,
26
+ children,
27
+ }: {
28
+ label: string
29
+ plain?: boolean
30
+ children: ReactNode
31
+ }) {
21
32
  return (
22
- <div className="rounded-10 bg-acc-l text-body text-txt flex gap-2.5 px-3.5 py-3 leading-[1.55]">
33
+ <div
34
+ className={`rounded-10 text-body text-txt flex gap-2.5 px-3.5 py-3 leading-[1.55] ${plain ? 'bg-bg' : 'bg-acc-l'}`}
35
+ >
23
36
  <span className="text-acc mt-0.5 flex shrink-0">
24
37
  <JobIcons.spark size={15} />
25
38
  </span>
@@ -1,9 +1,18 @@
1
1
  'use client'
2
2
 
3
- import type { MouseEvent, ReactNode } from 'react'
3
+ import { useEffect, useState, type MouseEvent, type ReactNode } from 'react'
4
4
  import type { ScanResults } from '@prenta/core'
5
+ import { Button } from '../../components/ui/Button.js'
5
6
  import { useAdminLinks } from '../../components/ui/admin-links.js'
7
+ import {
8
+ fixWithAiPick,
9
+ fixWithAiText,
10
+ type BatchOperation,
11
+ type BatchSelection,
12
+ type BatchSource,
13
+ } from '../../lib/batch-wizard.js'
6
14
  import { formatCreated } from '../../lib/job-view.js'
15
+ import { listSeoBatchTargets, type SeoBatchTarget } from '../../lib/jobs-service.js'
7
16
  import { AiNote, DrawerSection } from './DrawerOverview.js'
8
17
  import { JobIcons } from './icons.js'
9
18
 
@@ -30,6 +39,61 @@ function plainClick(event: MouseEvent) {
30
39
  return event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey
31
40
  }
32
41
 
42
+ export interface FixWithAiProps {
43
+ /** The config's page and post collections, to name a batch's content type. */
44
+ sources: BatchSource[]
45
+ /** Open the wizard with an issue's documents, at step 1 on its operation. */
46
+ onFix: (selection: BatchSelection, operation: BatchOperation) => void
47
+ }
48
+
49
+ /**
50
+ * jobs-drawer.jsx's "Fix with AI" box, after the digest line: a batch job for
51
+ * the largest kind of open issue a batch can fix, with its documents picked.
52
+ * The documents come from `GET /seo/issues/batch-targets` each time Results
53
+ * opens, so the box follows what's still open (the scan's counts are frozen),
54
+ * and leaves out what SEO autopilot or another suggestion already covers.
55
+ * Nothing shows while they load, or when nothing is left to fix.
56
+ */
57
+ function FixWithAi({
58
+ categories,
59
+ sources,
60
+ onFix,
61
+ }: FixWithAiProps & { categories: ScanResults['categories'] }) {
62
+ const [targets, setTargets] = useState<SeoBatchTarget[] | null>(null)
63
+ useEffect(() => {
64
+ const controller = new AbortController()
65
+ void listSeoBatchTargets(controller.signal).then((res) => {
66
+ if (!controller.signal.aborted && res.ok) setTargets(res.value)
67
+ })
68
+ return () => controller.abort()
69
+ }, [])
70
+ const target = targets ? fixWithAiPick(categories, targets) : null
71
+ if (!target) return null
72
+ const labelOf = (id: string) => sources.find((s) => s.id === id)?.label ?? id
73
+ const several = target.sources.length > 1
74
+ return (
75
+ <AiNote label="Fix with AI" plain>
76
+ <span data-fix-with-ai="">{fixWithAiText(target, labelOf)}</span>
77
+ <div className="mt-2 flex flex-wrap gap-2">
78
+ {target.sources.map((s) => (
79
+ <Button
80
+ key={s.source}
81
+ size="sm"
82
+ aria-haspopup="dialog"
83
+ onClick={(event) => {
84
+ // Safari doesn't focus a clicked button; the wizard returns focus here.
85
+ event.currentTarget.focus()
86
+ onFix({ source: s.source, documentIds: s.documentIds }, target.operation)
87
+ }}
88
+ >
89
+ {several ? `Set up batch job for ${labelOf(s.source)}` : 'Set up batch job'}
90
+ </Button>
91
+ ))}
92
+ </div>
93
+ </AiNote>
94
+ )
95
+ }
96
+
33
97
  export interface DrawerResultsProps {
34
98
  type: string
35
99
  results: ScanResults | undefined
@@ -41,12 +105,15 @@ export interface DrawerResultsProps {
41
105
  scanned: number
42
106
  now: number
43
107
  onNavigate: (path: string) => void
108
+ /** An SEO scan's "Fix with AI", for roles that may queue jobs. */
109
+ fixWithAi?: FixWithAiProps
44
110
  }
45
111
 
46
112
  /**
47
113
  * jobs-drawer.jsx Results, for SEO scans and content health checks: three
48
114
  * key numbers, the AI summary, the open issues by kind (each linking to the
49
- * screen that fixes it) and whether the SEO digest went out.
115
+ * screen that fixes it), whether the SEO digest went out and, for an SEO
116
+ * scan, "Fix with AI".
50
117
  */
51
118
  export function DrawerResults({
52
119
  type,
@@ -57,6 +124,7 @@ export function DrawerResults({
57
124
  scanned,
58
125
  now,
59
126
  onNavigate,
127
+ fixWithAi,
60
128
  }: DrawerResultsProps) {
61
129
  const links = useAdminLinks()
62
130
  if (!results) {
@@ -150,6 +218,7 @@ export function DrawerResults({
150
218
  </span>
151
219
  </p>
152
220
  ) : null}
221
+ {seo && fixWithAi ? <FixWithAi categories={results.categories} {...fixWithAi} /> : null}
153
222
  </>
154
223
  )
155
224
  }
@@ -111,7 +111,7 @@ function DiffLabel({ label, children }: { label: string; children?: ReactNode })
111
111
  * A link suggestion's line, as text: the words around the link, the linked
112
112
  * words marked, and where they link. The stored markup is never rendered.
113
113
  */
114
- function LinkLine({ after }: { after: string }) {
114
+ export function LinkLine({ after }: { after: string }) {
115
115
  const parts = linkParts(after)
116
116
  if (!parts) return <>{after}</>
117
117
  return (
@@ -13,7 +13,7 @@ import {
13
13
  drawerTabs,
14
14
  type DrawerTab,
15
15
  } from '../../lib/job-drawer.js'
16
- import { active, view, type JobRow } from '../../lib/job-view.js'
16
+ import { active, retryPoint, view, type JobActions, type JobRow } from '../../lib/job-view.js'
17
17
  import {
18
18
  approveAllReviewItems,
19
19
  decideReviewItem,
@@ -27,9 +27,9 @@ import { Pill, TypeTile } from './atoms.js'
27
27
  import { BusyButton } from './BusyButton.js'
28
28
  import { DrawerActivity } from './DrawerActivity.js'
29
29
  import { DrawerOverview } from './DrawerOverview.js'
30
- import { DrawerResults } from './DrawerResults.js'
30
+ import { DrawerResults, type FixWithAiProps } from './DrawerResults.js'
31
31
  import { DrawerReview, type ReviewItemState } from './DrawerReview.js'
32
- import { focusJobRow, useReturnFocus } from './focus.js'
32
+ import { focusJobDrawer, focusJobRow, useReturnFocus } from './focus.js'
33
33
  import { JobIcons } from './icons.js'
34
34
  import type { JobDrawerTab } from './JobsTable.js'
35
35
  import { useJobDetail, useJobEvents } from './useJobDetail.js'
@@ -71,6 +71,12 @@ interface FocusMove {
71
71
  fallback?: boolean
72
72
  }
73
73
 
74
+ /** An outcome the Jobs screen reported, for the drawer's live region; `n` makes a repeat new. */
75
+ export interface DrawerNotice {
76
+ text: string
77
+ n: number
78
+ }
79
+
74
80
  export interface JobDrawerProps {
75
81
  /** The list's copy of the job, read again every 5 seconds while Live is on. */
76
82
  job: Job
@@ -81,10 +87,26 @@ export interface JobDrawerProps {
81
87
  /** When the list was read, on the server's clock. Relative times count from it. */
82
88
  now: number
83
89
  worker: JobWorkerStatus | null
90
+ /** The footer's Cancel job, "Retry from document {n+1}" and "Retry now", for this viewer. */
91
+ actions: JobActions
92
+ /** A retry of this job is out. */
93
+ retrying: boolean
94
+ /**
95
+ * The screen's latest outcome (a cancel, a retry, a reused Run now). Radix
96
+ * hides the toaster from screen readers while the drawer is open, so the
97
+ * drawer announces it too.
98
+ */
99
+ notice: DrawerNotice | null
100
+ /** Cancel job: opens the cancel dialog over the drawer. */
101
+ onCancel: () => void
102
+ /** Retry from where it stopped, or retry now while it waits out a backoff. Resolves once answered. */
103
+ onRetry: (now: boolean) => Promise<void>
84
104
  onClose: () => void
85
105
  /** Read the list again: a decision changes the job's review counts. */
86
106
  onReload: () => void
87
107
  onNavigate: (path: string) => void
108
+ /** An SEO scan's "Fix with AI" (P-21), for roles that may queue jobs. */
109
+ fixWithAi?: FixWithAiProps
88
110
  }
89
111
 
90
112
  function without<T>(record: Record<string, T>, key: string): Record<string, T> {
@@ -112,7 +134,8 @@ async function copyText(text: string): Promise<boolean> {
112
134
  * It reads `GET /jobs/:id` (results, the full error) and, per tab, the
113
135
  * events and the review changes, each again only when the list's copy of the
114
136
  * job changes. The Review badge and footer use the job's own counts, never
115
- * the number of changes loaded. Cancel and retry in the footer are P-19.
137
+ * the number of changes loaded. The footer's Cancel job and retries (P-19)
138
+ * use the list's handlers, so they act and report the same way from here.
116
139
  */
117
140
  export function JobDrawer({
118
141
  job,
@@ -120,9 +143,15 @@ export function JobDrawer({
120
143
  tab,
121
144
  now,
122
145
  worker,
146
+ actions,
147
+ retrying,
148
+ notice,
149
+ onCancel,
150
+ onRetry,
123
151
  onClose,
124
152
  onReload,
125
153
  onNavigate,
154
+ fixWithAi,
126
155
  }: JobDrawerProps) {
127
156
  const batch = job.type === 'batch-ai'
128
157
  const counts = job.review ?? NO_COUNTS
@@ -162,6 +191,11 @@ export function JobDrawer({
162
191
  [],
163
192
  )
164
193
 
194
+ // The screen clears its notice when a drawer opens or closes, so one here is this drawer's.
195
+ useEffect(() => {
196
+ if (notice) announce(notice.text)
197
+ }, [notice, announce])
198
+
165
199
  const [itemState, setItemState] = useState<Record<string, ReviewItemState>>({})
166
200
  const [drafts, setDrafts] = useState<Record<string, string>>({})
167
201
  /** Documents known to be published or not, from decisions; keyed by document id. */
@@ -171,6 +205,8 @@ export function JobDrawer({
171
205
  /** Bumped so the focus effect runs for a move asked for after an await. */
172
206
  const [, setFocusTick] = useState(0)
173
207
  const afterApproveAll = useRef(false)
208
+ /** A footer retry was answered; its button may have gone with the failure. */
209
+ const afterRetry = useRef(false)
174
210
  /** "Approve all" ignores activations before this time (`APPROVE_ALL_ARM_MS`). */
175
211
  const approveAllFrom = useRef(0)
176
212
  /** A key held on the footer button is repeating, and each repeat clicks it. */
@@ -248,6 +284,24 @@ export function JobDrawer({
248
284
  }
249
285
  })
250
286
 
287
+ // A retry's button goes away with the failure it answered. Focus lost with
288
+ // it (Radix puts it on the dialog itself) moves to the panel, which now
289
+ // shows the job queued again.
290
+ useEffect(() => {
291
+ if (!afterRetry.current) return
292
+ afterRetry.current = false
293
+ const focused = document.activeElement
294
+ if (focused && focused !== document.body && focused !== content.current && focused.isConnected)
295
+ return
296
+ focusJobDrawer()
297
+ })
298
+
299
+ async function retryHere(retryNow: boolean) {
300
+ await onRetry(retryNow)
301
+ afterRetry.current = true
302
+ setFocusTick((tick) => tick + 1)
303
+ }
304
+
251
305
  // When approve-all leaves nothing to review its button goes away; focus
252
306
  // moves to the changes rather than staying on the dialog itself.
253
307
  useEffect(() => {
@@ -492,6 +546,7 @@ export function JobDrawer({
492
546
  scanned={row.total}
493
547
  now={now}
494
548
  onNavigate={onNavigate}
549
+ fixWithAi={fixWithAi}
495
550
  />
496
551
  ) : null}
497
552
  {shown === 'activity' ? (
@@ -514,6 +569,35 @@ export function JobDrawer({
514
569
  </UnderlineTabPanel>
515
570
 
516
571
  <div className="border-bdr mobile:pb-[calc(12px+env(safe-area-inset-bottom,0px))] flex flex-wrap items-center gap-2 border-t px-[18px] py-3">
572
+ {actions.cancel ? (
573
+ <Button
574
+ variant="danger"
575
+ aria-haspopup="dialog"
576
+ leftIcon={<JobIcons.stop size={12} />}
577
+ onClick={onCancel}
578
+ >
579
+ Cancel job
580
+ </Button>
581
+ ) : null}
582
+ {actions.retry ? (
583
+ <BusyButton
584
+ leftIcon={<JobIcons.retry size={13} />}
585
+ busy={retrying}
586
+ onClick={() => void retryHere(false)}
587
+ >
588
+ Retry from {retryPoint(row)}
589
+ </BusyButton>
590
+ ) : null}
591
+ {actions.retryNow ? (
592
+ <BusyButton
593
+ variant="secondary"
594
+ leftIcon={<JobIcons.retry size={13} />}
595
+ busy={retrying}
596
+ onClick={() => void retryHere(true)}
597
+ >
598
+ Retry now
599
+ </BusyButton>
600
+ ) : null}
517
601
  <span className="flex-1" />
518
602
  {/* One button for both, so it keeps focus when it turns into Approve all. */}
519
603
  {canReview && counts.pending > 0 ? (
@@ -5,11 +5,12 @@ import { Button } from '../../components/ui/Button.js'
5
5
  import { Card } from '../../components/ui/Card.js'
6
6
  import { Skeleton } from '../../components/ui/Skeleton.js'
7
7
  import {
8
- active,
9
8
  hasReviewAction,
9
+ jobActions,
10
10
  view,
11
11
  type JobFilter,
12
12
  type JobRow as JobRowModel,
13
+ type JobViewer,
13
14
  } from '../../lib/job-view.js'
14
15
  import { Bar, Pill, TypeTile } from './atoms.js'
15
16
  import { BusyButton } from './BusyButton.js'
@@ -53,6 +54,7 @@ interface RowProps {
53
54
  j: JobRowModel
54
55
  selected: boolean
55
56
  retrying: boolean
57
+ viewer: JobViewer
56
58
  onOpen: (id: string, tab: JobDrawerTab) => void
57
59
  onCancel: (row: JobRowModel) => void
58
60
  onRetry: (row: JobRowModel) => void
@@ -63,10 +65,11 @@ interface RowProps {
63
65
  * the button and its `::after` covers the row, so the Review, Cancel and Retry
64
66
  * buttons aren't nested inside another control. They sit above that layer.
65
67
  */
66
- function JobRowItem({ j, selected, retrying, onOpen, onCancel, onRetry }: RowProps) {
68
+ function JobRowItem({ j, selected, retrying, viewer, onOpen, onCancel, onRetry }: RowProps) {
67
69
  const v = view(j)
68
70
  const statusId = `job-status-${j.id}`
69
71
  const review = hasReviewAction(j)
72
+ const actions = jobActions(j, viewer)
70
73
  return (
71
74
  <li
72
75
  className={`${ROW_GRID} border-bdr relative border-t px-4 py-3 ${
@@ -114,7 +117,7 @@ function JobRowItem({ j, selected, retrying, onOpen, onCancel, onRetry }: RowPro
114
117
  Review
115
118
  </Button>
116
119
  ) : null}
117
- {active(j) && !j.cancelling ? (
120
+ {actions.cancel ? (
118
121
  <Button
119
122
  variant="icon"
120
123
  size="icon"
@@ -126,7 +129,7 @@ function JobRowItem({ j, selected, retrying, onOpen, onCancel, onRetry }: RowPro
126
129
  <JobIcons.stop size={13} />
127
130
  </Button>
128
131
  ) : null}
129
- {j.state === 'dead' ? (
132
+ {actions.retry ? (
130
133
  <BusyButton
131
134
  variant="icon"
132
135
  size="icon"
@@ -162,6 +165,8 @@ export interface JobsTableProps {
162
165
  selectedId: string | null
163
166
  /** The job whose retry request is out. */
164
167
  retryingId: string | null
168
+ /** Who's looking: Cancel and Retry show only to someone who may use them. */
169
+ viewer: JobViewer
165
170
  status: 'loading' | 'ready' | 'error'
166
171
  error: string | null
167
172
  onOpen: (id: string, tab: JobDrawerTab) => void
@@ -176,6 +181,7 @@ export function JobsTable({
176
181
  filter,
177
182
  selectedId,
178
183
  retryingId,
184
+ viewer,
179
185
  status,
180
186
  error,
181
187
  onOpen,
@@ -238,6 +244,7 @@ export function JobsTable({
238
244
  j={j}
239
245
  selected={selectedId === j.id}
240
246
  retrying={retryingId === j.id}
247
+ viewer={viewer}
241
248
  onOpen={onOpen}
242
249
  onCancel={onCancel}
243
250
  onRetry={onRetry}