import PropTypes from 'prop-types' import { useState, useContext } from 'react' import { Button, Dropdown, Modal } from 'antd' import ExcelIcon from '../../Icons/ExcelIcon' import ODataIcon from '../../Icons/ODataIcon' import CsvIcon from '../../Icons/CsvIcon' import DownloadIcon from '../../Icons/DownloadIcon' import OpenAppIcon from '../../Icons/OpenAppIcon' import ExportIcon from '../../Icons/ExportIcon' import ODataURL from './ODataURL' import { ApiServerContext } from '../context/ApiServerContext' const ExportListButton = ({ objectType, disabled = false, size = 'middle', ...buttonProps }) => { const [odataModalOpen, setOdataModalOpen] = useState(false) const [excelLoading, setExcelLoading] = useState(false) const [csvLoading, setCsvLoading] = useState(false) const { exportToExcel, exportToCsv } = useContext(ApiServerContext) const handleExcelExport = async (mode) => { setExcelLoading(true) try { await exportToExcel(objectType, mode) } finally { setExcelLoading(false) } } const exportLoading = excelLoading || csvLoading const menuItems = [ { key: 'excel', label: excelLoading ? 'Exporting...' : 'Excel File', icon: , disabled: exportLoading, children: [ { key: 'excel-download', label: 'Download File', icon: , disabled: exportLoading, onClick: () => handleExcelExport('download') }, { key: 'excel-open', label: 'Open in Excel', icon: , disabled: exportLoading, onClick: () => handleExcelExport('open') } ] }, { key: 'csv', label: csvLoading ? 'Exporting...' : 'CSV File', icon: , disabled: exportLoading, onClick: async () => { setCsvLoading(true) try { await exportToCsv(objectType) } finally { setCsvLoading(false) } } }, { type: 'divider' }, { key: 'odata', label: 'OData Connection', icon: , onClick: () => setOdataModalOpen(true) } ] return ( <>