Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/741#discussion_r69898965
  
    --- Diff: app/addons/documents/doc-editor/components.react.jsx ---
    @@ -218,44 +218,137 @@ var AttachmentsPanelButton = React.createClass({
         };
       },
     
    +  getInitialState: function () {
    +    return {
    +      filter: '',
    +      maxHeight: 'none'
    +    };
    +  },
    +
    +  componentDidMount: function () {
    +    $(window).on('resize.attachment-filter', this.updateMaxHeight);
    +    Stores.attachmentFilterStore.on('change', this.onChange);
    +  },
    +
    +  componentWillUnmount: function () {
    +    $(window).off('resize.attachment-filter', this.updateMaxHeight);
    +    Stores.attachmentFilterStore.off('change', this.onChange);
    +  },
    +
    +  onChange: function () {
    +    this.setState({
    +      maxHeight: this.state.maxHeight,
    +      filter: Stores.attachmentFilterStore.filter()
    +    });
    +  },
    +
    +  getMaxHeight: function () {
    +    var $btn = $(this._button);
    +    return $(document).height() - $btn.offset().top - $btn.outerHeight();
    +  },
    +
    +  updateMaxHeight: function (button) {
    +    if (!this._button && button) {
    +      this._button = button;
    +    }
    +
    +    this.setState({
    +      maxHeight: this.getMaxHeight(),
    +      filter: this.state.filter
    +    });
    +  },
    +
       getAttachmentList: function () {
         var db = this.props.doc.database.get('id');
         var doc = this.props.doc.get('_id');
    +    var attachments = this.props.doc.get('_attachments');
     
    -    return _.map(this.props.doc.get('_attachments'), function (item, 
filename) {
    +    function create(item, filename) {
           var url = FauxtonAPI.urls('document', 'attachment', db, doc, 
app.utils.safeURLName(filename));
           return (
    -        <li key={filename}>
    -          <a href={url} target="_blank" data-bypass="true"> 
<strong>{filename}</strong>
    -            <span className="attachment-delimiter">-</span>
    -            <span>{item.content_type}, 
{Helpers.formatSize(item.length)}</span>
    -          </a>
    -        </li>
    +          <li key={filename} className="attachment-row">
    +            <a href={url} target="_blank" data-bypass="true"> 
<strong>{filename}</strong>
    +              <span className="attachment-delimiter">-</span>
    +              <span>{item.content_type}, 
{Helpers.formatSize(item.length)}</span>
    +            </a>
    +          </li>
           );
    -    });
    +    }
    +
    +    function filter(predicate) {
    --- End diff --
    
    I think it would be better to do the filtering in the store. Here is a nice 
[example](https://github.com/apache/couchdb-fauxton/blob/master/app/addons/documents/changes/components.react.jsx#L117)
 of how we have done it before.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to