list.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. 'use client'
  2. import Pagination, { type Props as PaginationProps } from '@/app/components/base/pagination'
  3. import type { FC } from 'react'
  4. import { useState } from 'react'
  5. import Button from '@/app/components/base/button'
  6. import cn from '@/utils/classnames'
  7. import { delIntent } from '@/service/common'
  8. import Confirm from '@/app/components/base/confirm'
  9. import DetailModal from './detail-modal'
  10. import useTimestamp from '@/hooks/use-timestamp'
  11. import { useTranslation } from 'react-i18next'
  12. type PageListProps = {
  13. list: []
  14. pagination: PaginationProps
  15. onUpdate: () => void
  16. }
  17. const IntentPageList: FC<PageListProps> = ({
  18. list = [],
  19. pagination,
  20. onUpdate,
  21. }) => {
  22. const { t } = useTranslation()
  23. const { formatTime } = useTimestamp()
  24. const [showConfirmDelete, setShowConfirmDelete] = useState(false)
  25. const [row, setRow] = useState<any>({})
  26. const handleDel = async () => {
  27. try {
  28. await delIntent({
  29. url: `/intentions/${row.id}`,
  30. body: {},
  31. })
  32. setShowConfirmDelete(false)
  33. onUpdate()
  34. }
  35. catch (e) { }
  36. }
  37. const [detailModalVisible, setDetailModalVisible] = useState(false)
  38. const [transfer, setTransfer] = useState<any>({
  39. mode: 'add',
  40. row: {},
  41. })
  42. return (
  43. <>
  44. <div className='relative flex h-full w-full flex-col'>
  45. <div className='relative grow overflow-x-auto'>
  46. <table className={'mt-3 w-full min-w-[700px] max-w-full border-collapse border-0 text-sm'}>
  47. <thead className="h-8 border-b border-divider-subtle text-xs font-medium uppercase leading-8 text-text-tertiary">
  48. <tr>
  49. <td>意图类型</td>
  50. <td>意图名称</td>
  51. <td>语料数量</td>
  52. <td>关键词数量</td>
  53. <td>创建时间</td>
  54. <td className="w-[120px] text-center">操作</td>
  55. </tr>
  56. </thead>
  57. <tbody className="text-text-secondary">
  58. {list.map((item: any, index) => (
  59. <tr
  60. key={item.id}
  61. className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
  62. >
  63. <td>{item.type_name}</td>
  64. <td>{item.name}</td>
  65. <td>{item.corpus_count}</td>
  66. <td>{item.keywords_count}</td>
  67. <td>{formatTime(item.created_at, t('datasetHitTesting.dateTimeFormat') as string)}</td>
  68. <td className="flex justify-center gap-2">
  69. <Button variant='ghost-accent' size='small' className={cn('shrink-0')} onClick={() => {
  70. setTransfer({
  71. mode: 'edit',
  72. row: JSON.parse(JSON.stringify(item)),
  73. })
  74. setDetailModalVisible(true)
  75. }}>
  76. 编辑
  77. </Button>
  78. <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} onClick={() => {
  79. setRow(item)
  80. setShowConfirmDelete(true)
  81. }}>
  82. 刪除
  83. </Button>
  84. </td>
  85. </tr>
  86. ))}
  87. </tbody>
  88. </table>
  89. </div>
  90. {/* Show Pagination only if the total is more than the limit */}
  91. {pagination.total && (
  92. <Pagination
  93. {...pagination}
  94. className='w-full shrink-0 px-0 pb-0'
  95. />
  96. )}
  97. </div>
  98. {showConfirmDelete && (
  99. <Confirm
  100. title="删除确认"
  101. content={`请确认是否删除${row.name}?`}
  102. isShow={showConfirmDelete}
  103. onConfirm={handleDel}
  104. onCancel={() => setShowConfirmDelete(false)}
  105. />
  106. )}
  107. {
  108. detailModalVisible && (
  109. <DetailModal
  110. transfer={transfer}
  111. onCancel={() => {
  112. setDetailModalVisible(false)
  113. onUpdate()
  114. }}
  115. onSend={() => {
  116. setDetailModalVisible(false)
  117. onUpdate()
  118. }}
  119. />
  120. )
  121. }
  122. </>
  123. )
  124. }
  125. export default IntentPageList