Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/components/Skill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ class Skill extends React.Component {
this.doRequest = this.doRequest.bind(this);
this.createRequest = this.createRequest.bind(this);
this.setRequest = this.setRequest.bind(this);
this.copyLastAttributes = this.copyLastAttributes.bind(this);

this.state = {
request: this.createRequest(props),
validRequest: true
validRequest: true,
alwaysCopyResponseSession: false
}
}

createRequest(props) {
debug('Skill Component: createRequest')

const request = Object.assign({}, requests[props.requestType])

if ('intent' === props.requestType) {
request.request.intent.name = ''
request.request.intent.slots = {}
Expand Down Expand Up @@ -65,6 +66,10 @@ class Skill extends React.Component {
this.setState({
request: this.createRequest(nextProps)
})

if (this.state.alwaysCopyResponseSession) {
this.copyLastAttributes();
}
}

doRequest() {
Expand All @@ -74,12 +79,22 @@ class Skill extends React.Component {
}
}

copyLastAttributes() {
const response = this.props.response;
const request = JSON.parse(this.state.request);
request.session.attributes = Object.assign({}, request.session.attributes, response.sessionAttributes);
this.setState({
request: beautify(JSON.stringify(request))
});
}

render() {
debug('Skill Component: render');

const request = this.state.request
const response = beautify(JSON.stringify(this.props.response))
const requestClass = (this.state.validRequest) ? 'code' : 'invalid code'
const { alwaysCopyResponseSession } = this.state;

let slots = []

Expand Down Expand Up @@ -178,7 +193,13 @@ class Skill extends React.Component {
''
}
<div>
<input type="button" className="btn btn-primary btn-lg" value="Send Request" onClick={this.doRequest} />
<input type="button" className="btn btn-primary btn-lg" value="Send Request" onClick={this.doRequest}/>
{!this.state.alwaysCopyResponseSession && <input type="button" className="btn btn-primary btn-lg" value="Copy Response Attributes" onClick={this.copyLastAttributes} style={{marginLeft: 10}}/>}

</div>
<div style={{marginTop: 10}}>
<input type="checkbox" checked={this.state.alwaysCopyResponseSession} onChange={() => this.setState({alwaysCopyResponseSession: !alwaysCopyResponseSession})} style={{marginRight: 5}}/>
Always Copy Response Attributes
</div>

<div className="row req-resp">
Expand Down