From 71c0b963726b72137a9c8c0128d4a65579137f2e Mon Sep 17 00:00:00 2001 From: Richie Hsieh Date: Wed, 30 May 2018 14:03:24 +0800 Subject: [PATCH] Support IntegerField --- redocs/templates/redocs/index.html | 72 ++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/redocs/templates/redocs/index.html b/redocs/templates/redocs/index.html index 9debcf9..8b6f45f 100644 --- a/redocs/templates/redocs/index.html +++ b/redocs/templates/redocs/index.html @@ -274,24 +274,16 @@

Url Params: {!this.urlParams && '---'}

Params: {!endpoint.input && '---'}

{endpoint.input && ( )} @@ -316,6 +308,48 @@

Methods:

) } + + _getInputProps = ({name, type}, fields) => { + let props = { + name, + type: 'text', + value: fields[name], + onChange: e => { + let value = null; + if (e.target.type === 'checkbox') { + value = e.target.checked; + } else if (e.target.type === 'number') { + value = parseInt(e.target.value, 10); + } else { + value = e.target.value; + } + + this.setState({ + fields: { + ...fields, + [name]: value + } + }) + } + }; + + switch (type) { + case 'EmailField': + props.type = 'email'; + case 'IntegerField': + props.type = 'number'; + case 'BooleanField': + delete props.value; + props.type = 'checkbox'; + props.checked = fields[name] || false; + case 'CharField': + if (name === 'password' || name === 'pass') { + props.type = 'password'; + } + } + + return props; + } } class App extends React.Component { @@ -379,7 +413,7 @@

Methods:

render() { let {token, filter, auth} = this.state; - let filteredEndpoints = endpoints.filter( + let filteredEndpoints = endpoints.sort((a, b) => a.path - b.path).filter( endpoint => { if (filter) { return endpoint.path.toLocaleLowerCase().indexOf(filter.toLocaleLowerCase()) > -1