<commit_before>/*** @jsx React.DOM */

var React = require("react");
var classSet = require("react/lib/cx");

var GroupEventDataSection = require("../eventDataSection");
var PropTypes = require("../../../proptypes");

var Frame = React.createClass({
  propTypes: {
    data: React.PropTypes.object.isRequired
  },

  isDefined(item) {
    return typeof item !== "undefined" && item !== null;
  },

  isUrl(filename) {
    if (!filename) {
      return false;
    }
    return filename.indexOf('http:') !== -1 || filename.indexOf('https:') !== -1;
  },

  render() {
    var data = this.props.data;

    var className = classSet({
      "frame": true,
      "system-frame": !data.in_app,
      "frame-errors": data.errors,
    });

    var title = [];

    if (this.isDefined(data.filename || data.module)) {
      title.push(<code>{data.filename || data.module}</code>);
      if (this.isUrl(data.abs_path)) {
        title.push(<a href={data.abs_path} className="icon-share" />);
      }
      if (this.isDefined(data.function)) {
        title.push(<span> in </span>);
      }
    }

    if (this.isDefined(data.function)) {
        title.push(<code>{data.function}</code>);
    }

    if (this.isDefined(data.lineno)) {
      title.push(<span> at line </span>);
      if (this.isDefined(data.colno)) {
        title.push(<code>{data.lineno}:{data.colno}</code>);
      } else {
        title.push(<code>{data.lineno}</code>);
      }
    }

    var context = '';
    if (this.isDefined(data.context)) {
      context = (
        <ol start={data.start_lineno} className="context">
        {this.isDefined(data.errors) &&
          <li className="expandable error"
              key="errors">{data.errors.join(", ")}</li>
        }
        {data.pre_context.map((lineNo, line) => {
          return <li className="expandable" key={lineNo}>{line}</li>;
        })}
        <li className="active expandable" key="active">{data.context_line}</li>
        {data.post_context.map((lineNo, line) => {
          return <li className="expandable" key={lineNo}>{line}</li>;
        })}
        </ol>
      );
    } else if (this.isDefined(data.context_line)) {
      context = (
        <ol start={data.lineno} className="context">
          <li className="active">{data.context_line}</li>
        </ol>
      );
    }
    // TODO(dcramer): implement popover annotations
    // TODO(dcramer): implement local vars
    return (
      <li className={className}>
        <p>{title}</p>
        {context}
      </li>
    );
  }
});

var StacktraceContent = React.createClass({
  propTypes: {
    data: React.PropTypes.object.isRequired
  },

  render() {
    var data = this.props.data;
    var frames = [];
    var firstFrameOmitted, lastFrameOmitted;

    if (data.frames_omitted) {
      firstFrameOmitted = data.frames_omitted[0];
      lastFrameOmitted = data.frames_omitted[1];
    } else {
      firstFrameOmitted = null;
      lastFrameOmitted = null;
    }

    data.frames.forEach((frame, frameIdx) => {
      frames.push(<Frame key={frameIdx} data={frame} />);
      if (frameIdx === firstFrameOmitted) {<commit_msg>Update frame rendering for new API response + context expansion<commit_after>/*** @jsx React.DOM */

var React = require("react");
var classSet = require("react/lib/cx");

var GroupEventDataSection = require("../eventDataSection");
var PropTypes = require("../../../proptypes");

var Frame = React.createClass({
  propTypes: {
    data: React.PropTypes.object.isRequired
  },

  getInitialState() {
    return {
      isExpanded: false
    };
  },

  isDefined(item) {
    return typeof item !== "undefined" && item !== null;
  },

  isUrl(filename) {
    if (!filename) {
      return false;
    }
    return filename.indexOf('http:') !== -1 || filename.indexOf('https:') !== -1;
  },

  toggleContext() {
    this.setState({
      isExpanded: !this.state.isExpanded
    });
  },

  render() {
    var data = this.props.data;

    var className = classSet({
      "frame": true,
      "system-frame": !data.in_app,
      "frame-errors": data.errors,
    });

    var title = [];

    if (this.isDefined(data.filename || data.module)) {
      title.push(<code>{data.filename || data.module}</code>);
      if (this.isUrl(data.absPath)) {
        title.push(<a href={data.absPath} className="icon-share" />);
      }
      if (this.isDefined(data.function)) {
        title.push(<span> in </span>);
      }
    }

    if (this.isDefined(data.function)) {
        title.push(<code>{data.function}</code>);
    }

    if (this.isDefined(data.lineNo)) {
      title.push(<span> at line </span>);
      if (this.isDefined(data.colNo)) {
        title.push(<code>{data.lineNo}:{data.colNo}</code>);
      } else {
        title.push(<code>{data.lineNo}</code>);
      }
    }

    var outerClassName = "context";
    if (this.state.isExpanded) {
      outerClassName += " expanded";
    }

    var context = '';
    if (this.isDefined(data.context)) {
      var startLineNo = data.context[0][0];
      context = (
        <ol start={startLineNo} className={outerClassName}
            onClick={this.toggleContext}>
        {this.isDefined(data.errors) &&
          <li className="expandable error"
              key="errors">{data.errors.join(", ")}</li>
        }
        {data.context.map((line) => {
          var className = "expandable";
          if (line[0] === data.lineNo) {
            className += " active";
          }

          return <li className={className} key={line[0]}>{line[1]}</li>;
        })}
        </ol>
      );
    }
    // TODO(dcramer): implement popover annotations
    // TODO(dcramer): implement local vars
    return (
      <li className={className}>
        <p>{title}</p>
        {context}
      </li>
    );
  }
});

var StacktraceContent = React.createClass({
  propTypes: {
    data: React.PropTypes.object.isRequired
  },

  render() {
    var data = this.props.data;
    var frames = [];
    var firstFrameOmitted, lastFrameOmitted;

    if (data.frames_omitted) {
      firstFrameOmitted = data.framesOmitted[0];
      lastFrameOmitted = data.framesOmitted[1];
    } else {
      firstFrameOmitted = null;
      lastFrameOmitted = null;
    }

    data.frames.forEach((frame, frameIdx) => {
      frames.push(<Frame key={frameIdx} data={frame} />);
      if (frameIdx === firstFrameOmitted) {
{'fraction_non_alphanumeric': 0.17365269461077845, 'fraction_numerical': 0.0020485345099275133, 'mean_word_length': 2.4892798240791643, 'pattern_counts': {'":': 6, '<': 59, '<?xml version=': 0, '>': 64, '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': '4630570', 'n_tokens_mistral': 2069, 'n_tokens_neox': 2022, 'n_words': 356}