|
@@ -1,25 +1,25 @@
|
|
|
'use client'
|
|
|
|
|
|
import List from './list'
|
|
|
-import React, { useEffect, useState } from 'react'
|
|
|
+import React, { useEffect, useRef, useState } from 'react'
|
|
|
import Input from '@/app/components/base/input'
|
|
|
import cn from '@/utils/classnames'
|
|
|
import { RiAddLine, RiPriceTagLine, RiRefreshLine, RiSearchLine } from '@remixicon/react'
|
|
|
import Button from '@/app/components/base/button'
|
|
|
import useSWR from 'swr'
|
|
|
-import { fetchCorpus, fetchIntentName, fetchIntentType } from '@/service/common'
|
|
|
+import { fetchIntent, fetchIntentType } from '@/service/common'
|
|
|
import { SimpleSelect } from '@/app/components/base/select'
|
|
|
import DetailModal from './detail-modal'
|
|
|
import TypeModal from './type-modal'
|
|
|
|
|
|
const CorpusIndex = () => {
|
|
|
- const [page, setPage] = React.useState<number>(0)
|
|
|
+ const [page, setPage] = useState<number>(0)
|
|
|
const [limit, setLimit] = useState<number>(10)
|
|
|
- const [question, setQuestion] = useState<string>('') // the input value
|
|
|
+ const [intentName, setIntentName] = useState<string>('') // the input value
|
|
|
const [intentType, setIntentType] = useState<string>('') // the input value
|
|
|
- const { data: dataOptionsIntentType }: any = useSWR(
|
|
|
+ const { data: dataOptionsIntentType, mutate: mutateOptionsIntentType }: any = useSWR(
|
|
|
{
|
|
|
- url: '/xxx',
|
|
|
+ url: '/intentions/types',
|
|
|
params: {
|
|
|
page: 1,
|
|
|
limit: 1000,
|
|
@@ -28,53 +28,47 @@ const CorpusIndex = () => {
|
|
|
fetchIntentType,
|
|
|
)
|
|
|
const optionsIntentType: any = dataOptionsIntentType?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
|
|
|
- const [intentName, setIntentName] = useState<string>('') // the input value
|
|
|
- const { data: dataOptionsIntentName }: any = useSWR(
|
|
|
- {
|
|
|
- url: '/xxx',
|
|
|
- params: {
|
|
|
- page: 1,
|
|
|
- limit: 1000,
|
|
|
- intentType,
|
|
|
- },
|
|
|
- },
|
|
|
- fetchIntentName,
|
|
|
- )
|
|
|
- const optionsIntentName: any = dataOptionsIntentName?.data.map((v: any) => ({ name: v.name, value: v.id })) || []
|
|
|
- const [query, setQuery] = useState<any>({})
|
|
|
- const { data, mutate }: any = useSWR(
|
|
|
- {
|
|
|
- url: '/xxx',
|
|
|
- params: {
|
|
|
- page: page + 1,
|
|
|
- limit,
|
|
|
- ...query,
|
|
|
- },
|
|
|
- },
|
|
|
- fetchCorpus,
|
|
|
- )
|
|
|
- const list: any = data?.data || []
|
|
|
- const total = data?.total || 0
|
|
|
+ const query = useRef<any>({})
|
|
|
+ const [list, setList] = useState<any>([])
|
|
|
+ const [total, setTotal] = useState(0)
|
|
|
+ const handlePage = () => {
|
|
|
+ const params: any = {
|
|
|
+ page: page + 1,
|
|
|
+ limit,
|
|
|
+ }
|
|
|
+ if (query.current.intentType)
|
|
|
+ params.type_id = query.current.intentType
|
|
|
+ if (query.current.intentName)
|
|
|
+ params.name_search = query.current.intentName
|
|
|
+ fetchIntent({
|
|
|
+ url: '/intentions',
|
|
|
+ params,
|
|
|
+ }).then((res: any) => {
|
|
|
+ setList(res.data)
|
|
|
+ setTotal(res.total)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const [refresh, setRefresh] = useState<boolean>(false)
|
|
|
const handleSearch = (reset = false) => {
|
|
|
+ setRefresh(true)
|
|
|
+ setPage(0)
|
|
|
if (reset) {
|
|
|
- setQuestion('')
|
|
|
setIntentName('')
|
|
|
setIntentType('')
|
|
|
+ query.current = {}
|
|
|
}
|
|
|
- const params: any = {}
|
|
|
- if (question)
|
|
|
- params.question = question
|
|
|
- if (intentType)
|
|
|
- params.intentType = intentType
|
|
|
- if (intentName)
|
|
|
- params.intentName = intentName
|
|
|
- setQuery(params)
|
|
|
- setPage(0)
|
|
|
+ else {
|
|
|
+ query.current = {
|
|
|
+ intentType, intentName,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ handlePage()
|
|
|
+ setRefresh(false)
|
|
|
}
|
|
|
useEffect(() => {
|
|
|
- mutate()
|
|
|
+ if (!refresh)
|
|
|
+ handlePage()
|
|
|
}, [page, limit])
|
|
|
-
|
|
|
const [detailModalVisible, setDetailModalVisible] = useState(false)
|
|
|
const [transfer, setTransfer] = useState<any>({
|
|
|
mode: 'add',
|
|
@@ -106,9 +100,9 @@ const CorpusIndex = () => {
|
|
|
className="ml-2"
|
|
|
showClearIcon
|
|
|
wrapperClassName='!w-[200px]'
|
|
|
- value={question}
|
|
|
- onChange={e => setQuestion(e.target.value)}
|
|
|
- onClear={() => setQuestion('')}
|
|
|
+ value={intentName}
|
|
|
+ onChange={e => setIntentName(e.target.value)}
|
|
|
+ onClear={() => setIntentName('')}
|
|
|
/>
|
|
|
</div>
|
|
|
<Button variant='primary' className={cn('ml-auto shrink-0')} onClick={() => {
|
|
@@ -143,8 +137,8 @@ const CorpusIndex = () => {
|
|
|
</div>
|
|
|
<div className="flex-1">
|
|
|
<List
|
|
|
- list={list || []}
|
|
|
- onUpdate={mutate}
|
|
|
+ list={list}
|
|
|
+ onUpdate={() => handleSearch(false)}
|
|
|
pagination={{
|
|
|
total,
|
|
|
limit,
|
|
@@ -162,7 +156,7 @@ const CorpusIndex = () => {
|
|
|
onCancel={() => setDetailModalVisible(false)}
|
|
|
onSend={() => {
|
|
|
setDetailModalVisible(false)
|
|
|
- mutate()
|
|
|
+ handleSearch()
|
|
|
}}
|
|
|
/>
|
|
|
)
|
|
@@ -170,10 +164,9 @@ const CorpusIndex = () => {
|
|
|
{
|
|
|
showIntentTypeModalVisible && (
|
|
|
<TypeModal
|
|
|
- onCancel={() => setShowIntentTypeModalVisible(false)}
|
|
|
- onSend={() => {
|
|
|
+ onCancel={() => {
|
|
|
+ mutateOptionsIntentType()
|
|
|
setShowIntentTypeModalVisible(false)
|
|
|
- // mutate()
|
|
|
}}
|
|
|
/>
|
|
|
)
|