import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import autobind from 'autobind-decorator'; import ReactDOM from 'react-dom'; import {DragSource, DropTarget} from 'react-dnd'; import classnames from 'classnames'; import RequestActionsDropdown from '../dropdowns/request-actions-dropdown'; import Editable from '../base/editable'; import MethodTag from '../tags/method-tag'; import * as models from '../../../models'; import {trackEvent} from '../../../analytics/index'; import {showModal} from '../modals/index'; import RequestSettingsModal from '../modals/request-settings-modal'; @autobind class SidebarRequestRow extends PureComponent { constructor (props) { super(props); this.state = { dragDirection: 0, isEditing: false }; } _setRequestActionsDropdownRef (n) { this._requestActionsDropdown = n; } _handleShowRequestActions (e) { e.preventDefault(); this._requestActionsDropdown.show(); } _handleEditStart () { trackEvent('Request', 'Rename', 'In Place'); this.setState({isEditing: true}); } _handleRequestUpdateName (name) { models.request.update(this.props.request, {name}); this.setState({isEditing: false}); } _handleRequestCreateFromEmpty () { const parentId = this.props.requestGroup._id; this.props.requestCreate(parentId); trackEvent('Request', 'Create', 'Empty Folder'); } _handleRequestActivate () { const {isActive, request, handleActivateRequest} = this.props; if (isActive) { return; } handleActivateRequest(request._id); trackEvent('Request', 'Activate', 'Sidebar'); } _handleShowRequestSettings () { showModal(RequestSettingsModal, {request: this.props.request}); } setDragDirection (dragDirection) { if (dragDirection !== this.state.dragDirection) { this.setState({dragDirection}); } } render () { const { handleDuplicateRequest, handleGenerateCode, handleCopyAsCurl, connectDragSource, connectDropTarget, isDragging, isDraggingOver, request, requestGroup, isActive } = this.props; const {dragDirection} = this.state; let node; const classes = classnames('sidebar__row', { 'sidebar__row--dragging': isDragging, 'sidebar__row--dragging-above': isDraggingOver && dragDirection > 0, 'sidebar__row--dragging-below': isDraggingOver && dragDirection < 0 }); if (!request) { node = (