You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by benkeen <gi...@git.apache.org> on 2016/02/17 01:30:00 UTC

[GitHub] couchdb-fauxton pull request: Truncate large docs in JSON view

GitHub user benkeen opened a pull request:

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

    Truncate large docs in JSON view

    Currently there's no restriction on the size of documents that
    we attempt to display in JSON view. If the user uses
    include_docs=true it can actually crash people's browsers if the
    documents are too large.
    
    This PR adds in a truncation option to the Document component,
    defaulting to enabled, and 500 lines. It displays a simple
    "truncated" note at the bottom of the result.

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

    $ git pull https://github.com/benkeen/couchdb-fauxton truncate-docs

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

    https://github.com/apache/couchdb-fauxton/pull/649.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 #649
    
----
commit 482d6e487a7e496d4f860bdbbcf6c9c93013b08b
Author: Ben Keen <be...@gmail.com>
Date:   2016-02-17T00:25:22Z

    Truncate large docs in JSON view
    
    Currently there's no restriction on the size of documents that
    we attempt to display in JSON view. If the user uses
    include_docs=true it can actually crash people's browsers if the
    documents are too large.
    
    This PR adds in a truncation option to the Document component,
    defaulting to enabled, and 500 lines. It displays a simple
    "truncated" note at the bottom of the result.

----


---
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: Truncate large docs in JSON view

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

    https://github.com/apache/couchdb-fauxton/pull/649#discussion_r53373212
  
    --- Diff: app/addons/components/react-components.react.jsx ---
    @@ -1046,13 +1055,28 @@ function (app, FauxtonAPI, React, ReactDOM, Stores, Actions,
         },
     
         getDocContent: function () {
    -      if (!_.isEmpty(this.props.docContent)) {
    -        return (
    -          <div className="doc-data">
    -            <pre className="prettyprint">{this.props.docContent}</pre>
    -          </div>
    -        );
    +      if (_.isEmpty(this.props.docContent)) {
    +        return null;
    +      }
    +
    +      // if need be, truncate the document
    +      var content = this.props.docContent;
    +      var isTruncated = false;
    +      if (this.props.truncate) {
    +        var lines = this.props.docContent.split('\n');
    +        if (lines.length > this.props.maxRows) {
    +          isTruncated = true;
    +          lines = lines.slice(0, this.props.maxRows);
    +          content = lines.join('\n');
    +        }
    --- End diff --
    
    Yeah, this feels like the wrong place, hey. Almost feels like a helper function. I'll move it. 


---
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: Truncate large docs in JSON view

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

    https://github.com/apache/couchdb-fauxton/pull/649#issuecomment-187277266
  
    Thanks, Robert! I moved the truncation and added some tests. 


---
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: Truncate large docs in JSON view

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

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


---
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: Truncate large docs in JSON view

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

    https://github.com/apache/couchdb-fauxton/pull/649#discussion_r53340739
  
    --- Diff: app/addons/components/react-components.react.jsx ---
    @@ -1046,13 +1055,28 @@ function (app, FauxtonAPI, React, ReactDOM, Stores, Actions,
         },
     
         getDocContent: function () {
    -      if (!_.isEmpty(this.props.docContent)) {
    -        return (
    -          <div className="doc-data">
    -            <pre className="prettyprint">{this.props.docContent}</pre>
    -          </div>
    -        );
    +      if (_.isEmpty(this.props.docContent)) {
    +        return null;
    +      }
    +
    +      // if need be, truncate the document
    +      var content = this.props.docContent;
    +      var isTruncated = false;
    +      if (this.props.truncate) {
    +        var lines = this.props.docContent.split('\n');
    +        if (lines.length > this.props.maxRows) {
    +          isTruncated = true;
    +          lines = lines.slice(0, this.props.maxRows);
    +          content = lines.join('\n');
    +        }
    --- End diff --
    
    can we move the logic to the store / data model?


---
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: Truncate large docs in JSON view

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

    https://github.com/apache/couchdb-fauxton/pull/649#issuecomment-187687353
  
    +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: Truncate large docs in JSON view

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

    https://github.com/apache/couchdb-fauxton/pull/649#issuecomment-185805218
  
    wow, that is a super cool idea! super 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.
---