UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

43 lines (42 loc) 1.63 kB
import { useExportGridAsCsv as u } from "../../../synapse-queries/grid/useExportGrid.js"; import { displayToast as n } from "../../ToastMessage/ToastMessage.js"; import { useSynapseContext as f } from "../../../utils/context/SynapseContext.js"; import { getFileHandleByIdURL as g } from "../../../synapse-client/SynapseClient.js"; function R(d) { const { gridSessionId: i, filename: c } = d, { accessToken: l } = f(), { mutate: a, isPending: p } = u({ onSuccess: (o) => { o?.resultsFileHandleId && g(o.resultsFileHandleId, l).then((t) => fetch(t).then((r) => r.blob()).then((r) => { const s = URL.createObjectURL(r), e = document.createElement("a"); e.href = s; const m = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"); e.setAttribute("download", `${c}-${m}.csv`), document.body.appendChild(e), e.click(), document.body.removeChild(e), URL.revokeObjectURL(s), n("CSV export completed successfully", "success"); })).catch((t) => { n( `Failed to download CSV: ${t instanceof Error ? t.message : "Unknown error"}`, "danger" ); }); }, onError: (o) => { n( `CSV export failed: ${o.reason || "Unknown error"}`, "danger" ); } }); return { exportToCsv: () => { a({ sessionId: i, includeEtag: !1, includeRowIdAndRowVersion: !1, concreteType: "org.sagebionetworks.repo.model.grid.DownloadFromGridRequest" }); }, isExporting: p }; } export { R as useExportDataGridToCsv }; //# sourceMappingURL=useExportDataGridToCsv.js.map