### What? Selected documents in a relationship field can be opened in a new tab. ### Why? Related documents can be edited using the edit icon which opens the document in a drawer. Sometimes users would like to open the document in a new tab instead to e.g. modify the related document at a later point in time. This currently requires users to find the related document via the list view and open it there. There is no easy way to find and open a related document. ### How? Adds custom handling to the relationship edit button to support opening it in a new tab via middle-click, Ctrl+click, or right-click → 'Open in new tab'. --------- Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import type { Page } from '@playwright/test'
|
|
|
|
import { expect } from '@playwright/test'
|
|
import { wait } from 'payload/shared'
|
|
|
|
export async function openDocDrawer({
|
|
page,
|
|
selector,
|
|
withMetaKey = false,
|
|
}: {
|
|
page: Page
|
|
selector: string
|
|
withMetaKey?: boolean
|
|
}): Promise<void> {
|
|
let clickProperties = {}
|
|
if (withMetaKey) {
|
|
clickProperties = { modifiers: ['ControlOrMeta'] }
|
|
}
|
|
await wait(500) // wait for parent form state to initialize
|
|
await page.locator(selector).click(clickProperties)
|
|
await wait(500) // wait for drawer form state to initialize
|
|
}
|
|
|
|
export async function openCreateDocDrawer({
|
|
page,
|
|
fieldSelector,
|
|
}: {
|
|
fieldSelector: string
|
|
page: Page
|
|
}): Promise<void> {
|
|
await wait(500) // wait for parent form state to initialize
|
|
const relationshipField = page.locator(fieldSelector)
|
|
await expect(relationshipField.locator('input')).toBeEnabled()
|
|
const addNewButton = relationshipField.locator('.relationship-add-new__add-button')
|
|
await expect(addNewButton).toBeVisible()
|
|
await addNewButton.click()
|
|
await wait(500) // wait for drawer form state to initialize
|
|
}
|