Skip to content

Commit de4157e

Browse files
author
Emmanouil Konstantinidis
committed
Reset modal on close
1 parent 1ad1420 commit de4157e

File tree

6 files changed

+66
-1627
lines changed

6 files changed

+66
-1627
lines changed

rest_framework_docs/static/rest_framework_docs/js/components/liveapi.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ var LiveAPIEndpoints = React.createClass({
1414
};
1515
},
1616

17-
componentWillReceiveProps: function(nextProps) {
18-
this.setState({
19-
endpoint: nextProps.endpoint
20-
});
21-
},
22-
2317
getData: function () {
2418
var method = this.refs.request.state.selectedMethod;
2519
return RequestUtils.shouldAddData(method) ? null : (

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var _ = require('underscore');
21
var React = require('react');
32

43
var FieldsData = require('./request/fields-data');
@@ -10,7 +9,7 @@ var RequestUtils = require('../utils/request');
109
var Request = React.createClass({
1110
getInitialState: function () {
1211
return {
13-
endpoint: {},
12+
endpoint: null,
1413
data: {},
1514
selectedMethod: null,
1615
};
@@ -26,16 +25,6 @@ var Request = React.createClass({
2625
});
2726
},
2827

29-
componentWillReceiveProps: function (nextProps) {
30-
var endpoint = nextProps.endpoint;
31-
endpoint['methods'] = _.isArray(endpoint.methods) ? endpoint.methods : this.transformMethods(endpoint.methods);
32-
33-
this.setState({
34-
endpoint: endpoint,
35-
selectedMethod: endpoint['methods'][0]
36-
});
37-
},
38-
3928
transformMethods: function (methods) {
4029
return methods
4130
.replace(/\W+/g, ' ')
@@ -51,10 +40,13 @@ var Request = React.createClass({
5140
});
5241
},
5342

54-
handleInputChange: function (value, event) {
55-
var state = this.state;
56-
state[value] = event.target.value;
57-
this.setState(state);
43+
handleUrlChange: function (event) {
44+
var endpoint = this.state.endpoint;
45+
endpoint.path = event.target.value;
46+
47+
this.setState({
48+
endpoint: endpoint
49+
});
5850
},
5951

6052
handleDataFieldChange: function (value, fieldName) {
@@ -67,7 +59,6 @@ var Request = React.createClass({
6759

6860
render: function () {
6961
var endpoint = this.state.endpoint;
70-
7162
return (
7263
<div>
7364
<h3>Request</h3>
@@ -76,7 +67,7 @@ var Request = React.createClass({
7667
<FieldUrl
7768
name='urlEndpoint'
7869
url={endpoint.path}
79-
onChange={this.handleInputChange.bind(this, 'urlEndpoint')} />
70+
onChange={this.handleUrlChange} />
8071

8172
<Header title='Method' />
8273
<Methods

rest_framework_docs/static/rest_framework_docs/js/components/request/field-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var FieldUrl = React.createClass({
66

77
getInitialState: function() {
88
return {
9-
value: this.props.url
9+
url: this.props.url
1010
};
1111
},
1212

rest_framework_docs/static/rest_framework_docs/js/components/response.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@ var Response = React.createClass({
66

77
getInitialState: function () {
88
return {
9-
endpoints: [],
9+
payload: this.props.payload,
1010
};
1111
},
1212

13+
componentWillReceiveProps: function(nextProps) {
14+
this.setState({
15+
payload: nextProps.payload
16+
});
17+
},
18+
1319
saveToken: function () {
14-
window.token = 'Token ' + this.props.payload.body.token;
15-
console.log('Token ' + this.props.payload.body.token);
20+
window.token = 'Token ' + this.state.payload.body.token;
1621
},
1722

1823
render: function () {
19-
if (!this.props.payload) {
24+
if (!this.state.payload) {
2025
return (
2126
<div>
2227
<h3>Response</h3>
@@ -25,10 +30,10 @@ var Response = React.createClass({
2530
);
2631
}
2732

28-
var responseJSON = JSONpp.prettyPrint(this.props.payload.body);
29-
var hasToken = this.props.payload.body.hasOwnProperty('token');
30-
var statusText = this.props.payload.statusText.toLowerCase();
31-
var statusCodeFirstChar = String(this.props.payload.status).charAt(0);
33+
var responseJSON = JSONpp.prettyPrint(this.state.payload.body);
34+
var hasToken = this.state.payload.body.hasOwnProperty('token');
35+
var statusText = this.state.payload.statusText.toLowerCase();
36+
var statusCodeFirstChar = String(this.state.payload.status).charAt(0);
3237
var statusCodeClass = 'label status-code pull-right status-code-' + statusCodeFirstChar;
3338

3439
return (

0 commit comments

Comments
 (0)