@byline/admin 4.18.0 → 5.0.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/fields/field-services-types.d.ts +5 -2
- package/dist/forms/available-locales-widget.d.ts +2 -1
- package/dist/forms/available-locales-widget.js +4 -2
- package/dist/forms/document-actions.d.ts +2 -1
- package/dist/forms/document-actions.js +32 -14
- package/dist/forms/form-renderer.d.ts +9 -0
- package/dist/forms/form-renderer.js +338 -191
- package/dist/forms/form-renderer.module.js +11 -0
- package/dist/forms/form-renderer_module.css +46 -0
- package/dist/forms/form-status-display.d.ts +2 -1
- package/dist/forms/form-status-display.js +5 -2
- package/dist/forms/path-widget.d.ts +2 -1
- package/dist/forms/path-widget.js +7 -2
- package/dist/forms/scheduled-publication-control.d.ts +2 -1
- package/dist/forms/scheduled-publication-control.js +12 -8
- package/dist/forms/tree-placement-widget.d.ts +5 -1
- package/dist/forms/tree-placement-widget.js +14 -7
- package/package.json +7 -7
- package/src/fields/field-services-types.ts +10 -2
- package/src/forms/available-locales-widget.tsx +5 -2
- package/src/forms/document-actions.tsx +55 -20
- package/src/forms/form-renderer-submit.test.tsx +231 -8
- package/src/forms/form-renderer.module.css +62 -0
- package/src/forms/form-renderer.tsx +393 -200
- package/src/forms/form-status-display.tsx +6 -1
- package/src/forms/path-widget.tsx +8 -3
- package/src/forms/scheduled-publication-control.tsx +16 -7
- package/src/forms/tree-placement-widget.tsx +34 -7
|
@@ -41,6 +41,7 @@ export interface DocumentActionsLocaleOption {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function DocumentActions({
|
|
44
|
+
disabled = false,
|
|
44
45
|
publishedVersion,
|
|
45
46
|
onUnpublish,
|
|
46
47
|
onDelete,
|
|
@@ -59,6 +60,7 @@ export function DocumentActions({
|
|
|
59
60
|
onConfirmScheduledPublication,
|
|
60
61
|
onCancelScheduledPublication,
|
|
61
62
|
}: {
|
|
63
|
+
disabled?: boolean
|
|
62
64
|
publishedVersion?: PublishedVersionInfo | null
|
|
63
65
|
onUnpublish?: () => Promise<void>
|
|
64
66
|
onDelete?: () => Promise<void>
|
|
@@ -221,24 +223,29 @@ export function DocumentActions({
|
|
|
221
223
|
onDelete != null
|
|
222
224
|
|
|
223
225
|
const handleOnDelete = () => {
|
|
226
|
+
if (disabled) return
|
|
224
227
|
setShowDeleteConfirm(false)
|
|
225
228
|
if (onDelete) {
|
|
226
|
-
onDelete()
|
|
229
|
+
void onDelete().catch(() => {})
|
|
227
230
|
}
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
const handleOnDuplicate = async () => {
|
|
234
|
+
if (disabled) return
|
|
231
235
|
if (!onDuplicate) return
|
|
232
236
|
setDuplicateBusy(true)
|
|
233
237
|
try {
|
|
234
238
|
await onDuplicate()
|
|
235
239
|
setShowDuplicateConfirm(false)
|
|
240
|
+
} catch {
|
|
241
|
+
// The host reports the failure and retains the editor observation.
|
|
236
242
|
} finally {
|
|
237
243
|
setDuplicateBusy(false)
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
246
|
|
|
241
247
|
const handleOpenDuplicate = () => {
|
|
248
|
+
if (disabled) return
|
|
242
249
|
// Duplicate copies the saved version — block when the form is dirty so
|
|
243
250
|
// unsaved edits are not silently dropped from the copy.
|
|
244
251
|
if (hasUnsavedChanges) {
|
|
@@ -249,6 +256,7 @@ export function DocumentActions({
|
|
|
249
256
|
}
|
|
250
257
|
|
|
251
258
|
const handleOpenCopyToLocale = () => {
|
|
259
|
+
if (disabled) return
|
|
252
260
|
// Copy-to-Locale reads the saved version — block when the form is dirty.
|
|
253
261
|
if (hasUnsavedChanges) {
|
|
254
262
|
onUnsavedChanges?.()
|
|
@@ -263,17 +271,21 @@ export function DocumentActions({
|
|
|
263
271
|
}
|
|
264
272
|
|
|
265
273
|
const handleOnCopyToLocale = async () => {
|
|
274
|
+
if (disabled) return
|
|
266
275
|
if (!onCopyToLocale || !copyTargetLocale) return
|
|
267
276
|
setCopyToLocaleBusy(true)
|
|
268
277
|
try {
|
|
269
278
|
await onCopyToLocale({ targetLocale: copyTargetLocale, overwrite: copyOverwrite })
|
|
270
279
|
setShowCopyToLocaleConfirm(false)
|
|
280
|
+
} catch {
|
|
281
|
+
// The host reports the failure and retains the editor observation.
|
|
271
282
|
} finally {
|
|
272
283
|
setCopyToLocaleBusy(false)
|
|
273
284
|
}
|
|
274
285
|
}
|
|
275
286
|
|
|
276
287
|
const handleOpenDeleteLocale = () => {
|
|
288
|
+
if (disabled) return
|
|
277
289
|
// Delete-Locale removes the saved version's locale content — block when
|
|
278
290
|
// the form is dirty so the editor saves (or discards) first.
|
|
279
291
|
if (hasUnsavedChanges) {
|
|
@@ -288,11 +300,14 @@ export function DocumentActions({
|
|
|
288
300
|
}
|
|
289
301
|
|
|
290
302
|
const handleOnDeleteLocale = async () => {
|
|
303
|
+
if (disabled) return
|
|
291
304
|
if (!onDeleteLocale || !deleteTargetLocale) return
|
|
292
305
|
setDeleteLocaleBusy(true)
|
|
293
306
|
try {
|
|
294
307
|
await onDeleteLocale({ targetLocale: deleteTargetLocale })
|
|
295
308
|
setShowDeleteLocaleConfirm(false)
|
|
309
|
+
} catch {
|
|
310
|
+
// The host reports the failure and retains the editor observation.
|
|
296
311
|
} finally {
|
|
297
312
|
setDeleteLocaleBusy(false)
|
|
298
313
|
}
|
|
@@ -311,6 +326,7 @@ export function DocumentActions({
|
|
|
311
326
|
{hasAnyAction && (
|
|
312
327
|
<DropdownComponent.Root>
|
|
313
328
|
<DropdownComponent.Trigger
|
|
329
|
+
disabled={disabled}
|
|
314
330
|
render={<IconButton variant="text" intent="noeffect" size="sm" />}
|
|
315
331
|
>
|
|
316
332
|
<EllipsisIcon
|
|
@@ -329,7 +345,7 @@ export function DocumentActions({
|
|
|
329
345
|
>
|
|
330
346
|
{/*{publishedVersion && (
|
|
331
347
|
<>
|
|
332
|
-
<DropdownComponent.Item onClick={onUnpublish}>
|
|
348
|
+
<DropdownComponent.Item disabled={disabled} onClick={onUnpublish}>
|
|
333
349
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
334
350
|
<span className={cx('byline-form-actions-item-icon', styles['item-icon'])} />
|
|
335
351
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
@@ -343,10 +359,16 @@ export function DocumentActions({
|
|
|
343
359
|
{schedulingActions.length > 0 && (
|
|
344
360
|
<>
|
|
345
361
|
{schedulingActions.map((action) => (
|
|
346
|
-
<DropdownComponent.Item
|
|
362
|
+
<DropdownComponent.Item
|
|
363
|
+
disabled={disabled}
|
|
364
|
+
key={action.key}
|
|
365
|
+
onClick={action.onSelect}
|
|
366
|
+
>
|
|
347
367
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
348
368
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
349
|
-
<button type="button"
|
|
369
|
+
<button type="button" disabled={disabled}>
|
|
370
|
+
{action.label}
|
|
371
|
+
</button>
|
|
350
372
|
</span>
|
|
351
373
|
</div>
|
|
352
374
|
</DropdownComponent.Item>
|
|
@@ -355,28 +377,34 @@ export function DocumentActions({
|
|
|
355
377
|
</>
|
|
356
378
|
)}
|
|
357
379
|
{copyToLocaleAvailable && (
|
|
358
|
-
<DropdownComponent.Item onClick={handleOpenCopyToLocale}>
|
|
380
|
+
<DropdownComponent.Item disabled={disabled} onClick={handleOpenCopyToLocale}>
|
|
359
381
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
360
382
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
361
|
-
<button type="button"
|
|
383
|
+
<button type="button" disabled={disabled}>
|
|
384
|
+
{t('documentActions.copyToLocaleMenuItem')}
|
|
385
|
+
</button>
|
|
362
386
|
</span>
|
|
363
387
|
</div>
|
|
364
388
|
</DropdownComponent.Item>
|
|
365
389
|
)}
|
|
366
390
|
{deleteLocaleAvailable && (
|
|
367
|
-
<DropdownComponent.Item onClick={handleOpenDeleteLocale}>
|
|
391
|
+
<DropdownComponent.Item disabled={disabled} onClick={handleOpenDeleteLocale}>
|
|
368
392
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
369
393
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
370
|
-
<button type="button"
|
|
394
|
+
<button type="button" disabled={disabled}>
|
|
395
|
+
{t('documentActions.deleteLocale.menuItem')}
|
|
396
|
+
</button>
|
|
371
397
|
</span>
|
|
372
398
|
</div>
|
|
373
399
|
</DropdownComponent.Item>
|
|
374
400
|
)}
|
|
375
401
|
{onDuplicate && (
|
|
376
|
-
<DropdownComponent.Item onClick={handleOpenDuplicate}>
|
|
402
|
+
<DropdownComponent.Item disabled={disabled} onClick={handleOpenDuplicate}>
|
|
377
403
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
378
404
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
379
|
-
<button type="button"
|
|
405
|
+
<button type="button" disabled={disabled}>
|
|
406
|
+
{t('common.actions.duplicate')}
|
|
407
|
+
</button>
|
|
380
408
|
</span>
|
|
381
409
|
</div>
|
|
382
410
|
</DropdownComponent.Item>
|
|
@@ -385,6 +413,7 @@ export function DocumentActions({
|
|
|
385
413
|
<>
|
|
386
414
|
<DropdownComponent.Separator />
|
|
387
415
|
<DropdownComponent.Item
|
|
416
|
+
disabled={disabled}
|
|
388
417
|
onClick={() => {
|
|
389
418
|
setShowDeleteConfirm(true)
|
|
390
419
|
}}
|
|
@@ -454,7 +483,13 @@ export function DocumentActions({
|
|
|
454
483
|
>
|
|
455
484
|
{t('common.actions.cancel')}
|
|
456
485
|
</Button>
|
|
457
|
-
<Button
|
|
486
|
+
<Button
|
|
487
|
+
size="sm"
|
|
488
|
+
style={{ minWidth: '80px' }}
|
|
489
|
+
intent="danger"
|
|
490
|
+
disabled={disabled}
|
|
491
|
+
onClick={handleOnDelete}
|
|
492
|
+
>
|
|
458
493
|
{t('common.actions.delete')}
|
|
459
494
|
</Button>
|
|
460
495
|
</Modal.Actions>
|
|
@@ -533,7 +568,7 @@ export function DocumentActions({
|
|
|
533
568
|
onClick={() => {
|
|
534
569
|
if (!duplicateBusy) setShowDuplicateConfirm(false)
|
|
535
570
|
}}
|
|
536
|
-
disabled={duplicateBusy}
|
|
571
|
+
disabled={disabled || duplicateBusy}
|
|
537
572
|
>
|
|
538
573
|
{t('common.actions.cancel')}
|
|
539
574
|
</Button>
|
|
@@ -542,7 +577,7 @@ export function DocumentActions({
|
|
|
542
577
|
style={{ minWidth: '80px' }}
|
|
543
578
|
intent="primary"
|
|
544
579
|
onClick={handleOnDuplicate}
|
|
545
|
-
disabled={duplicateBusy}
|
|
580
|
+
disabled={disabled || duplicateBusy}
|
|
546
581
|
>
|
|
547
582
|
{duplicateBusy
|
|
548
583
|
? t('documentActions.duplicate.busyButton')
|
|
@@ -611,7 +646,7 @@ export function DocumentActions({
|
|
|
611
646
|
onValueChange={(value) => {
|
|
612
647
|
if (value != null) setCopyTargetLocale(value)
|
|
613
648
|
}}
|
|
614
|
-
disabled={copyToLocaleBusy}
|
|
649
|
+
disabled={disabled || copyToLocaleBusy}
|
|
615
650
|
/>
|
|
616
651
|
</div>
|
|
617
652
|
<div
|
|
@@ -623,7 +658,7 @@ export function DocumentActions({
|
|
|
623
658
|
name="overwrite"
|
|
624
659
|
label={t('documentActions.copyToLocale.overwriteLabel')}
|
|
625
660
|
checked={copyOverwrite}
|
|
626
|
-
disabled={copyToLocaleBusy}
|
|
661
|
+
disabled={disabled || copyToLocaleBusy}
|
|
627
662
|
helpText={t('documentActions.copyToLocale.overwriteHelp')}
|
|
628
663
|
onCheckedChange={(value) => {
|
|
629
664
|
setCopyOverwrite(value === true)
|
|
@@ -647,7 +682,7 @@ export function DocumentActions({
|
|
|
647
682
|
onClick={() => {
|
|
648
683
|
if (!copyToLocaleBusy) setShowCopyToLocaleConfirm(false)
|
|
649
684
|
}}
|
|
650
|
-
disabled={copyToLocaleBusy}
|
|
685
|
+
disabled={disabled || copyToLocaleBusy}
|
|
651
686
|
>
|
|
652
687
|
{t('common.actions.cancel')}
|
|
653
688
|
</Button>
|
|
@@ -656,7 +691,7 @@ export function DocumentActions({
|
|
|
656
691
|
style={{ minWidth: '80px' }}
|
|
657
692
|
intent="primary"
|
|
658
693
|
onClick={handleOnCopyToLocale}
|
|
659
|
-
disabled={copyToLocaleBusy || !copyTargetLocale}
|
|
694
|
+
disabled={disabled || copyToLocaleBusy || !copyTargetLocale}
|
|
660
695
|
>
|
|
661
696
|
{copyToLocaleBusy
|
|
662
697
|
? t('documentActions.copyToLocale.busyButton')
|
|
@@ -711,7 +746,7 @@ export function DocumentActions({
|
|
|
711
746
|
onValueChange={(value) => {
|
|
712
747
|
if (value != null) setDeleteTargetLocale(value)
|
|
713
748
|
}}
|
|
714
|
-
disabled={deleteLocaleBusy}
|
|
749
|
+
disabled={disabled || deleteLocaleBusy}
|
|
715
750
|
/>
|
|
716
751
|
</div>
|
|
717
752
|
<p style={{ marginTop: 'var(--spacing-12)' }}>
|
|
@@ -734,7 +769,7 @@ export function DocumentActions({
|
|
|
734
769
|
onClick={() => {
|
|
735
770
|
if (!deleteLocaleBusy) setShowDeleteLocaleConfirm(false)
|
|
736
771
|
}}
|
|
737
|
-
disabled={deleteLocaleBusy}
|
|
772
|
+
disabled={disabled || deleteLocaleBusy}
|
|
738
773
|
>
|
|
739
774
|
{t('common.actions.cancel')}
|
|
740
775
|
</Button>
|
|
@@ -743,7 +778,7 @@ export function DocumentActions({
|
|
|
743
778
|
style={{ minWidth: '80px' }}
|
|
744
779
|
intent="danger"
|
|
745
780
|
onClick={handleOnDeleteLocale}
|
|
746
|
-
disabled={deleteLocaleBusy || !deleteTargetLocale}
|
|
781
|
+
disabled={disabled || deleteLocaleBusy || !deleteTargetLocale}
|
|
747
782
|
>
|
|
748
783
|
{deleteLocaleBusy
|
|
749
784
|
? t('documentActions.deleteLocale.busyButton')
|
|
@@ -46,8 +46,8 @@ vi.mock('@byline/ui/react', async (importOriginal) => {
|
|
|
46
46
|
Separator: () => <hr />,
|
|
47
47
|
},
|
|
48
48
|
Modal,
|
|
49
|
-
Input: ({ name, value, onChange }:
|
|
50
|
-
<input name={name} value={value ?? ''} onChange={onChange} />
|
|
49
|
+
Input: ({ id, name, value, onChange, disabled }: React.ComponentProps<'input'>) => (
|
|
50
|
+
<input id={id} name={name} disabled={disabled} value={value ?? ''} onChange={onChange} />
|
|
51
51
|
),
|
|
52
52
|
}
|
|
53
53
|
})
|
|
@@ -129,6 +129,16 @@ const submitForm = () => {
|
|
|
129
129
|
})
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
const deferred = () => {
|
|
133
|
+
let resolve: () => void = () => {}
|
|
134
|
+
let reject: (reason?: unknown) => void = () => {}
|
|
135
|
+
const promise = new Promise<void>((resolvePromise, rejectPromise) => {
|
|
136
|
+
resolve = resolvePromise
|
|
137
|
+
reject = rejectPromise
|
|
138
|
+
})
|
|
139
|
+
return { promise, resolve, reject }
|
|
140
|
+
}
|
|
141
|
+
|
|
132
142
|
describe('FormRenderer submit contract', () => {
|
|
133
143
|
const render = (props: Record<string, unknown>) =>
|
|
134
144
|
renderInProvider(<FormRenderer {...(props as any)} />)
|
|
@@ -169,13 +179,97 @@ describe('FormRenderer submit contract', () => {
|
|
|
169
179
|
expect(container.textContent).toContain('Cancel')
|
|
170
180
|
})
|
|
171
181
|
|
|
172
|
-
it('
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
it('shows a named busy indicator until onSubmit resolves', async () => {
|
|
183
|
+
const submission = deferred()
|
|
184
|
+
render({ ...baseProps, onSubmit: () => submission.promise })
|
|
185
|
+
typeIntoTitle('Hello')
|
|
186
|
+
submitForm()
|
|
187
|
+
await act(async () => {})
|
|
188
|
+
|
|
189
|
+
const form = container.querySelector('form')
|
|
190
|
+
const busyRegion = form?.parentElement
|
|
191
|
+
const liveStatus = container.querySelector('[role="status"]')
|
|
192
|
+
const saveButton = container.querySelector<HTMLButtonElement>('button[type="submit"]')
|
|
193
|
+
expect(busyRegion?.getAttribute('aria-busy')).toBe('true')
|
|
194
|
+
expect(form?.getAttribute('aria-busy')).toBeNull()
|
|
195
|
+
expect(form?.hasAttribute('inert')).toBe(true)
|
|
196
|
+
expect(liveStatus?.textContent).toBe('Saving…')
|
|
197
|
+
expect(busyRegion?.contains(liveStatus)).toBe(false)
|
|
198
|
+
expect(saveButton?.getAttribute('aria-label')).toBe('Save')
|
|
199
|
+
expect(saveButton?.querySelector('.byline-loader-ellipsis')).not.toBeNull()
|
|
200
|
+
expect(saveButton?.querySelector('.byline-form-save-label')?.textContent).toBe('Save')
|
|
201
|
+
|
|
202
|
+
await act(async () => {
|
|
203
|
+
submission.resolve()
|
|
204
|
+
await submission.promise
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
expect(busyRegion?.getAttribute('aria-busy')).toBe('false')
|
|
208
|
+
expect(form?.hasAttribute('inert')).toBe(false)
|
|
209
|
+
expect(liveStatus?.textContent).toBe('')
|
|
210
|
+
expect(saveButton?.getAttribute('aria-label')).toBeNull()
|
|
211
|
+
expect(saveButton?.querySelector('.byline-loader-ellipsis')).toBeNull()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('hides the busy indicator when onSubmit rejects', async () => {
|
|
215
|
+
const submission = deferred()
|
|
216
|
+
render({ ...baseProps, onSubmit: () => submission.promise })
|
|
217
|
+
typeIntoTitle('Hello')
|
|
218
|
+
submitForm()
|
|
219
|
+
await act(async () => {})
|
|
220
|
+
|
|
221
|
+
const form = container.querySelector('form')
|
|
222
|
+
const busyRegion = form?.parentElement
|
|
223
|
+
const saveButton = container.querySelector<HTMLButtonElement>('button[type="submit"]')
|
|
224
|
+
expect(busyRegion?.getAttribute('aria-busy')).toBe('true')
|
|
225
|
+
expect(form?.getAttribute('aria-busy')).toBeNull()
|
|
226
|
+
expect(saveButton?.querySelector('.byline-loader-ellipsis')).not.toBeNull()
|
|
227
|
+
|
|
228
|
+
await act(async () => {
|
|
229
|
+
submission.reject(new Error('save failed'))
|
|
230
|
+
try {
|
|
231
|
+
await submission.promise
|
|
232
|
+
} catch {
|
|
233
|
+
// FormRenderer intentionally handles host-reported submission failures.
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
expect(form?.getAttribute('aria-busy')).toBeNull()
|
|
238
|
+
expect(busyRegion?.getAttribute('aria-busy')).toBe('false')
|
|
239
|
+
expect(form?.hasAttribute('inert')).toBe(false)
|
|
240
|
+
expect(saveButton?.getAttribute('aria-label')).toBeNull()
|
|
241
|
+
expect(saveButton?.querySelector('.byline-loader-ellipsis')).toBeNull()
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('restores keyboard focus after the inert submitting window closes', async () => {
|
|
245
|
+
const submission = deferred()
|
|
246
|
+
render({ ...baseProps, onSubmit: () => submission.promise })
|
|
247
|
+
typeIntoTitle('Hello')
|
|
248
|
+
const input = container.querySelector<HTMLInputElement>('input[name="title"]')
|
|
249
|
+
if (input == null) throw new Error('title input not found')
|
|
250
|
+
input.focus()
|
|
251
|
+
expect(document.activeElement).toBe(input)
|
|
252
|
+
|
|
253
|
+
submitForm()
|
|
254
|
+
await act(async () => {})
|
|
255
|
+
|
|
256
|
+
document.body.tabIndex = -1
|
|
257
|
+
document.body.focus()
|
|
258
|
+
expect(document.activeElement).toBe(document.body)
|
|
259
|
+
|
|
260
|
+
await act(async () => {
|
|
261
|
+
submission.resolve()
|
|
262
|
+
await submission.promise
|
|
176
263
|
})
|
|
264
|
+
|
|
265
|
+
expect(document.activeElement).toBe(input)
|
|
266
|
+
document.body.removeAttribute('tabindex')
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
it('ignores a second submit while the first is still in flight', async () => {
|
|
270
|
+
const submission = deferred()
|
|
177
271
|
const onSubmit = vi.fn(async () => {
|
|
178
|
-
await
|
|
272
|
+
await submission.promise
|
|
179
273
|
})
|
|
180
274
|
render({ ...baseProps, onSubmit })
|
|
181
275
|
typeIntoTitle('Hello')
|
|
@@ -187,8 +281,137 @@ describe('FormRenderer submit contract', () => {
|
|
|
187
281
|
await act(async () => {})
|
|
188
282
|
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
189
283
|
await act(async () => {
|
|
190
|
-
|
|
284
|
+
submission.resolve()
|
|
191
285
|
})
|
|
192
286
|
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
193
287
|
})
|
|
194
288
|
})
|
|
289
|
+
|
|
290
|
+
describe('persistent document concurrency recovery', () => {
|
|
291
|
+
const original = {
|
|
292
|
+
id: 'doc',
|
|
293
|
+
versionId: 'v1',
|
|
294
|
+
revision: 7,
|
|
295
|
+
path: 'opened',
|
|
296
|
+
status: 'draft',
|
|
297
|
+
fields: { title: 'Opened' },
|
|
298
|
+
_availableVersionLocales: ['en'],
|
|
299
|
+
}
|
|
300
|
+
const props = {
|
|
301
|
+
mode: 'edit' as const,
|
|
302
|
+
fields,
|
|
303
|
+
initialData: original,
|
|
304
|
+
collectionPath: 'pages',
|
|
305
|
+
useAsPath: 'title',
|
|
306
|
+
advertiseLocales: true,
|
|
307
|
+
contentLocales: [{ code: 'en', label: 'English' }],
|
|
308
|
+
workflowStatuses: [
|
|
309
|
+
{ name: 'draft', label: 'Draft' },
|
|
310
|
+
{ name: 'published', label: 'Published' },
|
|
311
|
+
],
|
|
312
|
+
}
|
|
313
|
+
it.each(['stale', 'reload', 'lock', 'unavailable'] as const)(
|
|
314
|
+
'retains dirty fields and blocks mutations for %s',
|
|
315
|
+
async (mutationIssue) => {
|
|
316
|
+
const onSubmit = vi.fn()
|
|
317
|
+
const onDelete = vi.fn()
|
|
318
|
+
const onStatusChange = vi.fn()
|
|
319
|
+
const guard = vi.fn(() => ({ isBlocked: false, stay() {}, proceed() {} }))
|
|
320
|
+
const render = (blocked: boolean) =>
|
|
321
|
+
renderInProvider(
|
|
322
|
+
<FormRenderer
|
|
323
|
+
{...props}
|
|
324
|
+
onSubmit={onSubmit}
|
|
325
|
+
onDelete={onDelete}
|
|
326
|
+
onStatusChange={onStatusChange}
|
|
327
|
+
mutationsBlocked={blocked}
|
|
328
|
+
mutationIssue={blocked ? mutationIssue : null}
|
|
329
|
+
useNavigationGuard={guard}
|
|
330
|
+
/>
|
|
331
|
+
)
|
|
332
|
+
render(false)
|
|
333
|
+
typeIntoTitle('Unsaved text to copy')
|
|
334
|
+
render(true)
|
|
335
|
+
expect(container.querySelector<HTMLInputElement>('input[name="title"]')?.value).toBe(
|
|
336
|
+
'Unsaved text to copy'
|
|
337
|
+
)
|
|
338
|
+
expect(container.querySelector<HTMLInputElement>('input[name="title"]')?.disabled).toBe(false)
|
|
339
|
+
expect(guard).toHaveBeenLastCalledWith(true)
|
|
340
|
+
expect(container.querySelector<HTMLButtonElement>('button[type="submit"]')?.disabled).toBe(
|
|
341
|
+
true
|
|
342
|
+
)
|
|
343
|
+
expect(container.querySelector<HTMLInputElement>('#system-path')?.disabled).toBe(true)
|
|
344
|
+
expect(container.querySelector<HTMLInputElement>('#available-locale-en')?.disabled).toBe(true)
|
|
345
|
+
const warning = container.querySelector('.byline-document-concurrency')
|
|
346
|
+
expect(warning?.getAttribute('role')).toBe('alert')
|
|
347
|
+
expect(document.activeElement).toBe(warning)
|
|
348
|
+
submitForm()
|
|
349
|
+
await act(async () => {})
|
|
350
|
+
expect(onSubmit).not.toHaveBeenCalled()
|
|
351
|
+
expect(onDelete).not.toHaveBeenCalled()
|
|
352
|
+
expect(onStatusChange).not.toHaveBeenCalled()
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
it('disables the dirty navigation guard only after explicit discard and retains it on reload failure', async () => {
|
|
356
|
+
const guard = vi.fn(() => ({ isBlocked: false, stay() {}, proceed() {} }))
|
|
357
|
+
const reload = vi.fn(async () => {
|
|
358
|
+
throw new Error('reload failed')
|
|
359
|
+
})
|
|
360
|
+
const render = (blocked: boolean) =>
|
|
361
|
+
renderInProvider(
|
|
362
|
+
<FormRenderer
|
|
363
|
+
{...props}
|
|
364
|
+
onSubmit={async () => {}}
|
|
365
|
+
mutationsBlocked={blocked}
|
|
366
|
+
mutationIssue={blocked ? 'stale' : null}
|
|
367
|
+
useNavigationGuard={guard}
|
|
368
|
+
onReloadDocument={reload}
|
|
369
|
+
/>
|
|
370
|
+
)
|
|
371
|
+
render(false)
|
|
372
|
+
typeIntoTitle('Keep until I discard')
|
|
373
|
+
render(true)
|
|
374
|
+
expect(reload).not.toHaveBeenCalled()
|
|
375
|
+
expect(guard).toHaveBeenLastCalledWith(true)
|
|
376
|
+
const reloadButton = Array.from(container.querySelectorAll('button')).find(
|
|
377
|
+
(button) => button.textContent === 'Reload and discard my changes'
|
|
378
|
+
)
|
|
379
|
+
expect(reloadButton).toBeDefined()
|
|
380
|
+
await act(async () => {
|
|
381
|
+
reloadButton?.click()
|
|
382
|
+
})
|
|
383
|
+
expect(reload).toHaveBeenCalledTimes(1)
|
|
384
|
+
expect(guard).toHaveBeenCalledWith(false)
|
|
385
|
+
expect(guard).toHaveBeenLastCalledWith(true)
|
|
386
|
+
expect(container.textContent).toContain('Reload failed. Your unsaved changes are still here.')
|
|
387
|
+
expect(container.querySelector<HTMLInputElement>('input[name="title"]')?.value).toBe(
|
|
388
|
+
'Keep until I discard'
|
|
389
|
+
)
|
|
390
|
+
})
|
|
391
|
+
it('shows structural schedule suspension separately without marking the form stale or clearing edits', () => {
|
|
392
|
+
const render = (notice: boolean) =>
|
|
393
|
+
renderInProvider(
|
|
394
|
+
<FormRenderer
|
|
395
|
+
{...props}
|
|
396
|
+
onSubmit={async () => {}}
|
|
397
|
+
scheduledPublicationsNeedReconfirmation={notice}
|
|
398
|
+
scheduledPublicationsHref="/admin/scheduled-publications"
|
|
399
|
+
/>
|
|
400
|
+
)
|
|
401
|
+
render(false)
|
|
402
|
+
typeIntoTitle('Draft retained after tree move')
|
|
403
|
+
render(true)
|
|
404
|
+
expect(container.textContent).toContain('The structure was saved.')
|
|
405
|
+
expect(
|
|
406
|
+
container.querySelector<HTMLAnchorElement>('a[href="/admin/scheduled-publications"]')
|
|
407
|
+
?.textContent
|
|
408
|
+
).toBe('Review scheduled publications')
|
|
409
|
+
expect(container.textContent).not.toContain('Your changes were not saved.')
|
|
410
|
+
expect(container.querySelector<HTMLButtonElement>('button[type="submit"]')?.disabled).toBe(
|
|
411
|
+
false
|
|
412
|
+
)
|
|
413
|
+
expect(container.querySelector<HTMLInputElement>('input[name="title"]')?.value).toBe(
|
|
414
|
+
'Draft retained after tree move'
|
|
415
|
+
)
|
|
416
|
+
})
|
|
417
|
+
})
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
* .byline-form-actions-status-wrap — relative positioned wrapper around the ComboButton
|
|
21
21
|
* .byline-form-actions-combo-button — ComboButton's main button minimums
|
|
22
22
|
* .byline-form-actions-combo-trigger — ComboButton's trigger button minimums
|
|
23
|
+
* .byline-form-busy-status — visually-hidden save/upload announcement
|
|
24
|
+
* .byline-form-save-content — stable-width Save label/loader wrapper
|
|
25
|
+
* .byline-form-save-label — visible label that determines button width
|
|
26
|
+
* .byline-form-save-loader — centered progress overlay
|
|
23
27
|
*
|
|
24
28
|
* .byline-form-layout — main + sidebar grid wrapper
|
|
25
29
|
* .byline-form-content — main column
|
|
@@ -206,6 +210,44 @@
|
|
|
206
210
|
min-height: 28px;
|
|
207
211
|
}
|
|
208
212
|
|
|
213
|
+
.busy-status,
|
|
214
|
+
:global(.byline-form-busy-status) {
|
|
215
|
+
position: absolute;
|
|
216
|
+
overflow: hidden;
|
|
217
|
+
width: 1px;
|
|
218
|
+
height: 1px;
|
|
219
|
+
padding: 0;
|
|
220
|
+
border: 0;
|
|
221
|
+
margin: -1px;
|
|
222
|
+
clip: rect(0 0 0 0);
|
|
223
|
+
clip-path: inset(50%);
|
|
224
|
+
white-space: nowrap;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.save-content,
|
|
228
|
+
:global(.byline-form-save-content) {
|
|
229
|
+
position: relative;
|
|
230
|
+
display: inline-block;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.save-label,
|
|
234
|
+
:global(.byline-form-save-label) {
|
|
235
|
+
display: inline-block;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.save-label-hidden {
|
|
239
|
+
visibility: hidden;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.save-loader,
|
|
243
|
+
:global(.byline-form-save-loader) {
|
|
244
|
+
position: absolute;
|
|
245
|
+
top: 50%;
|
|
246
|
+
left: 50%;
|
|
247
|
+
display: inline-flex;
|
|
248
|
+
transform: translate(-50%, -50%);
|
|
249
|
+
}
|
|
250
|
+
|
|
209
251
|
.actions-status-wrap,
|
|
210
252
|
:global(.byline-form-actions-status-wrap) {
|
|
211
253
|
position: relative;
|
|
@@ -223,6 +265,26 @@
|
|
|
223
265
|
min-height: 28px;
|
|
224
266
|
}
|
|
225
267
|
|
|
268
|
+
/*
|
|
269
|
+
* Concurrency alerts (stale document, lock conflict, schedule reconfirmation).
|
|
270
|
+
* Separated from the status bar above and from the form layout below, which
|
|
271
|
+
* otherwise carries its standing top padding on top of the alert's own gap.
|
|
272
|
+
*/
|
|
273
|
+
.concurrency,
|
|
274
|
+
:global(.byline-document-concurrency) {
|
|
275
|
+
margin-top: var(--spacing-16);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.concurrency button,
|
|
279
|
+
:global(.byline-document-concurrency) button {
|
|
280
|
+
margin-top: var(--spacing-12);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.concurrency ~ .layout,
|
|
284
|
+
:global(.byline-document-concurrency) ~ :global(.byline-form-layout) {
|
|
285
|
+
padding-top: var(--spacing-16);
|
|
286
|
+
}
|
|
287
|
+
|
|
226
288
|
.layout,
|
|
227
289
|
:global(.byline-form-layout) {
|
|
228
290
|
display: flex;
|