<commit_before>import React from 'react';
import { DropdownButton, MenuItem, Tab, Tabs } from 'react-bootstrap';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as Actions from '../actions';
import SqlEditor from './SqlEditor';
import CopyQueryTabUrl from './CopyQueryTabUrl';
import { areArraysShallowEqual } from '../../reduxUtils';
import { getParamFromQuery } from '../../../utils/common';

const propTypes = {
  actions: React.PropTypes.object.isRequired,
  databases: React.PropTypes.object.isRequired,
  queries: React.PropTypes.object.isRequired,
  queryEditors: React.PropTypes.array,
  tabHistory: React.PropTypes.array.isRequired,
  tables: React.PropTypes.array.isRequired,
  networkOn: React.PropTypes.bool,
  editorHeight: React.PropTypes.string.isRequired,
};
const defaultProps = {
  queryEditors: [],
  networkOn: true,
};

let queryCount = 1;

class TabbedSqlEditors extends React.PureComponent {
  constructor(props) {
    super(props);
    const sqlLabUrl = '/superset/sqllab';
    this.state = {
      sqlLabUrl,
      queriesArray: [],
      dataPreviewQueries: [],
      hideLeftBar: false,
    };
  }
  componentDidMount() {
    const search = window.location.search;
    if (search) {
      const queryString = search.substring(1);
      const urlId = getParamFromQuery(queryString, 'id');
      if (urlId) {
        this.props.actions.popStoredQuery(urlId);
      } else {
        const newQueryEditor = {
          title: getParamFromQuery(queryString, 'title'),
          dbId: getParamFromQuery(queryString, 'dbid'),
          schema: getParamFromQuery(queryString, 'schema'),
          autorun: getParamFromQuery(queryString, 'autorun'),
          sql: getParamFromQuery(queryString, 'sql'),
        };
        this.props.actions.addQueryEditor(newQueryEditor);<commit_msg>  **Allow user to put dbname in url (#2209)<commit_after>import React from 'react';
import { DropdownButton, MenuItem, Tab, Tabs } from 'react-bootstrap';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as Actions from '../actions';
import SqlEditor from './SqlEditor';
import CopyQueryTabUrl from './CopyQueryTabUrl';
import { areArraysShallowEqual } from '../../reduxUtils';
import { getParamFromQuery } from '../../../utils/common';

const propTypes = {
  actions: React.PropTypes.object.isRequired,
  databases: React.PropTypes.object.isRequired,
  queries: React.PropTypes.object.isRequired,
  queryEditors: React.PropTypes.array,
  tabHistory: React.PropTypes.array.isRequired,
  tables: React.PropTypes.array.isRequired,
  networkOn: React.PropTypes.bool,
  editorHeight: React.PropTypes.string.isRequired,
};
const defaultProps = {
  queryEditors: [],
  networkOn: true,
};

let queryCount = 1;

class TabbedSqlEditors extends React.PureComponent {
  constructor(props) {
    super(props);
    const sqlLabUrl = '/superset/sqllab';
    this.state = {
      sqlLabUrl,
      queriesArray: [],
      dataPreviewQueries: [],
      hideLeftBar: false,
    };
  }
  componentDidMount() {
    const search = window.location.search;
    if (search) {
      const queryString = search.substring(1);
      const urlId = getParamFromQuery(queryString, 'id');
      if (urlId) {
        this.props.actions.popStoredQuery(urlId);
      } else {
        let dbId = getParamFromQuery(queryString, 'dbid');
        if (dbId) {
          dbId = parseInt(dbId, 10);
        } else {
          const databases = this.props.databases;
          const dbName = getParamFromQuery(queryString, 'dbname');
          if (dbName) {
            Object.keys(databases).forEach((db) => {
              if (databases[db].database_name === dbName) {
                dbId = databases[db].id;
              }
            });
          }
        }
        const newQueryEditor = {
          title: getParamFromQuery(queryString, 'title'),
          dbId,
          schema: getParamFromQuery(queryString, 'schema'),
          autorun: getParamFromQuery(queryString, 'autorun'),
          sql: getParamFromQuery(queryString, 'sql'),
        };
        this.props.actions.addQueryEditor(newQueryEditor);
{'fraction_non_alphanumeric': 0.1257801248199712, 'fraction_numerical': 0.002400384061449832, 'mean_word_length': 3.167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '7660490', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1243, 'n_words': 262}