<commit_before>import React, {PropTypes} from 'react';
import {withRouter} from 'react-router';
import FlashMessages from 'shared/components/FlashMessages';
import {createSource, getSources} from 'shared/apis';

export const SelectSourcePage = React.createClass({
  propTypes: {
    router: PropTypes.shape({
      push: PropTypes.func.isRequired,
    }).isRequired,
    location: PropTypes.shape({
      query: PropTypes.shape({
        redirectPath: PropTypes.string,
      }).isRequired,
    }).isRequired,
  },

  getInitialState() {
    return {
      sources: [],
    };
  },

  componentDidMount() {
    getSources().then(({data: {sources}}) => {
      this.setState({
        sources,
      });
    });
  },

  handleSelectSource(e) {
    e.preventDefault();
    const source = this.state.sources.find((s) => s.name === this.selectedSource.value);
    this.redirectToApp(source);
  },

  handleNewSource(e) {
    e.preventDefault();
    const source = {
      url: this.sourceURL.value,
      name: this.sourceName.value,
      username: this.sourceUser.value,
      password: <PASSWORD>.source<PASSWORD>,
    };
    createSource(source).then(() => {
      // this.redirectToApp(sourceFromServer)
    });
  },

  redirectToApp(source) {
    const {redirectPath} = this.props.location.query;
    if (!redirectPath) {
      return this.props.router.push(`/sources/${source.id}/hosts`);
    }

    const fixedPath = redirectPath.replace(/\/sources\/[^/]*/, `/sources/${source.id}`);
    return this.props.router.push(fixedPath);
  },

  render() {
    const error = !!this.props.location.query.redirectPath;
    return (
      <div id="select-source-page">
        <div className="container">
          <div className="row"><commit_msg>Fix connection point for source creation<commit_after>import React, {PropTypes} from 'react';
import {withRouter} from 'react-router';
import FlashMessages from 'shared/components/FlashMessages';
import {createSource, getSources} from 'shared/apis';

export const SelectSourcePage = React.createClass({
  propTypes: {
    router: PropTypes.shape({
      push: PropTypes.func.isRequired,
    }).isRequired,
    location: PropTypes.shape({
      query: PropTypes.shape({
        redirectPath: PropTypes.string,
      }).isRequired,
    }).isRequired,
  },

  getInitialState() {
    return {
      sources: [],
    };
  },

  componentDidMount() {
    getSources().then(({data: {sources}}) => {
      this.setState({
        sources,
      });
    });
  },

  handleSelectSource(e) {
    e.preventDefault();
    const source = this.state.sources.find((s) => s.name === this.selectedSource.value);
    this.redirectToApp(source);
  },

  handleNewSource(e) {
    e.preventDefault();
    const source = {
      url: this.sourceURL.value,
      name: this.sourceName.value,
      username: this.sourceUser.value,
      password: <PASSWORD>,
    };
    createSource(source).then(({data: sourceFromServer}) => {
      this.redirectToApp(sourceFromServer);
    });
  },

  redirectToApp(source) {
    const {redirectPath} = this.props.location.query;
    if (!redirectPath) {
      return this.props.router.push(`/sources/${source.id}/hosts`);
    }

    const fixedPath = redirectPath.replace(/\/sources\/[^/]*/, `/sources/${source.id}`);
    return this.props.router.push(fixedPath);
  },

  render() {
    const error = !!this.props.location.query.redirectPath;
    return (
      <div id="select-source-page">
        <div className="container">
          <div className="row">
{'fraction_non_alphanumeric': 0.15793966989186112, 'fraction_numerical': 0.0, 'mean_word_length': 3.0635838150289016, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, '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': '4258777', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1063, 'n_words': 187}