Skip to content

Commit e682cb1

Browse files
r1tsuujessrynkar
andauthored
fix(ui): update relationship cell formatted value when when search changes (#6208)
## Description Fixes payloadcms/payload-3.0-demo#181 Although issue is about page changing, it happens as well when you change sort / limit / where filter (and probably locale) <!-- Please include a summary of the pull request and any related issues it fixes. Please also include relevant motivation and context. --> - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change <!-- Please delete options that are not relevant. --> - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] Existing test suite passes locally with my changes --------- Co-authored-by: Jessica Chowdhury <jessica@trbl.design>
1 parent 36fda30 commit e682cb1

File tree

2 files changed

+53
-2
lines changed
  • packages/ui/src/elements/Table/DefaultCell/fields/Relationship
  • test/fields-relationship

2 files changed

+53
-2
lines changed

packages/ui/src/elements/Table/DefaultCell/fields/Relationship/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const RelationshipCell: React.FC<RelationshipCellProps> = ({
3939
useEffect(() => {
4040
if (cellData && isAboveViewport && !hasRequested) {
4141
const formattedValues: Value[] = []
42-
4342
const arrayCellData = Array.isArray(cellData) ? cellData : [cellData]
4443
arrayCellData
4544
.slice(0, arrayCellData.length < totalToShow ? arrayCellData.length : totalToShow)
@@ -71,6 +70,13 @@ export const RelationshipCell: React.FC<RelationshipCellProps> = ({
7170
getRelationships,
7271
])
7372

73+
useEffect(() => {
74+
if (hasRequested) {
75+
setHasRequested(false)
76+
}
77+
// eslint-disable-next-line react-hooks/exhaustive-deps
78+
}, [cellData])
79+
7480
return (
7581
<div className={baseClass} ref={intersectionRef}>
7682
{values.map(({ relationTo, value }, i) => {

test/fields-relationship/e2e.spec.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from '../helpers.js'
2727
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
2828
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
29-
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'
29+
import { POLL_TOPASS_TIMEOUT, TEST_TIMEOUT_LONG } from '../playwright.config.js'
3030
import {
3131
relationFalseFilterOptionSlug,
3232
relationOneSlug,
@@ -531,6 +531,51 @@ describe('fields - relationship', () => {
531531
const relationship = page.locator('.row-1 .cell-relationshipWithTitle')
532532
await expect(relationship).toHaveText(relationWithTitle.name)
533533
})
534+
535+
test('should update relationship values on page change in list view', async () => {
536+
await clearCollectionDocs(slug)
537+
// create new docs to paginate to
538+
for (let i = 0; i < 10; i++) {
539+
await payload.create({
540+
collection: slug,
541+
data: {
542+
relationshipHasManyMultiple: [
543+
{
544+
relationTo: relationOneSlug,
545+
value: relationOneDoc.id,
546+
},
547+
],
548+
},
549+
})
550+
}
551+
552+
for (let i = 0; i < 10; i++) {
553+
await payload.create({
554+
collection: slug,
555+
data: {
556+
relationshipHasManyMultiple: [
557+
{
558+
relationTo: relationTwoSlug,
559+
value: relationTwoDoc.id,
560+
},
561+
],
562+
},
563+
})
564+
}
565+
566+
await page.goto(url.list)
567+
568+
// check first doc on first page
569+
const relationship = page.locator('.row-1 .cell-relationshipHasManyMultiple')
570+
await expect(relationship).toHaveText(relationTwoDoc.id)
571+
572+
const paginator = page.locator('.clickable-arrow--right')
573+
await paginator.click()
574+
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('page=2')
575+
576+
// check first doc on second page (should be different)
577+
await expect(relationship).toContainText(relationOneDoc.id)
578+
})
534579
})
535580

536581
describe('externally update relationship field', () => {

0 commit comments

Comments
 (0)