From 267c23616da753655db75accec500c8406513fb6 Mon Sep 17 00:00:00 2001 From: Jacob Fletcher Date: Thu, 6 Jun 2024 10:48:12 -0400 Subject: [PATCH] fix(ui): global documents disabled after save (#6652) --- .../ui/src/providers/DocumentInfo/index.tsx | 6 ++--- test/admin/e2e/1/e2e.spec.ts | 26 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/providers/DocumentInfo/index.tsx b/packages/ui/src/providers/DocumentInfo/index.tsx index 59f7730344..e92fcb4e1a 100644 --- a/packages/ui/src/providers/DocumentInfo/index.tsx +++ b/packages/ui/src/providers/DocumentInfo/index.tsx @@ -354,12 +354,14 @@ export const DocumentInfoProvider: React.FC< const docPreferences = await getDocPreferences() + const newData = collectionSlug ? json.doc : json.result + const newState = await getFormState({ apiRoute: api, body: { id, collectionSlug, - data: json.doc, + data: newData, docPreferences, globalSlug, locale, @@ -369,8 +371,6 @@ export const DocumentInfoProvider: React.FC< serverURL, }) - const newData = json.doc - setInitialState(newState) setData(newData) await getDocPermissions(newData) diff --git a/test/admin/e2e/1/e2e.spec.ts b/test/admin/e2e/1/e2e.spec.ts index 63e439edc8..24e0fb4e49 100644 --- a/test/admin/e2e/1/e2e.spec.ts +++ b/test/admin/e2e/1/e2e.spec.ts @@ -69,6 +69,7 @@ describe('admin1', () => { let page: Page let geoUrl: AdminUrlUtil let postsUrl: AdminUrlUtil + let globalURL: AdminUrlUtil let customViewsURL: AdminUrlUtil let disableDuplicateURL: AdminUrlUtil let serverURL: string @@ -87,6 +88,7 @@ describe('admin1', () => { })) geoUrl = new AdminUrlUtil(serverURL, geoCollectionSlug) postsUrl = new AdminUrlUtil(serverURL, postsCollectionSlug) + globalURL = new AdminUrlUtil(serverURL, globalSlug) customViewsURL = new AdminUrlUtil(serverURL, customViews2CollectionSlug) disableDuplicateURL = new AdminUrlUtil(serverURL, disableDuplicateSlug) @@ -616,6 +618,22 @@ describe('admin1', () => { }) }) + describe('form state', () => { + test('collection — should re-enable fields after save', async () => { + await page.goto(postsUrl.create) + await page.locator('#field-title').fill(title) + await saveDocAndAssert(page) + await expect(page.locator('#field-title')).toBeEnabled() + }) + + test('global — should re-enable fields after save', async () => { + await page.goto(globalURL.global(globalSlug)) + await page.locator('#field-title').fill(title) + await saveDocAndAssert(page) + await expect(page.locator('#field-title')).toBeEnabled() + }) + }) + describe('document titles', () => { test('collection — should render fallback titles when creating new', async () => { await page.goto(postsUrl.create) @@ -647,8 +665,8 @@ describe('admin1', () => { }) test('global — should render custom, localized label', async () => { - await page.goto(postsUrl.admin) - await page.waitForURL(postsUrl.admin) + await page.goto(globalURL.global(globalSlug)) + await page.waitForURL(globalURL.global(globalSlug)) await openNav(page) const label = 'My Global Label' const globalLabel = page.locator(`#nav-global-global`) @@ -656,6 +674,10 @@ describe('admin1', () => { await globalLabel.click() await checkPageTitle(page, label) await checkBreadcrumb(page, label) + await page.locator('#field-title').fill(title) + await saveDocAndAssert(page) + await checkPageTitle(page, label) + await checkBreadcrumb(page, label) }) test('global — should render simple label strings', async () => {