diff --git a/web/app/components/base/notion-page-selector/base.tsx b/web/app/components/base/notion-page-selector/base.tsx index 4dd56d142e..88ce343c47 100644 --- a/web/app/components/base/notion-page-selector/base.tsx +++ b/web/app/components/base/notion-page-selector/base.tsx @@ -19,6 +19,7 @@ type NotionPageSelectorProps = { onPreview?: (selectedPage: NotionPage) => void datasetId?: string credentialList: DataSourceCredential[] + onSelectCredential?: (credentialId: string) => void } const NotionPageSelector = ({ @@ -29,10 +30,13 @@ const NotionPageSelector = ({ onPreview, datasetId = '', credentialList, + onSelectCredential, }: NotionPageSelectorProps) => { const [searchValue, setSearchValue] = useState('') const setShowAccountSettingModal = useModalContextSelector(s => s.setShowAccountSettingModal) + const invalidPreImportNotionPages = useInvalidPreImportNotionPages() + const notionCredentials = useMemo((): NotionCredential[] => { return credentialList.map((item) => { return { @@ -47,8 +51,16 @@ const NotionPageSelector = ({ useEffect(() => { const credential = notionCredentials.find(item => item.credentialId === currentCredential?.credentialId) - if (!credential) + if (!credential) { + const firstCredential = notionCredentials[0] + invalidPreImportNotionPages({ datasetId, credentialId: firstCredential.credentialId }) setCurrentCredential(notionCredentials[0]) + onSelect([]) // Clear selected pages when changing credential + onSelectCredential?.(firstCredential.credentialId) + } + else { + onSelectCredential?.(credential?.credentialId || '') + } }, [notionCredentials]) const { @@ -91,14 +103,13 @@ const NotionPageSelector = ({ setSearchValue(value) }, []) - const invalidPreImportNotionPages = useInvalidPreImportNotionPages() - const handleSelectCredential = useCallback((credentialId: string) => { const credential = notionCredentials.find(item => item.credentialId === credentialId)! invalidPreImportNotionPages({ datasetId, credentialId: credential.credentialId }) setCurrentCredential(credential) onSelect([]) // Clear selected pages when changing credential - }, [onSelect]) + onSelectCredential?.(credential.credentialId) + }, [invalidPreImportNotionPages, onSelect, onSelectCredential]) const handleSelectPages = useCallback((newSelectedPagesId: Set) => { const selectedPages = Array.from(newSelectedPagesId).map(pageId => pagesMapAndSelectedPagesId[0][pageId]) diff --git a/web/app/components/datasets/create/index.tsx b/web/app/components/datasets/create/index.tsx index 5e9d6ea522..0ee17b45bf 100644 --- a/web/app/components/datasets/create/index.tsx +++ b/web/app/components/datasets/create/index.tsx @@ -44,15 +44,26 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => { const [fileList, setFiles] = useState([]) const [result, setResult] = useState() const [notionPages, setNotionPages] = useState([]) + const [notionCredentialId, setNotionCredentialId] = useState('') const [websitePages, setWebsitePages] = useState([]) const [crawlOptions, setCrawlOptions] = useState(DEFAULT_CRAWL_OPTIONS) const [websiteCrawlProvider, setWebsiteCrawlProvider] = useState(DataSourceProvider.fireCrawl) const [websiteCrawlJobId, setWebsiteCrawlJobId] = useState('') + const { + data: dataSourceList, + isLoading: isLoadingAuthedDataSourceList, + isError: fetchingAuthedDataSourceListError, + } = useGetDefaultDataSourceListAuth() + const updateNotionPages = useCallback((value: NotionPage[]) => { setNotionPages(value) }, []) + const updateNotionCredentialId = useCallback((credentialId: string) => { + setNotionCredentialId(credentialId) + }, []) + const updateFileList = useCallback((preparedFiles: FileItem[]) => { setFiles(preparedFiles) }, []) @@ -88,12 +99,6 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => { setStep(step + delta) }, [step, setStep]) - const { - data: dataSourceList, - isLoading: isLoadingAuthedDataSourceList, - isError: fetchingAuthedDataSourceListError, - } = useGetDefaultDataSourceListAuth() - if (fetchingAuthedDataSourceListError) return @@ -121,7 +126,9 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => { updateFile={updateFile} updateFileList={updateFileList} notionPages={notionPages} + notionCredentialId={notionCredentialId} updateNotionPages={updateNotionPages} + updateNotionCredentialId={updateNotionCredentialId} onStepChange={nextStep} websitePages={websitePages} updateWebsitePages={setWebsitePages} @@ -140,6 +147,7 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => { dataSourceType={dataSourceType} files={fileList.map(file => file.file)} notionPages={notionPages} + notionCredentialId={notionCredentialId} websitePages={websitePages} websiteCrawlProvider={websiteCrawlProvider} websiteCrawlJobId={websiteCrawlJobId} diff --git a/web/app/components/datasets/create/notion-page-preview/index.tsx b/web/app/components/datasets/create/notion-page-preview/index.tsx index 5b56036327..cbfe366f0b 100644 --- a/web/app/components/datasets/create/notion-page-preview/index.tsx +++ b/web/app/components/datasets/create/notion-page-preview/index.tsx @@ -11,11 +11,13 @@ import { fetchNotionPagePreview } from '@/service/datasets' type IProps = { currentPage?: NotionPage + notionCredentialId: string hidePreview: () => void } const NotionPagePreview = ({ currentPage, + notionCredentialId, hidePreview, }: IProps) => { const { t } = useTranslation() @@ -29,7 +31,7 @@ const NotionPagePreview = ({ const res = await fetchNotionPagePreview({ workspaceID: currentPage.workspace_id, pageID: currentPage.page_id, - pageType: currentPage.type, + credentialID: notionCredentialId, }) setPreviewContent(res.content) setLoading(false) diff --git a/web/app/components/datasets/create/step-one/index.tsx b/web/app/components/datasets/create/step-one/index.tsx index a89322160a..cab1637661 100644 --- a/web/app/components/datasets/create/step-one/index.tsx +++ b/web/app/components/datasets/create/step-one/index.tsx @@ -32,7 +32,9 @@ type IStepOneProps = { updateFileList: (files: FileItem[]) => void updateFile: (fileItem: FileItem, progress: number, list: FileItem[]) => void notionPages?: NotionPage[] + notionCredentialId: string updateNotionPages: (value: NotionPage[]) => void + updateNotionCredentialId: (credentialId: string) => void onStepChange: () => void changeType: (type: DataSourceType) => void websitePages?: CrawlResultItem[] @@ -55,7 +57,9 @@ const StepOne = ({ updateFileList, updateFile, notionPages = [], + notionCredentialId, updateNotionPages, + updateNotionCredentialId, websitePages = [], updateWebsitePages, onWebsiteCrawlProviderChange, @@ -253,6 +257,7 @@ const StepOne = ({ onSelect={updateNotionPages} onPreview={updateCurrentPage} credentialList={notionCredentialList} + onSelectCredential={updateNotionCredentialId} datasetId={datasetId} /> @@ -317,7 +322,13 @@ const StepOne = ({
{currentFile && } - {currentNotionPage && } + {currentNotionPage && ( + + )} {currentWebsite && }
diff --git a/web/app/components/datasets/create/step-two/index.tsx b/web/app/components/datasets/create/step-two/index.tsx index 818da67b7e..ed63f26b1b 100644 --- a/web/app/components/datasets/create/step-two/index.tsx +++ b/web/app/components/datasets/create/step-two/index.tsx @@ -79,6 +79,7 @@ type StepTwoProps = { dataSourceType: DataSourceType files: CustomFile[] notionPages?: NotionPage[] + notionCredentialId: string websitePages?: CrawlResultItem[] crawlOptions?: CrawlOptions websiteCrawlProvider?: DataSourceProvider @@ -134,6 +135,7 @@ const StepTwo = ({ dataSourceType: inCreatePageDataSourceType, files, notionPages = [], + notionCredentialId, websitePages = [], crawlOptions, websiteCrawlProvider = DataSourceProvider.fireCrawl, @@ -282,6 +284,7 @@ const StepTwo = ({ indexingTechnique: getIndexing_technique() as any, processRule: getProcessRule(), dataset_id: datasetId || '', + credential_id: notionCredentialId, }) const websiteIndexingEstimateQuery = useFetchFileIndexingEstimateForWeb({ diff --git a/web/service/datasets.ts b/web/service/datasets.ts index f145f2b421..acc1fe647e 100644 --- a/web/service/datasets.ts +++ b/web/service/datasets.ts @@ -183,8 +183,12 @@ export const fetchFileIndexingEstimate: Fetcher('/datasets/indexing-estimate', { body }) } -export const fetchNotionPagePreview: Fetcher<{ content: string }, { workspaceID: string; pageID: string; pageType: string }> = ({ workspaceID, pageID, pageType }) => { - return get<{ content: string }>(`notion/workspaces/${workspaceID}/pages/${pageID}/${pageType}/preview`) +export const fetchNotionPagePreview: Fetcher<{ content: string }, { workspaceID: string; pageID: string; credentialID: string; }> = ({ workspaceID, pageID, credentialID }) => { + return get<{ content: string }>(`notion/workspaces/${workspaceID}/pages/${pageID}/preview`, { + params: { + credential_id: credentialID, + }, + }) } export const fetchApiKeysList: Fetcher }> = ({ url, params }) => { diff --git a/web/service/knowledge/use-create-dataset.ts b/web/service/knowledge/use-create-dataset.ts index 987039a758..3f3451af2d 100644 --- a/web/service/knowledge/use-create-dataset.ts +++ b/web/service/knowledge/use-create-dataset.ts @@ -119,6 +119,7 @@ export const useFetchFileIndexingEstimateForFile = ( type GetFileIndexingEstimateParamsOptionNotion = GetFileIndexingEstimateParamsOptionBase & { dataSourceType: DataSourceType.NOTION notionPages: NotionPage[] + credential_id: string } const getFileIndexingEstimateParamsForNotion = ({