Render up and self links in collection/entity header
authorFrank Bessou <frank.bessou@logilab.fr>
Thu, 11 May 2017 17:42:52 +0200
changeset 200 024c7f53a589
parent 199 ed0d8132c38b
child 201 f155ec3bc4b9
Render up and self links in collection/entity header
src/components/Resource.js
--- a/src/components/Resource.js	Thu May 11 16:09:33 2017 +0200
+++ b/src/components/Resource.js	Thu May 11 17:42:52 2017 +0200
@@ -2,6 +2,7 @@
 import hypermediaClient from '../services/hypermedia';
 import {PropTypes} from 'prop-types';
 import {merge} from 'lodash/object';
+import {Link} from 'react-router-dom';
 
 import {buildFormData} from '../utils';
 import {EntityAttributes, EntityForm, EntityMeta, RelatedResources} from './Entity';
@@ -150,12 +151,37 @@
 
 export function ResourceView(props) {
     const data = props.resource.data;
+    function renderUpLink() {
+        const upLink = data.getLink('up');
+        if (upLink) {
+            return (
+                <span>
+                    <Link to={upLink.href}>
+                        {upLink.title}
+                    </Link>
+                    &nbsp;/&nbsp;
+                </span>
+            );
+        }
+        return null;
+    }
+    function renderTitle() {
+        const selfLink = data.getLink('self');
+        if (selfLink) {
+            return (
+                <Link to={selfLink.href}>
+                    <strong>{selfLink.title}</strong>
+                </Link>
+            );
+        }
+        return data.schemas().title();
+    }
     function renderHeader() {
         return (
             <div>
                 <ActionsDropDown target={props.resource} ignore={['view']}/>
                 <div className="clearfix" />
-                <h3>{ data.schemas().title() }</h3>
+                <h3>{ renderUpLink() }{ renderTitle() }</h3>
             </div>
         );
     }