import { ReactComponent as CancelIcon } from '@/assets/svg/cancel.svg'; import { ReactComponent as DeleteIcon } from '@/assets/svg/delete.svg'; import { ReactComponent as DisableIcon } from '@/assets/svg/disable.svg'; import { ReactComponent as EnableIcon } from '@/assets/svg/enable.svg'; import { ReactComponent as RunIcon } from '@/assets/svg/run.svg'; import { useShowDeleteConfirm, useTranslate } from '@/hooks/common-hooks'; import { useRemoveDocument, useRunDocument, useSetDocumentStatus, } from '@/hooks/document-hooks'; import { useGetKnowledgeSearchParams } from '@/hooks/route-hook'; import { DownOutlined, FileOutlined, FileTextOutlined, PlusOutlined, SearchOutlined, } from '@ant-design/icons'; import { Button, Dropdown, Flex, Input, MenuProps, Space } from 'antd'; import { useCallback, useMemo } from 'react'; import { useFetchDocumentListOnMount, useGetPagination, useHandleSearchChange, } from './hooks'; import styles from './index.less'; interface IProps { selectedRowKeys: string[]; showCreateModal(): void; showWebCrawlModal(): void; showDocumentUploadModal(): void; } const DocumentToolbar = ({ selectedRowKeys, showCreateModal, showWebCrawlModal, showDocumentUploadModal, }: IProps) => { const { t } = useTranslate('knowledgeDetails'); const { fetchDocumentList } = useFetchDocumentListOnMount(); const { setPagination, searchString } = useGetPagination(fetchDocumentList); const { handleInputChange } = useHandleSearchChange(setPagination); const removeDocument = useRemoveDocument(); const showDeleteConfirm = useShowDeleteConfirm(); const runDocumentByIds = useRunDocument(); const { knowledgeId } = useGetKnowledgeSearchParams(); const changeStatus = useSetDocumentStatus(); const actionItems: MenuProps['items'] = useMemo(() => { return [ { key: '1', onClick: showDocumentUploadModal, label: (
), }, { type: 'divider' }, // { // key: '2', // onClick: showWebCrawlModal, // label: ( //
// //
// ), // }, { type: 'divider' }, { key: '3', onClick: showCreateModal, label: (
), }, ]; }, [showDocumentUploadModal, showCreateModal, t]); const handleDelete = useCallback(() => { showDeleteConfirm({ onOk: () => { removeDocument(selectedRowKeys); }, }); }, [removeDocument, showDeleteConfirm, selectedRowKeys]); const runDocument = useCallback( (run: number) => { runDocumentByIds({ doc_ids: selectedRowKeys, run, knowledgeBaseId: knowledgeId, }); }, [runDocumentByIds, selectedRowKeys, knowledgeId], ); const handleRunClick = useCallback(() => { runDocument(1); }, [runDocument]); const handleCancelClick = useCallback(() => { runDocument(2); }, [runDocument]); const onChangeStatus = useCallback( (enabled: boolean) => { selectedRowKeys.forEach((id) => { changeStatus(enabled, id); }); }, [selectedRowKeys, changeStatus], ); const handleEnableClick = useCallback(() => { onChangeStatus(true); }, [onChangeStatus]); const handleDisableClick = useCallback(() => { onChangeStatus(false); }, [onChangeStatus]); const disabled = selectedRowKeys.length === 0; const items: MenuProps['items'] = useMemo(() => { return [ { key: '0', onClick: handleEnableClick, label: ( {t('enabled')} ), }, { key: '1', onClick: handleDisableClick, label: ( {t('disabled')} ), }, { type: 'divider' }, { key: '2', onClick: handleRunClick, label: ( {t('run')} ), }, { key: '3', onClick: handleCancelClick, label: ( {t('cancel')} ), }, { type: 'divider' }, { key: '4', onClick: handleDelete, label: ( {t('delete', { keyPrefix: 'common' })} ), }, ]; }, [ handleDelete, handleRunClick, handleCancelClick, t, handleDisableClick, handleEnableClick, ]); return (
} />
); }; export default DocumentToolbar;