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

364 lines (363 loc) 11.6 kB
import { jsx as n, jsxs as T, Fragment as Eo } from "react/jsx-runtime"; import { getValueOrMultiValue as Oo, getLinkParams as Q, getFileHandleAssociation as Bo } from "./CardUtils.js"; import Fo from "./CroissantButton/CroissantButton.js"; import { GenericCardIcon as Po } from "./GenericCardIcon.js"; import Ho from "./PortalDOI/PortalDOI.js"; import { getCandidateDoiId as Ro, useShowDoiCardLabel as Go } from "./PortalDOI/PortalDOIUtils.js"; import { mapRowToRecord as Mo } from "../SynapseTable/SynapseTableUtils.js"; 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 { getColumnIndex as zo } from "../../utils/functions/SqlFunctions.js"; import { parseSynId as Wo } from "../../utils/functions/RegularExpressions.js"; import { PRODUCTION_ENDPOINT_CONFIG as _o } from "../../utils/functions/getEndpoint.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import { EXPERIMENTAL as $o } from "../../utils/SynapseConstants.js"; import { useState as J, useCallback as jo, useMemo as U } from "react"; import "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import { ColumnTypeEnum as qo } from "@sage-bionetworks/synapse-types"; import { Stack as X, Typography as Qo, Link as Jo, Box as Uo, Collapse as Xo } 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 '../../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 "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import { useGetEntity as Ko } from "../../synapse-queries/entity/useEntity.js"; import { isTableEntity as Yo, isDatasetCollection as Zo } from "../../utils/functions/EntityTypeUtils.js"; import { calculateFriendlyFileSize as oe } from "../../utils/functions/calculateFriendlyFileSize.js"; import { TargetEnum as ee } from "../../utils/html/TargetEnum.js"; import { GetAppTwoTone as te } from "@mui/icons-material"; import { useInView as ne } from "react-intersection-observer"; import ie from "../CitationPopover/CitationPopover.js"; import { EntityDownloadConfirmation as re } from "../EntityDownloadConfirmation/EntityDownloadConfirmation.js"; import ae from "../IconList.js"; import { useQueryContext as se } from "../QueryContext/QueryContext.js"; import { useQueryVisualizationContext as le } from "../QueryVisualizationWrapper/QueryVisualizationContext.js"; import de from "../ShareThisPage/ShareThisPage.js"; import { GenericCard as me } from "./GenericCard.js"; import ce from "./GenericCardActionButton.js"; import { SynapseCardLabel as K } from "./SynapseCardLabel.js"; import { useResolvedSynapseEntity as pe } from "./useResolvedSynapseEntity.js"; function ue(v) { const { synapseId: L, version: d } = v; return /* @__PURE__ */ T("span", { children: [ d, "  ", /* @__PURE__ */ n( "a", { target: ee.NEW_WINDOW, rel: "noopener noreferrer", href: `${_o.PORTAL}Synapse:${L}.${d}`, children: "(Show Version History on Synapse)" } ) ] }); } function gt(v) { const [L, d] = J(!1), [Y, Z] = J(!1), { entityId: oo, versionNumber: eo } = se(), { getColumnDisplayName: g } = le(), { ref: to, inView: no } = ne(), { data: I } = Ko(oo, eo), { schema: t, data: o, rowId: w, versionNumber: io, genericCardSchema: i, secondaryLabelLimit: ro, sharePageLinkButtonProps: ao, selectColumns: p, columnModels: m, iconOptions: so, useTypeColumnForIcon: A = !1, isHeader: u = !1, sustainabilityScorecard: lo, headerCardVariant: mo, titleLinkConfig: E, ctaLinkConfig: h, labelLinkConfig: co, descriptionConfig: po, columnIconOptions: f, CardTypeAdornment: O, charCountCutoff: uo } = v, { link: fo = "", type: B, includeCitation: Co, includeShareButton: yo, defaultCitationFormat: go, citationBoilerplateText: Io, downloadCartSynId: F, portalDoiConfiguration: b } = i, P = o[t[i.title]]; let D = i.subTitle && o[t[i.subTitle]]; D = i.subTitle && Oo({ value: D, columnName: i.subTitle, selectColumns: p, columnModels: m }).str; const ho = o[t[i.description || ""]], bo = o[t[i.icon || ""]], H = o[t[i.dataTypeIconNames || ""]], V = o[t[i.imageFileHandleColumnName || ""]], To = m?.find( (e) => i.link === e.name )?.columnType, R = o[t[fo]] || "", { href: vo, target: Lo } = Q( R, E, o, t, w ), wo = i.synapseEntityConfig, G = jo( (e) => { if (!e) return; const r = t[e]; if (r !== void 0) return o[r]; }, [t, o] ), Do = U(() => { const { titleAreaDetails: e } = i; if (!e) return; const r = typeof e == "function" ? e(t, o) : e; if (r.length === 0) return; const s = r.map((a) => { const l = o[t[a]]; return l ? { name: g(a), rawValue: l, columnName: a } : null; }).filter(Boolean); if (s.length !== 0) return /* @__PURE__ */ n(X, { direction: "column", gap: "4px", children: s.map(({ name: a, rawValue: l, columnName: c }) => /* @__PURE__ */ T(X, { direction: "row", gap: "4px", alignItems: "center", children: [ /* @__PURE__ */ T(Qo, { component: "span", variant: "body1", children: [ a, ":" ] }), /* @__PURE__ */ n( K, { value: l, columnName: c, labelLink: void 0, isHeader: u, selectColumns: p, columnModels: m, rowData: o, columnIconOptions: f } ) ] }, c)) }); }, [ i, o, t, g, u, p, m, f ]), { entityId: N, entityVersionNumber: S } = pe({ synapseEntityConfig: wo, getColumnValue: G, rowId: w, rowVersionNumber: io }); let C = N, M = S; if (F) { const e = Wo(G(F) ?? ""); C = e?.targetId, M = e?.targetVersionNumber; } const Vo = U( () => Mo(o, t), [o, t] ), k = Ro({ data: Vo, portalDoiConfiguration: b }), No = Go({ portalId: b?.portalId, resourceId: k }), y = [], { secondaryLabels: z = [] } = i, W = i.customSecondaryLabelConfig; if (No && b && k && no && y.push({ columnDisplayName: "DOI", value: /* @__PURE__ */ n( Ho, { portalId: b.portalId, resourceId: k } ) }), W?.isVisible(t, o)) { const { key: e, value: r } = W; C ? y.push({ columnDisplayName: "HOW TO DOWNLOAD", value: /* @__PURE__ */ n(Jo, { onClick: () => d((s) => !s), children: "Click here to add to Synapse download list" }) }) : y.push({ columnDisplayName: e, value: r }); } const So = I && !Yo(I); for (let e = 0; e < z.length; e += 1) { const r = z[e], s = o[t[r]]; let a = s, l; if (a) { if (Zo(I) && r === "datasetSizeInBytes") l = "Size", a = oe(parseInt(s)); else if (So && r === "currentVersion") { const c = o[t.id]; a = /* @__PURE__ */ n(ue, { synapseId: c, version: s }), l = "Version"; } else { const c = co?.find( (Ao) => Ao.matchColumnName === r ); a = /* @__PURE__ */ n( K, { value: s, columnName: r, labelLink: c, isHeader: u, selectColumns: p, columnModels: m, rowData: o, columnIconOptions: f } ), l = g(r); } y.push({ columnDisplayName: l, value: a, columnName: r }); } } const x = Bo( I, V || R, o[t.id] ), ko = g( i.description || "" ), _ = zo("doi", p, m), $ = _ !== void 0 ? o[_] : void 0, j = (h ? Array.isArray(h) ? h : [h] : []).map((e) => { const r = o[t[e.link]] || ""; if (!r) return null; const { href: s, target: a } = Q( r, void 0, //card link config o, t, w ); return { text: e.text, href: s, target: a }; }).filter(Boolean); let q = /* @__PURE__ */ n(Eo, {}); N != null && S != null && (q = /* @__PURE__ */ n( Fo, { datasetId: N, datasetVersionNumber: S } )); const xo = O ? /* @__PURE__ */ n(O, { schema: t, data: o }) : null; return /* @__PURE__ */ n( me, { ref: to, icon: /* @__PURE__ */ n( Po, { type: A ? o[t.type] : i.type, useTypeForIcon: A, thumbnailRequiresPadding: i.thumbnailRequiresPadding, imageFileHandleId: V, fileHandleAssociation: x, iconOptions: so, iconValue: bo } ), isHeader: u, sustainabilityScorecard: lo, headerCardVariant: mo, type: B, title: P, subtitle: D, titleLinkConfiguration: { target: Lo, href: vo }, cardTypeAdornment: xo, titleAsFileHandleLinkConfiguration: !E && To === qo.FILEHANDLEID && x ? { fileHandleAssociation: x, showDownloadIcon: B !== $o } : void 0, ctaLinkConfig: j.length > 0 ? j : void 0, titleAreaRightContent: Do, description: ho, descriptionSubTitle: ko, descriptionConfig: po, charCountCutoff: uo, labels: y, secondaryLabelLimit: ro, useStylesForDisplayedImage: !!V, cardTopContent: C && /* @__PURE__ */ n(Xo, { in: L, children: /* @__PURE__ */ n( re, { entityId: C, versionNumber: M, handleClose: () => d(!1), onIsLoadingChange: (e) => { Z(e); } } ) }), renderedIconList: ( // If the portal configs has columnIconOptions.columns.dataType option // and the column value is not null, display the card data type icons f?.columns?.dataType && H?.length && /* @__PURE__ */ n("div", { style: { marginTop: "20px" }, children: /* @__PURE__ */ n( ae, { iconConfigs: f.columns.dataType, iconNames: JSON.parse(H), commonIconProps: { sx: { fontSize: "40px" } }, useBackground: !0, useTheme: !0 } ) }) ), cardTopButtons: /* @__PURE__ */ T(Uo, { sx: { display: "flex", gap: 1 }, children: [ q, C && /* @__PURE__ */ n( ce, { onClick: () => d((e) => !e), variant: "outlined", startIcon: /* @__PURE__ */ n(te, { sx: { height: "12px" } }), loading: Y, children: "Download" } ), Co && $ && /* @__PURE__ */ n( ie, { title: P, doi: $, boilerplateText: Io, defaultCitationFormat: go } ), yo && u && /* @__PURE__ */ n(de, { ...ao }) ] }) } ); } export { gt as TableRowGenericCard, gt as default }; //# sourceMappingURL=TableRowGenericCard.js.map