Skip to content

Commit 7697c09

Browse files
author
Emmanouil Konstantinidis
committed
Allow fields to be removed
1 parent 4fdf466 commit 7697c09

File tree

6 files changed

+33800
-15
lines changed

6 files changed

+33800
-15
lines changed

rest_framework_docs/static/rest_framework_docs/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest_framework_docs/static/rest_framework_docs/js/components/helpers/input.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ var React = require('react');
22

33
var Input = React.createClass({
44

5+
removeField: function (fieldName, event) {
6+
event.preventDefault();
7+
this.props.removeField(fieldName);
8+
},
9+
510
handleChange: function (value) {
611
this.props.onChange(value);
712
},
@@ -12,6 +17,13 @@ var Input = React.createClass({
1217
<label
1318
htmlFor={this.props.name}
1419
className="col-sm-4 control-label">
20+
{this.props.isCustom ? (
21+
<i
22+
className='fa fa-minus-circle'
23+
title='Remove Field'
24+
onClick={this.removeField.bind(this, this.props.name)}
25+
/>
26+
) : null}
1527
{this.props.name}
1628
</label>
1729
<div className="col-sm-8">

rest_framework_docs/static/rest_framework_docs/js/components/request.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var _ = require('underscore');
12
var React = require('react');
23

34
var AddFieldsForm = require('./request/add-fields');
@@ -37,7 +38,8 @@ var Request = React.createClass({
3738
fields.push({
3839
name: fieldName,
3940
required: false,
40-
type: 'Added Field'
41+
type: 'Added Field',
42+
isCustom: true
4143
});
4244

4345
endpoint.fields = fields;
@@ -47,6 +49,21 @@ var Request = React.createClass({
4749
});
4850
},
4951

52+
removeField: function (fieldName) {
53+
var data = this.state.data;
54+
var endpoint = this.state.endpoint;
55+
var fields = endpoint.fields;
56+
57+
data = _.omit(data, fieldName);
58+
fields = _.without(fields, _.findWhere(fields, {name: fieldName}));
59+
endpoint.fields = fields;
60+
61+
this.setState({
62+
data: data,
63+
endpoint: endpoint
64+
});
65+
},
66+
5067
setSelectedMethod: function (method) {
5168
this.setState({
5269
selectedMethod: method
@@ -105,6 +122,7 @@ var Request = React.createClass({
105122
<FieldsData
106123
fields={endpoint.fields}
107124
data={this.state.data}
125+
removeCustomField={this.removeField}
108126
onChange={this.handleDataFieldChange} />
109127

110128
<AddFieldsForm onAdd={this.addField} />

rest_framework_docs/static/rest_framework_docs/js/components/request/fields-data.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ var Input = require('../helpers/input');
44

55
var FieldsData = React.createClass({
66

7+
removeCustomField: function (fieldName) {
8+
this.props.removeCustomField(fieldName);
9+
},
10+
711
handleChange: function (fieldName, event) {
812
this.props.onChange(event.target.value, fieldName);
913
},
@@ -21,6 +25,8 @@ var FieldsData = React.createClass({
2125
value={value}
2226
placeholder={field.type}
2327
required={field.required ? 'required' : false}
28+
removeField={this.removeCustomField}
29+
isCustom={field.isCustom ? 'isCustom' : false}
2430
onChange={this.handleChange.bind(this, field.name)} />
2531
);
2632
}, this);

rest_framework_docs/static/rest_framework_docs/js/dist.js

Lines changed: 33749 additions & 11 deletions
Large diffs are not rendered by default.

rest_framework_docs/static/rest_framework_docs/less/style.less

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ body {
208208
&.options.active { background-color: @OptionsColor; }
209209
}
210210
}
211+
212+
.form-group {
213+
214+
label {
215+
216+
.fa {
217+
margin-right: 5px;
218+
color: @brand-danger;
219+
}
220+
}
221+
}
211222
}
212223

213224
.response {
@@ -236,7 +247,7 @@ body {
236247
/* @end Modal API */
237248

238249

239-
/* @group jQuery / JSON View */
250+
/* @group Response / JSON View */
240251

241252
.json-key {
242253
color: brown;
@@ -250,7 +261,7 @@ body {
250261
color: olive;
251262
}
252263

253-
/* @end jQuery / JSON View */
264+
/* @end Response / JSON View */
254265

255266

256267
/* @group Github Ribbon - SVG */

0 commit comments

Comments
 (0)