<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import _ from 'lodash';

import Modal from './modal';
import AuthenticationsModal from './authentications_modal';
import SettingsInputs from '../common/settings_inputs';
import ConfigXmlModal from './config_xml_modal';
import EnabledButton from '../common/enabled';
import DisabledButton from '../common/disabled';

export default class ListRow extends React.Component {
  static propTypes = {
    delete: PropTypes.func.isRequired,
    save: PropTypes.func.isRequired,
    sites: PropTypes.shape({}).isRequired,
    application: PropTypes.shape({}),
    applicationInstance: PropTypes.shape({
      site: PropTypes.shape({
        url: PropTypes.string,
      }),
      id: PropTypes.number.isRequired,
      application_id: PropTypes.number.isRequired,
    }).isRequired,
    settings: PropTypes.shape({
      lti_key: PropTypes.string,
      user_canvas_domains: PropTypes.arrayOf(PropTypes.string),
    }).isRequired,
    canvasOauthURL: PropTypes.string.isRequired,
    disable: PropTypes.func.isRequired,
  };

  static getStyles() {
    return {
      buttonIcon: {
        border: 'none',
        backgroundColor: 'transparent',
        color: 'grey',
        fontSize: '1.5em',
        cursor: 'pointer',
      },
      buttonNumber: {
        height: '3rem',
        borderRadius: '3px',
        background: '#f5f5f5',
        border: 'none',
        color: 'grey',
        fontSize: '1.5em',
        cursor: 'pointer',
      },
    };
  }

  constructor() {
    super();
    this.state = {
      modalOpen: false,
      authenticationModalOpen: false,
      modalConfigXmlOpen: false,
    };
  }

  checkAuthentication(e) {
    if (!_.find(this.props.settings.user_canvas_domains, canvasUrl =>
      canvasUrl === this.props.applicationInstance.site.url
    )) {
      e.stopPropagation();
      e.preventDefault();
      this.settingsForm.submit();
    }
  }

  renderAuthentications() {
    const styles = ListRow.getStyles();
    const { applicationInstance } = this.props;
    if (applicationInstance.authentications.length <= 0) {
      return (
        <td>
          {applicationInstance.authentications.length}
        </td>
      );
    }
    return (
      <td>
        <button
          style={styles.buttonNumber}
          onClick={() => this.setState({ authenticationModalOpen: true })}
        >
          {applicationInstance.authentications.length}
        </button>
        <AuthenticationsModal
          isOpen={this.state.authenticationModalOpen}
          closeModal={() => this.setState({ authenticationModalOpen: false })}
          authentications={applicationInstance.authentications}
          application={this.props.application}
          applicationInstance={applicationInstance}
        />
      </td>
    );<commit_msg>check for null before length<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import _ from 'lodash';

import Modal from './modal';
import AuthenticationsModal from './authentications_modal';
import SettingsInputs from '../common/settings_inputs';
import ConfigXmlModal from './config_xml_modal';
import EnabledButton from '../common/enabled';
import DisabledButton from '../common/disabled';

export default class ListRow extends React.Component {
  static propTypes = {
    delete: PropTypes.func.isRequired,
    save: PropTypes.func.isRequired,
    sites: PropTypes.shape({}).isRequired,
    application: PropTypes.shape({}),
    applicationInstance: PropTypes.shape({
      site: PropTypes.shape({
        url: PropTypes.string,
      }),
      id: PropTypes.number.isRequired,
      application_id: PropTypes.number.isRequired,
    }).isRequired,
    settings: PropTypes.shape({
      lti_key: PropTypes.string,
      user_canvas_domains: PropTypes.arrayOf(PropTypes.string),
    }).isRequired,
    canvasOauthURL: PropTypes.string.isRequired,
    disable: PropTypes.func.isRequired,
  };

  static getStyles() {
    return {
      buttonIcon: {
        border: 'none',
        backgroundColor: 'transparent',
        color: 'grey',
        fontSize: '1.5em',
        cursor: 'pointer',
      },
      buttonNumber: {
        height: '3rem',
        borderRadius: '3px',
        background: '#f5f5f5',
        border: 'none',
        color: 'grey',
        fontSize: '1.5em',
        cursor: 'pointer',
      },
    };
  }

  constructor() {
    super();
    this.state = {
      modalOpen: false,
      authenticationModalOpen: false,
      modalConfigXmlOpen: false,
    };
  }

  checkAuthentication(e) {
    if (!_.find(this.props.settings.user_canvas_domains, canvasUrl =>
      canvasUrl === this.props.applicationInstance.site.url
    )) {
      e.stopPropagation();
      e.preventDefault();
      this.settingsForm.submit();
    }
  }

  renderAuthentications() {
    const styles = ListRow.getStyles();
    const { applicationInstance } = this.props;
    const numberAuthentications = applicationInstance.authentications ?
      applicationInstance.authentications.length : 0;

    if (numberAuthentications <= 0) {
      return (
        <td>
          {numberAuthentications}
        </td>
      );
    }
    return (
      <td>
        <button
          style={styles.buttonNumber}
          onClick={() => this.setState({ authenticationModalOpen: true })}
        >
          {numberAuthentications}
        </button>
        <AuthenticationsModal
          isOpen={this.state.authenticationModalOpen}
          closeModal={() => this.setState({ authenticationModalOpen: false })}
          authentications={applicationInstance.authentications}
          application={this.props.application}
          applicationInstance={applicationInstance}
        />
      </td>
    );
{'fraction_non_alphanumeric': 0.12257843305331734, 'fraction_numerical': 0.003600205726041488, 'mean_word_length': 2.694743508549715, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2142094', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1623, 'n_words': 325}