fix: add notion page in knowledge (#5430)

This commit is contained in:
zxhlyh 2024-06-20 15:48:38 +08:00 committed by GitHub
parent 3db110c0b9
commit 0d20df9a51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 9 deletions

View File

@ -7,3 +7,8 @@
background-size: 12px 12px; background-size: 12px 12px;
border-color: #155eef; border-color: #155eef;
} }
.checked.disabled {
background-color: #d0d5dd;
border-color: #d0d5dd;
}

View File

@ -5,13 +5,25 @@ type CheckboxProps = {
checked?: boolean checked?: boolean
onCheck?: () => void onCheck?: () => void
className?: string className?: string
disabled?: boolean
} }
const Checkbox = ({ checked, onCheck, className }: CheckboxProps) => { const Checkbox = ({ checked, onCheck, className, disabled }: CheckboxProps) => {
return ( return (
<div <div
className={cn(s.wrapper, checked && s.checked, 'w-4 h-4 border rounded border-gray-300', className)} className={cn(
onClick={onCheck} s.wrapper,
checked && s.checked,
disabled && s.disabled,
'w-4 h-4 border rounded border-gray-300',
className,
)}
onClick={() => {
if (disabled)
return
onCheck?.()
}}
/> />
) )
} }

View File

@ -39,12 +39,15 @@ const NotionPageSelector = ({
const firstWorkspaceId = notionWorkspaces[0]?.workspace_id const firstWorkspaceId = notionWorkspaces[0]?.workspace_id
const currentWorkspace = notionWorkspaces.find(workspace => workspace.workspace_id === currentWorkspaceId) const currentWorkspace = notionWorkspaces.find(workspace => workspace.workspace_id === currentWorkspaceId)
const getPagesMapAndSelectedPagesId: [DataSourceNotionPageMap, Set<string>] = useMemo(() => { const getPagesMapAndSelectedPagesId: [DataSourceNotionPageMap, Set<string>, Set<string>] = useMemo(() => {
const selectedPagesId = new Set<string>() const selectedPagesId = new Set<string>()
const boundPagesId = new Set<string>()
const pagesMap = notionWorkspaces.reduce((prev: DataSourceNotionPageMap, next: DataSourceNotionWorkspace) => { const pagesMap = notionWorkspaces.reduce((prev: DataSourceNotionPageMap, next: DataSourceNotionWorkspace) => {
next.pages.forEach((page) => { next.pages.forEach((page) => {
if (page.is_bound) if (page.is_bound) {
selectedPagesId.add(page.page_id) selectedPagesId.add(page.page_id)
boundPagesId.add(page.page_id)
}
prev[page.page_id] = { prev[page.page_id] = {
...page, ...page,
workspace_id: next.workspace_id, workspace_id: next.workspace_id,
@ -53,7 +56,7 @@ const NotionPageSelector = ({
return prev return prev
}, {}) }, {})
return [pagesMap, selectedPagesId] return [pagesMap, selectedPagesId, boundPagesId]
}, [notionWorkspaces]) }, [notionWorkspaces])
const defaultSelectedPagesId = [...Array.from(getPagesMapAndSelectedPagesId[1]), ...(value || [])] const defaultSelectedPagesId = [...Array.from(getPagesMapAndSelectedPagesId[1]), ...(value || [])]
const [selectedPagesId, setSelectedPagesId] = useState<Set<string>>(new Set(defaultSelectedPagesId)) const [selectedPagesId, setSelectedPagesId] = useState<Set<string>>(new Set(defaultSelectedPagesId))
@ -110,6 +113,7 @@ const NotionPageSelector = ({
<div className='rounded-b-xl overflow-hidden'> <div className='rounded-b-xl overflow-hidden'>
<PageSelector <PageSelector
value={selectedPagesId} value={selectedPagesId}
disabledValue={getPagesMapAndSelectedPagesId[2]}
searchValue={searchValue} searchValue={searchValue}
list={currentWorkspace?.pages || []} list={currentWorkspace?.pages || []}
pagesMap={getPagesMapAndSelectedPagesId[0]} pagesMap={getPagesMapAndSelectedPagesId[0]}

View File

@ -10,6 +10,7 @@ import type { DataSourceNotionPage, DataSourceNotionPageMap } from '@/models/com
type PageSelectorProps = { type PageSelectorProps = {
value: Set<string> value: Set<string>
disabledValue: Set<string>
searchValue: string searchValue: string
pagesMap: DataSourceNotionPageMap pagesMap: DataSourceNotionPageMap
list: DataSourceNotionPage[] list: DataSourceNotionPage[]
@ -71,6 +72,7 @@ const ItemComponent = ({ index, style, data }: ListChildComponentProps<{
dataList: NotionPageItem[] dataList: NotionPageItem[]
handleToggle: (index: number) => void handleToggle: (index: number) => void
checkedIds: Set<string> checkedIds: Set<string>
disabledCheckedIds: Set<string>
handleCheck: (index: number) => void handleCheck: (index: number) => void
canPreview?: boolean canPreview?: boolean
handlePreview: (index: number) => void handlePreview: (index: number) => void
@ -80,12 +82,13 @@ const ItemComponent = ({ index, style, data }: ListChildComponentProps<{
pagesMap: DataSourceNotionPageMap pagesMap: DataSourceNotionPageMap
}>) => { }>) => {
const { t } = useTranslation() const { t } = useTranslation()
const { dataList, handleToggle, checkedIds, handleCheck, canPreview, handlePreview, listMapWithChildrenAndDescendants, searchValue, previewPageId, pagesMap } = data const { dataList, handleToggle, checkedIds, disabledCheckedIds, handleCheck, canPreview, handlePreview, listMapWithChildrenAndDescendants, searchValue, previewPageId, pagesMap } = data
const current = dataList[index] const current = dataList[index]
const currentWithChildrenAndDescendants = listMapWithChildrenAndDescendants[current.page_id] const currentWithChildrenAndDescendants = listMapWithChildrenAndDescendants[current.page_id]
const hasChild = currentWithChildrenAndDescendants.descendants.size > 0 const hasChild = currentWithChildrenAndDescendants.descendants.size > 0
const ancestors = currentWithChildrenAndDescendants.ancestors const ancestors = currentWithChildrenAndDescendants.ancestors
const breadCrumbs = ancestors.length ? [...ancestors, current.page_name] : [current.page_name] const breadCrumbs = ancestors.length ? [...ancestors, current.page_name] : [current.page_name]
const disabled = disabledCheckedIds.has(current.page_id)
const renderArrow = () => { const renderArrow = () => {
if (hasChild) { if (hasChild) {
@ -113,9 +116,17 @@ const ItemComponent = ({ index, style, data }: ListChildComponentProps<{
style={{ ...style, top: style.top as number + 8, left: 8, right: 8, width: 'calc(100% - 16px)' }} style={{ ...style, top: style.top as number + 8, left: 8, right: 8, width: 'calc(100% - 16px)' }}
> >
<Checkbox <Checkbox
className='shrink-0 mr-2 group-hover:border-primary-600 group-hover:border-[2px]' className={cn(
'shrink-0 mr-2 group-hover:border-primary-600 group-hover:border-[2px]',
disabled && 'group-hover:border-transparent',
)}
checked={checkedIds.has(current.page_id)} checked={checkedIds.has(current.page_id)}
onCheck={() => handleCheck(index)} disabled={disabled}
onCheck={() => {
if (disabled)
return
handleCheck(index)
}}
/> />
{!searchValue && renderArrow()} {!searchValue && renderArrow()}
<NotionIcon <NotionIcon
@ -155,6 +166,7 @@ const Item = memo(ItemComponent, areEqual)
const PageSelector = ({ const PageSelector = ({
value, value,
disabledValue,
searchValue, searchValue,
pagesMap, pagesMap,
list, list,
@ -284,6 +296,7 @@ const PageSelector = ({
dataList: currentDataList, dataList: currentDataList,
handleToggle, handleToggle,
checkedIds: value, checkedIds: value,
disabledCheckedIds: disabledValue,
handleCheck, handleCheck,
canPreview, canPreview,
handlePreview, handlePreview,