<commit_before>var React = require('react'),
    SubscriptionItem = require('./SubscriptionItem.js.jsx'),
    _ = require('lodash'),
    mui = require('material-ui'),
    RaisedButton = mui.RaisedButton;

var SubscriptionList = React.createClass({
  getInitialState: function () {
    return {
      dirtySubscriptionsForm: false,
      subscriptions: [],
      masterSubscriptions: []
    };
  },

  componentWillReceiveProps: function (nextProps) {
    var self = this;
    this.getSubscriptionsForPlaylist(nextProps.playlistItem).then(function (response) {
      self.setState({
        masterSubscriptions: response,
        subscriptions: _.cloneDeep(response)
      })
    });
  },

  getSubscriptionsForPlaylist: function (playlistItem) {
    var playlistId = playlistItem.id,
        api = new prBumpsApi();

    return api.getSubscriptions(playlistId);
  },

  onChangeHandler: function (playlistId, subscribed) {
    // update subscriptions.subscribed value for correct playlist
    var newSubscriptions = this.state.subscriptions;
    var masterSubscriptions = this.state.masterSubscriptions;
    var playlist = _.find(newSubscriptions, {id: playlistId});

    // set value on playlistItem
    playlist.subscribed = subscribed;
    // check if value we are setting is different from original form
    var isFormDirty = this.isSubscriptionFormDirty(masterSubscriptions, newSubscriptions);
    // update state
    this.setState({
      subscriptions: newSubscriptions,
      dirtySubscriptionsForm: isFormDirty
    });
  },

  isSubscriptionFormDirty: function (oldList, newList) {
    return !_.isEqual(oldList, newList);
  },

  render: function() {
    var self = this;
    var subscriptionItems = this.state.subscriptions.map(function (subscription) {
      return (
        <SubscriptionItem onChangeHandler={self.onChangeHandler} name={subscription.name} programId={subscription.id} key={subscription.id} subscribed={subscription.subscribed} />
      )
    });

    return (
      <div className="subscription-index">
        <h3>{this.props.playlistItem.name}</h3>
        <form>
          <input type="hidden" id="playlistId" name="playlistId" value={this.props.playlistItem.id}/>
          {subscriptionItems}
        </form>
        <div className="primary-action-button">
          <RaisedButton label="Update Subscription" secondary={true}/>
        </div>
        <RaisedButton label="Discard Changes" />
      </div>
    );
  }

});

module.exports = SubscriptionList;<commit_msg>Allow clearing of subscription form<commit_after>var React = require('react'),
    SubscriptionItem = require('./SubscriptionItem.js.jsx'),
    _ = require('lodash'),
    mui = require('material-ui'),
    RaisedButton = mui.RaisedButton;

var SubscriptionList = React.createClass({
  getInitialState: function () {
    return {
      dirtySubscriptionsForm: false,
      subscriptions: [],
      masterSubscriptions: []
    };
  },

  componentWillReceiveProps: function (nextProps) {
    var self = this;
    this.getSubscriptionsForPlaylist(nextProps.playlistItem).then(function (response) {
      self.setState({
        masterSubscriptions: response,
        subscriptions: _.cloneDeep(response)
      })
    });
  },

  getSubscriptionsForPlaylist: function (playlistItem) {
    var playlistId = playlistItem.id,
        api = new prBumpsApi();

    return api.getSubscriptions(playlistId);
  },

  onChangeHandler: function (playlistId, subscribed) {
    // update subscriptions.subscribed value for correct playlist
    var newSubscriptions = this.state.subscriptions;
    var masterSubscriptions = this.state.masterSubscriptions;
    var playlist = _.find(newSubscriptions, {id: playlistId});

    // set value on playlistItem
    playlist.subscribed = subscribed;
    // check if value we are setting is different from original form
    var isFormDirty = this.isSubscriptionFormDirty(masterSubscriptions, newSubscriptions);
    // update state
    this.setState({
      subscriptions: newSubscriptions,
      dirtySubscriptionsForm: isFormDirty
    });
  },

  cleanForm: function () {
    var master = this.state.masterSubscriptions;
    this.setState({
      subscriptions: _.cloneDeep(master)
    });
  },

  isSubscriptionFormDirty: function (oldList, newList) {
    return !_.isEqual(oldList, newList);
  },

  render: function() {
    var self = this;
    var subscriptionItems = this.state.subscriptions.map(function (subscription) {
      return (
        <SubscriptionItem onChangeHandler={self.onChangeHandler} name={subscription.name} programId={subscription.id} key={subscription.id} subscribed={subscription.subscribed} />
      )
    });

    return (
      <div className="subscription-index">
        <h3>{this.props.playlistItem.name}</h3>
        <form>
          <input type="hidden" id="playlistId" name="playlistId" value={this.props.playlistItem.id}/>
          {subscriptionItems}
        </form>
        <div className="primary-action-button">
          <RaisedButton label="Update Subscription" secondary={true}/>
        </div>
        <RaisedButton
          label="Discard Changes"
          onMouseDown={this.cleanForm}
          disabled={!this.state.dirtySubscriptionsForm}>
        </RaisedButton>
      </div>
    );
  }

});

module.exports = SubscriptionList;
{'fraction_non_alphanumeric': 0.11534112325669053, 'fraction_numerical': 0.0007538635506973238, 'mean_word_length': 3.30064829821718, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3868786', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1505, 'n_words': 296}