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

168 lines (167 loc) 5.34 kB
import { jsxs as u, Fragment as E, jsx as n } from "react/jsx-runtime"; import W from "../../../synapse-queries/entity/useEntityBundle.js"; import { isVersionableEntityType as j, entityTypeToFriendlyName as _ } from "../../../utils/functions/EntityTypeUtils.js"; import { getEndpoint as q, BackendDestinationEnum as G } from "../../../utils/functions/getEndpoint.js"; import { Button as l, Tooltip as U } from "@mui/material"; import z from "@mui/material/Skeleton"; import { noop as H } from "lodash-es"; import { useRef as J, useState as d, useEffect as K, useMemo as Q } from "react"; import { ConfirmationDialog as X } from "../../ConfirmationDialog/ConfirmationDialog.js"; import { DialogBase as Y } from "../../DialogBase.js"; import { SynapseErrorBoundary as Z } from "../../error/ErrorBanner.js"; import { SchemaDrivenAnnotationEditor as nn } from "../../SchemaDrivenAnnotationEditor/SchemaDrivenAnnotationEditor.js"; import { displayToast as tn } from "../../ToastMessage/ToastMessage.js"; import { AnnotationsTable as en } from "./AnnotationsTable.js"; import { MetadataTable as on } from "./MetadataTable.js"; const sn = [ // non-annotation metadata about the entity "METADATA", // annotation and schema information "ANNOTATIONS" // TODO: Access -- we haven't yet built a viewer/editor for ACLs in SRC -- consider a redesign before building //'ACCESS', // ACLs (and maybe ARs?) // TODO: Previews - we would need preview renderers that accomplish feature parity with SWC //'PREVIEW' // should only show this tab if a preview exists ]; function Nn(h) { const { entityId: i, versionNumber: c, show: C, onClose: f, initialTab: N = "METADATA", showTabs: O = !0, onEditModeChanged: m = H } = h, p = J(null), [o, v] = d(N), [w, a] = d(!1), [e, s] = d(!1), [b, A] = d( () => s(!1) ); K(() => (m(e), () => { m(!1); }), [e, m]); const { data: t } = W(i, c), S = t && t.permissions.canEdit, T = t && j(t.entityType), g = T && t.entity.isLatestVersion, B = o === "METADATA" && t && !(typeof window < "u" && window.location.href.includes(i)), M = /* @__PURE__ */ u( l, { variant: "contained", onClick: () => window.open( `${q( G.PORTAL_ENDPOINT )}Synapse:${i}`, "_blank", "noopener" ), children: [ "Open", " ", t ? _(t?.entityType) : "" ] } ), I = o === "ANNOTATIONS" && e, D = /* @__PURE__ */ n( l, { variant: "contained", onClick: () => { p.current.formElement.current.requestSubmit(); }, children: "Save Annotations" } ), k = o === "ANNOTATIONS" && e, P = /* @__PURE__ */ n( l, { variant: "outlined", onClick: () => { A(() => () => s(!1)), a(!0); }, children: "Cancel" } ), V = S && o === "ANNOTATIONS" && !e, y = T && !g, x = /* @__PURE__ */ n( U, { title: y ? "Annotations can only be edited on the latest version" : void 0, children: /* @__PURE__ */ n("span", { children: /* @__PURE__ */ n( l, { variant: "contained", disabled: y, onClick: () => { s(!0); }, children: "Edit" } ) }) } ), R = /* @__PURE__ */ u(E, { children: [ O && !e ? /* @__PURE__ */ n("div", { className: "Tabs", children: sn.map((r) => /* @__PURE__ */ n( "div", { className: "Tab", role: "tab", onClick: (L) => { L.stopPropagation(), v(r); }, "aria-selected": r === o, children: r }, r )) }) : null, /* @__PURE__ */ n("div", { style: o === "ANNOTATIONS" ? {} : { display: "none" }, children: e ? /* @__PURE__ */ n(Z, { children: /* @__PURE__ */ n( nn, { entityId: i, formRef: p, hideActions: !0, onSuccess: () => { tn("Annotations successfully updated.", "success"), s(!1); }, onCancel: () => s(!1) } ) }) : /* @__PURE__ */ n(en, { entityId: i, versionNumber: c }) }), /* @__PURE__ */ n("div", { style: o === "METADATA" ? {} : { display: "none" }, children: /* @__PURE__ */ n(on, { entityId: i, versionNumber: c }) }) ] }), $ = /* @__PURE__ */ n( X, { open: w, title: "Unsaved Changes", content: "Any unsaved changes will be lost. Are you sure you want to close the editor?", onCancel: () => { a(!1); }, onConfirm: () => { a(!1), b(); } } ), F = Q(() => { if (t?.entity.name) { if (o === "ANNOTATIONS") return `${e ? "Edit " : ""}Annotations for ${t.entity.name}`; } else return /* @__PURE__ */ n(z, { width: "40%" }); return t.entity.name; }, [o, t?.entity.name, e]); return /* @__PURE__ */ n( Y, { className: "EntityMetadata", open: C, onCancel: () => { e ? (a(!0), A(() => () => { s(!1), f(); })) : f(); }, maxWidth: e ? "md" : "sm", title: F, content: R, actions: /* @__PURE__ */ u(E, { children: [ $, k && P, I && D, V && x, B && M ] }) } ); } export { Nn as EntityModal, sn as EntityModalTabs, Nn as default }; //# sourceMappingURL=EntityModal.js.map