<commit_before>import React, { Component } from "react";
import classNames from "classnames";
import * as TYPES from "../middleware/constants";

const helper = require("../middleware/helper");

export default class DataController extends Component {
	constructor(props) {
		super(props);
		this.type = "match";
		this.value = "customValue";
		this.urlParams = helper.URLParams.get(this.props.componentId);
	}

	// Set query information
	componentWillMount() {
		this.setQueryInfo();
		this.checkDefault();
	}

	componentWillUpdate() {
		this.checkDefault();
	}

	checkDefault() {
		this.defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
		if (this.defaultValue && this.defaultSelected != this.defaultValue) {
			this.defaultSelected = this.defaultValue;
			setTimeout(this.setValue.bind(this, this.defaultSelected), 100);
		}
	}

	// set the query type and input data
	setQueryInfo() {
		const valObj = {
			queryType: this.type,
			reactiveId: this.context.reactiveId,
			showFilter: this.props.showFilter,
			filterLabel: this.props.filterLabel ? this.props.filterLabel : this.props.componentId,
			component: "DataController",
			defaultSelected: this.urlParams !== null ? this.urlParams : this.props.defaultSelected
		};
		if (this.props.customQuery) {
			valObj.customQuery = this.props.customQuery;
		}
		const obj = {
			key: this.props.componentId,
			value: valObj
		};
		helper.selectedSensor.setSensorInfo(obj);
	}

	setValue(value) {
		const obj = {
			key: this.props.componentId,
			value
		};

		const execQuery = () => {
			if (this.props.onValueChange) {
				this.props.onValueChange(obj.value);
			}
			// pass the selected sensor value with componentId as key,
			const isExecuteQuery = true;
			helper.URLParams.update(this.props.componentId, value, this.props.URLParams);
			helper.selectedSensor.set(obj, isExecuteQuery);
		};

		if (this.props.beforeValueChange) {
			this.props.beforeValueChange(obj.value)
			.then(() => {
				execQuery();
			})
			.catch((e) => {<commit_msg>Fix DataController showFilter and filterLabel for #188<commit_after>import React, { Component } from "react";
import classNames from "classnames";
import * as TYPES from "../middleware/constants";

const helper = require("../middleware/helper");

export default class DataController extends Component {
	constructor(props) {
		super(props);
		this.type = "match";
		this.value = "customValue";
		this.urlParams = helper.URLParams.get(this.props.componentId);
	}

	// Set query information
	componentWillMount() {
		this.setQueryInfo(this.props);
		this.checkDefault();
	}

	componentWillReceiveProps(nextProps) {
		if (this.props.showFilter !== nextProps.showFilter || this.props.filterLabel !== nextProps.filterLabel) {
			this.setQueryInfo(nextProps);
			this.setValue(this.defaultSelected);
		}
	}

	componentWillUpdate() {
		this.checkDefault();
	}

	checkDefault() {
		this.defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
		if (this.defaultValue && this.defaultSelected != this.defaultValue) {
			this.defaultSelected = this.defaultValue;
			setTimeout(this.setValue.bind(this, this.defaultSelected), 100);
		}
	}

	// set the query type and input data
	setQueryInfo(props) {
		const valObj = {
			queryType: this.type,
			reactiveId: this.context.reactiveId,
			showFilter: props.showFilter,
			filterLabel: props.filterLabel ? props.filterLabel : props.componentId,
			component: "DataController",
			defaultSelected: this.urlParams !== null ? this.urlParams : props.defaultSelected
		};
		if (props.customQuery) {
			valObj.customQuery = props.customQuery;
		}
		const obj = {
			key: props.componentId,
			value: valObj
		};
		helper.selectedSensor.setSensorInfo(obj);
	}

	setValue(value) {
		const obj = {
			key: this.props.componentId,
			value
		};

		const execQuery = () => {
			if (this.props.onValueChange) {
				this.props.onValueChange(obj.value);
			}
			// pass the selected sensor value with componentId as key,
			const isExecuteQuery = true;
			helper.URLParams.update(this.props.componentId, value, this.props.URLParams);
			helper.selectedSensor.set(obj, isExecuteQuery);
		};

		if (this.props.beforeValueChange) {
			this.props.beforeValueChange(obj.value)
			.then(() => {
				execQuery();
			})
			.catch((e) => {
{'fraction_non_alphanumeric': 0.1317434591340588, 'fraction_numerical': 0.002083815698078259, 'mean_word_length': 4.005793742757821, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4506094', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1349, 'n_words': 266}