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

339 lines (333 loc) 9.79 kB
import { jsx as u, jsxs as j, Fragment as H } from "react/jsx-runtime"; import "../../synapse-client/SynapseClient.js"; import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode"; import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse"; import "@sage-bionetworks/synapse-client/util/SynapseClientError"; import { FileHandleAssociateType as G } from "@sage-bionetworks/synapse-types"; import { isContainerType as U, isEntityView as B, hasFilesInView as Q, isDataset as Y, isVersionableEntity as z, entityTypeToFriendlyName as K } from "../../utils/functions/EntityTypeUtils.js"; import "../../utils/SynapseConstants.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import { useState as w } from "react"; import { useSynapseContext as W } from "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import "@mui/material"; import "../../utils/hooks/useCookiePreferences.js"; import "../../utils/hooks/useSourceAppConfigs.js"; import "universal-cookie"; import "../../utils/AppUtils/session/ApplicationSessionContext.js"; import "../../utils/context/FullContextProvider.js"; import "../../utils/context/DocumentMetadataContext.js"; import '../../style/components/_spinner.css';/* empty css */ import "@tanstack/query-core"; import "lodash-es/isEmpty"; import "lodash-es/isEqual"; import "lodash-es/xorWith"; import "react-router"; import { EntityType as t } from "@sage-bionetworks/synapse-client"; import { isFileEntity as J } from "../../utils/types/IsType.js"; import { useAddFileToDownloadList as X, useGetAddToDownloadListStats as Z } from "../../synapse-queries/download/useDownloadList.js"; import { useGetEntity as F, useGetVersions as ee } from "../../synapse-queries/entity/useEntity.js"; import { useDirectDownloadHandler as te } from "../../utils/hooks/useDirectDownloadHandler.js"; import { DownloadOutlined as oe } from "@mui/icons-material"; import { createPortal as ne } from "react-dom"; import { displayFilesWereAddedToDownloadListSuccess as ie } from "../download_list/DownloadConfirmationUtils.js"; import { EntityDownloadConfirmation as ae } from "../EntityDownloadConfirmation/EntityDownloadConfirmation.js"; import { DropdownMenu as se } from "../menu/DropdownMenu.js"; import { ModalDownload as re } from "../ModalDownload/ModalDownload.js"; import { ProgrammaticInstructionsModal as de } from "../ProgrammaticInstructionsModal/ProgrammaticInstructionsModal.js"; import { displayToast as E } from "../ToastMessage/ToastMessage.js"; const h = `import synapseclient syn = synapseclient.Synapse() syn.login(authToken="YOUR_TOKEN_HERE")`, b = `library(synapser) synLogin(authToken="YOUR_TOKEN_HERE")`; function le(e, o, n) { const i = e === t.dataset && n ? `${o}.${n}` : o; switch (e) { case t.file: case t.folder: case t.project: case t.link: return { cliCode: `synapse get -r ${o}`, rCode: `${b} # Download file synGet('${o}')`, pythonCode: `${h} # Download file syn.get('${o}')` }; case t.dockerrepo: return { cliCode: `docker login -u <synapse username> -p <synapse password> docker.synapse.org docker pull docker.synapse.org/${o}/myrepo`, rCode: void 0, pythonCode: void 0 }; case t.dataset: case t.entityview: case t.datasetcollection: case t.table: case t.materializedview: case t.submissionview: case t.virtualtable: case t.recordset: return { cliCode: `synapse get -q "SELECT * FROM ${i}"`, rCode: `${b} query <- synTableQuery("SELECT * FROM ${i}") read.table(query$filepath, sep=",")`, pythonCode: `${h} query = syn.tableQuery("SELECT * FROM ${i}") query.asDataFrame()` }; default: throw new Error(`Unhandled EntityType: ${e}`); } } function ce(e, o, n, i, r, d, l, s, y, c, p, f) { switch (i) { case 0: return { text: "Download File", onClick: () => { p && p(); }, tooltipText: f ? "Download this file directly" : "Sign in to download this file", disabled: !f }; case 1: return { text: "Add to Download List", disabled: c, tooltipText: me(n, !!c), onClick: () => { n === t.file || n === t.recordset ? l({ entityId: e, entityVersionNumber: y }) : s(!0); } }; case 2: return { text: "Programmatic Access", onClick: () => { r(!0); }, tooltipText: "View programmatic access options" }; case 3: return { text: "Programmatic Access (Docker)", onClick: () => { r(!0); }, tooltipText: "View programmatic options to pull Docker image" }; case 4: return { text: "Export Table", onClick: () => { d(!0); }, tooltipText: "Export table data" }; } } const me = (e, o) => o ? `This ${K(e)} has no accessible files` : "Add file(s) to your download list"; function ue(e) { switch (e) { case t.file: case t.recordset: return [ [ 0 /* downloadFile */ ], [ 1, 2 /* programmaticAccess */ ] ]; case t.project: case t.folder: return [[ 1, 2 /* programmaticAccess */ ]]; case t.dockerrepo: return [[ 3 /* programmaticAccessDocker */ ]]; case t.entityview: case t.dataset: return [ [ 4, 2, 1 /* addToCart */ ] ]; case t.datasetcollection: case t.table: case t.materializedview: case t.submissionview: case t.virtualtable: return [[ 4, 2 /* programmaticAccess */ ]]; case t.link: return [[ 2 /* programmaticAccess */ ]]; default: throw new Error(`Unhandled EntityType: ${e}`); } } function ye(e, o) { const { data: n, isLoading: i } = F(e), r = o === t.dataset, { data: d, isLoading: l } = ee( e, 0, 1, { enabled: r } ); let s; return r ? d?.results && d.results.length > 0 ? s = d.results[0].versionNumber : s = void 0 : s = n && z(n) ? n.versionNumber : void 0, { latestVersionNumber: s, isLoading: i || l }; } function pe(e, o, n) { let i; return n === t.dataset ? i = o ? `SELECT * FROM ${e}.${o}` : `SELECT * FROM ${e}` : i = `SELECT * FROM ${e}`, { concreteType: "org.sagebionetworks.repo.model.table.QueryBundleRequest", entityId: `${e}`, query: { sql: i }, partMask: 0 }; } function nt(e) { const { latestVersionNumber: o } = ye( e.entityId, e.entityType ), n = pe( e.entityId, o, e.entityType ), { downloadCartPageUrl: i, isAuthenticated: r } = W(), { mutate: d } = X({ onSuccess: (m) => { m.numberOfFilesAdded > 0 ? ie(i) : E("0 Files added to your Download List", "info"); }, onError: (m) => { E(m.reason, "danger"); } }), [l, s] = w(!1), [y, c] = w(!1), [p, f] = w(!1), L = () => { s(!1); }, T = U(e.entityType), { data: k, isLoading: O } = Z( { concreteType: "org.sagebionetworks.repo.model.download.AddToDownloadListStatsRequest", request: { parentId: e.entityId, concreteType: "org.sagebionetworks.repo.model.download.AddToDownloadListRequest", recursive: !0 } }, { enabled: T } ), $ = T && (O || k?.fileCount === 0), { data: a } = F(e.entityId), { downloadFile: A } = te(), C = a && J(a) ? a.dataFileHandleId : void 0, R = C ? () => { A({ fileHandleId: C, associatedObjectId: e.entityId, associatedObjectType: G.FileEntity }); } : void 0, S = a && B(a) && !Q(a), N = a && Y(a) && (!a.items || a.items.length === 0), x = $ || S || N, [v, D] = w(!1), I = () => { D(!1); }, M = ue(e.entityType).map( (m) => m.map( (_) => ce( e.entityId, e.name, e.entityType, _, s, D, d, c, o, x, R, r ) ) ), { cliCode: P, rCode: q, pythonCode: V } = le( e.entityType, e.entityId, o ), g = y ? /* @__PURE__ */ u( ae, { entityId: e.entityId, handleClose: () => c(!1), onIsLoadingChange: f } ) : null; return /* @__PURE__ */ j(H, { children: [ /* @__PURE__ */ u( se, { items: M, dropdownButtonText: "Download", buttonTooltip: "Download options for this entity", buttonProps: { variant: "outlined", startIcon: /* @__PURE__ */ u(oe, {}), disabled: e.disabled || p } } ), g && (e.downloadConfirmationContainer?.current ? ne( g, e.downloadConfirmationContainer.current ) : g), /* @__PURE__ */ u( de, { show: l, title: `Programmatic Access: ${e.name}`, onClose: L, pythonCode: V, rCode: q, cliCode: P, helpUrl: "https://help.synapse.org/docs/Synapse-Docker-Registry.2011037752.html#SynapseDockerRegistry-UsingDockerImagesStoredintheSynapseDockerRegistry" } ), v && /* @__PURE__ */ u( re, { queryBundleRequest: n, onClose: I } ) ] }); } export { nt as EntityDownloadButton, h as PYTHON_CLIENT_IMPORT_AND_LOGIN, b as R_CLIENT_IMPORT_AND_LOGIN, ue as getDownloadActionsForEntityType }; //# sourceMappingURL=EntityDownloadButton.js.map