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

262 lines (261 loc) 8.85 kB
import { jsx as t, Fragment as d, jsxs as l } 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 { ALL_ENTITY_BUNDLE_FIELDS as $ } from "@sage-bionetworks/synapse-types"; import "../../utils/functions/EntityTypeUtils.js"; import "../../utils/SynapseConstants.js"; import { isEmpty as J } from "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import { useState as u, useEffect as Y } from "react"; import "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import { Tooltip as a } 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 { EntityType as q } from "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import { useGetJson as z, useDeleteEntity as K } from "../../synapse-queries/entity/useEntity.js"; import { useGetSchemaBinding as Q, useGetValidationResults as X } from "../../synapse-queries/entity/useEntityBoundSchema.js"; import Z from "../../synapse-queries/entity/useEntityBundle.js"; import { useGetRealmPrincipals as tt } from "../../synapse-queries/realm/useRealmPrincipals.js"; import { isEntityPublic as B } from "../../utils/functions/AccessControlListUtils.js"; import { PublicTwoTone as et, LockTwoTone as it, CheckTwoTone as nt, LocalOfferTwoTone as ot, DescriptionTwoTone as at, ChatBubbleTwoTone as rt, LinkOffTwoTone as st } from "@mui/icons-material"; import { useInView as lt } from "react-intersection-observer"; import { getDisplayedAnnotation as A } from "../entity/metadata/AnnotationsTable.js"; import { EntityModal as ct } from "../entity/metadata/EntityModal.js"; import { HoverPopover as dt } from "../styled/HoverPopover.js"; import { WarningDialog as mt } from "../SynapseForm/WarningDialog.js"; const Zt = (_) => { const { entityId: n, versionNumber: g, flexWrap: C = "nowrap", justifyContent: I = "flex-start", showIsPublicPrivate: b = !0, showHasLocalSharingSettings: D = !0, showHasAnnotations: v = !0, showHasWiki: S = !0, showHasDiscussionThread: x = !0, showUnlink: V = !0, onUnlink: M = () => { }, onUnlinkError: O = () => { }, canOpenModal: y } = _, { data: L } = tt(), T = L || {}; let w; ((i) => { i.NO_SCHEMA = "", i.VALID = "Valid", i.INVALID = "Invalid", i.ANNOTATIONS_MISSING = "Missing"; })(w || (w = {})); const { ref: P, inView: c } = lt(), { data: H } = z(n, g, !0, { enabled: c }), o = H?.annotations, { data: e } = Z( n, g, $, { enabled: c } ), [U, N] = u(!1), [j, m] = u(!1), [E, h] = u( "" /* NO_SCHEMA */ ), { data: p } = Q(n, { enabled: c, staleTime: 60 * 1e3 // 60 seconds }), { data: r } = X(n, { enabled: c && !!p, staleTime: 60 * 1e3 // 60 seconds }), f = o && !J(o) ? Object.keys(o).length : 0; Y(() => { r && (r.isValid ? h( "Valid" /* VALID */ ) : h( f ? "Invalid" : "Missing" /* INVALID */ )); }, [ r, f, o, "Valid", "Invalid", "Missing" /* ANNOTATIONS_MISSING */ ]); const { mutate: G } = K({ onSuccess: (i, s) => { M(s); }, onError: O }), k = /* @__PURE__ */ t(d, { children: o ? Object.entries(o ?? []).map(([i, s]) => /* @__PURE__ */ l("tr", { children: [ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ t("b", { children: i }) }), /* @__PURE__ */ t("td", { children: Array.isArray(s) ? s.map(A).join(", ") : A(s) }) ] }, i)) : "" }), R = /* @__PURE__ */ t(d, { children: p ? /* @__PURE__ */ l("tr", { children: [ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ t("b", { children: "Validation Schema" }) }), /* @__PURE__ */ t("td", { children: p.jsonSchemaVersionInfo.schemaName }) ] }) : "" }), W = r ? `${E} Annotations` : "", F = /* @__PURE__ */ t("div", { className: "EntityBadgeTooltip", children: /* @__PURE__ */ t("table", { children: /* @__PURE__ */ l("tbody", { children: [ k || "", R ] }) }) }); return /* @__PURE__ */ t("div", { className: "EntityBadge", ref: P, style: { flexWrap: C, justifyContent: I }, children: e && /* @__PURE__ */ l(d, { children: [ /* @__PURE__ */ t("div", { onClick: (i) => i.stopPropagation(), children: /* @__PURE__ */ t( ct, { entityId: n, show: U, showTabs: !1, onClose: () => N(!1), initialTab: "ANNOTATIONS" } ) }), b && e.benefactorAcl && B( e.benefactorAcl.resourceAccess, T ) ? /* @__PURE__ */ t(a, { title: "Public", enterNextDelay: 100, placement: "right", children: /* @__PURE__ */ t( et, { "aria-hidden": !1, role: "img", className: "EntityBadge__Badge", "data-testid": "is-public-icon" } ) }) : null, b && e.benefactorAcl && !B( e.benefactorAcl.resourceAccess, T ) ? /* @__PURE__ */ t(a, { title: "Private", enterNextDelay: 100, placement: "right", children: /* @__PURE__ */ t( it, { "aria-hidden": !1, role: "img", className: "EntityBadge__Badge", "data-testid": "is-private-icon" } ) }) : null, D && e.benefactorAcl && n === e.benefactorAcl.id ? /* @__PURE__ */ t( a, { title: "Sharing Settings have been set", enterNextDelay: 100, placement: "right", children: /* @__PURE__ */ t( nt, { "aria-hidden": !1, role: "img", className: "EntityBadge__Badge", "data-testid": "sharing-settings-icon" } ) } ) : null, v && !!(f || r) && /* @__PURE__ */ t( dt, { title: W, popoverContent: F, placement: "right", maxWidth: 500, actionButton: y ? { content: "Edit Annotations", onClick: () => N(!0), closeOnClick: !0 } : void 0, children: /* @__PURE__ */ t( ot, { "aria-hidden": !1, role: y ? "button" : "img", className: `EntityBadge__Badge ${E}`, "data-html": !0, "data-testid": "annotations-icon" } ) } ), S && e.rootWikiId && /* @__PURE__ */ t(a, { title: "Has a wiki", enterNextDelay: 100, placement: "right", children: /* @__PURE__ */ t( at, { "aria-hidden": !1, role: "img", className: "EntityBadge__Badge", "data-testid": "wiki-icon" } ) }), x && !!e.threadCount && e.threadCount > 0 && /* @__PURE__ */ t( a, { title: "Has been mentioned in discussion", enterNextDelay: 100, placement: "right", children: /* @__PURE__ */ t( rt, { "aria-hidden": !1, role: "img", className: "EntityBadge__Badge", "data-testid": "discussion-icon" } ) } ), V && e.entityType === q.link && e.permissions?.canDelete && /* @__PURE__ */ l(d, { children: [ /* @__PURE__ */ t( mt, { open: j, title: "Confirm Unlink", content: "Are you sure you want to remove this link? The original object will not be changed.", confirmButtonText: "Unlink", confirmButtonColor: "error", onConfirm: () => { G(n), m(!1); }, onCancel: () => { m(!1); } } ), /* @__PURE__ */ t( a, { title: "Remove this link", enterNextDelay: 100, placement: "right", children: /* @__PURE__ */ t( st, { "aria-hidden": !1, role: "button", onClick: () => m(!0), className: "EntityBadge__Badge Unlink", "data-testid": "unlink-icon" } ) } ) ] }) ] }) }); }; export { Zt as EntityBadgeIcons, Zt as default }; //# sourceMappingURL=EntityBadgeIcons.js.map