synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
214 lines (213 loc) • 6.23 kB
JavaScript
import { jsxs as d, jsx as t, Fragment as j } from "react/jsx-runtime";
import * as g 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 "@sage-bionetworks/synapse-types";
import "../../utils/functions/EntityTypeUtils.js";
import "../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import { useGlobalIsEditingContext as A } from "../../utils/context/GlobalIsEditingContext.js";
import { useSynapseContext as T } from "../../utils/context/SynapseContext.js";
import { Box as W, Stack as F, TextField as C, Alert as Q, Button as U, IconButton as G, Menu as P, MenuItem as N, Divider as q } from "@mui/material";
import { useState as s, useEffect as E } from "react";
import { ErrorBanner as z } from "../error/ErrorBanner.js";
import H from "../IconSvg/IconSvg.js";
import { CreatedOnByUserDiv as J } from "./CreatedOnByUserDiv.js";
import { DeleteEvaluationQueueConfirmationDialog as K } from "./DeleteEvaluationQueueConfirmationDialog.js";
function de({
evaluationId: c,
entityId: l,
onDeleteSuccess: p,
onSaveSuccess: u
}) {
if (c && l)
throw new Error("please use either evaluationId or entityId but not both");
const { accessToken: o } = T(), { setIsEditing: m } = A(), [f, i] = s(!1), [r, a] = s(), [O, h] = s(!1);
E(() => (m(f), () => {
m(!1);
}), [f, m]), E(() => {
r && h(!1);
}, [r]);
const [S, b] = s(""), [x, w] = s(""), [M, y] = s(""), [D, I] = s(""), [n, k] = s({
contentSource: l
});
E(() => {
b(n.name ?? ""), w(n.description ?? ""), y(
n.submissionInstructionsMessage ?? ""
), I(n.submissionReceiptMessage ?? ""), i(!1);
}, [n]), E(() => {
c && (a(void 0), g.getEvaluation(c, o).then((e) => {
k(e);
}).catch((e) => a(e)));
}, [c, o]);
const B = () => {
a(void 0), h(!1);
const e = {
...n,
name: S,
description: x,
submissionInstructionsMessage: M,
submissionReceiptMessage: D
};
(e.id ? g.updateEvaluation(e, o) : g.createEvaluation(e, o)).then((v) => {
k(v), i(!1), h(!0), u && u(v.id);
}).catch((v) => a(v));
}, R = n?.id ? () => {
a(void 0), g.deleteEvaluation(n.id, o).then(p).catch((e) => a(e));
} : void 0;
return /* @__PURE__ */ d("div", { className: "evaluation-editor", children: [
/* @__PURE__ */ d(W, { sx: { display: "flex", justifyContent: "space-between" }, children: [
/* @__PURE__ */ d("h4", { children: [
n.id ? "Edit" : "Create",
" Evaluation Queue"
] }),
/* @__PURE__ */ t(L, { onClick: B, onDelete: R })
] }),
/* @__PURE__ */ d(
F,
{
sx: {
gap: 2
},
children: [
/* @__PURE__ */ t(
C,
{
label: "Name",
fullWidth: !0,
value: S,
onChange: (e) => {
b(e.target.value), i(!0);
}
}
),
/* @__PURE__ */ t(
C,
{
label: "Description",
fullWidth: !0,
multiline: !0,
value: x,
rows: 2,
onChange: (e) => {
w(e.target.value), i(!0);
}
}
),
/* @__PURE__ */ t(
C,
{
fullWidth: !0,
label: "Submission Instructions",
value: M,
multiline: !0,
rows: 2,
onChange: (e) => {
y(e.target.value), i(!0);
}
}
),
/* @__PURE__ */ t(
C,
{
label: "Submission Receipt Message",
fullWidth: !0,
value: D,
onChange: (e) => {
I(e.target.value), i(!0);
}
}
),
n?.createdOn && /* @__PURE__ */ t(
J,
{
userId: n.ownerId,
date: new Date(n.createdOn)
}
),
r && /* @__PURE__ */ t(z, { error: r }),
O && /* @__PURE__ */ t(
Q,
{
className: "save-success-alert",
severity: "success",
onClose: () => h(!1),
sx: { marginBottom: "20px" },
children: "Successfully saved."
}
),
/* @__PURE__ */ t(W, { sx: { mb: 3, alignSelf: "flex-end" }, children: /* @__PURE__ */ t(
U,
{
variant: "contained",
color: "primary",
className: "save-button",
onClick: B,
children: "Save"
}
) })
]
}
)
] });
}
function L({
onClick: c,
onDelete: l
}) {
const [p, u] = s(!1), [o, m] = s(null), f = !!o, i = (a) => {
m(a.currentTarget);
}, r = () => {
m(null);
};
return /* @__PURE__ */ d(j, { children: [
l && /* @__PURE__ */ t(
K,
{
open: p,
onConfirm: () => {
l(), u(!1);
},
onCancel: () => u(!1)
},
String(p)
),
/* @__PURE__ */ t(G, { onClick: i, children: /* @__PURE__ */ t(H, { icon: "verticalEllipsis", wrap: !1 }) }),
/* @__PURE__ */ d(
P,
{
anchorEl: o,
open: f,
onClose: r,
slotProps: { paper: { sx: { minWidth: "120px" } } },
children: [
/* @__PURE__ */ t(
N,
{
onClick: () => {
r(), c();
},
children: "Save"
}
),
l && /* @__PURE__ */ t(q, {}),
l && /* @__PURE__ */ t(
N,
{
onClick: () => {
r(), u(!0);
},
children: "Delete"
}
)
]
}
)
] });
}
export {
de as EvaluationEditor
};
//# sourceMappingURL=EvaluationEditor.js.map