<commit_before>/*global module: false, require: false, URL: false, Blob: false */
'use strict';

var React = require('react');
var Rx = require('rx');
require('rx/dist/rx.time');
var {Table, Pagination, DataMixin} = require('react-data-components-bd2k');
var {Button, Row, Col, Panel} = require('react-bootstrap');
var VariantSearch = require('./VariantSearch');
var SelectField = require('./SelectField');
var ColumnCheckbox = require('./ColumnCheckbox');
var _ = require('underscore');
var cx = require('classnames');
var hgvs = require('./hgvs');
var PureRenderMixin = require('./PureRenderMixin'); // deep-equals version of PRM

var filterDisplay = v => v == null ? 'Any' : v;
var filterAny = v => v === 'Any' ? null : v;
var addAny = opts => ['Any', ...opts];

var pluralize = (n, s) => n === 1 ? s : s + 's';

var merge = (...args) => _.extend({}, ...args);


function setPages({data, count}, pageLength) {
	return {
		data,
		count,
		totalPages: Math.ceil(count / pageLength)
	};
}

// Wrap Table with a version having PureRenderMixin
var FastTable = React.createClass({
	mixins: [PureRenderMixin],
	render: function () {
		return <Table {...this.props}/>;
	}
});

// Merge new state (e.g. initialState) with existing state,
// deep-merging columnSelect.
function mergeState(state, newState) {
	var {columnSelection, ...otherProps} = newState,
		cs = {...state.columnSelection, ...columnSelection};
	return {...state, columnSelection: cs, ...otherProps};
}

var DataTable = React.createClass({
	mixins: [PureRenderMixin],
	componentWillMount: function () {
		var q = this.fetchq = new Rx.Subject();
		this.subs = q.map(this.props.fetch).debounce(100).switchLatest().subscribe(
			resp => this.setState(setPages(resp, this.state.pageLength)), // set data, count, totalPages
			() => this.setState({error: 'Problem connecting to server'}));
	},
	componentWillUnmount: function () {
		this.subs.dispose();
	},
	componentDidMount: function () {
		this.fetch(this.state);
	},
	getInitialState: function () {
        var defaultColumns = ['Gene_symbol', 'Genomic_Coordinate', 'HGVS_cDNA', 'HGVS_protein', 'Abbrev_AA_change', 'BIC_Nomenclature', 'Clinical_significance'];
        //_.map(this.props.columns, c=> (_.contains(defaultColumns, c.prop) ? console.log(c.prop) : console.log('False')));
		return mergeState({
			data: [],
			filtersOpen: false,
			filterValues: {},
			search: '',
			columnSelection: _.object(_.map(this.props.columns, c => _.contains(defaultColumns, c.prop) ? [c.prop, true] : [c.prop, false])),
			pageLength: 20,
			page: 0,
			totalPages: 20 // XXX this is imaginary. Do we need it?
		}, this.props.initialState);
	},
	componentWillReceiveProps: function(newProps) {
		var newState = mergeState(this.state, newProps.initialState);
		this.setState(newState);
		this.fetch(newState);
	},
	setFilters: function (obj) {
		var {filterValues} = this.state,
			newFilterValues = merge(filterValues, obj);
<commit_msg>Update DataTable.js<commit_after>/*global module: false, require: false, URL: false, Blob: false */
'use strict';

var React = require('react');
var Rx = require('rx');
require('rx/dist/rx.time');
var {Table, Pagination, DataMixin} = require('react-data-components-bd2k');
var {Button, Row, Col, Panel} = require('react-bootstrap');
var VariantSearch = require('./VariantSearch');
var SelectField = require('./SelectField');
var ColumnCheckbox = require('./ColumnCheckbox');
var _ = require('underscore');
var cx = require('classnames');
var hgvs = require('./hgvs');
var PureRenderMixin = require('./PureRenderMixin'); // deep-equals version of PRM

var filterDisplay = v => v == null ? 'Any' : v;
var filterAny = v => v === 'Any' ? null : v;
var addAny = opts => ['Any', ...opts];

var pluralize = (n, s) => n === 1 ? s : s + 's';

var merge = (...args) => _.extend({}, ...args);


function setPages({data, count}, pageLength) {
	return {
		data,
		count,
		totalPages: Math.ceil(count / pageLength)
	};
}

// Wrap Table with a version having PureRenderMixin
var FastTable = React.createClass({
	mixins: [PureRenderMixin],
	render: function () {
		return <Table {...this.props}/>;
	}
});

// Merge new state (e.g. initialState) with existing state,
// deep-merging columnSelect.
function mergeState(state, newState) {
	var {columnSelection, ...otherProps} = newState,
		cs = {...state.columnSelection, ...columnSelection};
	return {...state, columnSelection: cs, ...otherProps};
}

var DataTable = React.createClass({
	mixins: [PureRenderMixin],
	componentWillMount: function () {
		var q = this.fetchq = new Rx.Subject();
		this.subs = q.map(this.props.fetch).debounce(100).switchLatest().subscribe(
			resp => this.setState(setPages(resp, this.state.pageLength)), // set data, count, totalPages
			() => this.setState({error: 'Problem connecting to server'}));
	},
	componentWillUnmount: function () {
		this.subs.dispose();
	},
	componentDidMount: function () {
		this.fetch(this.state);
	},
	getInitialState: function () {
		var defaultColumns = ['Gene_symbol', 'Genomic_Coordinate', 'HGVS_cDNA', 'HGVS_protein', 'Abbrev_AA_change', 'BIC_Nomenclature', 'Clinical_significance'];
		return mergeState({
			data: [],
			filtersOpen: false,
			filterValues: {},
			search: '',
			columnSelection: _.object(_.map(this.props.columns, c => _.contains(defaultColumns, c.prop) ? [c.prop, true] : [c.prop, false])),
			pageLength: 20,
			page: 0,
			totalPages: 20 // XXX this is imaginary. Do we need it?
		}, this.props.initialState);
	},
	componentWillReceiveProps: function(newProps) {
		var newState = mergeState(this.state, newProps.initialState);
		this.setState(newState);
		this.fetch(newState);
	},
	setFilters: function (obj) {
		var {filterValues} = this.state,
			newFilterValues = merge(filterValues, obj);

{'fraction_non_alphanumeric': 0.17471344216741924, 'fraction_numerical': 0.0034734282737061478, 'mean_word_length': 4.4381491973559966, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '57947', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1866, 'n_words': 465}