Skip to content

Commit

Permalink
feat(core): implement auto pick content (resolve #517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Paniontko committed Jun 19, 2018
1 parent 536c297 commit d100d87
Show file tree
Hide file tree
Showing 3 changed files with 717 additions and 601 deletions.
13 changes: 9 additions & 4 deletions packages/core/botpress/src/content/service.js
Expand Up @@ -314,23 +314,28 @@ module.exports = async ({ botfile, projectLocation, logger, ghostManager }) => {
const item = { formData, ...(await fillComputedProps(category, formData)) }
const body = transformItemApiToDb(item)

if (itemId) {
const isNewItemCreation = !itemId
if (isNewItemCreation) {
itemId = getNewItemId(category)
}

if (!isNewItemCreation) {
await knex('content_items')
.update(body)
.where({ id: itemId })
.then()
} else {
const newItemId = getNewItemId(category)
await knex('content_items').insert({
...body,
createdBy: 'admin',
createdOn: helpers(knex).date.now(),
id: newItemId,
id: itemId,
categoryId
})
}

return dumpDataToFile(categoryId)
await dumpDataToFile(categoryId)
return itemId
}

const categoryItemsCount = categoryId => {
Expand Down
14 changes: 10 additions & 4 deletions packages/core/botpress/src/web/components/Content/Select/index.js
Expand Up @@ -114,15 +114,21 @@ class SelectContent extends Component {
this.setState({ newItemData: data })
}

resetCreateContent = (resetSearch = false) => () => {
resetCreateContent = (resetSearch = false) => response => {
const item = Object.assign(this.state.newItemData, { id: response.data })
const stateUpdate = { newItemCategory: null, newItemData: null }
if (resetSearch) {
Object.assign(stateUpdate, {
searchTerm: '',
activeItemIndex: 0
})
}
return new Promise(resolve => this.setState(stateUpdate, resolve))
return new Promise(resolve =>
this.setState(stateUpdate, () => {
this.handlePick(item)
resolve()
})
)
}

onClose = () => {
Expand Down Expand Up @@ -212,8 +218,8 @@ class SelectContent extends Component {
if (!categories.length) {
return (
<Alert bsStyle="warning">
<strong>We think you don't have any content types defined.</strong> Please&nbsp;
<a href="https://botpress.io/docs/foundamentals/content/" target="_blank">
<strong>We think you don&apos;t have any content types defined.</strong> Please&nbsp;
<a href="https://botpress.io/docs/foundamentals/content/" target="_blank" rel="noopener noreferrer">
<strong>read the docs</strong>
</a>
&nbsp;to see how you can make use of this feature.
Expand Down

0 comments on commit d100d87

Please sign in to comment.