You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by benkeen <gi...@git.apache.org> on 2015/06/11 00:24:27 UTC

[GitHub] couchdb-fauxton pull request: Refactoring

GitHub user benkeen opened a pull request:

    https://github.com/apache/couchdb-fauxton/pull/459

    Refactoring <CodeEditor />

    This PR refactors the `<CodeEditor />` component to make it
    more generic. The existing React Ace editor instances now 
    use this via wrapper components (`<CodeEditorPanel />` and 
    `<ZenModeOverlay />`). The goal is to make this the one any 
    only place where the ace editor is actually instantiated. It'll 
    also be needed for the next step: refactoring the full page 
    doc editor.
    
    Other change:
    - the small editors on the Mango + add/edit index pages now
    dynamically resize up to 10 lines according to the content
    that's been entered.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/benkeen/couchdb-fauxton code-editor-component-refactor

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-fauxton/pull/459.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #459
    
----
commit 868638dbc47540595f11abcde4307a51b0a1aa3e
Author: Ben Keen <be...@gmail.com>
Date:   2015-06-10T18:41:06Z

    Refactoring <CodeEditor />
    
    This PR refactors the <CodeEditor /> component to make it
    more generic. Ace editor instances such as the mango, index
    editor, and Zen mode now use this via wrapper components
    (<CodeEditorPanel /> and <ZenModeOverlay />). The goal is
    to make this the one any only place where the ace editor
    is instantiated. It'll also be needed for the next step:
    refactoring the full page doc editor.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-fauxton pull request: Refactoring

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:

    https://github.com/apache/couchdb-fauxton/pull/459#issuecomment-112002992
  
    +1 this looks cool.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-fauxton pull request: Refactoring

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/couchdb-fauxton/pull/459


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-fauxton pull request: Refactoring

Posted by michellephung <gi...@git.apache.org>.
Github user michellephung commented on the pull request:

    https://github.com/apache/couchdb-fauxton/pull/459#issuecomment-112023342
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-fauxton pull request: Refactoring

Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/459#discussion_r32405708
  
    --- Diff: app/addons/components/react-components.react.jsx ---
    @@ -220,56 +332,49 @@ function (app, FauxtonAPI, React, Components, ace, beautifyHelper) {
         },
     
         componentWillReceiveProps: function (nextProps) {
    -      var codeChanged = !_.isEqual(nextProps.code, this.getValue());
    +      var codeChanged = !_.isEqual(nextProps.defaultCode, this.getValue());
           this.setupAce(nextProps, codeChanged);
         },
     
    -    editSaved: function () {
    -      return this.hasChanged();
    -    },
    -
    -    zenModeIcon: function () {
    -      if (this.props.allowZenMode) {
    -        return <span className="fonticon fonticon-resize-full zen-editor-icon" title="Enter Zen mode" onClick={this.enterZenMode}></span>;
    -      }
    +    getAnnotations: function () {
    +      return this.editor.getSession().getAnnotations();
         },
     
    -    enterZenMode: function () {
    -      this.setState({ zenModeEnabled: true });
    +    isIgnorableError: function (msg) {
    +      return _.contains(this.props.ignorableErrors, msg);
         },
     
    -    getTitleFragment: function () {
    -      if (!this.props.docs) {
    -        return (<strong>{this.props.title}</strong>);
    -      }
    -
    -      return (
    -        <label>
    -          <strong>{this.props.title + ' '}</strong>
    -          <a
    -            className="help-link"
    -            data-bypass="true"
    -            href={this.props.docs}
    -            target="_blank"
    -          >
    -          <i className="icon-question-sign"></i>
    -          </a>
    -          {this.zenModeIcon()}
    -        </label>
    -      );
    -    },
    +    removeIgnorableAnnotations: function () {
    +      var isIgnorableError = this.isIgnorableError;
    +      this.editor.getSession().on('changeAnnotation', function () {
    +        var annotations = this.editor.getSession().getAnnotations();
    +        var newAnnotations = _.reduce(annotations, function (annotations, error) {
    +          if (!isIgnorableError(error.raw)) {
    +            annotations.push(error);
    +          }
    +          return annotations;
    +        }, []);
     
    -    getAnnotations: function () {
    -      return this.editor.getSession().getAnnotations();
    +        if (annotations.length !== newAnnotations.length) {
    +          this.editor.getSession().setAnnotations(newAnnotations);
    +        }
    +      }.bind(this));
         },
     
    +    // ------------------
    +    // TODO two things to do after full page doc editor refactor:
    +    // 1. rename to hasErrors()
         hadValidCode: function () {
           var errors = this.getAnnotations();
    -      // By default CouchDB view functions don't pass lint
           return _.every(errors, function (error) {
             return this.isIgnorableError(error.raw);
           }, this);
         },
    +    // 2. This doesn't make sense. Could just call hasChanged() directly. Replace with clearChanges()
    +    editSaved: function () {
    --- End diff --
    
    This could be replaced with hasChanged(). I cannot remember why I kept this in. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---