import React, { PropTypes } from 'react'; import * as FileActions from '../actions/files'; import * as IDEActions from '../actions/ide'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import InlineSVG from 'react-inlinesvg'; const downArrowUrl = require('../../../images/down-arrow.svg'); import classNames from 'classnames'; export class FileNode extends React.Component { constructor(props) { super(props); this.renderChild = this.renderChild.bind(this); this.handleKeyPress = this.handleKeyPress.bind(this); this.handleFileNameChange = this.handleFileNameChange.bind(this); this.validateFileName = this.validateFileName.bind(this); this.handleFileClick = this.handleFileClick.bind(this); } handleFileClick(e) { e.stopPropagation(); this.props.setSelectedFile(this.props.id); } handleFileNameChange(event) { this.props.updateFileName(this.props.id, event.target.value); } handleKeyPress(event) { if (event.key === 'Enter') { this.props.hideEditFileName(this.props.id); } } validateFileName() { const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i); const newFileExtension = this.props.name.match(/\.[0-9a-z]+$/i); if (oldFileExtension && !newFileExtension) { this.props.updateFileName(this.props.id, this.originalFileName); } if (oldFileExtension && newFileExtension && oldFileExtension[0] !== newFileExtension[0]) { this.props.updateFileName(this.props.id, this.originalFileName); } } renderChild(childId) { return (