-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly render many relationships in cells
- Loading branch information
1 parent
ae9f156
commit c68dbc6
Showing
1 changed file
with
14 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import React from 'react'; | ||
import React, { Fragment } from 'react'; | ||
import renderTemplate from '@keystonejs/ui/src/template'; | ||
|
||
export default ({ data, field, Link }) => { | ||
if (!data) { | ||
return null; | ||
} | ||
const refList = field.adminMeta.getListByKey(field.config.ref); | ||
return ( | ||
<Link path={refList.path} id={data.id}> | ||
{renderTemplate({ template: refList.displayTemplate, data })} | ||
</Link> | ||
<Fragment> | ||
{(Array.isArray(data) ? data : [data]).filter(Boolean).map((item, index) => | ||
<Fragment key={item.id}> | ||
{!!index ? ', ' : ''} | ||
<Link path={refList.path} id={item.id}> | ||
{renderTemplate({ template: refList.displayTemplate, data: item })} | ||
</Link> | ||
</Fragment> | ||
)} | ||
</Fragment> | ||
); | ||
}; |