Skip to content

Commit

Permalink
fix(choices): use content picker and fix retry attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
rndlaine committed Jun 26, 2019
1 parent 1a71842 commit ad4ea28
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion modules/basic-skills/src/actions/choice_invalid_answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const invalidAnswer = async () => {
const value = (temp[key] || 0) + 1

temp[key] = value
console.log('skill-choice-invalid-count', value)
}

return invalidAnswer()
9 changes: 3 additions & 6 deletions modules/basic-skills/src/backend/choice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as sdk from 'botpress/sdk'

import _ from 'lodash'

const setup = async bp => {
Expand Down Expand Up @@ -36,8 +35,6 @@ const generateFlow = async (data: any, metadata: sdk.FlowGeneratorMetadata): Pro
const hardLimit = 10
const maxAttempts = Math.min(data.config.nbMaxRetries, hardLimit)

console.log('maxAttempts', maxAttempts, 'contenId', data.contentId, 'data', data)

const nodes: sdk.SkillFlowNode[] = [
{
name: 'entry',
Expand Down Expand Up @@ -71,10 +68,10 @@ const generateFlow = async (data: any, metadata: sdk.FlowGeneratorMetadata): Pro
],
next: [
{
condition: `temp['skill-choice-invalid-count'] <= Number(${maxAttempts})`,
node: 'sorry'
condition: `temp['skill-choice-invalid-count'] == ${maxAttempts}`,
node: '#'
},
{ condition: 'true', node: '#' }
{ condition: 'true', node: 'sorry' }
]
},
{
Expand Down
21 changes: 10 additions & 11 deletions modules/basic-skills/src/views/full/choice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class Choice extends React.Component {
}

updateParent = () => {
console.log('UPDATE')
this.props.onDataChanged &&
this.props.onDataChanged({
contentId: this.state.contentId,
Expand Down Expand Up @@ -141,9 +140,9 @@ export class Choice extends React.Component {
)

const contentPickerProps = {}
const contentElement = this.getContentElement()
if (contentElement && contentElement.length) {
contentPickerProps.categoryId = contentElement
const contentType = this.getContentType()
if (contentType && contentType.length) {
contentPickerProps.categoryId = contentType
}

return (
Expand All @@ -154,7 +153,7 @@ export class Choice extends React.Component {
<div>
<ContentPickerWidget
{...contentPickerProps}
contentType={this.getContentElement()}
contentType={this.getContentType()}
itemId={this.state.contentId}
onChange={this.onContentChanged}
placeholder="Pick content (question and choices)"
Expand All @@ -168,7 +167,8 @@ export class Choice extends React.Component {
)
}

getContentElement() {
getContentType() {
// FIXME: defaultContentElement should really be defaultContentType in the config
return typeof this.state.config.contentElement === 'string'
? this.state.config.contentElement
: this.state.defaultConfig && this.state.defaultConfig.defaultContentElement
Expand All @@ -194,11 +194,10 @@ export class Choice extends React.Component {
}

renderAdvanced() {
console.log('state', this.state)
return (
<div className={style.content}>
<div>
<Label htmlFor="inputMaxRetries">Max number of retries</Label>
<Label htmlFor="inputMaxRetries">Max number of retries:</Label>
<Input
id="inputMaxRetries"
type="number"
Expand All @@ -222,11 +221,11 @@ export class Choice extends React.Component {
</div>

<div>
<Label htmlFor="contentElementName">Content Element to use (optionnal)</Label>
<Label htmlFor="contentElementType">Default choice content type:</Label>
<Input
id="contentElementName"
id="contentElementType"
type="text"
value={this.getContentElement()}
value={this.getContentType()}
onChange={this.handleConfigTextChanged('contentElement')}
/>
</div>
Expand Down
17 changes: 17 additions & 0 deletions modules/basic-skills/src/views/full/style.scss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is automatically generated.
// Please do not change this file!
interface CssExports {
'actionSelect': string;
'callApiNote': string;
'callApiSection': string;
'callApiWarning': string;
'contentPicker': string;
'intentSelect': string;
'keywords': string;
'modalContent': string;
'notFoundSelect': string;
'slotSelect': string;
'warning': string;
}
declare var cssExports: CssExports;
export = cssExports;

0 comments on commit ad4ea28

Please sign in to comment.