Fixes #9873. The relationship filter in the "where" builder renders stale values when switching between fields or adding additional "and" conditions. This was because the `RelationshipFilter` component was not responding to changes in the `relationTo` prop and failing to reset internal state when these events took place. While it sounds like a simple fix, it was actually quite extensive. The `RelationshipFilter` component was previously relying on a `useEffect` that had a callback in its dependencies. This was causing the effect to run uncontrollably using old references. To avoid this, we use the new `useEffectEvent` approach which allows the underlying effect to run much more precisely. Same with the `Condition` component that wraps it. We now run callbacks directly within event handlers as much as possible, and rely on `useEffectEvent` _only_ for debounced value changes. This component was also unnecessarily complex...and still is to some degree. Previously, it was maintaining two separate refs, one to track the relationships that have yet to fully load, and another to track the next pages of each relationship that need to load on the next run. These have been combined into a single ref that tracks both simultaneously, as this data is interrelated. This change also does some much needed housekeeping to the `WhereBuilder` by improving types, defaulting the operator field, etc. Related: #11023 and #11032 Unrelated: finds a few more instances where the new `addListFilter` helper from #11026 could be used. Also removes a few duplicative tests.
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import type { Page } from '@playwright/test'
|
|
|
|
import { expect, test } from '@playwright/test'
|
|
import { addListFilter } from 'helpers/e2e/addListFilter.js'
|
|
import path from 'path'
|
|
import { wait } from 'payload/shared'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import { ensureCompilationIsDone, initPageConsoleErrorCatch } from '../../../helpers.js'
|
|
import { AdminUrlUtil } from '../../../helpers/adminUrlUtil.js'
|
|
import { initPayloadE2ENoConfig } from '../../../helpers/initPayloadE2ENoConfig.js'
|
|
import { reInitializeDB } from '../../../helpers/reInitializeDB.js'
|
|
import { RESTClient } from '../../../helpers/rest.js'
|
|
import { TEST_TIMEOUT_LONG } from '../../../playwright.config.js'
|
|
import { checkboxFieldsSlug } from '../../slugs.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const currentFolder = path.dirname(filename)
|
|
const dirname = path.resolve(currentFolder, '../../')
|
|
|
|
const { beforeAll, beforeEach, describe } = test
|
|
|
|
let client: RESTClient
|
|
let page: Page
|
|
let serverURL: string
|
|
let url: AdminUrlUtil
|
|
|
|
describe('Checkboxes', () => {
|
|
beforeAll(async ({ browser }, testInfo) => {
|
|
testInfo.setTimeout(TEST_TIMEOUT_LONG)
|
|
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
|
|
;({ serverURL } = await initPayloadE2ENoConfig({
|
|
dirname,
|
|
// prebuild,
|
|
}))
|
|
|
|
url = new AdminUrlUtil(serverURL, checkboxFieldsSlug)
|
|
|
|
const context = await browser.newContext()
|
|
page = await context.newPage()
|
|
initPageConsoleErrorCatch(page)
|
|
|
|
await ensureCompilationIsDone({ page, serverURL })
|
|
})
|
|
|
|
beforeEach(async () => {
|
|
await reInitializeDB({
|
|
serverURL,
|
|
snapshotKey: 'fieldsTest',
|
|
uploadsDir: path.resolve(dirname, './collections/Upload/uploads'),
|
|
})
|
|
if (client) {
|
|
await client.logout()
|
|
}
|
|
client = new RESTClient({ defaultSlug: 'users', serverURL })
|
|
await client.login()
|
|
await ensureCompilationIsDone({ page, serverURL })
|
|
})
|
|
|
|
test('should not crash on filtering where checkbox is first field', async () => {
|
|
await page.goto(url.list)
|
|
|
|
await addListFilter({
|
|
page,
|
|
fieldLabel: 'Checkbox',
|
|
operatorLabel: 'equals',
|
|
value: 'True',
|
|
})
|
|
|
|
await expect(page.locator('table > tbody > tr')).toHaveCount(1)
|
|
})
|
|
})
|