couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [5/7] fauxton commit: updated refs/heads/master to 73521f1
Date Mon, 04 Jul 2016 13:29:35 GMT
Breadcrumbs React port: refactor clone-doc action

 - use helper function for docId sanitizing
 - move clone-doc-action out of route ofbject
 - delete route-event `duplicateDoc`
 - fix issue where breadcrumb header was not updating after clone

PR: #732
PR-URL: https://github.com/apache/couchdb-fauxton/pull/732
Reviewed-By: garren smith <garren.smith@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/50e08c89
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/50e08c89
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/50e08c89

Branch: refs/heads/master
Commit: 50e08c899b574d22784392755814284341936a48
Parents: de9b12b
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Tue Jun 21 14:14:18 2016 +0200
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Mon Jul 4 15:25:28 2016 +0200

----------------------------------------------------------------------
 app/addons/documents/doc-editor/actions.js      | 27 +++++++++++++----
 .../documents/doc-editor/components.react.jsx   | 12 ++++++--
 app/addons/documents/routes-doc-editor.js       | 31 +-------------------
 .../documents/tests/nightwatch/cloneDoc.js      |  1 -
 4 files changed, 31 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/50e08c89/app/addons/documents/doc-editor/actions.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/doc-editor/actions.js b/app/addons/documents/doc-editor/actions.js
index ed00f94..9b6a1fc 100644
--- a/app/addons/documents/doc-editor/actions.js
+++ b/app/addons/documents/doc-editor/actions.js
@@ -112,13 +112,28 @@ function hideCloneDocModal () {
   FauxtonAPI.dispatch({ type: ActionTypes.HIDE_CLONE_DOC_MODAL });
 }
 
-function cloneDoc (newId) {
-  var isDDoc = newId.match(/^_design\//),
-    removeDDocID = newId.replace(/^_design\//, ''),
-    encodedID = isDDoc ? '_design/' + app.utils.safeURLName(removeDDocID) : app.utils.safeURLName(newId);
+function cloneDoc (database, doc, newId) {
+  const docId = app.utils.getSafeIdForDoc(newId);
+
+  hideCloneDocModal();
+
+  doc.copy(docId).then(() => {
+    doc.set({ _id: docId });
+
+    FauxtonAPI.navigate('/database/' + database.safeID() + '/' + docId, { trigger: true });
+
+    FauxtonAPI.addNotification({
+      msg: 'Document has been duplicated.'
+    });
+
+  }, (error) => {
+    const errorMsg = `Could not duplicate document, reason: ${error.responseText}.`;
+    FauxtonAPI.addNotification({
+      msg: errorMsg,
+      type: 'error'
+    });
+  });
 
-  this.hideCloneDocModal();
-  FauxtonAPI.triggerRouteEvent('duplicateDoc', encodedID);
 }
 
 function showUploadModal () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/50e08c89/app/addons/documents/doc-editor/components.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/documents/doc-editor/components.react.jsx b/app/addons/documents/doc-editor/components.react.jsx
index c2a7f15..7c53dd6 100644
--- a/app/addons/documents/doc-editor/components.react.jsx
+++ b/app/addons/documents/doc-editor/components.react.jsx
@@ -190,6 +190,8 @@ var DocEditorController = React.createClass({
           visible={this.state.uploadModalVisible}
           doc={this.state.doc} />
         <CloneDocModal
+          doc={this.state.doc}
+          database={this.props.database}
           visible={this.state.cloneDocModalVisible}
           onSubmit={this.clearChanges} />
         <FauxtonComponents.ConfirmationModal
@@ -369,9 +371,12 @@ var UploadModal = React.createClass({
 });
 
 
-var CloneDocModal = React.createClass({
+const CloneDocModal = React.createClass({
   propTypes: {
-    visible: React.PropTypes.bool.isRequired
+    visible: React.PropTypes.bool.isRequired,
+    doc: React.PropTypes.object,
+    database: React.PropTypes.object.isRequired,
+    onSubmit: React.PropTypes.func.isRequired
   },
 
   getInitialState: function () {
@@ -384,7 +389,8 @@ var CloneDocModal = React.createClass({
     if (this.props.onSubmit) {
       this.props.onSubmit();
     }
-    Actions.cloneDoc(this.state.uuid);
+
+    Actions.cloneDoc(this.props.database, this.props.doc, this.state.uuid);
   },
 
   componentDidUpdate: function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/50e08c89/app/addons/documents/routes-doc-editor.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes-doc-editor.js b/app/addons/documents/routes-doc-editor.js
index c830ec9..0600105 100644
--- a/app/addons/documents/routes-doc-editor.js
+++ b/app/addons/documents/routes-doc-editor.js
@@ -40,7 +40,7 @@ const RevBrowserRouteObject = FauxtonAPI.RouteObject.extend({
   },
 
   crumbs: function () {
-    const previousPage = Helpers.getPreviousPageForDoc(this.database, this.wasCloned);
+    const previousPage = Helpers.getPreviousPageForDoc(this.database);
     const docUrl = FauxtonAPI.urls('document', 'app', this.database.safeID(), this.docId);
 
     return [
@@ -83,10 +83,6 @@ const DocEditorRouteObject = FauxtonAPI.RouteObject.extend({
     'database/:database/new': 'codeEditor'
   },
 
-  events: {
-    'route:duplicateDoc': 'duplicateDoc'
-  },
-
   crumbs: function () {
 
     if (this.docId) {
@@ -124,31 +120,6 @@ const DocEditorRouteObject = FauxtonAPI.RouteObject.extend({
     this.codeEditor(database, '_design/' + ddoc);
   },
 
-  duplicateDoc: function (newId) {
-    var doc = this.doc,
-        database = this.database;
-
-    this.docID = newId;
-
-    var that = this;
-    doc.copy(newId).then(function () {
-      doc.set({ _id: newId });
-      that.wasCloned = true;
-
-      FauxtonAPI.navigate('/database/' + database.safeID() + '/' + app.utils.safeURLName(newId),
{ trigger: true });
-      FauxtonAPI.addNotification({
-        msg: 'Document has been duplicated.'
-      });
-
-    }, function (error) {
-      var errorMsg = 'Could not duplicate document, reason: ' + error.responseText + '.';
-      FauxtonAPI.addNotification({
-        msg: errorMsg,
-        type: 'error'
-      });
-    });
-  },
-
   apiUrl: function () {
     return [this.doc.url('apiurl'), this.doc.documentation()];
   }

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/50e08c89/app/addons/documents/tests/nightwatch/cloneDoc.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/nightwatch/cloneDoc.js b/app/addons/documents/tests/nightwatch/cloneDoc.js
index 70988db..7932ac4 100644
--- a/app/addons/documents/tests/nightwatch/cloneDoc.js
+++ b/app/addons/documents/tests/nightwatch/cloneDoc.js
@@ -38,7 +38,6 @@ module.exports = {
       .closeNotification()
 
       .waitForAttribute('.faux-header__breadcrumbs .faux-header__breadcrumbs-element:last-child',
'textContent', function (docContents) {
-        console.log(docContents);
         return 'ente' === docContents.trim();
       })
 


Mime
View raw message