synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
185 lines (184 loc) • 5.82 kB
JavaScript
import { jsxs as D, jsx as h, Fragment as W } from "react/jsx-runtime";
import { createEntity as q } from "../../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 { ACCESS_TYPE as n, PROJECT_CONCRETE_TYPE_VALUE as z } 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 { useState as o, useEffect as i } from "react";
import { useSynapseContext as K } from "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import "@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 { useUpdateEntityACL as Q, useGetEntityAlias as X, useGetEntityACL as Z, useGetEntityPermissions as ee } from "../../synapse-queries/entity/useEntity.js";
import { useGetEntityChallenge as te } from "../../synapse-queries/entity/useGetEntityChallenge.js";
import { useGetTeam as re } from "../../synapse-queries/team/useTeam.js";
import { useGetUserSubmissionTeams as oe } from "../../synapse-queries/user/useGetUserTeams.js";
import { useGetCurrentUserProfile as se } from "../../synapse-queries/user/useUserBundle.js";
import { SynapseErrorBoundary as ne, ErrorBanner as ie } from "../error/ErrorBanner.js";
import ae from "./ChallengeSubmissionStepper.js";
import me from "./SubmissionDirectoryList.js";
function We({
entityType: b,
projectId: g,
pageSize: M = 10
}) {
const { isAuthenticated: t, accessToken: T } = K(), [v, u] = o(!0), [A, C] = o(), [S, U] = o(), [c, I] = o(), [a, Y] = o(), [j, w] = o(), [L, O] = o(), { mutate: x } = Q(), [$, B] = o(!1), [N, F] = o(), [H, G] = o(!1), y = "", R = (e, E) => {
const m = `Challenge Submission Project-${e.projectId}-${E.id}`, J = m.replace(/\s+/g, "_").replace(/-+/g, "_").toLowerCase();
return {
name: m,
alias: J,
concreteType: z,
description: `This Project was automatically created for Team "${E.name}" for Challenge "${e.id}"`
};
}, { data: d, isLoading: _ } = se({
enabled: t,
throwOnError: !0
}), { data: r } = te(g, {
enabled: t && !!g,
refetchInterval: 1 / 0,
throwOnError: !0
}), { data: l } = oe(
r?.id ?? y,
2
);
i(() => {
if (t && r && l) {
if (!(l.results.length > 0))
return C(
"Error: Please join a Submission Team before continuing."
), u(!1);
if (l.results.length > 1)
return C(
"Error: You are a member of more than one Submission Team. You may only belong to one Submission Team per Challenge."
), u(!1);
U(l.results[0]);
}
}, [r, t, l]);
const { data: s } = re(S, {
enabled: !!S,
refetchInterval: 1 / 0,
throwOnError: !0
}), { data: P } = X(
a?.alias ?? y,
{
enabled: a !== void 0 && !!r && !!s,
throwOnError: !0
}
);
i(() => {
P ? (O(!0), I(P.id)) : O(!1);
}, [P]);
const { data: p } = Z(c ?? y, {
enabled: !!c && j === !0,
refetchInterval: 1 / 0,
throwOnError: !0
});
i(() => {
if (p && j === !0) {
const e = {
principalId: Number(s.id),
accessType: [
n.CHANGE_PERMISSIONS,
n.CHANGE_SETTINGS,
n.CREATE,
n.DELETE,
n.DOWNLOAD,
n.MODERATE,
n.READ,
n.UPDATE
]
};
x({
...p,
resourceAccess: [...p.resourceAccess, e]
}), w(!1);
}
}, [p]);
const { data: f } = ee(
c,
{
enabled: !!c,
refetchInterval: 1 / 0,
throwOnError: !0
}
);
i(() => {
f && f.canView && f.canAddChild && B(!0), u(!1);
}, [f]), i(() => {
!t && (d || !_) && (u(!1), C("Please login to continue."));
}, [t, d, _]), i(() => {
if (t && s && r && !a) {
const e = R(r, s);
Y(e);
}
}, [t, s, r, a]), i(() => {
async function e() {
const E = R(r, s), m = await q(E, T);
m && m.id && (I(m.id), w(!0));
}
t && s && r && a && L === !1 && e();
}, [
t,
s,
r,
a,
L,
T
]);
const V = (e) => {
F(e), G(!0);
}, k = () => {
G(!1);
};
return /* @__PURE__ */ D(ne, { children: [
v && /* @__PURE__ */ h("span", { "data-testid": "SpinnerButton-spinner", className: "spinner" }),
$ && /* @__PURE__ */ D(W, { children: [
/* @__PURE__ */ h(
me,
{
entityType: b,
pageSize: M,
challengeProjectId: c,
onItemSelected: V
}
),
d && N && /* @__PURE__ */ h(
ae,
{
projectId: g,
userId: d?.ownerId,
teamId: S,
entity: N,
entityType: b,
isShowingModal: H,
onClose: k
}
)
] }),
A && /* @__PURE__ */ h(ie, { error: A })
] });
}
export {
We as ChallengeSubmission,
We as default
};
//# sourceMappingURL=ChallengeSubmission.js.map