Commit 1866b0e9 authored by StyleZhang's avatar StyleZhang

fix: dataset detail context update

parent 7cfa76d0
...@@ -93,7 +93,7 @@ const DatasetDetailLayout: FC<IAppDetailLayoutProps> = (props) => { ...@@ -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) => { ...@@ -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>
......
...@@ -59,7 +59,7 @@ const StepOne = ({ ...@@ -59,7 +59,7 @@ const StepOne = ({
notionPages = [], notionPages = [],
updateNotionPages, updateNotionPages,
}: IStepOneProps) => { }: IStepOneProps) => {
const { dataset } = useDatasetDetailContext() const { dataset, mutateDatasetRes } = 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>()
...@@ -79,6 +79,12 @@ const StepOne = ({ ...@@ -79,6 +79,12 @@ const StepOne = ({
setCurrentNotionPage(undefined) setCurrentNotionPage(undefined)
} }
const handleStepChange = () => {
if (mutateDatasetRes)
mutateDatasetRes()
onStepChange()
}
const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type) const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type)
return ( return (
...@@ -139,7 +145,7 @@ const StepOne = ({ ...@@ -139,7 +145,7 @@ const StepOne = ({
{dataSourceType === DataSourceType.FILE && ( {dataSourceType === DataSourceType.FILE && (
<> <>
<FileUploader onFileUpdate={updateFile} file={file} titleClassName={(!shouldShowDataSourceTypeList) ? 'mt-[30px] !mb-[44px] !text-lg !font-semibold !text-gray-900' : undefined} /> <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 && ( {dataSourceType === DataSourceType.NOTION && (
...@@ -150,7 +156,7 @@ const StepOne = ({ ...@@ -150,7 +156,7 @@ const StepOne = ({
<div className='mb-8 w-[640px]'> <div className='mb-8 w-[640px]'>
<NotionPageSelector value={notionPages.map(page => page.page_id)} onSelect={updateNotionPages} onPreview={updateCurrentPage} /> <NotionPageSelector value={notionPages.map(page => page.page_id)} onSelect={updateNotionPages} onPreview={updateCurrentPage} />
</div> </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 { 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)
......
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