Fix/dataset add pages tip (#410)

This commit is contained in:
zxhlyh 2023-06-19 16:32:25 +08:00 committed by GitHub
parent ce2996e7d4
commit f797fab206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 50 deletions

View File

@ -93,7 +93,7 @@ const DatasetDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
const pathname = usePathname() const pathname = usePathname()
const hideSideBar = /documents\/create$/.test(pathname) const hideSideBar = /documents\/create$/.test(pathname)
const { t } = useTranslation() const { t } = useTranslation()
const { data: datasetRes, error } = useSWR({ const { data: datasetRes, error, mutate: mutateDatasetRes } = useSWR({
action: 'fetchDataDetail', action: 'fetchDataDetail',
datasetId, datasetId,
}, apiParams => fetchDataDetail(apiParams.datasetId)) }, apiParams => fetchDataDetail(apiParams.datasetId))
@ -168,6 +168,7 @@ const DatasetDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
<DatasetDetailContext.Provider value={{ <DatasetDetailContext.Provider value={{
indexingTechnique: datasetRes?.indexing_technique, indexingTechnique: datasetRes?.indexing_technique,
dataset: datasetRes, dataset: datasetRes,
mutateDatasetRes: () => mutateDatasetRes(),
}}> }}>
<div className="bg-white grow">{children}</div> <div className="bg-white grow">{children}</div>
</DatasetDetailContext.Provider> </DatasetDetailContext.Provider>

View File

@ -12,6 +12,7 @@ import { upload } from '@/service/base'
type IFileUploaderProps = { type IFileUploaderProps = {
file?: FileEntity file?: FileEntity
titleClassName?: string
onFileUpdate: (file?: FileEntity) => void onFileUpdate: (file?: FileEntity) => void
} }
@ -29,7 +30,7 @@ const ACCEPTS = [
const MAX_SIZE = 15 * 1024 * 1024 const MAX_SIZE = 15 * 1024 * 1024
const FileUploader = ({ file, onFileUpdate }: IFileUploaderProps) => { const FileUploader = ({ file, onFileUpdate, titleClassName }: IFileUploaderProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const { notify } = useContext(ToastContext) const { notify } = useContext(ToastContext)
const [dragging, setDragging] = useState(false) const [dragging, setDragging] = useState(false)
@ -189,7 +190,7 @@ const FileUploader = ({ file, onFileUpdate }: IFileUploaderProps) => {
accept={ACCEPTS.join(',')} accept={ACCEPTS.join(',')}
onChange={fileChangeHandle} onChange={fileChangeHandle}
/> />
<div className={s.title}>{t('datasetCreation.stepOne.uploader.title')}</div> <div className={cn(s.title, titleClassName)}>{t('datasetCreation.stepOne.uploader.title')}</div>
<div ref={dropRef}> <div ref={dropRef}>
{!currentFile && !file && ( {!currentFile && !file && (
<div className={cn(s.uploader, dragging && s.dragging)}> <div className={cn(s.uploader, dragging && s.dragging)}>

View File

@ -12,10 +12,11 @@ import type { DataSourceNotionPage } from '@/models/common'
import { DataSourceType } from '@/models/datasets' import { DataSourceType } from '@/models/datasets'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import { NotionPageSelector } from '@/app/components/base/notion-page-selector' import { NotionPageSelector } from '@/app/components/base/notion-page-selector'
import { useDatasetDetailContext } from '@/context/dataset-detail'
type IStepOneProps = { type IStepOneProps = {
datasetId?: string datasetId?: string
dataSourceType: DataSourceType dataSourceType?: DataSourceType
dataSourceTypeDisable: Boolean dataSourceTypeDisable: Boolean
hasConnection: boolean hasConnection: boolean
onSetting: () => void onSetting: () => void
@ -58,6 +59,7 @@ const StepOne = ({
notionPages = [], notionPages = [],
updateNotionPages, updateNotionPages,
}: IStepOneProps) => { }: IStepOneProps) => {
const { dataset } = useDatasetDetailContext()
const [showModal, setShowModal] = useState(false) const [showModal, setShowModal] = useState(false)
const [showFilePreview, setShowFilePreview] = useState(true) const [showFilePreview, setShowFilePreview] = useState(true)
const [currentNotionPage, setCurrentNotionPage] = useState<Page | undefined>() const [currentNotionPage, setCurrentNotionPage] = useState<Page | undefined>()
@ -77,11 +79,19 @@ const StepOne = ({
setCurrentNotionPage(undefined) setCurrentNotionPage(undefined)
} }
const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type)
return ( return (
<div className='flex w-full h-full'> <div className='flex w-full h-full'>
<div className='grow overflow-y-auto relative'> <div className='grow overflow-y-auto relative'>
{
shouldShowDataSourceTypeList && (
<div className={s.stepHeader}>{t('datasetCreation.steps.one')}</div> <div className={s.stepHeader}>{t('datasetCreation.steps.one')}</div>
)
}
<div className={s.form}> <div className={s.form}>
{
shouldShowDataSourceTypeList && (
<div className={s.dataSourceTypeList}> <div className={s.dataSourceTypeList}>
<div <div
className={cn( className={cn(
@ -124,9 +134,11 @@ const StepOne = ({
{t('datasetCreation.stepOne.dataSourceType.web')} {t('datasetCreation.stepOne.dataSourceType.web')}
</div> </div>
</div> </div>
)
}
{dataSourceType === DataSourceType.FILE && ( {dataSourceType === DataSourceType.FILE && (
<> <>
<FileUploader onFileUpdate={updateFile} file={file} /> <FileUploader onFileUpdate={updateFile} file={file} titleClassName={(!shouldShowDataSourceTypeList) ? 'mt-[30px] !mb-[44px] !text-lg !font-semibold !text-gray-900' : undefined} />
<Button disabled={!file} className={s.submitButton} type='primary' onClick={onStepChange}>{t('datasetCreation.stepOne.button')}</Button> <Button disabled={!file} className={s.submitButton} type='primary' onClick={onStepChange}>{t('datasetCreation.stepOne.button')}</Button>
</> </>
)} )}

View File

@ -24,6 +24,7 @@ import { formatNumber } from '@/utils/format'
import type { DataSourceNotionPage } from '@/models/common' import type { DataSourceNotionPage } from '@/models/common'
import { DataSourceType } from '@/models/datasets' import { DataSourceType } from '@/models/datasets'
import NotionIcon from '@/app/components/base/notion-icon' import NotionIcon from '@/app/components/base/notion-icon'
import { useDatasetDetailContext } from '@/context/dataset-detail'
type Page = DataSourceNotionPage & { workspace_id: string } type Page = DataSourceNotionPage & { workspace_id: string }
@ -70,6 +71,7 @@ const StepTwo = ({
onCancel, onCancel,
}: StepTwoProps) => { }: StepTwoProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const { mutateDatasetRes } = useDatasetDetailContext()
const scrollRef = useRef<HTMLDivElement>(null) const scrollRef = useRef<HTMLDivElement>(null)
const [scrolled, setScrolled] = useState(false) const [scrolled, setScrolled] = useState(false)
const previewScrollRef = useRef<HTMLDivElement>(null) const previewScrollRef = useRef<HTMLDivElement>(null)
@ -312,6 +314,8 @@ const StepTwo = ({
updateIndexingTypeCache && updateIndexingTypeCache(indexType) updateIndexingTypeCache && updateIndexingTypeCache(indexType)
updateResultCache && updateResultCache(res) updateResultCache && updateResultCache(res)
} }
if (mutateDatasetRes)
mutateDatasetRes()
onStepChange && onStepChange(+1) onStepChange && onStepChange(+1)
isSetting && onSave && onSave() isSetting && onSave && onSave()
} }

View File

@ -220,7 +220,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
? <Loading type='app' /> ? <Loading type='app' />
: total > 0 : total > 0
? <List documents={documentsList || []} datasetId={datasetId} onUpdate={mutate} /> ? <List documents={documentsList || []} datasetId={datasetId} onUpdate={mutate} />
: <EmptyElement onClick={routeToDocCreate} /> : <EmptyElement onClick={routeToDocCreate} type={isDataSourceNotion ? 'sync' : 'upload'} />
} }
{/* Show Pagination only if the total is more than the limit */} {/* Show Pagination only if the total is more than the limit */}
{(total && total > limit) {(total && total > limit)

View File

@ -1,7 +1,7 @@
import { createContext, useContext } from 'use-context-selector' import { createContext, useContext } from 'use-context-selector'
import type { DataSet } from '@/models/datasets' import type { DataSet } from '@/models/datasets'
const DatasetDetailContext = createContext<{ indexingTechnique?: string; dataset?: DataSet }>({}) const DatasetDetailContext = createContext<{ indexingTechnique?: string; dataset?: DataSet; mutateDatasetRes?: () => void }>({})
export const useDatasetDetailContext = () => useContext(DatasetDetailContext) export const useDatasetDetailContext = () => useContext(DatasetDetailContext)