Skip to content

Commit bd98758

Browse files
committed
add option to open document in a new tab from drawer
1 parent 6572bf4 commit bd98758

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

Diff for: packages/ui/src/elements/IDLabel/index.tsx

+32-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import React from 'react'
33

44
import './index.scss'
5+
import { useConfig } from '../../providers/Config/index.js'
6+
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js'
7+
import { useEditDepth } from '../../providers/EditDepth/index.js'
8+
import { formatAdminURL } from '../../utilities/formatAdminURL.js'
59
import { sanitizeID } from '../../utilities/sanitizeID.js'
610

711
const baseClass = 'id-label'
@@ -10,10 +14,31 @@ export const IDLabel: React.FC<{ className?: string; id: string; prefix?: string
1014
id,
1115
className,
1216
prefix = 'ID:',
13-
}) => (
14-
<div className={[baseClass, className].filter(Boolean).join(' ')} title={id}>
15-
{prefix}
16-
&nbsp;
17-
{sanitizeID(id)}
18-
</div>
19-
)
17+
}) => {
18+
const {
19+
config: {
20+
routes: { admin: adminRoute },
21+
},
22+
} = useConfig()
23+
const { collectionSlug, globalSlug } = useDocumentInfo()
24+
const editDepth = useEditDepth()
25+
26+
const docPath = formatAdminURL({
27+
adminRoute,
28+
path: `/${collectionSlug ? `collections/${collectionSlug}` : `globals/${globalSlug}`}/${id}`,
29+
})
30+
31+
return (
32+
<div className={[baseClass, className].filter(Boolean).join(' ')} title={id}>
33+
{prefix}
34+
&nbsp;
35+
{editDepth === 0 ? (
36+
sanitizeID(id)
37+
) : (
38+
<a href={docPath} rel="noopener noreferrer" target="_blank">
39+
{sanitizeID(id)}
40+
</a>
41+
)}
42+
</div>
43+
)
44+
}

0 commit comments

Comments
 (0)