synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
295 lines (294 loc) • 9.27 kB
JavaScript
import { jsx as n, jsxs as g, Fragment as te } 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 ie } from "@sage-bionetworks/synapse-types";
import { entityTypeToFriendlyName as B } from "../../utils/functions/EntityTypeUtils.js";
import { getEndpoint as se, BackendDestinationEnum as re } from "../../utils/functions/getEndpoint.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import { getAccessTypeFromPermissionLevel as x, permissionLevelToLabel as G } from "../../utils/PermissionLevelToAccessType.js";
import { SYNAPSE_DOCS_SHARING_SETTINGS_PERMISSIONS_CONDITIONS_FOR_USE_URL as ne } from "../../utils/SynapseConstants.js";
import { forwardRef as F, Suspense as oe, useMemo as j, useState as N, useEffect as E, useImperativeHandle as ce } from "react";
import "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import { Stack as ae, Link as le, Alert as de } 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 pe } from "@sage-bionetworks/synapse-client";
import "../../utils/types/IsType.js";
import { useSuspenseGetEntityBenefactorACL as me, useCreateEntityACL as ue, useUpdateEntityACL as fe, useDeleteEntityACL as Ae } from "../../synapse-queries/entity/useEntity.js";
import { useSuspenseGetEntityBundle as ye } from "../../synapse-queries/entity/useEntityBundle.js";
import { useSuspenseGetCurrentUserProfile as ge } from "../../synapse-queries/user/useUserBundle.js";
import { useGetRealmPrincipals as Ee } from "../../synapse-queries/realm/useRealmPrincipals.js";
import { isEntityPublic as Se, resourceAccessListIsEqual as he } from "../../utils/functions/AccessControlListUtils.js";
import { getDisplayNameFromProfile as Ie } from "../../utils/functions/DisplayUtils.js";
import { AclEditor as Le } from "../AclEditor/AclEditor.js";
import { AclEditorSkeleton as Ce } from "../AclEditor/AclEditorSkeleton.js";
import Ne from "../AclEditor/useUpdateAcl.js";
import { SynapseErrorBoundary as Pe } from "../error/ErrorBanner.js";
import ve from "../FullWidthAlert/FullWidthAlert.js";
import { CreateOrDeleteLocalSharingSettingsButton as De } from "./CreateOrDeleteLocalSharingSettingsButton.js";
import { InheritanceMessage as Te } from "./InheritanceMessage.js";
import _e from "./OpenData.js";
import Re from "./useNotifyNewACLUsers.js";
const be = [
"CAN_VIEW",
"CAN_DOWNLOAD",
"CAN_EDIT",
"CAN_EDIT_DELETE",
"CAN_ADMINISTER"
];
function we(t) {
return `${t} (shared on Synapse)`;
}
function Oe(t, i) {
return `${Ie(
t
)} has shared an item with you on Synapse:
${se(
re.PORTAL_ENDPOINT
)}Synapse:${i}`;
}
function Ue(t, i, o, s) {
return !t || i ? !1 : (d) => {
const S = o.ownerId === String(d.principalId), m = s !== void 0 && String(d.principalId) === s;
return !(S || m);
};
}
function We(t, i, o) {
return !t || i ? !1 : (s) => o.ownerId === String(s.principalId) ? !1 : t;
}
function ke(t, i) {
return (o) => {
if (i !== void 0 && String(o.principalId) === i)
return t ? G.CAN_DOWNLOAD : G.CAN_VIEW;
};
}
const Be = F(function(i, o) {
const {
entityId: s,
onCanSaveChange: d,
onUpdateSuccess: S,
isAfterUpload: m = !1
} = i, { data: h } = ge(), { data: P } = Ee(), { publicGroup: A } = P || {}, { data: r } = ye(
s,
void 0,
ie,
{ staleTime: 1 / 0 }
), v = pe.project == r.entityType, { data: I } = me(
r.entity.parentId,
{
staleTime: 1 / 0
}
), c = r.benefactorAcl.resourceAccess, D = j(
() => I?.resourceAccess ?? [],
[I]
), L = r.permissions.canChangePermissions, T = r.permissions.isEntityOpenData, a = r.benefactorAcl.id != s, [e, _] = N(a), [R, M] = N(!1), [b, V] = N(), {
resourceAccessList: l,
setResourceAccessList: u,
addResourceAccessItem: w,
updateResourceAccessItem: $,
removeResourceAccessItem: H,
resetDirtyState: p
} = Ne({ initialResourceAccessList: c });
E(() => {
c && (p(), u([...c]));
}, [c, p, u]), E(() => {
p(), _(a);
}, [a, p]), E(() => {
a == e ? u(c) : e && u(D), p();
}, [
a,
c,
D,
p,
u,
e
]);
const Y = Se(
l,
P ?? {}
), {
sendNotification: q,
isLoading: z,
isPending: J
} = Re({
subject: we(r.entity.name || ""),
body: Oe(h, s),
initialResourceAccessList: c,
newResourceAccessList: l
}), C = {
onSuccess: () => {
R && q(), S();
},
onError: (f) => {
V(f);
}
}, { mutate: O, isPending: K } = ue(C), { mutate: U, isPending: Q } = fe(C), { mutate: W, isPending: X } = Ae(C), Z = K || Q || X || J, k = j(() => a != e || !he(
c,
l
), [
c,
a,
e,
l
]), y = k || z || Z, ee = k && m;
return E(() => {
d(y);
}, [d, y]), ce(
o,
() => ({
save() {
y ? a != e ? e ? W(s) : O({
id: s,
resourceAccess: l
}) : U({
// ensure we get all fields from the original ACL, including the etag
...r.accessControlList,
resourceAccess: l
}) : console.error("EntityAclEditor: save() called but canSave is false");
}
}),
[
y,
O,
W,
r,
s,
a,
U,
e,
l
]
), /* @__PURE__ */ g(
ae,
{
sx: {
gap: 2
},
children: [
/* @__PURE__ */ n(
_e,
{
isOpenData: T,
isPublic: Y,
currentUserCanUpdateSharingSettings: L
}
),
/* @__PURE__ */ n(
Te,
{
isProject: v,
isInherited: e,
benefactorId: e ? I?.id : s,
isAfterUpload: m
}
),
ee && /* @__PURE__ */ n(
ve,
{
isGlobal: !1,
variant: "warning",
title: `Edits will affect settings of entire ${B(
r?.entityType
).toLowerCase()}.`,
description: /* @__PURE__ */ g(te, { children: [
/* @__PURE__ */ g("p", { children: [
"Editing the settings here will impact the sharing settings for all files and folders within this",
" ",
B(
r?.entityType
).toLowerCase(),
", not just the ones you've recently uploaded."
] }),
/* @__PURE__ */ g("p", { children: [
"View the instructions above for setting your",
" ",
/* @__PURE__ */ n(
le,
{
href: ne,
target: "_blank",
children: "Local Sharing Settings"
}
),
"."
] })
] })
}
),
/* @__PURE__ */ n(
Le,
{
isInherited: e,
canEdit: Ue(
L,
e,
h,
A
),
canRemoveEntry: We(
L,
e,
h
),
resourceAccessList: l,
availablePermissionLevels: be,
emptyText: (
/* This should never happen */
""
),
displayedPermissionLevelOverride: ke(
T,
A
),
onAddPrincipalToAcl: (f) => {
A !== void 0 && String(f) === A ? w(
f,
x("CAN_VIEW")
) : w(
f,
x("CAN_DOWNLOAD")
);
},
updateResourceAccessItem: $,
removeResourceAccessItem: H,
showNotifyCheckbox: !0,
notifyCheckboxValue: R,
onNotifyCheckboxChange: M,
showAddRemovePublicButton: !0
}
),
!m && !v && r.permissions.canEnableInheritance && /* @__PURE__ */ n(
De,
{
isInherited: e,
setIsInherited: _
}
),
b && /* @__PURE__ */ n(de, { severity: "error", children: b.message })
]
}
);
}), Rt = F(
function(i, o) {
return /* @__PURE__ */ n(Pe, { children: /* @__PURE__ */ n(oe, { fallback: /* @__PURE__ */ n(Ce, {}), children: /* @__PURE__ */ n(Be, { ...i, ref: o }) }) });
}
);
export {
Rt as default
};
//# sourceMappingURL=EntityAclEditor.js.map