diff --git a/web/app/components/base/notion-connector/index.tsx b/web/app/components/base/notion-connector/index.tsx index cd6293780d..8e172608cc 100644 --- a/web/app/components/base/notion-connector/index.tsx +++ b/web/app/components/base/notion-connector/index.tsx @@ -2,11 +2,13 @@ import { useTranslation } from 'react-i18next' import { Notion } from '../icons/src/public/common' import { Icon3Dots } from '../icons/src/vender/line/others' import Button from '../button' +import React from 'react' type NotionConnectorProps = { onSetting: () => void } -export const NotionConnector = ({ onSetting }: NotionConnectorProps) => { + +const NotionConnector = ({ onSetting }: NotionConnectorProps) => { const { t } = useTranslation() return ( @@ -25,3 +27,5 @@ export const NotionConnector = ({ onSetting }: NotionConnectorProps) => { ) } + +export default React.memo(NotionConnector) diff --git a/web/app/components/base/notion-page-selector/base.tsx b/web/app/components/base/notion-page-selector/base.tsx index 3860520514..cbeba00ffd 100644 --- a/web/app/components/base/notion-page-selector/base.tsx +++ b/web/app/components/base/notion-page-selector/base.tsx @@ -1,13 +1,12 @@ import { useCallback, useEffect, useMemo, useState } from 'react' -import useSWR from 'swr' -import { RiEqualizer2Line } from '@remixicon/react' import WorkspaceSelector from './workspace-selector' import SearchInput from './search-input' import PageSelector from './page-selector' -import { preImportNotionPages } from '@/service/datasets' import type { DataSourceNotionPageMap, DataSourceNotionWorkspace, NotionPage } from '@/models/common' import { useModalContextSelector } from '@/context/modal-context' -import { NotionConnector } from '../notion-connector' +import NotionConnector from '../notion-connector' +import { usePreImportNotionPages } from '@/service/knowledge/use-import' +import Header from './header' type NotionPageSelectorProps = { value?: string[] @@ -16,6 +15,7 @@ type NotionPageSelectorProps = { previewPageId?: string onPreview?: (selectedPage: NotionPage) => void datasetId?: string + isInPipeline?: boolean } const NotionPageSelector = ({ @@ -25,8 +25,9 @@ const NotionPageSelector = ({ previewPageId, onPreview, datasetId = '', + isInPipeline = false, }: NotionPageSelectorProps) => { - const { data, mutate } = useSWR({ url: '/notion/pre-import/pages', datasetId }, preImportNotionPages) + const { data, refetch } = usePreImportNotionPages({ url: '/notion/pre-import/pages', datasetId }) const [prevData, setPrevData] = useState(data) const [searchValue, setSearchValue] = useState('') const [currentWorkspaceId, setCurrentWorkspaceId] = useState('') @@ -86,47 +87,52 @@ const NotionPageSelector = ({ setCurrentWorkspaceId(firstWorkspaceId) }, [firstWorkspaceId]) + const handleConfigureNotion = useCallback(() => { + setShowAccountSettingModal({ payload: 'data-source', onCancelCallback: refetch }) + }, [setShowAccountSettingModal, refetch]) + return ( <> { data?.notion_info?.length ? ( -
-
-
- -
- setShowAccountSettingModal({ payload: 'data-source', onCancelCallback: mutate })} +
+
+
+
+
+ +
+ +
+
+
- -
-
-
) : ( - setShowAccountSettingModal({ payload: 'data-source', onCancelCallback: mutate })} /> + ) } diff --git a/web/app/components/base/notion-page-selector/header/index.tsx b/web/app/components/base/notion-page-selector/header/index.tsx new file mode 100644 index 0000000000..5aec106561 --- /dev/null +++ b/web/app/components/base/notion-page-selector/header/index.tsx @@ -0,0 +1,55 @@ +import React from 'react' +import Divider from '../../divider' +import Button from '../../button' +import cn from '@/utils/classnames' +import { RiBookOpenLine, RiEqualizer2Line } from '@remixicon/react' + +type HeaderProps = { + isInPipeline?: boolean + handleConfigureNotion: () => void +} + +const Header = ({ + isInPipeline = false, + handleConfigureNotion, +}: HeaderProps) => { + return ( +
+
+
+ Choose notion pages +
+ + +
+ + + Notion docs + +
+ ) +} + +export default React.memo(Header) diff --git a/web/app/components/base/notion-page-selector/workspace-selector/index.tsx b/web/app/components/base/notion-page-selector/workspace-selector/index.tsx index 2e7b57fddd..433ad49061 100644 --- a/web/app/components/base/notion-page-selector/workspace-selector/index.tsx +++ b/web/app/components/base/notion-page-selector/workspace-selector/index.tsx @@ -31,7 +31,6 @@ export default function WorkspaceSelector({ name={currentWorkspace?.workspace_name} />
{currentWorkspace?.workspace_name}
- {/*
{currentWorkspace?.pages.length}
*/} page.page_id)} onSelect={updateNotionPages} canPreview={false} + isInPipeline /> )} diff --git a/web/service/knowledge/use-import.ts b/web/service/knowledge/use-import.ts index e69de29bb2..cdbf31a67c 100644 --- a/web/service/knowledge/use-import.ts +++ b/web/service/knowledge/use-import.ts @@ -0,0 +1,16 @@ +import { useQuery } from '@tanstack/react-query' +import { preImportNotionPages } from '../datasets' + +type PreImportNotionPagesParams = { + url: string + datasetId?: string +} + +export const usePreImportNotionPages = ({ datasetId }: PreImportNotionPagesParams) => { + return useQuery({ + queryKey: ['notion-pre-import-pages'], + queryFn: async () => { + return preImportNotionPages({ url: '/notion/pre-import/pages', datasetId }) + }, + }) +}