mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Rename request in place
This commit is contained in:
parent
d9a1ba2f4e
commit
16eb53dbe0
@ -1,14 +1,16 @@
|
|||||||
import React, {PropTypes} from 'react'
|
import React, {PropTypes} from 'react'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
|
||||||
import RequestGroupActionsDropdown from './../containers/RequestGroupActionsDropdown'
|
import RequestGroupActionsDropdown from './../containers/RequestGroupActionsDropdown'
|
||||||
import SidebarRequestRow from './SidebarRequestRow'
|
import SidebarRequestRow from './SidebarRequestRow'
|
||||||
|
import * as db from '../database'
|
||||||
|
|
||||||
const SidebarRequestGroupRow = ({
|
const SidebarRequestGroupRow = ({
|
||||||
children,
|
children,
|
||||||
requestGroup,
|
requestGroup,
|
||||||
isActive,
|
isActive,
|
||||||
toggleRequestGroup,
|
toggleRequestGroup,
|
||||||
addRequestToRequestGroup
|
addRequestToRequestGroup,
|
||||||
}) => {
|
}) => {
|
||||||
let folderIconClass = 'fa-folder';
|
let folderIconClass = 'fa-folder';
|
||||||
let expanded = !requestGroup.collapsed;
|
let expanded = !requestGroup.collapsed;
|
||||||
@ -20,10 +22,11 @@ const SidebarRequestGroupRow = ({
|
|||||||
className={classnames('sidebar__row', {active: isActive})}>
|
className={classnames('sidebar__row', {active: isActive})}>
|
||||||
|
|
||||||
<div className={classnames('sidebar__item sidebar__item--big', {active: isActive})}>
|
<div className={classnames('sidebar__item sidebar__item--big', {active: isActive})}>
|
||||||
|
<button onClick={e => toggleRequestGroup(requestGroup)}>
|
||||||
<button className="sidebar__clickable" onClick={e => toggleRequestGroup(requestGroup)}>
|
<div className="sidebar__clickable">
|
||||||
<i className={'fa ' + folderIconClass}></i>
|
<i className={'sidebar__item__icon fa ' + folderIconClass}></i>
|
||||||
{requestGroup.name}
|
<span>{requestGroup.name}</span>
|
||||||
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div className="sidebar__actions">
|
<div className="sidebar__actions">
|
||||||
@ -35,7 +38,6 @@ const SidebarRequestGroupRow = ({
|
|||||||
right={true}
|
right={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul className="sidebar__list">
|
<ul className="sidebar__list">
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import React, {PropTypes} from 'react'
|
import React, {PropTypes, Component} from 'react'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
|
||||||
import RequestActionsDropdown from './../containers/RequestActionsDropdown'
|
import RequestActionsDropdown from '../containers/RequestActionsDropdown'
|
||||||
|
import Editable from './base/Editable'
|
||||||
import MethodTag from './MethodTag'
|
import MethodTag from './MethodTag'
|
||||||
import * as db from '../database'
|
import * as db from '../database'
|
||||||
|
|
||||||
|
|
||||||
const SidebarRequestRow = ({request, requestGroup, isActive, activateRequest}) => {
|
const SidebarRequestRow = ({request, requestGroup, isActive, activateRequest}) => {
|
||||||
if (!request) {
|
if (!request) {
|
||||||
return (
|
return (
|
||||||
<li className="sidebar__item">
|
<li className="sidebar__item">
|
||||||
<button className="sidebar__clickable"
|
<button className="sidebar__clickable" onClick={() => db.requestCreate({parentId: requestGroup._id})}>
|
||||||
onClick={() => db.requestCreate({parentId: requestGroup._id})}>
|
|
||||||
<em>click to add first request...</em>
|
<em>click to add first request...</em>
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
@ -19,10 +20,15 @@ const SidebarRequestRow = ({request, requestGroup, isActive, activateRequest}) =
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="sidebar__row">
|
<li className="sidebar__row">
|
||||||
|
|
||||||
<div className={classnames('sidebar__item', {active: isActive})}>
|
<div className={classnames('sidebar__item', {active: isActive})}>
|
||||||
<button className="sidebar__clickable" onClick={() => {activateRequest(request)}}>
|
<button onClick={() => {activateRequest(request)}}>
|
||||||
<MethodTag method={request.method}/> {request.name}
|
<div className="sidebar__clickable">
|
||||||
|
<MethodTag method={request.method}/>
|
||||||
|
<Editable
|
||||||
|
value={request.name}
|
||||||
|
onSubmit={name => db.requestUpdate(request, {name})}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div className="sidebar__actions">
|
<div className="sidebar__actions">
|
||||||
|
63
app/components/base/Editable.js
Normal file
63
app/components/base/Editable.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import React, {Component, PropTypes} from 'react';
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
|
|
||||||
|
class Editable extends Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
editing: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleEditStart () {
|
||||||
|
this.setState({editing: true});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.refs.input && this.refs.input.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleEditEnd () {
|
||||||
|
this.setState({editing: false})
|
||||||
|
this.props.onSubmit(this.refs.input.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleEditKeyDown (e) {
|
||||||
|
if (e.keyCode === 13) {
|
||||||
|
// Pressed Enter
|
||||||
|
this._handleEditEnd();
|
||||||
|
} else if (e.keyCode === 27) {
|
||||||
|
// Pressed Escape
|
||||||
|
this.refs.input && this.refs.input.blur();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const {value, ...extra} = this.props;
|
||||||
|
const {editing} = this.state;
|
||||||
|
|
||||||
|
if (editing) {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
ref="input"
|
||||||
|
defaultValue={value}
|
||||||
|
onKeyDown={e => this._handleEditKeyDown(e)}
|
||||||
|
onBlur={e => this._handleEditEnd()}
|
||||||
|
{...extra}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<span onDoubleClick={e => this._handleEditStart()} {...extra}>{value}</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Editable.propTypes = {
|
||||||
|
onSubmit: PropTypes.func.isRequired,
|
||||||
|
value: PropTypes.string.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Editable;
|
@ -86,6 +86,7 @@ textarea, input, button {
|
|||||||
border: 0;
|
border: 0;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
|
|
||||||
&::-webkit-input-placeholder {
|
&::-webkit-input-placeholder {
|
||||||
|
@ -115,11 +115,15 @@
|
|||||||
.tag {
|
.tag {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
width: 3.25em;
|
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
width: 2.8em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar__item__icon {
|
||||||
|
padding-right: $padding-sm;
|
||||||
|
}
|
||||||
|
|
||||||
// put border on folders
|
// put border on folders
|
||||||
|
|
||||||
.sidebar__row:not(:first-child) .sidebar__item--big {
|
.sidebar__row:not(:first-child) .sidebar__item--big {
|
||||||
@ -131,7 +135,9 @@
|
|||||||
// ~~~~~~~~~~~~~~~~~ //
|
// ~~~~~~~~~~~~~~~~~ //
|
||||||
|
|
||||||
.sidebar__clickable {
|
.sidebar__clickable {
|
||||||
// Nothing yet...
|
display: grid;
|
||||||
|
grid-template-columns: auto 1fr;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Padding
|
// Padding
|
||||||
|
Loading…
Reference in New Issue
Block a user