forked from botpress/v12
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
509 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 79 additions & 37 deletions
116
modules/misunderstood/src/views/full/MainScreen/AmendForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,91 @@ | ||
import { Button, ButtonGroup, Intent } from '@blueprintjs/core' | ||
import { AxiosStatic } from 'axios' | ||
import React from 'react' | ||
|
||
import { RESOLUTION_TYPE } from '../../../types' | ||
|
||
import style from './style.scss' | ||
import QnAPicker from './QnAPicker' | ||
|
||
const AmendForm = ({ mode, setMode }) => ( | ||
<div className={style.amendForm}> | ||
<h5>What is this message type?</h5> | ||
interface Props { | ||
axios: AxiosStatic | ||
language: string | ||
mode: RESOLUTION_TYPE | ||
resolution: string | null | ||
resolutionParams: string | object | null | ||
setMode: (mode: RESOLUTION_TYPE) => void | ||
onUpdate: (resolution: string, resolutionParams?: string | object | null) => void | ||
onSave: () => void | ||
onCancel: () => void | ||
} | ||
|
||
<ButtonGroup> | ||
<Button | ||
onClick={() => { | ||
if (mode === RESOLUTION_TYPE.intent) { | ||
return | ||
} | ||
setMode(RESOLUTION_TYPE.intent) | ||
}} | ||
intent={mode === RESOLUTION_TYPE.intent ? Intent.SUCCESS : Intent.NONE} | ||
> | ||
Goal | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
if (mode === RESOLUTION_TYPE.qna) { | ||
return | ||
} | ||
setMode(RESOLUTION_TYPE.qna) | ||
}} | ||
intent={mode === RESOLUTION_TYPE.qna ? Intent.SUCCESS : Intent.NONE} | ||
> | ||
Query | ||
</Button> | ||
{mode != null && ( | ||
<Button | ||
onClick={() => { | ||
setMode(null) | ||
}} | ||
icon="undo" | ||
> | ||
Undo | ||
const AmendForm = ({ | ||
axios, | ||
language, | ||
mode, | ||
setMode, | ||
resolution, | ||
resolutionParams, | ||
onUpdate, | ||
onSave, | ||
onCancel | ||
}: Props) => ( | ||
<div className={style.amendForm}> | ||
<h4> | ||
What is this message type? | ||
<ButtonGroup> | ||
<Button | ||
onClick={() => { | ||
if (mode === RESOLUTION_TYPE.intent) { | ||
return | ||
} | ||
setMode(RESOLUTION_TYPE.intent) | ||
}} | ||
intent={mode === RESOLUTION_TYPE.intent ? Intent.SUCCESS : Intent.NONE} | ||
> | ||
Goal | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
if (mode === RESOLUTION_TYPE.qna) { | ||
return | ||
} | ||
setMode(RESOLUTION_TYPE.qna) | ||
}} | ||
intent={mode === RESOLUTION_TYPE.qna ? Intent.SUCCESS : Intent.NONE} | ||
> | ||
Query | ||
</Button> | ||
{mode != null && ( | ||
<Button | ||
onClick={() => { | ||
setMode(null) | ||
}} | ||
icon="undo" | ||
> | ||
Undo | ||
</Button> | ||
)} | ||
</ButtonGroup> | ||
</h4> | ||
|
||
{mode === RESOLUTION_TYPE.qna && ( | ||
<div className={style.amendFormPicker}> | ||
<QnAPicker axios={axios} language={language} selected={resolution} onSelect={(id: string) => { | ||
onUpdate(id) | ||
}} /> | ||
</div> | ||
)} | ||
</ButtonGroup> | ||
</div> | ||
) | ||
|
||
<ButtonGroup large> | ||
<Button onClick={onSave} icon="tick" intent={Intent.SUCCESS} disabled={!mode || !resolution}> | ||
Save | ||
</Button> | ||
<Button onClick={onCancel} icon="cross" intent={Intent.NONE}> | ||
Cancel | ||
</Button> | ||
</ButtonGroup> | ||
</div> | ||
) | ||
|
||
export default AmendForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Button, ButtonGroup, Intent } from "@blueprintjs/core" | ||
import range from "lodash/range" | ||
import uniq from "lodash/uniq" | ||
import React from "react" | ||
|
||
const buildPager = ({ pagesCount, currentPage, depth = 5 }) => { | ||
const pageNumbers = uniq( | ||
[ | ||
0, | ||
pagesCount - 1, | ||
...range(currentPage - depth, currentPage + depth + 1) | ||
].filter(n => n >= 0 && n < pagesCount) | ||
).sort((a, b) => a - b) | ||
|
||
const pager = [] | ||
|
||
for (let i = 0; i < pageNumbers.length; i++) { | ||
if (i > 0 && pageNumbers[i] !== pageNumbers[i - 1] + 1) { | ||
pager.push({ ellipsis: true }) | ||
} | ||
pager.push({ | ||
index: pageNumbers[i], | ||
displayIndex: pageNumbers[i] + 1, | ||
isCurrent: pageNumbers[i] === currentPage | ||
}) | ||
} | ||
|
||
return pager | ||
} | ||
|
||
const Pager = ({ pagesCount, currentPage, depth = 5, goTo }) => { | ||
if (pagesCount <= 1) { | ||
return null | ||
} | ||
|
||
const pager = buildPager({ pagesCount, currentPage, depth }) | ||
|
||
return ( | ||
<div> | ||
<ButtonGroup> | ||
<Button | ||
disabled={currentPage === 0} | ||
onClick={() => goTo(currentPage - 1)} | ||
> | ||
< | ||
</Button> | ||
{pager.map((el, i) => ( | ||
<Button | ||
key={i} | ||
intent={el.isCurrent ? Intent.PRIMARY : Intent.NONE} | ||
onClick={el.isCurrent ? undefined : () => goTo(el.index)} | ||
disabled={el.ellipsis} | ||
> | ||
{el.ellipsis ? <>…</> : el.displayIndex} | ||
</Button> | ||
))} | ||
<Button | ||
disabled={currentPage === pagesCount - 1} | ||
onClick={() => goTo(currentPage + 1)} | ||
> | ||
> | ||
</Button> | ||
</ButtonGroup> | ||
</div> | ||
) | ||
} | ||
|
||
export default Pager |
58 changes: 58 additions & 0 deletions
58
modules/misunderstood/src/views/full/MainScreen/QnAApiClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { AxiosRequestConfig, AxiosStatic } from "axios" | ||
|
||
const MODULE_URL_PREFIX = "/mod/qna" | ||
|
||
class QnAApiClient { | ||
constructor(private axios: AxiosStatic) { } | ||
|
||
async get(url: string, config?: AxiosRequestConfig) { | ||
const res = await this.axios.get(MODULE_URL_PREFIX + url, config) | ||
return res.data | ||
} | ||
|
||
getQuestion(id) { | ||
return this.get(`/questions/${id}`) | ||
} | ||
|
||
async getQuestions({ | ||
page, | ||
pageSize, | ||
question, | ||
categories | ||
}: { | ||
page: number; | ||
pageSize: number; | ||
question?: string; | ||
categories?: { label: string; value: string }[]; | ||
}) { | ||
const params = { | ||
limit: pageSize, | ||
offset: page * pageSize, | ||
question: question || undefined, | ||
categories: | ||
categories && categories.length | ||
? categories.map(({ value }) => value) | ||
: undefined | ||
} | ||
|
||
const data = await this.get("/questions", { params }) | ||
|
||
return { | ||
...data, | ||
// TODO: this shouldn't be needed but the API is returning more results than requested | ||
items: data.items.slice(0, pageSize) | ||
} | ||
} | ||
|
||
async getCategories() { | ||
const { | ||
data: { categories } | ||
} = await this.get("/categories") | ||
return ( | ||
categories && | ||
categories.map(category => ({ label: category, value: category })) | ||
) | ||
} | ||
} | ||
|
||
export default QnAApiClient |
Oops, something went wrong.