import { ReactComponent as FilterIcon } from '@/assets/filter.svg'; import { KnowledgeRouteKey } from '@/constants/knowledge'; import { IChunkListResult, useSelectChunkList } from '@/hooks/chunk-hooks'; import { useTranslate } from '@/hooks/common-hooks'; import { useKnowledgeBaseId } from '@/hooks/knowledge-hooks'; import { ArrowLeftOutlined, CheckCircleOutlined, CloseCircleOutlined, DeleteOutlined, DownOutlined, FilePdfOutlined, PlusOutlined, SearchOutlined, } from '@ant-design/icons'; import { Button, Checkbox, Flex, Input, Menu, MenuProps, Popover, Radio, RadioChangeEvent, Segmented, SegmentedProps, Space, Typography, } from 'antd'; import { useCallback, useMemo, useState } from 'react'; import { Link } from 'umi'; import { ChunkTextMode } from '../../constant'; const { Text } = Typography; interface IProps extends Pick< IChunkListResult, 'searchString' | 'handleInputChange' | 'available' | 'handleSetAvailable' > { checked: boolean; selectAllChunk: (checked: boolean) => void; createChunk: () => void; removeChunk: () => void; switchChunk: (available: number) => void; changeChunkTextMode(mode: ChunkTextMode): void; } const ChunkToolBar = ({ selectAllChunk, checked, createChunk, removeChunk, switchChunk, changeChunkTextMode, available, handleSetAvailable, searchString, handleInputChange, }: IProps) => { const data = useSelectChunkList(); const documentInfo = data?.documentInfo; const knowledgeBaseId = useKnowledgeBaseId(); const [isShowSearchBox, setIsShowSearchBox] = useState(false); const { t } = useTranslate('chunk'); const handleSelectAllCheck = useCallback( (e: any) => { selectAllChunk(e.target.checked); }, [selectAllChunk], ); const handleSearchIconClick = () => { setIsShowSearchBox(true); }; const handleSearchBlur = () => { if (!searchString?.trim()) { setIsShowSearchBox(false); } }; const handleDelete = useCallback(() => { removeChunk(); }, [removeChunk]); const handleEnabledClick = useCallback(() => { switchChunk(1); }, [switchChunk]); const handleDisabledClick = useCallback(() => { switchChunk(0); }, [switchChunk]); const items: MenuProps['items'] = useMemo(() => { return [ { key: '1', label: ( <> {t('selectAll')} ), }, { type: 'divider' }, { key: '2', label: ( {t('enabledSelected')} ), }, { key: '3', label: ( {t('disabledSelected')} ), }, { type: 'divider' }, { key: '4', label: ( {t('deleteSelected')} ), }, ]; }, [ checked, handleSelectAllCheck, handleDelete, handleEnabledClick, handleDisabledClick, t, ]); const content = ( ); const handleFilterChange = (e: RadioChangeEvent) => { selectAllChunk(false); handleSetAvailable(e.target.value); }; const filterContent = ( {t('all')} {t('enabled')} {t('disabled')} ); return ( {documentInfo?.name} {isShowSearchBox ? ( } allowClear onChange={handleInputChange} onBlur={handleSearchBlur} value={searchString} /> ) : (