fix: overrides entity visibility within drawers (#9546)

When using the `admin.hidden: true` property on a collection, it
rightfully removes all navigation and routing for that particular
collection. However, this also affects the expected behavior of hidden
entities when they are rendered within a drawer, such as the document
drawer or list drawer. For example, when creating a new _admin.hidden_
document through the relationship or join field, the drawer should still
render the view, despite the underlying route for that view being
disabled. This change was a result of the introduction of on-demand
server components in #8364, where we now make a server roundtrip to
render the view in its entirety, which include the logic that redirects
these hidden entities.

Now, we pass a new `overrideEntityVisibility` argument through the
server function that, when true, skips this step. This way documents can
continue to respect `admin.hidden` while also having the ability to
override on a case-by-case basis throughout the UI.
This commit is contained in:
Jacob Fletcher
2024-11-26 18:22:04 -05:00
committed by GitHub
parent defa13e4fe
commit 5d18a5288e
21 changed files with 176 additions and 24 deletions

View File

@@ -56,12 +56,34 @@ test.describe('Admin Panel', () => {
test('should render initial rows within relationship table', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
await expect(joinField.locator('.relationship-table table')).toBeVisible()
const columns = await joinField.locator('.relationship-table tbody tr').count()
expect(columns).toBe(3)
})
test('should render join field for hidden posts', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('#field-hiddenPosts.field-type.join')
await expect(joinField).toBeVisible()
await expect(joinField.locator('.relationship-table table')).toBeVisible()
const columns = await joinField.locator('.relationship-table tbody tr').count()
expect(columns).toBe(1)
const button = joinField.locator('button.doc-drawer__toggler.relationship-table__add-new')
await expect(button).toBeVisible()
await button.click()
const drawer = page.locator('[id^=doc-drawer_hidden-posts_1_]')
await expect(drawer).toBeVisible()
const titleField = drawer.locator('#field-title')
await expect(titleField).toBeVisible()
await titleField.fill('Test Hidden Post')
await drawer.locator('button[id="action-save"]').click()
await expect(joinField.locator('.relationship-table tbody tr')).toBeVisible()
const newColumns = await joinField.locator('.relationship-table tbody tr').count()
expect(newColumns).toBe(2)
})
test('should render the create page and create doc with the join field', async () => {
await page.goto(categoriesURL.create)
const nameField = page.locator('#field-name')
@@ -72,7 +94,7 @@ test.describe('Admin Panel', () => {
test('should render collection type in first column of relationship table', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
const collectionTypeColumn = joinField.locator('thead tr th#heading-collection:first-child')
const text = collectionTypeColumn
@@ -91,7 +113,7 @@ test.describe('Admin Panel', () => {
test('should render drawer toggler without document link in second column of relationship table', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
const actionColumn = joinField.locator('tbody tr td:nth-child(2)').first()
const toggler = actionColumn.locator('button.doc-drawer__toggler')
@@ -123,7 +145,7 @@ test.describe('Admin Panel', () => {
test('should sort relationship table by clicking on column headers', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
const titleColumn = joinField.locator('thead tr th#heading-title')
const titleAscButton = titleColumn.locator('button.sort-column__asc')
@@ -143,7 +165,7 @@ test.describe('Admin Panel', () => {
test('should update relationship table when new document is created', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
const addButton = joinField.locator('.relationship-table__actions button.doc-drawer__toggler', {
@@ -173,7 +195,7 @@ test.describe('Admin Panel', () => {
test('should update relationship table when document is updated', async () => {
await navigateToDoc(page, categoriesURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
const editButton = joinField.locator(
'tbody tr:first-child td:nth-child(2) button.doc-drawer__toggler',
@@ -194,14 +216,14 @@ test.describe('Admin Panel', () => {
test('should render empty relationship table when creating new document', async () => {
await page.goto(categoriesURL.create)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
await expect(joinField.locator('.relationship-table tbody tr')).toBeHidden()
})
test('should update relationship table when new upload is created', async () => {
await navigateToDoc(page, uploadsURL)
const joinField = page.locator('.field-type.join').first()
const joinField = page.locator('#field-relatedPosts.field-type.join')
await expect(joinField).toBeVisible()
// TODO: change this to edit the first row in the join table