Skip to content

Commit 0facc44

Browse files
authored
fix(ui): respect formatDocURL returning null in ListDrawer (#16464)
Backport of #16398
1 parent 695df3c commit 0facc44

4 files changed

Lines changed: 62 additions & 1 deletion

File tree

packages/ui/src/providers/TableColumns/RenderDefaultCell/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const RenderDefaultCell: React.FC<{
2828
columnIndex,
2929
}
3030

31-
if (isLinkedColumn && drawerSlug) {
31+
if (isLinkedColumn && drawerSlug && clientProps.link !== false) {
3232
propsToPass.className = `${baseClass}__first-cell`
3333
propsToPass.link = false
3434
propsToPass.onClick = ({ collectionSlug: rowColl, rowData }) => {

test/admin/collections/FormatDocURL/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import type { CollectionConfig } from 'payload'
33
export const FormatDocURL: CollectionConfig = {
44
slug: 'format-doc-url',
55
admin: {
6+
components: {
7+
beforeListTable: [
8+
{
9+
path: '/components/BeforeList/index.js#SelectFormatDocURLButton',
10+
},
11+
],
12+
},
613
// Custom formatDocURL function to control linking behavior
714
formatDocURL: ({ doc, defaultURL, req, collectionSlug, viewType }) => {
815
// Disable linking for documents with title 'no-link'

test/admin/components/BeforeList/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ export const SelectPostsButton = () => {
2121
</>
2222
)
2323
}
24+
25+
export const SelectFormatDocURLButton = () => {
26+
const listDrawerArgs = useMemo<UseListDrawerArgs>(
27+
() => ({
28+
collectionSlugs: ['format-doc-url'],
29+
}),
30+
[],
31+
)
32+
const [ListDrawer, _, { toggleDrawer }] = useListDrawer(listDrawerArgs)
33+
34+
return (
35+
<>
36+
<Button onClick={() => toggleDrawer()}>Select format doc</Button>
37+
<ListDrawer allowCreate={false} enableRowSelections={false} />
38+
</>
39+
)
40+
}

test/admin/e2e/list-view/e2e.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,43 @@ describe('List View', () => {
22012201
),
22022202
)
22032203
})
2204+
2205+
test('should disable linking in ListDrawer for documents with formatDocURL returning null', async () => {
2206+
await payload.create({
2207+
collection: formatDocURLCollectionSlug,
2208+
data: { title: 'no-link', description: 'This should not be linkable in drawer' },
2209+
})
2210+
2211+
await payload.create({
2212+
collection: formatDocURLCollectionSlug,
2213+
data: { title: 'linkable', description: 'This should be linkable in drawer' },
2214+
})
2215+
2216+
await page.goto(formatDocURLUrl.list)
2217+
2218+
const selectButton = page.locator('button:has-text("Select format doc")')
2219+
await selectButton.waitFor({ state: 'visible' })
2220+
await selectButton.click()
2221+
2222+
const listDrawer = page.locator('.list-drawer.drawer--is-open')
2223+
await listDrawer.waitFor({ state: 'visible' })
2224+
await expect(listDrawer).toBeVisible()
2225+
2226+
await expect(listDrawer.locator('table tbody tr')).toHaveCount(2)
2227+
2228+
// The 'no-link' row should NOT have any clickable link-styled cell —
2229+
// formatDocURL returned null for it, so the drawer must not attach the
2230+
// underline className or the selection click handler to any cell.
2231+
const noLinkRow = listDrawer.locator('table tbody tr').filter({ hasText: 'no-link' })
2232+
await expect(noLinkRow.locator('button.default-cell__first-cell')).toHaveCount(0)
2233+
await expect(noLinkRow.locator('a')).toHaveCount(0)
2234+
2235+
// The 'linkable' row's linked cell should still be rendered as a
2236+
// clickable selection button (drawer overrides the link with an
2237+
// onSelect handler).
2238+
const linkableRow = listDrawer.locator('table tbody tr').filter({ hasText: 'linkable' })
2239+
await expect(linkableRow.locator('button.default-cell__first-cell')).toHaveCount(1)
2240+
})
22042241
})
22052242
})
22062243

0 commit comments

Comments
 (0)