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

95 lines (94 loc) 2.75 kB
import { isTableEntity as d } from "../../utils/functions/EntityTypeUtils.js"; import { PRODUCTION_ENDPOINT_CONFIG as p } from "../../utils/functions/getEndpoint.js"; import { convertDoiToLink as C, SYNAPSE_ENTITY_ID_REGEX as T } from "../../utils/functions/RegularExpressions.js"; import { TargetEnum as c } from "../../utils/html/TargetEnum.js"; import { isExternalLink as N } from "../../utils/functions/IsExternalLink.js"; import { FileHandleAssociateType as f } from "@sage-bionetworks/synapse-types"; const I = (e, t, r) => { let s; return e && t && (d(e) ? s = { fileHandleId: t, associateObjectId: e?.id ?? "", associateObjectType: f.TableEntity } : r && (s = { fileHandleId: t, associateObjectId: r, associateObjectType: f.FileEntity })), s; }, g = ({ columnName: e, value: t, selectColumns: r, columnModels: s }) => { if (!t) return { str: "", strList: void 0, selectColumn: void 0 }; const l = r?.find((o) => o.name === e) || s?.find((o) => o.name === e); if (l?.columnType.endsWith("_LIST")) { let o = t, n; try { return n = JSON.parse(o), o = n.join(", "), { strList: n, str: o, selectColumn: l }; } catch (a) { console.error( "Could not parse multivalue string ", o, " caught err ", a ); } } return { str: t, selectColumn: l }; }; function O(e, t, r, s) { if (e) { if (!t || !r) throw Error("Must specify CardLink and data for linking to work"); const { matchColumnName: l, overrideValueWithRowID: i } = e; if ("overrideLinkURLColumnName" in e) { const { overrideLinkURLColumnName: n, overrideLinkURLColumnTransform: a } = e; if (r[n]) { const m = r[n], u = t[m]; if (u && a) return a(u); if (u) return u; } } const o = r[l]; if (o === void 0) console.error( `Could not find match for data: ${t} with columnName ${l}` ); else if ("baseURL" in e) { const { baseURL: n, URLColumnName: a, urlParamStyle: m = "query-param" } = e, u = i ? `syn${s}` : t[o]; if (u) return m === "path-segment" ? `/${n}/${encodeURIComponent(u)}` : `/${n}?${a}=${encodeURIComponent(u)}`; } } } function $(e, t, r, s, l) { e = e.trim(); let i = e; const o = C(i); e.match(T) ? i = `${p.PORTAL}Synapse:${e}` : o ? i = o : t && (i = O(t, r, s, l) ?? ""); const a = !!(i && N(i)) ? c.NEW_WINDOW : c.CURRENT_WINDOW, m = t?.target ?? a; return { href: i, target: m }; } export { O as getCardLinkHref, I as getFileHandleAssociation, $ as getLinkParams, g as getValueOrMultiValue }; //# sourceMappingURL=CardUtils.js.map