Use resource 'item' link to generate CollectionItemLink
authorFrank Bessou <frank.bessou@logilab.fr>
Fri, 07 Apr 2017 14:16:13 +0200
changeset 96 288f2c1973f9
parent 95 3b50d57dfc06
child 97 7744b1901e7b
Use resource 'item' link to generate CollectionItemLink
src/components/BaseViews.js
test/index.js
--- a/src/components/BaseViews.js	Fri Apr 07 13:48:34 2017 +0200
+++ b/src/components/BaseViews.js	Fri Apr 07 14:16:13 2017 +0200
@@ -5,11 +5,11 @@
 import {PropTypeJsonaryWrapper} from '../jsonaryutils';
 import {appendPath} from '../utils';
 
-export function CollectionItemLink({entity, etype}) {
+export function CollectionItemLink({entity}) {
     // XXX Use schema link when it becomes available
-    const id = entity.get('/id');
+    const itemRoute = entity.getLink('item').href;
     return (
-        <Link to={`/${etype}/${id}`}>
+        <Link to={`${itemRoute}`}>
             {entity.get('/title')}
         </Link>
     );
@@ -17,7 +17,6 @@
 
 CollectionItemLink.propTypes = {
     entity: PropTypeJsonaryWrapper.isRequired,
-    etype: React.PropTypes.string.isRequired,
 };
 
 export function CollectionView(props) {
--- a/test/index.js	Fri Apr 07 13:48:34 2017 +0200
+++ b/test/index.js	Fri Apr 07 14:16:13 2017 +0200
@@ -123,8 +123,10 @@
 
 describe('<CollectionItemLink />', () => {
     it('renders a link with title and proper URL', () => {
-        const entity = Jsonary.create({title: 'bob', id:'123'});
-        const wrapper = shallow(<CollectionItemLink entity={entity} etype={'user'}/>);
+        const item = {title: 'bob', id:'123'};
+        const itemSchema = {links: [{rel: 'item', href: '/user/{id}'}]};
+        const wrappedItem = wrapEntityData(item, itemSchema);
+        const wrapper = shallow(<CollectionItemLink entity={wrappedItem}/>);
 
         const link = wrapper.render();