Skip to content

Commit

Permalink
fix(qna): fix pagination not appearing on initial render (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaminond committed Oct 5, 2018
1 parent 94d4a25 commit 87fba19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/functionals/botpress-qna/src/index.js
Expand Up @@ -215,7 +215,7 @@ module.exports = {
router.get('/', async ({ query: { question = '', categories = [], limit, offset } }, res) => {
try {
const items = await getQuestions({ question, categories }, { limit, offset })
res.send({ ...items, hasCategory: !!this.isMicrosoftMakerUsed })
res.send({ ...items })
} catch (e) {
logger.error('QnA Error', e, e.stack)
res.status(500).send(e.message || 'Error')
Expand Down
2 changes: 1 addition & 1 deletion packages/functionals/botpress-qna/src/views/FormModal.js
Expand Up @@ -164,7 +164,7 @@ export default class FormModal extends Component {

<Modal.Body className={style.qnaModalBody}>
{this.alertMessage()}
{this.props.hasCategory ? (
{categories.length ? (
<div className={style.qnaCategory}>
<span className={style.qnaCategoryTitle}>Category</span>
<Select
Expand Down
23 changes: 13 additions & 10 deletions packages/functionals/botpress-qna/src/views/index.js
Expand Up @@ -40,12 +40,11 @@ export default class QnaAdmin extends Component {
showBulkImport: undefined,
page: 1,
overallItemsCount: 0,
hasCategory: false,
showQnAModal: false,
category: '',
QnAModalType: 'create',
quentionsOptions: [],
categoriesOptions: [],
categoryOptions: [],
filterCategory: [],
filterQuestion: '',
selectedQuestion: []
Expand All @@ -69,15 +68,20 @@ export default class QnaAdmin extends Component {
value: id
}))

this.setState({ ...data, page, quentionsOptions })
this.setState({
items: data.items,
overallItemsCount: data.count,
page,
quentionsOptions
})
})
}

fetchCategories() {
this.props.bp.axios.get('/api/botpress-qna/categories').then(({ data: { categories } }) => {
const categoriesOptions = categories.map(category => ({ label: category, value: category }))
const categoryOptions = categories.map(category => ({ label: category, value: category }))

this.setState({ categoriesOptions })
this.setState({ categoryOptions })
})
}

Expand Down Expand Up @@ -275,12 +279,12 @@ export default class QnaAdmin extends Component {
onChange={this.onQuestioinsFilter}
placeholder="Filter questions"
/>
{this.state.hasCategory ? (
{this.state.categoryOptions.length ? (
<Select
className={style.serachQuestions}
multi
value={this.state.filterCategory}
options={this.state.categoriesOptions}
options={this.state.categoryOptions}
onChange={this.onCategoriesFilter}
placeholder="Filter caterories"
/>
Expand Down Expand Up @@ -329,7 +333,7 @@ export default class QnaAdmin extends Component {
</div>
</div>
</div>
{this.state.hasCategory || item.category ? (
{item.category ? (
<div className={style.questionCategory}>
Category: <span className={style.questionCategoryTitle}>&nbsp;{item.category}</span>
</div>
Expand Down Expand Up @@ -426,8 +430,7 @@ export default class QnaAdmin extends Component {
bp={this.props.bp}
showQnAModal={this.state.showQnAModal}
closeQnAModal={this.closeQnAModal}
hasCategory={this.state.hasCategory}
categories={this.state.categoriesOptions}
categories={this.state.categoryOptions}
fetchData={this.fetchData}
id={this.state.currentItemId}
modalType={this.state.QnAModalType}
Expand Down

0 comments on commit 87fba19

Please sign in to comment.