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

108 lines (107 loc) 3.05 kB
import { jsx as o, jsxs as F, Fragment as k } from "react/jsx-runtime"; import { useGetFileBatch as b } from "../../synapse-queries/file/useFiles.js"; import { implementsExternalFileHandleInterface as L } from "../../utils/types/IsType.js"; import { Tooltip as h } from "@mui/material"; import { forwardRef as x } from "react"; import g from "../IconSvg/IconSvg.js"; import { TOOLTIP_DELAY_SHOW as P } from "../SynapseTable/SynapseTableConstants.js"; import { useDirectDownloadHandler as N } from "../../utils/hooks/useDirectDownloadHandler.js"; const O = x(function(l, n) { const { isExternalFile: i, onClick: r, getDownloadLink: t, stopPropagation: s, externalURL: d, hasFileAccess: f, displayFileName: m, fileName: e, iconSvgPropOverrides: c = {} } = l; return i ? /* @__PURE__ */ o( "button", { ref: n, className: "btn-download-icon", onClick: (a) => { r && (r(i), s && a.stopPropagation()); }, children: /* @__PURE__ */ o( "a", { className: "ignoreLink", rel: "noopener noreferrer", href: d, target: "_blank", children: /* @__PURE__ */ o(g, { icon: "download", ...c }) } ) } ) : f ? /* @__PURE__ */ F( "button", { ref: n, className: "btn-download-icon", onClick: (a) => { t(), s && a.stopPropagation(); }, children: [ /* @__PURE__ */ o(g, { icon: "download", ...c }), m && e ? e : "" ] } ) : /* @__PURE__ */ o(k, {}); }); function U(p) { const { associatedObjectId: l, associatedObjectType: n, fileHandleId: i, displayFileName: r = !1, onClickCallback: t, stopPropagation: s = !1, iconSvgPropOverrides: d } = p, f = { fileHandleId: i, associateObjectId: l, associateObjectType: n }, { data: m } = b({ requestedFiles: [f], includeFileHandles: !0, // don't get the presigned URL with this query, it may expire before the user clicks the download button includePreSignedURLs: !1, includePreviewPreSignedURLs: !1 }), e = m?.requestedFiles[0]?.fileHandle, c = !!e, a = e?.fileName, u = e ? L(e) : void 0, w = e ? e.externalURL : void 0, { downloadFile: D } = N(); return /* @__PURE__ */ o( h, { title: "Click to begin download of this file", enterNextDelay: P, placement: "left", children: /* @__PURE__ */ o("span", { children: /* @__PURE__ */ o( O, { isExternalFile: u, hasFileAccess: c, onClick: t, getDownloadLink: async () => { await D({ fileHandleId: i, associatedObjectId: l, associatedObjectType: n }), t && t(u); }, stopPropagation: s, externalURL: w, displayFileName: r, fileName: a, iconSvgPropOverrides: d } ) }) } ); } export { U as default }; //# sourceMappingURL=DirectDownload.js.map