@prenta/admin 2.8.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 (81) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/AdminRoot.d.ts.map +1 -1
  3. package/dist/AdminRoot.js +6 -6
  4. package/dist/AdminRoot.js.map +1 -1
  5. package/dist/__tests__/components/batch-ai-actions.test.js +4 -0
  6. package/dist/__tests__/components/batch-ai-actions.test.js.map +1 -1
  7. package/dist/__tests__/lib/batch-wizard.test.js +84 -1
  8. package/dist/__tests__/lib/batch-wizard.test.js.map +1 -1
  9. package/dist/__tests__/lib/jobs-service.test.js +19 -1
  10. package/dist/__tests__/lib/jobs-service.test.js.map +1 -1
  11. package/dist/__tests__/views/run-with-ai.render.test.d.ts +2 -0
  12. package/dist/__tests__/views/run-with-ai.render.test.d.ts.map +1 -0
  13. package/dist/__tests__/views/run-with-ai.render.test.js +689 -0
  14. package/dist/__tests__/views/run-with-ai.render.test.js.map +1 -0
  15. package/dist/components/BatchAiActions.d.ts +8 -1
  16. package/dist/components/BatchAiActions.d.ts.map +1 -1
  17. package/dist/components/BatchAiActions.js +3 -2
  18. package/dist/components/BatchAiActions.js.map +1 -1
  19. package/dist/lib/batch-wizard.d.ts +34 -0
  20. package/dist/lib/batch-wizard.d.ts.map +1 -1
  21. package/dist/lib/batch-wizard.js +94 -0
  22. package/dist/lib/batch-wizard.js.map +1 -1
  23. package/dist/lib/jobs-service.d.ts +29 -0
  24. package/dist/lib/jobs-service.d.ts.map +1 -1
  25. package/dist/lib/jobs-service.js +9 -0
  26. package/dist/lib/jobs-service.js.map +1 -1
  27. package/dist/prenta-admin.css +1 -1
  28. package/dist/views/CollectionList.d.ts +3 -1
  29. package/dist/views/CollectionList.d.ts.map +1 -1
  30. package/dist/views/CollectionList.js +5 -2
  31. package/dist/views/CollectionList.js.map +1 -1
  32. package/dist/views/Jobs/DrawerOverview.d.ts +6 -2
  33. package/dist/views/Jobs/DrawerOverview.d.ts.map +1 -1
  34. package/dist/views/Jobs/DrawerOverview.js +6 -3
  35. package/dist/views/Jobs/DrawerOverview.js.map +1 -1
  36. package/dist/views/Jobs/DrawerResults.d.ts +13 -3
  37. package/dist/views/Jobs/DrawerResults.d.ts.map +1 -1
  38. package/dist/views/Jobs/DrawerResults.js +37 -3
  39. package/dist/views/Jobs/DrawerResults.js.map +1 -1
  40. package/dist/views/Jobs/JobDrawer.d.ts +4 -1
  41. package/dist/views/Jobs/JobDrawer.d.ts.map +1 -1
  42. package/dist/views/Jobs/JobDrawer.js +2 -2
  43. package/dist/views/Jobs/JobDrawer.js.map +1 -1
  44. package/dist/views/Jobs/RunWithAi.d.ts +25 -0
  45. package/dist/views/Jobs/RunWithAi.d.ts.map +1 -0
  46. package/dist/views/Jobs/RunWithAi.js +46 -0
  47. package/dist/views/Jobs/RunWithAi.js.map +1 -0
  48. package/dist/views/Jobs.d.ts +3 -1
  49. package/dist/views/Jobs.d.ts.map +1 -1
  50. package/dist/views/Jobs.js +42 -8
  51. package/dist/views/Jobs.js.map +1 -1
  52. package/dist/views/MediaBrowser.d.ts +5 -1
  53. package/dist/views/MediaBrowser.d.ts.map +1 -1
  54. package/dist/views/MediaBrowser.js +6 -2
  55. package/dist/views/MediaBrowser.js.map +1 -1
  56. package/dist/views/Pages/PagesListView.d.ts +5 -1
  57. package/dist/views/Pages/PagesListView.d.ts.map +1 -1
  58. package/dist/views/Pages/PagesListView.js +7 -4
  59. package/dist/views/Pages/PagesListView.js.map +1 -1
  60. package/dist/views/Posts/PostsListView.d.ts +5 -1
  61. package/dist/views/Posts/PostsListView.d.ts.map +1 -1
  62. package/dist/views/Posts/PostsListView.js +7 -4
  63. package/dist/views/Posts/PostsListView.js.map +1 -1
  64. package/package.json +3 -3
  65. package/src/AdminRoot.tsx +20 -4
  66. package/src/__tests__/components/batch-ai-actions.test.tsx +10 -0
  67. package/src/__tests__/lib/batch-wizard.test.ts +126 -0
  68. package/src/__tests__/lib/jobs-service.test.ts +20 -0
  69. package/src/__tests__/views/run-with-ai.render.test.tsx +807 -0
  70. package/src/components/BatchAiActions.tsx +15 -2
  71. package/src/lib/batch-wizard.ts +125 -0
  72. package/src/lib/jobs-service.ts +36 -0
  73. package/src/views/CollectionList.tsx +20 -1
  74. package/src/views/Jobs/DrawerOverview.tsx +16 -3
  75. package/src/views/Jobs/DrawerResults.tsx +71 -2
  76. package/src/views/Jobs/JobDrawer.tsx +5 -1
  77. package/src/views/Jobs/RunWithAi.tsx +89 -0
  78. package/src/views/Jobs.tsx +58 -10
  79. package/src/views/MediaBrowser.tsx +20 -1
  80. package/src/views/Pages/PagesListView.tsx +28 -3
  81. package/src/views/Posts/PostsListView.tsx +26 -3
@@ -5,13 +5,18 @@ import {
5
5
  estimateKey,
6
6
  estimateNote,
7
7
  estimateTiles,
8
+ fixWithAiPick,
9
+ fixWithAiText,
8
10
  instructionError,
9
11
  isAdminRole,
10
12
  matchProblem,
11
13
  operationFits,
14
+ pickedDocuments,
15
+ pickedImages,
12
16
  previewKey,
13
17
  type BatchDraft,
14
18
  } from '../../lib/batch-wizard.js'
19
+ import type { SeoBatchTarget } from '../../lib/jobs-service.js'
15
20
 
16
21
  /*
17
22
  * The batch wizard's rules (P-20), against cms-core `jobs/batch-ai.ts`:
@@ -197,3 +202,124 @@ describe('the estimate', () => {
197
202
  )
198
203
  })
199
204
  })
205
+
206
+ describe('a list’s picked documents (P-21)', () => {
207
+ it('runs picked posts of one type as one batch', () => {
208
+ expect(
209
+ pickedDocuments([
210
+ { collection: 'articles', id: 'a1' },
211
+ { collection: 'articles', id: 'a2' },
212
+ ]),
213
+ ).toEqual({ selection: { source: 'articles', documentIds: ['a1', 'a2'] }, reason: null })
214
+ })
215
+
216
+ it('holds posts of two types, or none, and says why', () => {
217
+ const why = 'Run with AI works on one post type at a time. Pick posts of a single type.'
218
+ expect(
219
+ pickedDocuments([
220
+ { collection: 'articles', id: 'a1' },
221
+ { collection: 'news', id: 'n1' },
222
+ ]),
223
+ ).toEqual({ selection: null, reason: why })
224
+ expect(pickedDocuments([])).toEqual({ selection: null, reason: why })
225
+ })
226
+
227
+ it('runs picked images on the media library, and holds a pick with none', () => {
228
+ expect(pickedImages(['m1', 'm2'])).toEqual({
229
+ selection: { source: 'media', documentIds: ['m1', 'm2'] },
230
+ reason: null,
231
+ })
232
+ expect(pickedImages([])).toEqual({
233
+ selection: null,
234
+ reason: 'Run with AI writes alt text for images. Pick at least one image.',
235
+ })
236
+ })
237
+
238
+ it('holds a pick of more than 400, which the estimate can’t carry in its URL', () => {
239
+ const docs = (n: number) =>
240
+ Array.from({ length: n }, (_, i) => ({ collection: 'pages', id: `p${i}` }))
241
+ expect(pickedDocuments(docs(400)).selection?.documentIds).toHaveLength(400)
242
+ expect(pickedDocuments(docs(401))).toEqual({
243
+ selection: null,
244
+ reason: 'Run with AI takes at most 400 documents at a time. Pick fewer.',
245
+ })
246
+ const images = Array.from({ length: 401 }, (_, i) => `m${i}`)
247
+ expect(pickedImages(images)).toEqual({
248
+ selection: null,
249
+ reason: 'Run with AI takes at most 400 images at a time. Pick fewer.',
250
+ })
251
+ })
252
+ })
253
+
254
+ describe('Fix with AI (P-21)', () => {
255
+ function target(
256
+ type: string,
257
+ sources: Array<[string, number, number?]>,
258
+ over: Partial<SeoBatchTarget> = {},
259
+ ): SeoBatchTarget {
260
+ return {
261
+ type,
262
+ operation: 'meta',
263
+ autopilot: false,
264
+ sources: sources.map(([source, n, total]) => ({
265
+ source,
266
+ documentIds: Array.from({ length: n }, (_, i) => `${source}-${i}`),
267
+ total: total ?? n,
268
+ })),
269
+ waiting: 0,
270
+ ...over,
271
+ }
272
+ }
273
+ const label = (id: string) => ({ pages: 'Pages', posts: 'Posts' })[id] ?? id
274
+
275
+ it('picks the first category, so the largest, with documents and not left to autopilot', () => {
276
+ const categories = [
277
+ { key: 'thin-content' },
278
+ { key: 'missing-meta-description' },
279
+ { key: 'meta-description-length' },
280
+ ]
281
+ const meta = target('missing-meta-description', [['pages', 5]])
282
+ const long = target('meta-description-length', [['pages', 1]])
283
+ expect(fixWithAiPick(categories, [long, meta])).toBe(meta)
284
+ expect(fixWithAiPick(categories, [{ ...meta, autopilot: true }, long])).toBe(long)
285
+ expect(fixWithAiPick(categories, [target('missing-meta-description', []), long])).toBe(long)
286
+ expect(fixWithAiPick([{ key: 'thin-content' }], [meta])).toBeNull()
287
+ expect(fixWithAiPick(categories, [])).toBeNull()
288
+ })
289
+
290
+ it('reads as the kit for one content type', () => {
291
+ expect(fixWithAiText(target('missing-meta-description', [['pages', 5]]), label)).toBe(
292
+ 'Start a batch job for the 5 missing meta descriptions. You’ll review each one before it’s applied.',
293
+ )
294
+ expect(fixWithAiText(target('missing-meta-description', [['pages', 1]]), label)).toBe(
295
+ 'Start a batch job for the 1 missing meta description. You’ll review each one before it’s applied.',
296
+ )
297
+ expect(fixWithAiText(target('meta-description-length', [['pages', 3]]), label)).toBe(
298
+ 'Start a batch job to shorten the 3 meta descriptions that are too long. You’ll review each one before it’s applied.',
299
+ )
300
+ expect(fixWithAiText(target('meta-description-length', [['posts', 1]]), label)).toBe(
301
+ 'Start a batch job to shorten the 1 meta description that is too long. You’ll review each one before it’s applied.',
302
+ )
303
+ })
304
+
305
+ it('names each content type, the cap, and the documents already waiting', () => {
306
+ expect(
307
+ fixWithAiText(
308
+ target(
309
+ 'missing-meta-description',
310
+ [
311
+ ['pages', 400, 1203],
312
+ ['posts', 2],
313
+ ],
314
+ { waiting: 3 },
315
+ ),
316
+ label,
317
+ ),
318
+ ).toBe(
319
+ 'Start a batch job for the 1,205 missing meta descriptions: 1,203 in Pages and 2 in Posts. A batch runs on one content type, so there’s one to set up for each. A batch takes 400 at most, so it starts with the most recently found. 3 others already have a suggestion waiting. You’ll review each one before it’s applied.',
320
+ )
321
+ expect(
322
+ fixWithAiText(target('missing-meta-description', [['pages', 2]], { waiting: 1 }), label),
323
+ ).toContain('1 other already has a suggestion waiting.')
324
+ })
325
+ })
@@ -11,6 +11,7 @@ vi.mock('../../lib/api.js', () => ({ cmsApi, getApiBase: () => '/api/cms' }))
11
11
 
12
12
  const {
13
13
  createBatchAiJob,
14
+ listSeoBatchTargets,
14
15
  decideReviewItem,
15
16
  estimateBatchAi,
16
17
  listReviewItems,
@@ -165,3 +166,22 @@ describe('reviewConflict', () => {
165
166
  expect(reviewConflict(400, 'This change was already decided.')).toBeNull()
166
167
  })
167
168
  })
169
+
170
+ describe('listSeoBatchTargets', () => {
171
+ it('reads the targets for Fix with AI, or the server’s refusal', async () => {
172
+ const targets = [
173
+ {
174
+ type: 'missing-meta-description',
175
+ operation: 'meta',
176
+ autopilot: false,
177
+ sources: [{ source: 'pages', documentIds: ['p1'], total: 1 }],
178
+ waiting: 0,
179
+ },
180
+ ]
181
+ cmsApi.mockResolvedValue({ data: { targets }, status: 200 })
182
+ expect(await listSeoBatchTargets()).toEqual({ ok: true, value: targets })
183
+ expect(cmsApi.mock.calls[0]![0]).toBe('/seo/issues/batch-targets')
184
+ cmsApi.mockResolvedValue({ error: 'Unauthorized', status: 401 })
185
+ expect(await listSeoBatchTargets()).toEqual({ ok: false, error: 'Unauthorized', status: 401 })
186
+ })
187
+ })