|
|
|
|
@ -13,7 +13,6 @@ import s from './style.module.css'
|
|
|
|
|
import Loading from '@/app/components/base/loading'
|
|
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
|
import Input from '@/app/components/base/input'
|
|
|
|
|
import Pagination from '@/app/components/base/pagination'
|
|
|
|
|
import { get } from '@/service/base'
|
|
|
|
|
import { createDocument, fetchDocuments } from '@/service/datasets'
|
|
|
|
|
import { useDatasetDetailContext } from '@/context/dataset-detail'
|
|
|
|
|
@ -22,8 +21,6 @@ import type { NotionPage } from '@/models/common'
|
|
|
|
|
import type { CreateDocumentReq } from '@/models/datasets'
|
|
|
|
|
import { DataSourceType } from '@/models/datasets'
|
|
|
|
|
import RetryButton from '@/app/components/base/retry-button'
|
|
|
|
|
// Custom page count is not currently supported.
|
|
|
|
|
const limit = 15
|
|
|
|
|
|
|
|
|
|
const FolderPlusIcon = ({ className }: React.SVGProps<SVGElement>) => {
|
|
|
|
|
return <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" className={className ?? ''}>
|
|
|
|
|
@ -75,12 +72,14 @@ type IDocumentsProps = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const fetcher = (url: string) => get(url, {}, {})
|
|
|
|
|
const DEFAULT_LIMIT = 15
|
|
|
|
|
|
|
|
|
|
const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
const [inputValue, setInputValue] = useState<string>('') // the input value
|
|
|
|
|
const [searchValue, setSearchValue] = useState<string>('')
|
|
|
|
|
const [currPage, setCurrPage] = React.useState<number>(0)
|
|
|
|
|
const [limit, setLimit] = useState<number>(DEFAULT_LIMIT)
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const { dataset } = useDatasetDetailContext()
|
|
|
|
|
const [notionPageSelectorModalVisible, setNotionPageSelectorModalVisible] = useState(false)
|
|
|
|
|
@ -94,7 +93,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
|
|
|
|
|
|
|
|
const query = useMemo(() => {
|
|
|
|
|
return { page: currPage + 1, limit, keyword: debouncedSearchValue, fetch: isDataSourceNotion ? true : '' }
|
|
|
|
|
}, [currPage, debouncedSearchValue, isDataSourceNotion])
|
|
|
|
|
}, [currPage, debouncedSearchValue, isDataSourceNotion, limit])
|
|
|
|
|
|
|
|
|
|
const { data: documentsRes, error, mutate } = useSWR(
|
|
|
|
|
{
|
|
|
|
|
@ -246,13 +245,20 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
|
|
|
{isLoading
|
|
|
|
|
? <Loading type='app' />
|
|
|
|
|
: total > 0
|
|
|
|
|
? <List embeddingAvailable={embeddingAvailable} documents={documentsList || []} datasetId={datasetId} onUpdate={mutate} />
|
|
|
|
|
? <List
|
|
|
|
|
embeddingAvailable={embeddingAvailable}
|
|
|
|
|
documents={documentsList || []}
|
|
|
|
|
datasetId={datasetId} onUpdate={mutate}
|
|
|
|
|
pagination={{
|
|
|
|
|
total,
|
|
|
|
|
limit,
|
|
|
|
|
onLimitChange: setLimit,
|
|
|
|
|
current: currPage,
|
|
|
|
|
onChange: setCurrPage,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
: <EmptyElement canAdd={embeddingAvailable} onClick={routeToDocCreate} type={isDataSourceNotion ? 'sync' : 'upload'} />
|
|
|
|
|
}
|
|
|
|
|
{/* Show Pagination only if the total is more than the limit */}
|
|
|
|
|
{(total && total > limit)
|
|
|
|
|
? <Pagination current={currPage} onChange={setCurrPage} total={total} limit={limit} />
|
|
|
|
|
: null}
|
|
|
|
|
<NotionPageSelectorModal
|
|
|
|
|
isShow={notionPageSelectorModalVisible}
|
|
|
|
|
onClose={() => setNotionPageSelectorModalVisible(false)}
|
|
|
|
|
|