File tree 1 file changed +32
-7
lines changed
packages/ui/src/elements/IDLabel
1 file changed +32
-7
lines changed Original file line number Diff line number Diff line change 2
2
import React from 'react'
3
3
4
4
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'
5
9
import { sanitizeID } from '../../utilities/sanitizeID.js'
6
10
7
11
const baseClass = 'id-label'
@@ -10,10 +14,31 @@ export const IDLabel: React.FC<{ className?: string; id: string; prefix?: string
10
14
id,
11
15
className,
12
16
prefix = 'ID:' ,
13
- } ) => (
14
- < div className = { [ baseClass , className ] . filter ( Boolean ) . join ( ' ' ) } title = { id } >
15
- { prefix }
16
-
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
+
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
+ }
You can’t perform that action at this time.
0 commit comments