<commit_before>import React, {PropTypes} from 'react'

import {showDatabases, showRetentionPolicies} from 'shared/apis/metaQuery'
import showDatabasesParser from 'shared/parsing/showDatabases'
import showRetentionPoliciesParser from 'shared/parsing/showRetentionPolicies'
import Dropdown from 'shared/components/Dropdown'

const {func, shape, string} = PropTypes

const DatabaseList = React.createClass({
  propTypes: {
    query: shape({}).isRequired,
    onChooseNamespace: func.isRequired,
  },

  contextTypes: {
    source: shape({
      links: shape({
        proxy: string.isRequired,
      }).isRequired,
    }).isRequired,
  },

  getInitialState() {
    return {
      namespaces: [],
    }
  },

  componentDidMount() {
    const {source} = this.context
    const proxy = source.links.proxy
    showDatabases(proxy).then(resp => {
      const {errors, databases} = showDatabasesParser(resp.data)
      if (errors.length) {
        // do something
      }

      const namespaces = []
      showRetentionPolicies(proxy, databases).then(res => {
        res.data.results.forEach((result, index) => {
          const {errors: errs, retentionPolicies} = showRetentionPoliciesParser(
            result
          )
          if (errs.length) {
            // do something
          }

          retentionPolicies.forEach(rp => {
            namespaces.push({
              database: databases[index],
              retentionPolicy: rp.name,
            })
          })
        })

        this.setState({namespaces})
      })
    })
  },

  render() {
    const {query, onChooseNamespace} = this.props
    const {namespaces} = this.state

    return (
      <div className="query-builder--column">
        <div className="query-builder--heading">Databases</div>
        <div className="query-builder--list">
          {this.state.namespaces.map(namespace => {
            const {database, retentionPolicy} = namespace
            const isActive =
              database === query.database &&
              retentionPolicy === query.retentionPolicy

            return (
              <div
                className={classNames('query-builder--list-item', {
                  active: isActive,
                })}
                key={`${database}..${retentionPolicy}`}
                onClick={_.wrap(namespace, onChooseNamespace)}
              >
                {database}.{retentionPolicy}
              </div>
            )
          })}
        </div>
      </div><commit_msg>Fix errors in database list<commit_after>import React, {PropTypes} from 'react'
import classNames from 'classnames'
import _ from 'lodash'

import {showDatabases, showRetentionPolicies} from 'shared/apis/metaQuery'
import showDatabasesParser from 'shared/parsing/showDatabases'
import showRetentionPoliciesParser from 'shared/parsing/showRetentionPolicies'

const {func, shape, string} = PropTypes

const DatabaseList = React.createClass({
  propTypes: {
    query: shape({}).isRequired,
    onChooseNamespace: func.isRequired,
  },

  contextTypes: {
    source: shape({
      links: shape({
        proxy: string.isRequired,
      }).isRequired,
    }).isRequired,
  },

  getInitialState() {
    return {
      namespaces: [],
    }
  },

  componentDidMount() {
    const {source} = this.context
    const proxy = source.links.proxy
    showDatabases(proxy).then(resp => {
      const {errors, databases} = showDatabasesParser(resp.data)
      if (errors.length) {
        // do something
      }

      const namespaces = []
      showRetentionPolicies(proxy, databases).then(res => {
        res.data.results.forEach((result, index) => {
          const {errors: errs, retentionPolicies} = showRetentionPoliciesParser(
            result
          )
          if (errs.length) {
            // do something
          }

          retentionPolicies.forEach(rp => {
            namespaces.push({
              database: databases[index],
              retentionPolicy: rp.name,
            })
          })
        })

        this.setState({namespaces})
      })
    })
  },

  render() {
    const {query, onChooseNamespace} = this.props

    return (
      <div className="query-builder--column">
        <div className="query-builder--heading">Databases</div>
        <div className="query-builder--list">
          {this.state.namespaces.map(namespace => {
            const {database, retentionPolicy} = namespace
            const isActive =
              database === query.database &&
              retentionPolicy === query.retentionPolicy

            return (
              <div
                className={classNames('query-builder--list-item', {
                  active: isActive,
                })}
                key={`${database}..${retentionPolicy}`}
                onClick={_.wrap(namespace, onChooseNamespace)}
              >
                {database}.{retentionPolicy}
              </div>
            )
          })}
        </div>
      </div>
{'fraction_non_alphanumeric': 0.12013706913928643, 'fraction_numerical': 0.0, 'mean_word_length': 2.0145808019441067, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, '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': '3218623', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1334, 'n_words': 251}