Commit 1866b0e9 authored by StyleZhang's avatar StyleZhang

fix: dataset detail context update

parent 7cfa76d0
......@@ -93,7 +93,7 @@ const DatasetDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
const pathname = usePathname()
const hideSideBar = /documents\/create$/.test(pathname)
const { t } = useTranslation()
const { data: datasetRes, error } = useSWR({
const { data: datasetRes, error, mutate: mutateDatasetRes } = useSWR({
action: 'fetchDataDetail',
datasetId,
}, apiParams => fetchDataDetail(apiParams.datasetId))
......@@ -168,6 +168,7 @@ const DatasetDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
<DatasetDetailContext.Provider value={{
indexingTechnique: datasetRes?.indexing_technique,
dataset: datasetRes,
mutateDatasetRes: () => mutateDatasetRes(),
}}>
<div className="bg-white grow">{children}</div>
</DatasetDetailContext.Provider>
......
......@@ -59,7 +59,7 @@ const StepOne = ({
notionPages = [],
updateNotionPages,
}: IStepOneProps) => {
const { dataset } = useDatasetDetailContext()
const { dataset, mutateDatasetRes } = useDatasetDetailContext()
const [showModal, setShowModal] = useState(false)
const [showFilePreview, setShowFilePreview] = useState(true)
const [currentNotionPage, setCurrentNotionPage] = useState<Page | undefined>()
......@@ -79,6 +79,12 @@ const StepOne = ({
setCurrentNotionPage(undefined)
}
const handleStepChange = () => {
if (mutateDatasetRes)
mutateDatasetRes()
onStepChange()
}
const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type)
return (
......@@ -139,7 +145,7 @@ const StepOne = ({
{dataSourceType === DataSourceType.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={handleStepChange}>{t('datasetCreation.stepOne.button')}</Button>
</>
)}
{dataSourceType === DataSourceType.NOTION && (
......@@ -150,7 +156,7 @@ const StepOne = ({
<div className='mb-8 w-[640px]'>
<NotionPageSelector value={notionPages.map(page => page.page_id)} onSelect={updateNotionPages} onPreview={updateCurrentPage} />
</div>
<Button disabled={!notionPages.length} className={s.submitButton} type='primary' onClick={onStepChange}>{t('datasetCreation.stepOne.button')}</Button>
<Button disabled={!notionPages.length} className={s.submitButton} type='primary' onClick={handleStepChange}>{t('datasetCreation.stepOne.button')}</Button>
</>
)}
</>
......
import { createContext, useContext } from 'use-context-selector'
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment