Pārlūkot izejas kodu

Fix/dataset add pages tip (#410)

tags/0.3.4
zxhlyh pirms 2 gadiem
vecāks
revīzija
f797fab206
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 2
- 1
web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx Parādīt failu

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))
<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>

+ 3
- 2
web/app/components/datasets/create/file-uploader/index.tsx Parādīt failu



type IFileUploaderProps = { type IFileUploaderProps = {
file?: FileEntity file?: FileEntity
titleClassName?: string
onFileUpdate: (file?: FileEntity) => void onFileUpdate: (file?: FileEntity) => void
} }




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)
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)}>

+ 57
- 45
web/app/components/datasets/create/step-one/index.tsx Parādīt failu

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
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>()
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'>
<div className={s.stepHeader}>{t('datasetCreation.steps.one')}</div>
{
shouldShowDataSourceTypeList && (
<div className={s.stepHeader}>{t('datasetCreation.steps.one')}</div>
)
}
<div className={s.form}> <div className={s.form}>
<div className={s.dataSourceTypeList}>
<div
className={cn(
s.dataSourceItem,
dataSourceType === DataSourceType.FILE && s.active,
dataSourceTypeDisable && dataSourceType !== DataSourceType.FILE && s.disabled,
)}
onClick={() => {
if (dataSourceTypeDisable)
return
changeType(DataSourceType.FILE)
hidePreview()
}}
>
<span className={cn(s.datasetIcon)} />
{t('datasetCreation.stepOne.dataSourceType.file')}
</div>
<div
className={cn(
s.dataSourceItem,
dataSourceType === DataSourceType.NOTION && s.active,
dataSourceTypeDisable && dataSourceType !== DataSourceType.NOTION && s.disabled,
)}
onClick={() => {
if (dataSourceTypeDisable)
return
changeType(DataSourceType.NOTION)
hidePreview()
}}
>
<span className={cn(s.datasetIcon, s.notion)} />
{t('datasetCreation.stepOne.dataSourceType.notion')}
</div>
<div
className={cn(s.dataSourceItem, s.disabled, dataSourceType === DataSourceType.WEB && s.active)}
// onClick={() => changeType(DataSourceType.WEB)}
>
<span className={s.comingTag}>Coming soon</span>
<span className={cn(s.datasetIcon, s.web)} />
{t('datasetCreation.stepOne.dataSourceType.web')}
</div>
</div>
{
shouldShowDataSourceTypeList && (
<div className={s.dataSourceTypeList}>
<div
className={cn(
s.dataSourceItem,
dataSourceType === DataSourceType.FILE && s.active,
dataSourceTypeDisable && dataSourceType !== DataSourceType.FILE && s.disabled,
)}
onClick={() => {
if (dataSourceTypeDisable)
return
changeType(DataSourceType.FILE)
hidePreview()
}}
>
<span className={cn(s.datasetIcon)} />
{t('datasetCreation.stepOne.dataSourceType.file')}
</div>
<div
className={cn(
s.dataSourceItem,
dataSourceType === DataSourceType.NOTION && s.active,
dataSourceTypeDisable && dataSourceType !== DataSourceType.NOTION && s.disabled,
)}
onClick={() => {
if (dataSourceTypeDisable)
return
changeType(DataSourceType.NOTION)
hidePreview()
}}
>
<span className={cn(s.datasetIcon, s.notion)} />
{t('datasetCreation.stepOne.dataSourceType.notion')}
</div>
<div
className={cn(s.dataSourceItem, s.disabled, dataSourceType === DataSourceType.WEB && s.active)}
// onClick={() => changeType(DataSourceType.WEB)}
>
<span className={s.comingTag}>Coming soon</span>
<span className={cn(s.datasetIcon, s.web)} />
{t('datasetCreation.stepOne.dataSourceType.web')}
</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>
</> </>
)} )}

+ 4
- 0
web/app/components/datasets/create/step-two/index.tsx Parādīt failu

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 }


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)
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()
} }

+ 1
- 1
web/app/components/datasets/documents/index.tsx Parādīt failu

? <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)

+ 1
- 1
web/context/dataset-detail.ts Parādīt failu

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)



Notiek ielāde…
Atcelt
Saglabāt