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

import Authorized, {EDITOR_ROLE} from 'src/auth/Authorized'

import DashboardsTable from 'src/dashboards/components/DashboardsTable'
import SearchBar from 'src/hosts/components/SearchBar'
import FancyScrollbar from 'shared/components/FancyScrollbar'

class DashboardsPageContents extends Component {
  constructor(props) {
    super(props)

    this.state = {
      searchTerm: '',
    }
  }

  filterDashboards = searchTerm => {
    this.setState({searchTerm})
  }

  render() {
    const {
      dashboards,
      onDeleteDashboard,
      onCreateDashboard,
      dashboardLink,
    } = this.props

    let tableHeader
    if (dashboards === null) {
      tableHeader = 'Loading Dashboards...'
    } else if (dashboards.length === 1) {
      tableHeader = '1 Dashboard'
    } else {
      tableHeader = `${dashboards.length} Dashboards`
    }
    const filteredDashboards = dashboards.filter(d =>
      d.name.includes(this.state.searchTerm)
    )

    return (
      <FancyScrollbar className="page-contents">
        <div className="container-fluid">
          <div className="row">
            <div className="col-md-12">
              <div className="panel panel-minimal">
                <div className="panel-heading u-flex u-ai-center u-jc-space-between">
                  <h2 className="panel-title">
                    {tableHeader}
                  </h2>
                  <div className="u-flex u-ai-center dashboards-page--actions">
                    <SearchBar
                      placeholder="Filter by Name..."
                      onSearch={this.filterDashboards}
                    />
                    <Authorized requiredRole={EDITOR_ROLE}>
                      <button
                        className="btn btn-sm btn-primary"
                        onClick={onCreateDashboard}
                      >
                        <span className="icon plus" /> Create Dashboard
                      </button>
                    </Authorized>
                  </div>
                </div>
                <div className="panel-body">
                  <DashboardsTable
                    dashboards={filteredDashboards}
                    onDeleteDashboard={onDeleteDashboard}
                    onCreateDashboard={onCreateDashboard}
                    dashboardLink={dashboardLink}
                  />
                </div>
              </div>
            </div>
          </div>
        </div>
      </FancyScrollbar>
    )
  }
}

const {arrayOf, func, shape, string} = PropTypes

DashboardsPageContents.propTypes = {
  dashboards: arrayOf(shape()),
  onDeleteDashboard: func.isRequired,
  onCreateDashboard: func.isRequired,
  dashboardLink: string.isRequired,
}

export default DashboardsPageContents
<commit_msg>Make dashboards filter work for lowercase search terms<commit_after>import React, {PropTypes, Component} from 'react'

import Authorized, {EDITOR_ROLE} from 'src/auth/Authorized'

import DashboardsTable from 'src/dashboards/components/DashboardsTable'
import SearchBar from 'src/hosts/components/SearchBar'
import FancyScrollbar from 'shared/components/FancyScrollbar'

class DashboardsPageContents extends Component {
  constructor(props) {
    super(props)

    this.state = {
      searchTerm: '',
    }
  }

  filterDashboards = searchTerm => {
    this.setState({searchTerm})
  }

  render() {
    const {
      dashboards,
      onDeleteDashboard,
      onCreateDashboard,
      dashboardLink,
    } = this.props
    const {searchTerm} = this.state

    let tableHeader
    if (dashboards === null) {
      tableHeader = 'Loading Dashboards...'
    } else if (dashboards.length === 1) {
      tableHeader = '1 Dashboard'
    } else {
      tableHeader = `${dashboards.length} Dashboards`
    }
    const filteredDashboards = dashboards.filter(d =>
      d.name.toLowerCase().includes(searchTerm.toLowerCase())
    )

    return (
      <FancyScrollbar className="page-contents">
        <div className="container-fluid">
          <div className="row">
            <div className="col-md-12">
              <div className="panel panel-minimal">
                <div className="panel-heading u-flex u-ai-center u-jc-space-between">
                  <h2 className="panel-title">
                    {tableHeader}
                  </h2>
                  <div className="u-flex u-ai-center dashboards-page--actions">
                    <SearchBar
                      placeholder="Filter by Name..."
                      onSearch={this.filterDashboards}
                    />
                    <Authorized requiredRole={EDITOR_ROLE}>
                      <button
                        className="btn btn-sm btn-primary"
                        onClick={onCreateDashboard}
                      >
                        <span className="icon plus" /> Create Dashboard
                      </button>
                    </Authorized>
                  </div>
                </div>
                <div className="panel-body">
                  <DashboardsTable
                    dashboards={filteredDashboards}
                    onDeleteDashboard={onDeleteDashboard}
                    onCreateDashboard={onCreateDashboard}
                    dashboardLink={dashboardLink}
                  />
                </div>
              </div>
            </div>
          </div>
        </div>
      </FancyScrollbar>
    )
  }
}

const {arrayOf, func, shape, string} = PropTypes

DashboardsPageContents.propTypes = {
  dashboards: arrayOf(shape()),
  onDeleteDashboard: func.isRequired,
  onCreateDashboard: func.isRequired,
  dashboardLink: string.isRequired,
}

export default DashboardsPageContents

{'fraction_non_alphanumeric': 0.10201949860724234, 'fraction_numerical': 0.0020891364902506965, 'mean_word_length': 1.7713458755426919, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, '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': '7146639', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1498, 'n_words': 292}