synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
269 lines (268 loc) • 9.03 kB
JavaScript
import { jsx as t, Fragment as p, jsxs as h } 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 { SELF_SIGN_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as Y, MANAGED_ACT_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as B, RestrictableObjectType as c, ACCESS_TYPE as G } from "@sage-bionetworks/synapse-types";
import "../../utils/functions/EntityTypeUtils.js";
import "../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../utils/PermissionLevelToAccessType.js";
import { forwardRef as z, useState as u, useEffect as X, useMemo as $, useImperativeHandle as K } from "react";
import "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import { Skeleton as T, TextField as j, Alert as I, Typography as w, FormControlLabel as x, Checkbox as Z, Stack as ee, Tooltip as te, RadioGroup as re, Radio as H } 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 { useCreateAccessRequirement as oe, useUpdateAccessRequirement as ne, useGetAccessRequirements as se } from "../../synapse-queries/dataaccess/useAccessRequirements.js";
import { spreadSx as ie } from "../../theme/spreadSx.js";
import { HelpOutlineTwoTone as ce } from "@mui/icons-material";
import ae from "pluralize";
import le from "../EntitySubjectsSelector/EntitySubjectsSelector.js";
import { SynapseErrorBoundary as me } from "../error/ErrorBanner.js";
import ue from "../TeamSubjectsSelector/TeamSubjectsSelector.js";
const pe = "Please select at least one resource for this Access Requirement to be associated with.", de = (l) => {
const f = l === c.ENTITY ? "Synapse" : "Team", S = l[0].toUpperCase() + l.slice(1).toLowerCase();
return `${f} IDs were specified but not added to the subjects list. Please either clear out the Add ${f} IDs textbox or click the Add ${ae(
S
)} button.`;
}, Ee = "Enter access requirement name. This will also be used when sending notifications for expiring or revoked approval. For example, 'The approval for the name access requirement was revoked...'", A = {
variant: "body1",
fontWeight: 700
};
function he(l) {
switch (l) {
case c.ENTITY:
return G.DOWNLOAD;
case c.TEAM:
return G.PARTICIPATE;
default:
throw new Error(
`RestrictableObjectType ${l} does not have an access type specified.`
);
}
}
const et = z(
function(f, S) {
const { subject: i, accessRequirementId: _, onSave: V, onError: y } = f, d = !i, [a, R] = u(
i ? [i] : []
), [g, W] = u(!1), [v, E] = u(null), [b, N] = u(""), [n, U] = u(!1), [C, q] = u(
i?.type === c.TEAM ? Y : B
), [M, D] = u(null), P = (e) => {
D(null), V(e.id.toString(), e.concreteType);
}, L = (e) => {
D(e.reason), y();
}, { mutate: O } = oe({
onSuccess: (e) => P(e),
onError: (e) => L(e)
}), { mutate: k } = ne({
onSuccess: (e) => P(e),
onError: (e) => L(e)
}), {
data: r,
isLoading: J,
error: F
} = se(_, {
enabled: !!_
});
X(() => {
r && (q(r.concreteType), N(r.name), R(r.subjectIds), U(
r.subjectsDefinedByAnnotations
));
}, [r]);
const s = $(() => {
if (i)
return i.type;
if (r) {
const e = r.subjectIds;
if (e.length > 0)
return e[0].type;
}
return n ? c.ENTITY : null;
}, [i, r, n]), Q = $(() => {
if (!s) return /* @__PURE__ */ t(p, {});
function e(o) {
E(null), R(o);
}
function m(o) {
E(null), W(o.trim() !== "");
}
if (n)
return /* @__PURE__ */ t(p, {});
switch (s) {
case c.TEAM:
return /* @__PURE__ */ t(
ue,
{
subjects: a,
onUpdate: (o) => e(o),
onUpdateTeamIDsTextbox: (o) => m(o)
}
);
case c.ENTITY:
return /* @__PURE__ */ t(
le,
{
subjects: a,
onUpdate: (o) => e(o),
onUpdateEntityIDsTextbox: (o) => m(o)
}
);
default:
return console.error(
`RestrictableObjectType ${s} does not have a selector implemented.`
), /* @__PURE__ */ t(p, {});
}
}, [s, a, n]);
return K(
S,
() => ({
save() {
const e = d && !r || !s, m = !n && (g || a.length === 0);
if (e || m) {
m && !e && (g ? E(de(s)) : a.length === 0 && E(pe)), y();
return;
}
const o = he(s);
d || O({
concreteType: C,
subjectIds: a,
name: b,
accessType: o,
subjectsDefinedByAnnotations: n
}), d && r && k({
...r,
subjectIds: a,
name: b,
accessType: o,
subjectsDefinedByAnnotations: n
});
}
}),
[
g,
s,
a,
b,
C,
r,
d,
y,
O,
k,
n
]
), J || !s ? /* @__PURE__ */ h(p, { children: [
/* @__PURE__ */ t(T, { width: 100, height: 30 }),
/* @__PURE__ */ t(T, { width: 125, height: 30 }),
/* @__PURE__ */ t(T, { width: "100%", children: /* @__PURE__ */ t(j, {}) }),
/* @__PURE__ */ t(T, { width: 100, height: 30 }),
/* @__PURE__ */ t(T, { width: "100%", children: /* @__PURE__ */ t(j, {}) })
] }) : F ? /* @__PURE__ */ t(I, { severity: "error", children: F.reason }) : /* @__PURE__ */ h(p, { children: [
/* @__PURE__ */ t(w, { ...A, children: "Resources" }),
s !== c.TEAM && /* @__PURE__ */ t(
x,
{
control: /* @__PURE__ */ t(Z, {}),
label: "Associated entities should be defined by annotations (DUO)",
checked: n,
onChange: () => {
E(null);
let e = [];
n && (r ? e = r.subjectIds : i && (e = [i])), R(e), U(!n);
}
}
),
/* @__PURE__ */ t(me, { children: Q }),
v && /* @__PURE__ */ t(I, { severity: "error", children: v }),
/* @__PURE__ */ h(
ee,
{
direction: "row",
sx: {
gap: 1,
alignItems: "center",
mb: 1,
mt: 2
},
children: [
/* @__PURE__ */ t(w, { component: "label", htmlFor: "arName", ...A, children: "Name" }),
/* @__PURE__ */ t(te, { title: Ee, placement: "right", children: /* @__PURE__ */ t(ce, { sx: { color: "grey.600" } }) })
]
}
),
/* @__PURE__ */ t(
j,
{
id: "arName",
name: "arName",
value: b,
placeholder: "Access requirement name",
fullWidth: !0,
onChange: (e) => N(e.target.value)
}
),
!d && s !== c.TEAM && /* @__PURE__ */ h(p, { children: [
/* @__PURE__ */ t(
w,
{
...A,
sx: ie(
{
mt: 2
},
A.sx
),
children: "Access requirement type"
}
),
/* @__PURE__ */ h(
re,
{
value: C,
onChange: (e, m) => q(m),
children: [
/* @__PURE__ */ t(
x,
{
value: B,
control: /* @__PURE__ */ t(H, {}),
label: "Controlled - requests are in Synapse"
}
),
/* @__PURE__ */ t(
x,
{
value: Y,
control: /* @__PURE__ */ t(H, {}),
label: "Click wrap"
}
)
]
}
)
] }),
M && /* @__PURE__ */ t(I, { severity: "error", sx: { marginTop: 2 }, children: M })
] });
}
);
export {
pe as EMPTY_SUBJECT_LIST_ERROR_MESSAGE,
et as SetAccessRequirementCommonFields,
de as UNSAVED_SUBJECTS_ERROR_MESSAGE
};
//# sourceMappingURL=SetAccessRequirementCommonFields.js.map