Ignore some actions in ActionsDropDown
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 06 Apr 2017 09:06:13 +0200
changeset 85 3af45ba4cb13
parent 84 f3320a200bf7
child 86 52b73d0dacee
Ignore some actions in ActionsDropDown For instance from EntityView we filter out the "view" action which is not very useful from the user point of view as they are already viewing the entity.
src/components/BaseViews.js
src/components/Entity.js
test/index.js
--- a/src/components/BaseViews.js	Thu Apr 06 09:36:54 2017 +0200
+++ b/src/components/BaseViews.js	Thu Apr 06 09:06:13 2017 +0200
@@ -40,8 +40,8 @@
     entities: PropTypesEntitiesModel.isRequired,
 };
 
-export function ActionsDropDown({target}) {
-    const actions = target.allowedActions;
+export function ActionsDropDown({target, ignore=[]}) {
+    const actions = target.allowedActions.filter(x => !ignore.includes(x));
     if (isEmpty(actions)) {
         return null;
     }
@@ -54,6 +54,7 @@
 
 ActionsDropDown.propTypes = {
     target: PropTypesResourceModel.isRequired,
+    ignore: React.PropTypes.arrayOf(React.PropTypes.string),
 }
 
 export function ActionLink({target, action}) {
--- a/src/components/Entity.js	Thu Apr 06 09:36:54 2017 +0200
+++ b/src/components/Entity.js	Thu Apr 06 09:06:13 2017 +0200
@@ -241,7 +241,7 @@
     }
 
     renderActions() {
-        return <ActionsDropDown target={this.props.entity} />;
+        return <ActionsDropDown target={this.props.entity} ignore={["view"]} />;
     }
 
     renderAttributes() {
--- a/test/index.js	Thu Apr 06 09:36:54 2017 +0200
+++ b/test/index.js	Thu Apr 06 09:06:13 2017 +0200
@@ -197,6 +197,13 @@
     it('renders a dropdown button with actions from target', () => {
         const wrapper = shallow(<ActionsDropDown target={targetResource}/>);
         expect(wrapper.find('ActionLink')).to.have.length(4);
+        expect(wrapper.find({action: "view"})).to.have.length(1);
+    });
+
+    it('renders a dropdown button with actions from target but those in "ignore" array', () => {
+        const wrapper = shallow(<ActionsDropDown target={targetResource} ignore={["view"]}/>);
+        expect(wrapper.find('ActionLink')).to.have.length(3);
+        expect(wrapper.find({action: "view"})).to.have.length(0);
     });
 
 });