Skip to content

Commit aa02801

Browse files
authored
fix(plugin-search): Render error on custom UI component (#6562)
## Type of change - [x] Bug fix (non-breaking change which fixes an issue)
1 parent a3ee07f commit aa02801

File tree

2 files changed

+68
-53
lines changed

2 files changed

+68
-53
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use client'
2+
3+
import type { FormState } from 'payload/types'
4+
5+
import { useWatchForm } from '@payloadcms/ui/forms/Form'
6+
import { useConfig } from '@payloadcms/ui/providers/Config'
7+
import React from 'react'
8+
// TODO: fix this import to work in dev mode within the monorepo in a way that is backwards compatible with 1.x
9+
// import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'
10+
11+
type FieldsWithDoc = FormState & {
12+
doc: {
13+
value: {
14+
relationTo: string
15+
value: string
16+
}
17+
}
18+
}
19+
20+
export const LinkToDocClient: React.FC = () => {
21+
const form = useWatchForm()
22+
const fields = form.fields as FieldsWithDoc
23+
24+
const {
25+
doc: {
26+
value: { relationTo, value: docId },
27+
},
28+
} = fields
29+
30+
const config = useConfig()
31+
32+
const {
33+
routes: {
34+
admin: adminRoute, // already includes leading slash
35+
},
36+
serverURL,
37+
} = config
38+
39+
const href = `${serverURL}${adminRoute}/collections/${relationTo}/${docId}`
40+
41+
return (
42+
<div>
43+
<div>
44+
<span
45+
className="label"
46+
style={{
47+
color: '#9A9A9A',
48+
}}
49+
>
50+
Doc URL
51+
</span>
52+
{/* <CopyToClipboard value={href} /> */}
53+
</div>
54+
<div
55+
style={{
56+
fontWeight: '600',
57+
overflow: 'hidden',
58+
textOverflow: 'ellipsis',
59+
}}
60+
>
61+
<a href={href}>{href}</a>
62+
</div>
63+
</div>
64+
)
65+
}
Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,13 @@
1-
import type { FormState, UIField } from 'payload/types'
1+
import type { UIField } from 'payload/types'
22

3-
import { useWatchForm } from '@payloadcms/ui/forms/Form'
4-
import { useConfig } from '@payloadcms/ui/providers/Config'
53
import React from 'react'
6-
// TODO: fix this import to work in dev mode within the monorepo in a way that is backwards compatible with 1.x
7-
// import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'
84

9-
type FieldsWithDoc = FormState & {
10-
doc: {
11-
value: {
12-
relationTo: string
13-
value: string
14-
}
15-
}
16-
}
5+
import { LinkToDocClient } from './index.client.js'
176

187
export const LinkToDoc: React.FC<UIField> = () => {
19-
const form = useWatchForm()
20-
const fields = form.fields as FieldsWithDoc
21-
22-
const {
23-
doc: {
24-
value: { relationTo, value: docId },
25-
},
26-
} = fields
27-
28-
const config = useConfig()
29-
30-
const {
31-
routes: {
32-
admin: adminRoute, // already includes leading slash
33-
},
34-
serverURL,
35-
} = config
36-
37-
const href = `${serverURL}${adminRoute}/collections/${relationTo}/${docId}`
38-
398
return (
409
<div>
41-
<div>
42-
<span
43-
className="label"
44-
style={{
45-
color: '#9A9A9A',
46-
}}
47-
>
48-
Doc URL
49-
</span>
50-
{/* <CopyToClipboard value={href} /> */}
51-
</div>
52-
<div
53-
style={{
54-
fontWeight: '600',
55-
overflow: 'hidden',
56-
textOverflow: 'ellipsis',
57-
}}
58-
>
59-
<a href={href}>{href}</a>
60-
</div>
10+
<LinkToDocClient />
6111
</div>
6212
)
6313
}

0 commit comments

Comments
 (0)