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

312 lines (311 loc) 10.5 kB
import { jsxs as u, jsx as o, Fragment as C } 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 "@sage-bionetworks/synapse-types"; import "../../utils/functions/EntityTypeUtils.js"; import { copyStringToClipboard as _ } from "../../utils/functions/StringUtils.js"; import { PRODUCTION_ENDPOINT_CONFIG as j } from "../../utils/functions/getEndpoint.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import "../../utils/SynapseConstants.js"; import { useState as T, useEffect as F, useCallback as V, useMemo as D } from "react"; import "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import { Box as $, Button as H, Typography as E, Tooltip as R } from "@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 { BlockingLoader as M, SynapseSpinner as A } from "../LoadingScreen/LoadingScreen.js"; import "@tanstack/query-core"; import "lodash-es/isEmpty"; import "lodash-es/isEqual"; import "lodash-es/xorWith"; import "react-router"; import "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import { useGetAvailableFilesToDownloadInfinite as x, useRemoveFilesFromDownloadList as k } from "../../synapse-queries/download/useDownloadList.js"; import { calculateFriendlyFileSize as G } from "../../utils/functions/calculateFriendlyFileSize.js"; import { formatDate as U } from "../../utils/functions/DateFormatter.js"; import { useReactTable as W, getCoreRowModel as Y, createColumnHelper as q } from "@tanstack/react-table"; import Z from "dayjs"; import { useErrorHandler as J } from "react-error-boundary"; import K from "../DirectDownload/FileEntityDirectDownload.js"; import z from "../IconSvg/IconSvg.js"; import { InteractiveCopyIdsIcon as Q } from "../InteractiveCopyIdsIcon.js"; import "@mui/material/Skeleton"; import { SkeletonTable as X } from "../Skeleton/SkeletonTable.js"; import { TOOLTIP_DELAY_SHOW as L } from "../SynapseTable/SynapseTableConstants.js"; import a from "../TanStackTable/ColumnHeader.js"; import ee from "../TanStackTable/StyledTanStackTable.js"; import { displayToast as h } from "../ToastMessage/ToastMessage.js"; import oe from "./DirectProgrammaticDownload.js"; const ie = "TESTING_TRASH_BTN_CLASS"; function te(r, i) { h(`${i} has been removed from your list.`, "success", { title: r }); } function re(r) { const { ctx: i } = r, { mutateAsync: t, isPending: e } = k({ onSuccess: () => h( `${i.row.original.fileName} has been removed from your list.`, "success", { title: "File Removed" } ) }); return /* @__PURE__ */ o( R, { title: "Remove from Download List", placement: "left", enterNextDelay: L, children: /* @__PURE__ */ o("span", { className: "removeItem", children: /* @__PURE__ */ o( "button", { className: ie, onClick: () => { t({ batchToRemove: [ { fileEntityId: i.row.original.fileEntityId, versionNumber: i.row.original.versionNumber } ] }); }, children: e ? /* @__PURE__ */ o(A, {}) : /* @__PURE__ */ o(z, { icon: "removeCircle" }) } ) }) } ); } const l = q(), ne = (r) => { const { onCopySynIds: i, removeItem: t } = r; return [ l.accessor("isEligibleForPackaging", { header: () => /* @__PURE__ */ o(C, {}), cell: (e) => /* @__PURE__ */ o("div", { children: !e.getValue() && /* @__PURE__ */ o( R, { title: /* @__PURE__ */ u(C, { children: [ "This file can’t be packaged as a ZIP because it is ", ">", "100MB, or it is an external link, or it is not stored on Synapse native storage.", /* @__PURE__ */ o("br", {}), "Try clicking the “download” icon at the end of the row, or download programmatically." ] }), enterNextDelay: L, placement: "right", children: /* @__PURE__ */ o("span", { className: "ineligibileIcon", children: /* @__PURE__ */ o(z, { wrap: !1, icon: "unpackagableFile" }) }) } ) }), enableResizing: !1, enableColumnFilter: !1, size: 50 }), l.accessor("fileName", { header: (e) => /* @__PURE__ */ o(a, { ...e, title: "Name" }), cell: (e) => /* @__PURE__ */ o( "a", { target: "_blank", rel: "noopener noreferrer", href: `${j.PORTAL}Synapse:${e.row.original.fileEntityId}.${e.row.original.versionNumber}`, children: e.getValue() } ), enableColumnFilter: !1, size: 360 }), l.accessor("fileSizeBytes", { header: (e) => /* @__PURE__ */ o(a, { ...e, title: "Size" }), cell: (e) => e.getValue() != null && e.getValue() > 0 ? G(e.getValue()) : /* @__PURE__ */ o(E, { variant: "smallText1", sx: { color: "grey.600" }, children: "Unknown" }), enableColumnFilter: !1, size: 117 }), l.accessor("fileEntityId", { header: (e) => /* @__PURE__ */ o( a, { ...e, title: "SynID", additionalButtons: /* @__PURE__ */ o(Q, { size: "small", onCopy: i }) } ), cell: (e) => `${e.getValue()}.${e.row.original.versionNumber}`, enableColumnFilter: !1, size: 143 }), l.accessor("addedOn", { header: (e) => /* @__PURE__ */ o(a, { ...e, title: "Added On" }), cell: (e) => U(Z(e.getValue())), enableColumnFilter: !1, size: 150 }), l.accessor("projectName", { header: (e) => /* @__PURE__ */ o(a, { ...e, title: "Project" }), enableColumnFilter: !1, size: 170 }), l.display({ id: "actions", header: (e) => /* @__PURE__ */ o(a, { ...e, title: "Actions" }), cell: (e) => /* @__PURE__ */ u("div", { className: "actionsContainer", children: [ /* @__PURE__ */ o("span", { className: "downloadItem", children: /* @__PURE__ */ o( K, { entityId: e.row.original.fileEntityId, entityVersionNumber: e.row.original.versionNumber, displayFileName: !1, onClickCallback: (d) => { d || t( { fileEntityId: e.row.original.fileEntityId, versionNumber: e.row.original.versionNumber }, e.row.original.fileName, "File Downloaded" ); } } ) }), /* @__PURE__ */ o("span", { className: "programmaticAccessItem", children: /* @__PURE__ */ o( oe, { entityId: e.row.original.fileEntityId, version: e.row.original.versionNumber } ) }), /* @__PURE__ */ o(re, { ctx: e }) ] }), enableResizing: !1, enableColumnFilter: !1, size: 140, meta: { textAlign: "center" } }) ]; }; function le(r) { if (r.length === 0) return; const i = r[0]; let t = "addedOn"; return i.id === "fileName" ? t = "fileName" : i.id === "fileSizeBytes" ? t = "fileSize" : i.id === "fileEntityId" ? t = "synId" : i.id === "projectName" ? t = "projectName" : i.id === "addedOn" ? t = "addedOn" : i.id === "createdBy" ? t = "createdBy" : i.id === "createdOn" && (t = "createdOn"), { field: t, direction: i.desc ? "DESC" : "ASC" }; } function oo({ filter: r }) { const i = J(), [t, e] = T(!1), [d, O] = T([ { desc: !0, id: "addedOn" } ]), { data: b, status: v, isFetchingNextPage: s, isLoading: S, hasNextPage: c, fetchNextPage: p, isError: I, error: g } = x( le(d), r ); F(() => { I && g && i(g); }, [I, g, i]); const { mutateAsync: w } = k(), N = V( async (n, y, f) => { await w({ batchToRemove: [n] }), te(f, y); }, [w] ), m = D( () => b?.pages.flatMap((n) => n.page) ?? [], [b?.pages] ), P = D( () => ne({ removeItem: (...n) => { N(...n); }, onCopySynIds: () => { e(!0); } }), [N] ), B = W({ data: m, columns: P, getCoreRowModel: Y(), manualSorting: !0, onSortingChange: O, state: { columnPinning: { right: ["actions"] }, sorting: d }, columnResizeMode: "onChange", meta: { getRowClassNames(n) { return n.original.isEligibleForPackaging ? "" : "ineligibleForPackaging"; } } }); return F(() => { v === "success" && !s && c && p && t ? p() : !c && t && (() => { const y = m.map((f) => `${f.fileEntityId}.${f.versionNumber}`).join(` `); _(y).then(() => { h("Successfully copied to clipboard"); }), e(!1); })(); }, [ v, s, c, p, t, m ]), /* @__PURE__ */ u("div", { children: [ /* @__PURE__ */ o(M, { show: t }), m.length > 0 && /* @__PURE__ */ u("div", { className: "DownloadListTableV2", children: [ /* @__PURE__ */ o(ee, { table: B, fullWidth: !1 }), c && /* @__PURE__ */ o($, { sx: { display: "flex", justifyContent: "right" }, children: /* @__PURE__ */ o( H, { variant: "contained", sx: { my: 2, ml: "auto" }, onClick: () => { p(); }, disabled: s, startIcon: s ? /* @__PURE__ */ o(A, {}) : void 0, children: s ? "Loading..." : "Show More" } ) }) ] }), m.length === 0 && !S && /* @__PURE__ */ o(E, { variant: "body1Italic", children: "You have no matching files in your download list." }), S && /* @__PURE__ */ o(X, { numCols: 5, numRows: 3 }) ] }); } export { ie as TESTING_TRASH_BTN_CLASS, oo as default }; //# sourceMappingURL=DownloadListTable.js.map