Skip to content

Commit c742518

Browse files
committed
feat(ui): convert relationship cell texts into links
1 parent a7a0501 commit c742518

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import { useIntersect } from '../../../../../hooks/useIntersect.js'
1313
import { useConfig } from '../../../../../providers/Config/index.js'
1414
import { useTranslation } from '../../../../../providers/Translation/index.js'
1515
import { canUseDOM } from '../../../../../utilities/canUseDOM.js'
16+
import { formatAdminURL } from '../../../../../utilities/formatAdminURL.js'
1617
import { formatDocTitle } from '../../../../../utilities/formatDocTitle/index.js'
18+
import { Link } from '../../../../Link/index.js'
1719
import { useListRelationships } from '../../../RelationshipProvider/index.js'
1820
import { FileCell } from '../File/index.js'
1921
import './index.scss'
@@ -43,6 +45,7 @@ export const RelationshipCell: React.FC<RelationshipCellProps> = ({
4345

4446
const { config, getEntityConfig } = useConfig()
4547
const { collections, routes } = config
48+
const { admin: adminRoute } = routes
4649
const [intersectionRef, entry] = useIntersect()
4750
const [values, setValues] = useState<Value[]>([])
4851
const { documents, getRelationships } = useListRelationships()
@@ -128,11 +131,22 @@ export const RelationshipCell: React.FC<RelationshipCellProps> = ({
128131
}
129132
}
130133

134+
const documentHref = formatAdminURL({
135+
adminRoute,
136+
path: `/collections/${relationTo}/${encodeURIComponent(value)}`,
137+
})
138+
131139
return (
132140
<React.Fragment key={i}>
133141
{document === false && `${t('general:untitled')} - ID: ${value}`}
134142
{document === null && `${t('general:loading')}...`}
135-
{document ? fileField || label : null}
143+
{document
144+
? fileField || (
145+
<Link href={documentHref} prefetch={false}>
146+
{label}
147+
</Link>
148+
)
149+
: null}
136150
{values.length > i + 1 && ', '}
137151
</React.Fragment>
138152
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const DefaultCell: React.FC<DefaultCellComponentProps> = (props) => {
8484
return (
8585
<WrapElement {...wrapElementProps}>
8686
<CodeCell
87+
// cellData={`${cellData}`}
8788
cellData={`ID: ${cellData}`}
8889
collectionConfig={collectionConfig}
8990
collectionSlug={collectionSlug}

0 commit comments

Comments
 (0)