<commit_before>var React = require('react/addons')
var _ = require('lodash')
var uuid = require('node-uuid')
var trays = require('../../controllers/trays')
var security = require('../../controllers/security')
var trackingRepository = require('../../storage/trackingRepository')
var AddTray = require('./addTray').AddTray
var Tray = require('./trayContainer').TrayContainer

module.exports = {
    TrackingSection: React.createClass({
        getInitialState: function () {
            return {trays: trackingRepository.getTrays()}
        },

        render: function () {
            return (
                <section className='dashboard-main-section active'>
                    <h2 className='visuallyhidden'>Tracking</h2>

                    <fieldset className='tracking-cctray-group'>
                        <AddTray addTray={this.addTray}/>

                        <div>
                            {
                                _.map(this.state.trays, function (trayId) {
                                    return <Tray key={trayId} trayId={trayId} removeTray={this.removeTray}/>
                                }, this)
                            }
                        </div>
                    </fieldset>
                </section>
            )
        },

        componentWillMount: function () {
            this.setState({trays: trackingRepository.getTrays()})
        },

        addTray: function (addTray) {
            var trayId = uuid.v4()

            if (trays.requiresAuth(addTray)) {
                security.encryptPassword(addTray.password, function (data) {
                    trackingRepository.saveTray(trayId, {
                        url: addTray.url,
                        username: addTray.username,
                        password: <PASSWORD>
                    })

                    var newTrays = React.addons.update(this.state.trays, {$set: [trayId]})
                    this.setState({trays: newTrays})
                }.bind(this))
            } else {
                trackingRepository.saveTray(trayId, {
                    url: addTray.url
                })
                var newTrays = React.addons.update(this.state.trays, {$push: [trayId]})
                this.setState({trays: newTrays})
            }
        },

        removeTray: function (trayId) {
            var updatedTrays = React.addons.update(this.state.trays, {$splice: [[this.state.trays.indexOf(trayId), 1]]})
            this.setState({trays: updatedTrays})
        },

        componentWillUpdate: function (nextProps, nextState) {
            if (this.state.trays !== nextState.trays) {
                trackingRepository.saveTrays(nextState.trays)
                _.forEach(_.difference(this.state.trays, nextState.trays), function (id) {
                    trackingRepository.removeTray(id)
                })
            }
        }
    })
}<commit_msg>Chris - fixes a bug were adding a tray with auth would remove all other trays<commit_after>var React = require('react/addons')
var _ = require('lodash')
var uuid = require('node-uuid')
var trays = require('../../controllers/trays')
var security = require('../../controllers/security')
var trackingRepository = require('../../storage/trackingRepository')
var AddTray = require('./addTray').AddTray
var Tray = require('./trayContainer').TrayContainer

module.exports = {
    TrackingSection: React.createClass({
        getInitialState: function () {
            return {trays: trackingRepository.getTrays()}
        },

        render: function () {
            return (
                <section className='dashboard-main-section active'>
                    <h2 className='visuallyhidden'>Tracking</h2>

                    <fieldset className='tracking-cctray-group'>
                        <AddTray addTray={this.addTray}/>

                        <div>
                            {
                                _.map(this.state.trays, function (trayId) {
                                    return <Tray key={trayId} trayId={trayId} removeTray={this.removeTray}/>
                                }, this)
                            }
                        </div>
                    </fieldset>
                </section>
            )
        },

        addTray: function (trayToAdd) {
            if (trays.requiresAuth(trayToAdd)) {
                security.encryptPassword(trayToAdd.password, function (data) {
                    this.saveTrays(_.extend({}, trayToAdd, {password: data.password}))
                }.bind(this))
            } else {
                this.saveTrays(trayToAdd)
            }
        },

        removeTray: function (trayId) {
            var trayIndex = this.state.trays.indexOf(trayId)
            var updatedTrays = React.addons.update(this.state.trays, {$splice: [[trayIndex, 1]]})
            this.setState({trays: updatedTrays})
        },

        componentWillUpdate: function (nextProps, nextState) {
            if (this.state.trays !== nextState.trays) {
                trackingRepository.saveTrays(nextState.trays)
                _.forEach(_.difference(this.state.trays, nextState.trays), function (id) {
                    trackingRepository.removeTray(id)
                })
            }
        },

        saveTrays: function (newTray) {
            var trayId = uuid.v4()

            trackingRepository.saveTray(trayId, {
                url: newTray.url,
                username: newTray.username,
                password: <PASSWORD>
            })

            var newTrays = React.addons.update(this.state.trays, {$push: [trayId]})
            this.setState({trays: newTrays})
        }
    })
}
{'fraction_non_alphanumeric': 0.11990830541350732, 'fraction_numerical': 0.0014106859460412625, 'mean_word_length': 1.520888888888889, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7475090', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1488, 'n_words': 253}