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

298 lines (294 loc) 10.6 kB
import { jsxs as a, Fragment as h, jsx as t } from "react/jsx-runtime"; import ie from "../Dialog/ConfirmCloseWithoutSavingDialog.js"; import { DialogBase as re } from "../DialogBase.js"; import { doiFormUiSchema as oe, doiFormSchema as ne } from "./DoiFormSchemas.js"; import { PrivateEntityDoiWarning as ae } from "./PrivateEntityDoiWarning.js"; import { JsonSchemaForm as se } from "../JsonSchemaForm/JsonSchemaForm.js"; import { MarkdownPopover as le } from "../Markdown/MarkdownPopover.js"; import { StyledFormControl as ce } from "../styled/StyledFormControl.js"; import { displayToast as de } from "../ToastMessage/ToastMessage.js"; import { useGetDOI as me, useCreateOrUpdateDOI as ue } from "../../synapse-queries/doi/useDOI.js"; import { useGetVersions as pe } from "../../synapse-queries/entity/useEntity.js"; import fe from "../../synapse-queries/entity/useEntityBundle.js"; import { useGetPortal as he } from "../../synapse-queries/portal/usePortal.js"; import { useGetRealmPrincipals as ye } from "../../synapse-queries/realm/useRealmPrincipals.js"; import { useGetCurrentUserProfile as ge } from "../../synapse-queries/user/useUserBundle.js"; import { useGlobalIsEditingContext as be } from "../../utils/context/GlobalIsEditingContext.js"; import { isEntityPublic as ve } from "../../utils/functions/AccessControlListUtils.js"; import { isVersionableEntity as we, entityTypeToFriendlyName as Te, isTable as De, isDataset as Ie } from "../../utils/functions/EntityTypeUtils.js"; import { getEndpoint as Ce, BackendDestinationEnum as Se } from "../../utils/functions/getEndpoint.js"; import { DATA_CATALOG_PATH_SEGMENT as Oe } from "../../utils/SynapseConstants.js"; import { HelpTwoTone as Ne } from "@mui/icons-material"; import { Typography as d, Link as Ee, TextField as Ae, InputLabel as Le, Select as Pe, MenuItem as $, Alert as N, Button as j } from "@mui/material"; import { DoiObjectType as M, EntityType as A, DoiResourceTypeGeneral as R } from "@sage-bionetworks/synapse-client"; import { isEmpty as Fe } from "lodash-es"; import { useState as y, useRef as U, useEffect as E, useMemo as Ge } from "react"; import { SynapseSpinner as ke } from "../LoadingScreen/LoadingScreen.js"; function xe(r) { return r === A.project || r === A.folder ? R.Collection : R.Dataset; } function Ve(r) { return { titles: (r.titles || []).map((i) => i.title), creators: (r.creators || []).map((i) => i.creatorName), resourceTypeGeneral: r.resourceType?.resourceTypeGeneral, publicationYear: r.publicationYear }; } function Be(r) { return !!r.creators?.some((i) => !Fe(i.nameIdentifiers)); } function $e(r) { return { titles: r.titles?.map((i) => ({ title: i })) || [], creators: r.creators?.map((i) => ({ creatorName: i })) || [], resourceType: { resourceTypeGeneral: r.resourceTypeGeneral }, publicationYear: r.publicationYear }; } function ut(r) { const { open: i, onClose: g, objectType: m, objectId: u, defaultVersionNumber: Y, portalId: c } = r, [W, b] = y(!1), [s, v] = y(null), w = U(!1), { isEditing: _, setIsEditing: T } = be(); E(() => (T(i), () => { T(!1); }), [i, T]); function L() { _ ? b(!0) : g(); } const [p, P] = y(Y), { data: H } = he(c, { enabled: !!c }), [F, D] = y({ titles: [""], creators: [""] }), { data: l, isLoading: q } = ge(), { data: o, isLoading: J } = fe( u, p, { includeEntity: !0, includeBenefactorACL: !0 }, { enabled: m === M.ENTITY, staleTime: 1 / 0, throwOnError: !0 } ), { data: I, isLoading: z } = ye(), { data: n, isLoading: K } = me( { id: u, version: p, type: m, portalId: c }, { staleTime: 1 / 0, throwOnError: !0 } ), C = Ge(() => i && n === null && // Creating new DOI o?.benefactorAcl && I && !ve( o.benefactorAcl.resourceAccess, I ), [i, n, o, I]); E(() => { i && !w.current && n !== void 0 && // Wait for DOI query to resolve before determining step C !== void 0 ? (v(C ? "warning" : "form"), w.current = !0) : i || (v(null), w.current = !1); }, [C, i, n]); const G = m === M.ENTITY && o?.entity && we(o.entity), { data: k } = pe( u, void 0, void 0, { enabled: G } ), S = U(null), Q = o?.entityType ?? A.file, f = Te(Q); let x = `A DOI can be associated with a specific version of this ${f}. Versioned DOIs will link to the specified version of the ${f}. A DOI without a version will always link to the newest version of this ${f}, so the data that someone retrieves using the DOI may change over time.`; if (o?.entity && De(o.entity)) { const e = Ie(o.entity) ? "version" : "snapshot"; x += ` To create a DOI that will always link to the current set of data in the ${f}, create a new ${e} and mint a DOI for that ${e}.`; } const { mutate: X, isPending: Z, error: V } = ue({ onSuccess: () => { de("The DOI was successfully updated.", "success"), g(); } }), O = Z || q || J || K || z, B = !!(n && Be(n)); E(() => { if (n && D(Ve(n)), l && o?.entity && n === null) { const e = { titles: [o.entity.name], creators: new Array(), resourceTypeGeneral: xe( o.entityType ), publicationYear: (/* @__PURE__ */ new Date()).getFullYear() }; l.lastName && l.firstName && e.creators.push( `${l.lastName}, ${l.firstName}` ), D(e); } }, [l, n, o]); function ee() { if (S.current && S.current.validateForm()) { const e = $e(F); e.objectType = m, e.objectId = u, e.objectVersion = p, e.etag = n?.etag, e.portalId = c, X({ doi: e, concreteType: "org.sagebionetworks.repo.model.doi.v2.DoiRequest" }); } } const te = /* @__PURE__ */ a(h, { children: [ /* @__PURE__ */ t(d, { variant: "body1", gutterBottom: !0, children: "Minting a DOI allows you to credit contributors and makes it easy to cite your work." }), /* @__PURE__ */ a(d, { variant: "body1", gutterBottom: !0, sx: { mb: 2 }, children: [ "Note that while the DOI and its associated metadata will be publicly visible outside of Synapse, your data will still adhere to its existing access conditions. If your data is private, it will remain restricted, but the DOI will still be listed. Resources with DOIs may be added to the", " ", /* @__PURE__ */ t( Ee, { href: `${Ce( Se.PORTAL_ENDPOINT )}${Oe}`, target: "_blank", rel: "noopener", children: "Synapse Data Catalog" } ), "." ] }), c && /* @__PURE__ */ t( Ae, { label: "Publisher", fullWidth: !0, value: H?.name || "", disabled: !0 } ), G && /* @__PURE__ */ a(ce, { className: "limit-type", fullWidth: !0, sx: { my: 2 }, children: [ /* @__PURE__ */ a( Le, { htmlFor: "doi-version-select", sx: { display: "flex", alignItems: "center", justifyContent: "space-between", width: "100%" }, children: [ /* @__PURE__ */ t("span", { children: "Version" }), /* @__PURE__ */ t( le, { contentProps: { markdown: x }, maxWidth: "350px", children: /* @__PURE__ */ t(Ne, { className: "HelpButton" }) } ) ] } ), /* @__PURE__ */ a( Pe, { id: "doi-version-select", value: p ?? -1, onChange: (e) => { e.target.value === -1 ? P(void 0) : P(e.target.value); }, children: [ /* @__PURE__ */ t($, { value: -1, children: "No version" }), k && k.results.map((e) => /* @__PURE__ */ a( $, { value: e.versionNumber, children: [ "Version ", e.versionNumber, e.versionLabel && e.versionLabel !== String(e.versionNumber) ? ` / ${e.versionLabel}` : "" ] }, e.versionNumber )) ] } ) ] }), /* @__PURE__ */ t("div", { className: "JsonSchemaFormContainer", children: /* @__PURE__ */ t( se, { formRef: S, disabled: O || B, schema: ne, formData: F, onChange: (e) => { D(e.formData); }, uiSchema: oe, showErrorList: !1 } ) }), n && /* @__PURE__ */ t(N, { severity: "warning", children: /* @__PURE__ */ t(d, { variant: "body1", children: "A DOI has already been created. Updating the DOI information will cause old information to be lost!" }) }), B && /* @__PURE__ */ t(N, { severity: "warning", sx: { my: 1 }, children: /* @__PURE__ */ t(d, { variant: "body1", children: "The metadata for this DOI was modified using a programmatic client, so data may be hidden from this view. Any changes may result in metadata being lost." }) }), V && /* @__PURE__ */ t(N, { severity: "error", sx: { mt: 1 }, children: /* @__PURE__ */ t(d, { variant: "body1", children: V.message }) }) ] }); return /* @__PURE__ */ a(h, { children: [ /* @__PURE__ */ t( ie, { open: W, onCancel: () => { b(!1); }, onConfirm: () => { b(!1), g(); } } ), /* @__PURE__ */ t( re, { open: i, onCancel: L, title: s === "warning" ? "This page is private" : "Create or Update a DOI", content: s ? /* @__PURE__ */ a(h, { children: [ s === "warning" && /* @__PURE__ */ t(ae, {}), s === "form" && te ] }) : /* @__PURE__ */ t(ke, {}), actions: /* @__PURE__ */ a(h, { children: [ /* @__PURE__ */ t(j, { variant: "outlined", disabled: O, onClick: L, children: "Cancel" }), /* @__PURE__ */ t( j, { variant: "contained", disabled: O, onClick: s === "warning" ? () => v("form") : (e) => { e.preventDefault(), ee(); }, children: s === "warning" ? "Continue" : "Save" } ) ] }) } ) ] }); } export { ut as CreateOrUpdateDoiModal, ut as default }; //# sourceMappingURL=CreateOrUpdateDoiModal.js.map