UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

31 lines 1.47 kB
import { useCallback } from 'react'; import { useResourceContext } from "../core/useResourceContext.js"; import { useListContext } from "../controller/list/useListContext.js"; import { useDataProvider } from "../dataProvider/useDataProvider.js"; import { useNotify } from "../notification/useNotify.js"; import { fetchRelatedRecords } from "./fetchRelatedRecords.js"; /** * A hook that provides a callback to export the selected records from the nearest ListContext and call the exporter function for them. */ export function useBulkExport(options = {}) { const { exporter: customExporter, meta } = options; const resource = useResourceContext(options); const { exporter: exporterFromContext, selectedIds } = useListContext(); const exporter = customExporter || exporterFromContext; const dataProvider = useDataProvider(); const notify = useNotify(); return useCallback(() => { if (exporter && resource) { dataProvider .getMany(resource, { ids: selectedIds, meta }) .then(({ data }) => exporter(data, fetchRelatedRecords(dataProvider), dataProvider, resource)) .catch(error => { console.error(error); notify('ra.notification.http_error', { type: 'error', }); }); } }, [dataProvider, exporter, notify, resource, selectedIds, meta]); } //# sourceMappingURL=useBulkExport.js.map