Skip to content

Commit

Permalink
Add result list to search huids method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Sep 11, 2024
1 parent 9398050 commit 27f2d35
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 16 deletions.
32 changes: 32 additions & 0 deletions frontend/app/modules/bot-command/AttrList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { FC } from 'react'
import styled from 'styled-components'
import { AttrResponse } from './bot-command.types'

const AttrDiv = styled.div`
display: flex;
margin-bottom: 6px;
& > svg {
margin-left: 10px;
cursor: pointer;
width: 16px;
height: 16px;
min-width: 16px;
min-height: 16px;
}
& > span {
margin-right: 6px;
}
`

const AttrList: FC<{ attrs: AttrResponse[] }> = ({ attrs }) => {
return attrs.map(({ attr, value }, idx) => (
<AttrDiv key={idx}>
<span>{attr}:</span>
<b>{value}</b>
</AttrDiv>
))
}

export default AttrList
12 changes: 4 additions & 8 deletions frontend/app/modules/bot-command/FileCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Button from '../../components/Button'
import RemoveIcon from '../../assets/clear-input.svg'
import JsonViewer from '../../components/JsonViewer'
import MainLoader from '../../components/MainLoader'
import AttrList from './AttrList'

const FileDiv = styled.div`
display: flex;
Expand Down Expand Up @@ -69,17 +70,12 @@ const FileCommand: FC<BotCommandPageProps> = ({ botFeature }) => {
</FileDiv>
))}
<br />
{!!store.filesResponse.length &&
store.filesResponse.map(({ attr, value }, idx) => (
<FileDiv key={idx}>
<span>{attr}:</span>
<b>{value}</b>
</FileDiv>
))}
<br />
<Button onClick={handleSubmit} id="submit" title="Отправить" icon="send" disabled={!store.files.length} />
<br />
<br />
{!!store.filesResponse.length && <AttrList attrs={store.filesResponse} />}
<br />
<br />
{store.response && <JsonViewer data={store.response} id="response" />}
{store.isLoading && <MainLoader />}
</>
Expand Down
6 changes: 6 additions & 0 deletions frontend/app/modules/bot-command/TextCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import JsonViewer from '../../components/JsonViewer'
import Input from '../../components/Input'
import Button from '../../components/Button'
import UuidInput from './UuidInput'
import AttrList from './AttrList'

const TextCommand: FC<BotCommandPageProps> = ({ botFeature }) => {
const { botCommandStore: store } = useStore()
const [formData, setFormData] = useState<{ [key: string]: string | string[] | FileData[] }>({})

useEffect(() => {
store.clearResponse()
store.clearHuids()
}, [])

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -33,6 +35,7 @@ const TextCommand: FC<BotCommandPageProps> = ({ botFeature }) => {
)

const handleSubmit = () => {
store.clearHuids()
store.sendTextAppEvent(botFeature.method, formData)
}

Expand Down Expand Up @@ -61,6 +64,9 @@ const TextCommand: FC<BotCommandPageProps> = ({ botFeature }) => {
<Button onClick={handleSubmit} id="submit" title="Отправить" icon="send" />
<br />
<br />
{botFeature.method === 'search_users' && <AttrList attrs={store.huidsResponse} />}
<br />
<br />
{store.response && <JsonViewer data={store.response} id="response" />}
</>
)
Expand Down
20 changes: 15 additions & 5 deletions frontend/app/modules/bot-command/bot-command.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import * as SDK from '@expressms/smartapp-sdk'
import { RootStore } from '../../store/rootStore'
import { STATUS, StatusResponse } from '@expressms/smartapp-sdk/build/main/types'
import { makeAutoObservable, runInAction } from 'mobx'
import { FileData, FileTextResponse, UploadFileResponse, UploadFilesResponse } from './bot-command.types'
import { FileData, AttrResponse, UploadFileResponse, UploadFilesResponse } from './bot-command.types'

export class BotCommandStore {
rootStore: RootStore
response: object | null
files: FileData[]
filesResponse: FileTextResponse[]
filesResponse: AttrResponse[]
huidsResponse: AttrResponse[]
isLoading: boolean

constructor(rootStore: RootStore) {
Expand All @@ -18,6 +19,7 @@ export class BotCommandStore {
this.response = null
this.files = []
this.filesResponse = []
this.huidsResponse = []
this.isLoading = false
}

Expand All @@ -38,6 +40,11 @@ export class BotCommandStore {
if (method === 'send_notification') {
this.rootStore.toastStore.showToast('NotificationStatus: ok', 6000)
}

if (method === 'search_users') {
// @ts-expect-error: object cast error
this.huidsResponse = this.parseTextResponse(response.payload?.result)
}
})
} catch (e) {
this.rootStore.toastStore.showToast(`Ошибка при отправке команды ${e?.message}`)
Expand Down Expand Up @@ -87,12 +94,15 @@ export class BotCommandStore {
this.filesResponse = []
}

private parseFilesResponse(text: string): Array<FileTextResponse> {
clearHuids() {
this.huidsResponse = []
}

private parseTextResponse(text: string): Array<AttrResponse> {
return text
.split('\n')
.filter(textRow => !!textRow.trim())
.map(textRow => {
console.log(textRow)
const [attr, rawText] = textRow.split(':')
return {
attr,
Expand Down Expand Up @@ -120,7 +130,7 @@ export class BotCommandStore {
this.response = response

// @ts-expect-error: object cast error
this.filesResponse = this.parseFilesResponse(response.payload?.result)
this.filesResponse = this.parseTextResponse(response.payload?.result)
})
} catch (e) {
this.rootStore.toastStore.showToast(`Ошибка при отправке команды с файлами ${e?.message}`)
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/modules/bot-command/bot-command.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface UploadFilesResponse extends Omit<EmitterEventPayload, 'payload'
}
}

export type FileTextResponse = {
export type AttrResponse = {
attr: string
value: string
}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-feature-smartapp",
"version": "2.4.3",
"version": "2.4.4",
"description": "SmartApp with all features",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/smartapp-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"manifestVersion": "1.0.0",
"smartAppVersion": "",
"bundlePath": "",
"changeLog": "CCS-100748 Очистка кеша"
"changeLog": "Вывод найденных пользователей"
}

0 comments on commit 27f2d35

Please sign in to comment.