<commit_before>
import React from "react";

import SK from "../../SK";

export default class VertexPositionEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      positions: props.positions,
      vertexId: props.vertexId,
    };
  }

  handleChange(inputName, field, e) {
    const positions = {...this.state.positions};
    positions[inputName][field] = parseInt(e.target.value);
    this.setState({positions});
  }

  handleSave() {
    const newVertex = {
      params: {
        inputCount: Object.keys(this.state.positions).length,
        positions: this.state.positions
      }
    };
    SK.vertices.update(this.state.vertexId, newVertex)
    .then(() => {
      // console.log("Success!");
    })
    .catch((err) => {
      // console.error(err);
    });
  }

  render() {
    const inputs = Object.keys(this.state.positions).map((inputName) => {
      const input = this.state.positions[inputName];
      return (
        <div key={inputName}>
          <strong>{inputName}</strong>
          <p>X: <input onChange={this.handleChange.bind(this, inputName, "x")} type="text" length="4" value={input.x}/></p>
          <p>Y: <input onChange={this.handleChange.bind(this, inputName, "y")} type="text" length="4" value={input.y}/></p>
          <p>Width: <input onChange={this.handleChange.bind(this, inputName, "width")} type="text" length="4" value={input.width}/></p>
          <p>Height: <input onChange={this.handleChange.bind(this, inputName, "height")} type="text" length="4" value={input.height}/></p><commit_msg>Fix NaN bug when changing overlay positions<commit_after>
import React from "react";

import SK from "../../SK";

export default class VertexPositionEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      positions: props.positions,
      vertexId: props.vertexId,
    };
  }

  handleChange(inputName, field, e) {
    const positions = {...this.state.positions};
    let result = parseInt(e.target.value);
    if (result !== result) { // NaN
      result = e.target.value;
    }
    positions[inputName][field] = result;
    this.setState({positions});
  }

  handleSave() {
    const newVertex = {
      params: {
        inputCount: Object.keys(this.state.positions).length,
        positions: this.state.positions
      }
    };
    SK.vertices.update(this.state.vertexId, newVertex)
    .then(() => {
      // console.log("Success!");
    })
    .catch((err) => {
      // console.error(err);
    });
  }

  render() {
    const inputs = Object.keys(this.state.positions).map((inputName) => {
      const input = this.state.positions[inputName];
      return (
        <div key={inputName}>
          <strong>{inputName}</strong>
          <p>X: <input onChange={this.handleChange.bind(this, inputName, "x")} type="text" length="4" value={input.x}/></p>
          <p>Y: <input onChange={this.handleChange.bind(this, inputName, "y")} type="text" length="4" value={input.y}/></p>
          <p>Width: <input onChange={this.handleChange.bind(this, inputName, "width")} type="text" length="4" value={input.width}/></p>
          <p>Height: <input onChange={this.handleChange.bind(this, inputName, "height")} type="text" length="4" value={input.height}/></p>
{'fraction_non_alphanumeric': 0.17817848410757947, 'fraction_numerical': 0.0024449877750611247, 'mean_word_length': 3.09125, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, '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': '6124892', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1026, 'n_words': 190}