Rename "create" action as "add"
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 23 May 2017 10:37:37 +0200
changeset 215 bdde73b3869e
parent 214 d6b4dfb58e1d
child 216 29ef6742d635
Rename "create" action as "add" The "create" term is not quite suitable when one wants to add a new relation. On the other hand "add" is suitable for both entity creation and relation addition.
src/components/BaseViews.js
src/components/Resource.js
src/index.js
src/model.js
src/services/hypermedia.js
test/index.js
--- a/src/components/BaseViews.js	Fri May 19 09:52:15 2017 +0200
+++ b/src/components/BaseViews.js	Tue May 23 10:37:37 2017 +0200
@@ -64,8 +64,8 @@
         case 'edit':
             url += '@@edit';
             break;
-        case 'create':
-            url += '@@create';
+        case 'add':
+            url += '@@add';
             break;
         default:
             return null;
--- a/src/components/Resource.js	Fri May 19 09:52:15 2017 +0200
+++ b/src/components/Resource.js	Tue May 23 10:37:37 2017 +0200
@@ -299,7 +299,7 @@
 export function Resource(props) {
     function selectView() {
         switch (props.match.params.action) {
-            case 'create':
+            case 'add':
                 return ResourceCreationForm;
             case 'delete':
                 return ResourceDeletionView;
--- a/src/index.js	Fri May 19 09:52:15 2017 +0200
+++ b/src/index.js	Tue May 23 10:37:37 2017 +0200
@@ -18,7 +18,7 @@
                 <Route exact path='/' component={Root} />
                 <Route path="/:etype/:eid/relationships/:rtype" component={AddRelated} />
 
-                <Route exact path=":apiUrl(.*)@@:action(view|create|delete|edit)" component={Resource} />
+                <Route exact path=":apiUrl(.*)@@:action(view|add|delete|edit)" component={Resource} />
                 <Route exact path=":apiUrl(.*)" component={Resource} />
 
                 <Route path="*" component={NotFound} />
--- a/src/model.js	Fri May 19 09:52:15 2017 +0200
+++ b/src/model.js	Tue May 23 10:37:37 2017 +0200
@@ -3,7 +3,7 @@
 import {PropTypeJsonaryWrapper} from './jsonaryutils';
 
 export const PropTypeAction = PropTypes.oneOf([
-    'create',
+    'add',
     'view',
     'edit',
     'delete',
--- a/src/services/hypermedia.js	Fri May 19 09:52:15 2017 +0200
+++ b/src/services/hypermedia.js	Tue May 23 10:37:37 2017 +0200
@@ -65,7 +65,7 @@
         return allowedMethods.map((method) => {
             switch(method) {
                 case 'POST':
-                    return 'create';
+                    return 'add';
                 case 'GET':
                     return 'view';
                 case 'PUT':
--- a/test/index.js	Fri May 19 09:52:15 2017 +0200
+++ b/test/index.js	Tue May 23 10:37:37 2017 +0200
@@ -214,12 +214,12 @@
         targetUrl = "/any/123";
     });
 
-    it('given a "create" action, it renders a link pointing to "create" view', () => {
-        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='create'/>);
+    it('given an "add" action, it renders a link pointing to "add" view', () => {
+        const wrapper = shallow(<ActionLink targetUrl={targetUrl} action='add'/>);
 
         expect(wrapper.is('Link')).to.be.equal(true);
-        expect(wrapper.prop('to')).to.be.equal('/any/123@@create');
-        expect(wrapper.prop('title')).to.be.equal('create');
+        expect(wrapper.prop('to')).to.be.equal('/any/123@@add');
+        expect(wrapper.prop('title')).to.be.equal('add');
     });
 
     it('given an "edit" action, it renders a link pointing to "edit" view', () => {
@@ -751,10 +751,10 @@
 });
 
 describe('Resource', () => {
-    it('should select "ResourceCreationForm" when action is "create"', () => {
+    it('should select "ResourceCreationForm" when action is "add"', () => {
         const params = {
             apiUrl: '/book/',
-            action: 'create',
+            action: 'add',
         };
         const wrapper = shallow(<Resource match={{params: params}}/>);
         const component = wrapper.props().component;