You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by am...@apache.org on 2020/04/02 21:01:28 UTC

[couchdb-fauxton] branch master updated: Show error message if it can't retrieve ddoc metadata (#1260)

This is an automated email from the ASF dual-hosted git repository.

amaranhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git


The following commit(s) were added to refs/heads/master by this push:
     new e8e2b90  Show error message if it can't retrieve ddoc metadata (#1260)
e8e2b90 is described below

commit e8e2b9096d186a1fb45f75cb70d6b67faaf5c8b3
Author: Antonio Maranhao <30...@users.noreply.github.com>
AuthorDate: Thu Apr 2 16:29:49 2020 -0400

    Show error message if it can't retrieve ddoc metadata (#1260)
---
 .../__tests__/designdocinfo-action.test.js          | 21 +++++++++++++++++++++
 app/addons/documents/designdocinfo/actions.js       | 10 ++++++++++
 app/addons/documents/designdocinfo/actiontypes.js   |  1 +
 .../designdocinfo/components/DesignDocInfo.js       | 14 ++++++++++++++
 .../components/DesignDocInfoContainer.js            |  1 +
 app/addons/documents/designdocinfo/reducers.js      | 10 ++++++++++
 6 files changed, 57 insertions(+)

diff --git a/app/addons/documents/__tests__/designdocinfo-action.test.js b/app/addons/documents/__tests__/designdocinfo-action.test.js
index c2a7efe..2b0c523 100644
--- a/app/addons/documents/__tests__/designdocinfo-action.test.js
+++ b/app/addons/documents/__tests__/designdocinfo-action.test.js
@@ -23,6 +23,7 @@ describe('DesignDocInfo Actions', () => {
 
     afterEach(() => {
       restore(window.setInterval);
+      testUtils.restore(FauxtonAPI.addNotification);
     });
 
     it('schedules regular updates on successful fetch', () => {
@@ -44,5 +45,25 @@ describe('DesignDocInfo Actions', () => {
         expect(spy.calledOnce).toBeTruthy();
       });
     });
+
+    it('shows error message in case of failure', () => {
+      const promise = FauxtonAPI.Deferred();
+      promise.reject();
+      const fakeDesignDocInfo = {
+        fetch: () => {
+          return promise;
+        }
+      };
+
+      const notificationSpy = sinon.spy(FauxtonAPI, 'addNotification');
+      const dispatch = sinon.stub();
+
+      return Actions.fetchDesignDocInfo({
+        ddocName: 'test-designdoc-info',
+        designDocInfo: fakeDesignDocInfo
+      })(dispatch).then(() => {
+        sinon.assert.calledOnce(notificationSpy);
+      });
+    });
   });
 });
diff --git a/app/addons/documents/designdocinfo/actions.js b/app/addons/documents/designdocinfo/actions.js
index 79004e6..3ec85e6 100644
--- a/app/addons/documents/designdocinfo/actions.js
+++ b/app/addons/documents/designdocinfo/actions.js
@@ -10,6 +10,7 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
+import FauxtonAPI from '../../../core/api';
 import ActionTypes from "./actiontypes";
 
 const fetchDesignDocInfo = ({designDocName, designDocInfo}) => (dispatch) => {
@@ -22,6 +23,15 @@ const fetchDesignDocInfo = ({designDocName, designDocInfo}) => (dispatch) => {
       designDocName,
       designDocInfo
     }, dispatch);
+  }).catch(() => {
+    dispatch({
+      type: ActionTypes.DESIGN_FETCHING_FAILED
+    });
+    FauxtonAPI.addNotification({
+      msg: 'Error loading design document metadata.',
+      type: 'error',
+      clear: true
+    });
   });
 };
 
diff --git a/app/addons/documents/designdocinfo/actiontypes.js b/app/addons/documents/designdocinfo/actiontypes.js
index 063072e..4c5f49e 100644
--- a/app/addons/documents/designdocinfo/actiontypes.js
+++ b/app/addons/documents/designdocinfo/actiontypes.js
@@ -13,5 +13,6 @@
 export default {
   DESIGN_DOC_MONITOR: 'DESIGN_DOC_MONITOR',
   DESIGN_FETCHING: 'DESIGN_FETCHING',
+  DESIGN_FETCHING_FAILED: 'DESIGN_FETCHING_FAILED',
   DESIGN_REFRESH: 'DESIGN_REFRESH'
 };
diff --git a/app/addons/documents/designdocinfo/components/DesignDocInfo.js b/app/addons/documents/designdocinfo/components/DesignDocInfo.js
index 3c80c94..10c72b9 100644
--- a/app/addons/documents/designdocinfo/components/DesignDocInfo.js
+++ b/app/addons/documents/designdocinfo/components/DesignDocInfo.js
@@ -55,6 +55,19 @@ export default class DesignDocInfo extends React.Component {
     if (this.props.isLoading) {
       return <LoadLines />;
     }
+    if (this.props.showLoadError) {
+      return (
+        <div className="metadata-page">
+          <header>
+            <h2>_design/{this.props.designDocName} Metadata</h2>
+          </header>
+
+          <section className="container">
+            Error retrieving metadata. Try reloading the page.
+          </section>
+        </div>
+      );
+    }
     const viewIndex = this.props.viewIndex;
     const {sizes} = viewIndex;
     const actualSize = (sizes.active) ? sizes.active.toLocaleString('en') : 0;
@@ -130,6 +143,7 @@ export default class DesignDocInfo extends React.Component {
 
 DesignDocInfo.propTypes = {
   isLoading: PropTypes.bool.isRequired,
+  showLoadError: PropTypes.bool.isRequired,
   viewIndex: PropTypes.object,
   designDocName: PropTypes.string.isRequired,
   stopRefresh: PropTypes.func.isRequired,
diff --git a/app/addons/documents/designdocinfo/components/DesignDocInfoContainer.js b/app/addons/documents/designdocinfo/components/DesignDocInfoContainer.js
index 2984b86..98feedb 100644
--- a/app/addons/documents/designdocinfo/components/DesignDocInfoContainer.js
+++ b/app/addons/documents/designdocinfo/components/DesignDocInfoContainer.js
@@ -5,6 +5,7 @@ import Actions from '../actions';
 const mapStateToProps = ({ designDocInfo }, ownProps) => {
   return {
     isLoading: designDocInfo.isLoading,
+    showLoadError: designDocInfo.showLoadError,
     viewIndex: designDocInfo.viewIndex,
     designDocInfo: ownProps.designDocInfo,
     designDocName: ownProps.designDocName
diff --git a/app/addons/documents/designdocinfo/reducers.js b/app/addons/documents/designdocinfo/reducers.js
index 9b62b91..0b34356 100644
--- a/app/addons/documents/designdocinfo/reducers.js
+++ b/app/addons/documents/designdocinfo/reducers.js
@@ -14,6 +14,7 @@ import ActionTypes from './actiontypes';
 
 const initialState = {
   isLoading: true,
+  showLoadError: false,
   viewIndex: undefined
 };
 
@@ -28,16 +29,25 @@ export default function designDocInfo (state = initialState, action) {
         isLoading: true
       };
 
+    case ActionTypes.DESIGN_FETCHING_FAILED:
+      return {
+        ...state,
+        isLoading: false,
+        showLoadError: true,
+      };
+
     case ActionTypes.DESIGN_DOC_MONITOR:
       return {
         ...state,
         isLoading: false,
+        showLoadError: false,
         viewIndex: options.designDocInfo.get('view_index')
       };
 
     case ActionTypes.DESIGN_DOC_REFRESH:
       return {
         ...state,
+        showLoadError: false,
         viewIndex: options.designDocInfo.get('view_index')
       };