<commit_before>import React from 'react';
import PropTypes from 'prop-types';

import { getSearchStr, getTimeFields, getJobMachineUrl } from '../../../helpers/job';
import { getInspectTaskUrl, getJobSearchStrHref } from '../../../helpers/url';

import ActionBar from './ActionBar';
import ClassificationsPanel from './ClassificationsPanel';
import StatusPanel from './StatusPanel';

export default class SummaryPanel extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      machineUrl: '',
    };
  }

  componentWillReceiveProps(nextProps) {
    const { selectedJob } = nextProps;
    if (!selectedJob || !Object.keys(selectedJob).length) {
      return;
    }

    this.setJobMachineUrl(selectedJob);
  }

  async setJobMachineUrl(job) {
    let machineUrl = null;

    try {
      machineUrl = await getJobMachineUrl(job);
    } catch (err) {
      machineUrl = '';
    }

    if (this.state.machineUrl !== machineUrl) {
      this.setState({ machineUrl });
    }
  }

  render() {
    const {
      repoName, selectedJob, latestClassification, bugs, jobLogUrls,
      jobDetailLoading, buildUrl, logViewerUrl, logViewerFullUrl, isTryRepo, logParseStatus,
      pinJob, $injector, user,
    } = this.props;

    const timeFields = getTimeFields(selectedJob);
    const jobMachineName = selectedJob.machine_name;
    const jobSearchStr = getSearchStr(selectedJob);
    let iconCircleClass = null;

    const buildDirectoryUrl = (selectedJob.build_system_type === 'buildbot' && !!jobLogUrls.length) ?
      jobLogUrls[0].buildUrl : buildUrl;

    if (selectedJob.job_type_description) {
      iconCircleClass = 'fa fa-info-circle';
    }

    return (
      <div id="summary-panel">
        <ActionBar
          repoName={repoName}
          selectedJob={selectedJob}
          logParseStatus={logParseStatus}
          isTryRepo={isTryRepo}
          logViewerUrl={logViewerUrl}
          logViewerFullUrl={logViewerFullUrl}
          jobLogUrls={jobLogUrls}
          pinJob={pinJob}
          $injector={$injector}
          user={user}
        />
        <div id="summary-panel-content">
          <div>
            {jobDetailLoading &&
              <div className="overlay">
                <div>
                  <span className="fa fa-spinner fa-pulse th-spinner-lg" />
                </div>
              </div>
            }

            <ul className="list-unstyled">
              {latestClassification &&
                <ClassificationsPanel
                  job={selectedJob}
                  classification={latestClassification}
                  bugs={bugs}
                  repoName={repoName}
                  $injector={$injector}
                />}
              <StatusPanel selectedJob={selectedJob} />
              <div>
                <li className="small">
                  <label title="">Job</label>
                  <a
                    title="Filter jobs with this unique SHA signature"
                    href={getJobSearchStrHref(selectedJob.signature)}
                  >(sig)</a>:&nbsp;
                  <a
                    title="Filter jobs containing these keywords"
                    href={getJobSearchStrHref(jobSearchStr)}
                  >{jobSearchStr}</a>
                </li>
                {jobMachineName &&
                  <li className="small">
                    <label>Machine: </label>
                    <a
                      title="Inspect machine"
                      target="_blank"
                      href={this.state.machineUrl}
                    >{jobMachineName}</a>
                  </li>
                }
                {selectedJob.taskcluster_metadata &&
                  <li className="small">
                    <label>Task: </label>
                    <a
                      href={getInspectTaskUrl(selectedJob.taskcluster_metadata.task_id)}
                      target="_blank"
                    >{selectedJob.taskcluster_metadata.task_id}</a>
                  </li>
                }
                <li className="small">
                  <label>Build: </label>
                  <a
                    title="Open build directory in a new tab"
                    href={buildUrl}
                    target="_blank"
                  >{`${selectedJob.build_architecture} ${selectedJob.build_platform} ${selectedJob.build_os || ''}`}</a>
                  <span className={`ml-1${iconCircleClass}`} />
                </li>
                <li className="small">
                  <label>Job name: </label>
                  <a
                    title="Open build directory in a new tab"
                    href={buildDirectoryUrl}
                    target="_blank"
                  >{selectedJob.job_type_name}</a>
                  <span className={`ml-1${iconCircleClass}`} />
                </li>
                {timeFields && <span>
                  <li className="small"><commit_msg>Bug 1472204 - Clean up error handling for machine name (#3740)<commit_after>import React from 'react';
import PropTypes from 'prop-types';

import { getSearchStr, getTimeFields, getJobMachineUrl } from '../../../helpers/job';
import { getInspectTaskUrl, getJobSearchStrHref } from '../../../helpers/url';

import ActionBar from './ActionBar';
import ClassificationsPanel from './ClassificationsPanel';
import StatusPanel from './StatusPanel';

export default class SummaryPanel extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      machineUrl: null,
      machineUrlStatus: '',
    };
  }

  componentDidMount() {
    this.setJobMachineUrl(this.props.selectedJob, null);
  }

  componentDidUpdate(prevProps, prevState) {
    const { selectedJob } = this.props;
    if (!selectedJob || selectedJob === prevProps.selectedJob) {
      return;
    }
    this.setJobMachineUrl(selectedJob, prevState.machineUrl);
  }

  async setJobMachineUrl(selectedJob, prevMachineUrl) {
    // If we can't get the machineUrl, then this text will be added as a suffix
    // after the machine name to let the user know there was a problem.
    let machineUrl = null;
    let machineUrlStatus = '';

    try {
      machineUrl = await getJobMachineUrl(selectedJob);
    } catch (err) {
      machineUrlStatus = '(Load error)';
      console.error(`Error fetching machine URL: ${err}`); // eslint-disable-line no-console
    }
    if (machineUrl !== prevMachineUrl) {
      this.setState({ machineUrl, machineUrlStatus });
    }
  }

  render() {
    const {
      repoName, selectedJob, latestClassification, bugs, jobLogUrls,
      jobDetailLoading, buildUrl, logViewerUrl, logViewerFullUrl, isTryRepo, logParseStatus,
      pinJob, $injector, user,
    } = this.props;
    const { machineUrl, machineUrlStatus } = this.state;

    const timeFields = getTimeFields(selectedJob);
    const jobMachineName = selectedJob.machine_name;
    const jobSearchStr = getSearchStr(selectedJob);
    let iconCircleClass = null;

    const buildDirectoryUrl = (selectedJob.build_system_type === 'buildbot' && !!jobLogUrls.length) ?
      jobLogUrls[0].buildUrl : buildUrl;

    if (selectedJob.job_type_description) {
      iconCircleClass = 'fa fa-info-circle';
    }

    return (
      <div id="summary-panel">
        <ActionBar
          repoName={repoName}
          selectedJob={selectedJob}
          logParseStatus={logParseStatus}
          isTryRepo={isTryRepo}
          logViewerUrl={logViewerUrl}
          logViewerFullUrl={logViewerFullUrl}
          jobLogUrls={jobLogUrls}
          pinJob={pinJob}
          $injector={$injector}
          user={user}
        />
        <div id="summary-panel-content">
          <div>
            {jobDetailLoading &&
              <div className="overlay">
                <div>
                  <span className="fa fa-spinner fa-pulse th-spinner-lg" />
                </div>
              </div>
            }

            <ul className="list-unstyled">
              {latestClassification &&
                <ClassificationsPanel
                  job={selectedJob}
                  classification={latestClassification}
                  bugs={bugs}
                  repoName={repoName}
                  $injector={$injector}
                />}
              <StatusPanel selectedJob={selectedJob} />
              <div>
                <li className="small">
                  <label title="">Job</label>
                  <a
                    title="Filter jobs with this unique SHA signature"
                    href={getJobSearchStrHref(selectedJob.signature)}
                  >(sig)</a>:&nbsp;
                  <a
                    title="Filter jobs containing these keywords"
                    href={getJobSearchStrHref(jobSearchStr)}
                  >{jobSearchStr}</a>
                </li>
                {jobMachineName &&
                  <li className="small">
                    <label>Machine: </label>
                    {machineUrl ? <a
                      title="Inspect machine"
                      target="_blank"
                      href={machineUrl}
                    >{jobMachineName}</a> :
                    <span>{jobMachineName} {machineUrlStatus}</span>}
                  </li>
                }
                {selectedJob.taskcluster_metadata &&
                  <li className="small">
                    <label>Task: </label>
                    <a
                      href={getInspectTaskUrl(selectedJob.taskcluster_metadata.task_id)}
                      target="_blank"
                    >{selectedJob.taskcluster_metadata.task_id}</a>
                  </li>
                }
                <li className="small">
                  <label>Build: </label>
                  <a
                    title="Open build directory in a new tab"
                    href={buildUrl}
                    target="_blank"
                  >{`${selectedJob.build_architecture} ${selectedJob.build_platform} ${selectedJob.build_os || ''}`}</a>
                  <span className={`ml-1${iconCircleClass}`} />
                </li>
                <li className="small">
                  <label>Job name: </label>
                  <a
                    title="Open build directory in a new tab"
                    href={buildDirectoryUrl}
                    target="_blank"
                  >{selectedJob.job_type_name}</a>
                  <span className={`ml-1${iconCircleClass}`} />
                </li>
                {timeFields && <span>
                  <li className="small">
{'fraction_non_alphanumeric': 0.11126867082624314, 'fraction_numerical': 0.0016071090943467574, 'mean_word_length': 1.654039136979428, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, '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': '2641228', 'n_tokens_mistral': 2827, 'n_tokens_neox': 2675, 'n_words': 538}