Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): update relationship cell formatted value when when search changes #6208

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const RelationshipCell: React.FC<RelationshipCellProps> = ({
useEffect(() => {
if (cellData && isAboveViewport && !hasRequested) {
const formattedValues: Value[] = []

const arrayCellData = Array.isArray(cellData) ? cellData : [cellData]
arrayCellData
.slice(0, arrayCellData.length < totalToShow ? arrayCellData.length : totalToShow)
Expand Down Expand Up @@ -71,6 +70,13 @@ export const RelationshipCell: React.FC<RelationshipCellProps> = ({
getRelationships,
])

useEffect(() => {
if (hasRequested) {
setHasRequested(false)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cellData])

return (
<div className={baseClass} ref={intersectionRef}>
{values.map(({ relationTo, value }, i) => {
Expand Down
47 changes: 46 additions & 1 deletion test/fields-relationship/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'
import { POLL_TOPASS_TIMEOUT, TEST_TIMEOUT_LONG } from '../playwright.config.js'
import {
relationFalseFilterOptionSlug,
relationOneSlug,
Expand Down Expand Up @@ -531,6 +531,51 @@ describe('fields - relationship', () => {
const relationship = page.locator('.row-1 .cell-relationshipWithTitle')
await expect(relationship).toHaveText(relationWithTitle.name)
})

test('should update relationship values on page change in list view', async () => {
await clearCollectionDocs(slug)
// create new docs to paginate to
for (let i = 0; i < 10; i++) {
await payload.create({
collection: slug,
data: {
relationshipHasManyMultiple: [
{
relationTo: relationOneSlug,
value: relationOneDoc.id,
},
],
},
})
}

for (let i = 0; i < 10; i++) {
await payload.create({
collection: slug,
data: {
relationshipHasManyMultiple: [
{
relationTo: relationTwoSlug,
value: relationTwoDoc.id,
},
],
},
})
}

await page.goto(url.list)

// check first doc on first page
const relationship = page.locator('.row-1 .cell-relationshipHasManyMultiple')
await expect(relationship).toHaveText(relationTwoDoc.id)

const paginator = page.locator('.clickable-arrow--right')
await paginator.click()
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('page=2')

// check first doc on second page (should be different)
await expect(relationship).toContainText(relationOneDoc.id)
})
})

describe('externally update relationship field', () => {
Expand Down
Loading