synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
245 lines (244 loc) • 7.31 kB
JavaScript
import { jsx as t, jsxs as h } from "react/jsx-runtime";
import { updateEvaluationRound as Q, createEvaluationRound as V, deleteEvaluationRound as X } from "../../synapse-client/SynapseClient.js";
import { useGlobalIsEditingContext as Z } from "../../utils/context/GlobalIsEditingContext.js";
import { useSynapseContext as _ } from "../../utils/context/SynapseContext.js";
import { useListState as ee } from "../../utils/hooks/useListState.js";
import { Card as te, CardContent as re, Box as u, Grid as b, TextField as se, Button as N, Alert as ie } from "@mui/material";
import c from "dayjs";
import ne from "dayjs/plugin/isSameOrAfter";
import oe from "dayjs/plugin/utc";
import { upperFirst as ae } from "lodash-es";
import { useState as l, useEffect as A } from "react";
import O from "../DateTimePicker/DateTimePicker.js";
import { ErrorBanner as de } from "../error/ErrorBanner.js";
import le from "../IconSvg/IconSvg.js";
import { EvaluationRoundEditorDropdown as ce } from "./EvaluationRoundEditorDropdown.js";
import { convertEvaluationRoundToInput as me } from "./input_models/models.js";
import { EvaluationRoundLimitOptionsList as ue } from "./round_limits/EvaluationRoundLimitOptionsList.js";
c.extend(oe);
c.extend(ne);
const he = (e) => {
const o = e.startOf("day");
return (n) => n.isSameOrAfter(o);
}, B = (e, o) => {
let n, i, a;
const d = c();
return d.isSameOrAfter(e) ? d.isBefore(o) ? (n = "status-in-progress", i = { icon: "sync" }, a = "IN PROGRESS") : (n = "status-completed", i = { icon: "clipboardCheck" }, a = "COMPLETED") : (n = "status-not-yet-started", i = void 0, a = "NOT YET STARTED"), /* @__PURE__ */ t("div", { className: n, children: /* @__PURE__ */ h("div", { className: "status", children: [
i && /* @__PURE__ */ t(le, { ...i }),
/* @__PURE__ */ t("span", { children: a })
] }) });
}, P = (e, o, n, i, a) => {
const d = [];
if (i) {
const s = Number(i);
if (Number.isNaN(s))
throw TypeError("Total Submission is not an integer");
d.push({
limitType: "TOTAL",
maximumSubmissions: s
});
}
return a.forEach((s) => {
if (s.maxSubmissionString) {
const m = Number(s.maxSubmissionString);
if (Number.isNaN(m))
throw TypeError(s.type + " Limit is not an integer");
d.push({
limitType: s.type,
maximumSubmissions: m
});
}
}), {
id: e.id,
etag: e.etag,
evaluationId: e.evaluationId,
roundStart: c.utc(o).toJSON(),
roundEnd: c.utc(n).toJSON(),
limits: d
};
};
function w(e, o) {
return o == null ? null : o === "disablePast" ? `${ae(e)} date cannot be in the past` : "Invalid date";
}
function Be({
evaluationRoundInput: e,
onSave: o,
onDelete: n
}) {
const { accessToken: i } = _(), { setIsEditing: a } = Z(), [d, s] = l(!1), [m, f] = l(), [k, S] = l(!1);
A(() => (a(d), () => {
a(!1);
}), [d, a]), A(() => {
m && S(!1);
}, [m]);
const [T, F] = l(
e.roundStart ? c(e.roundStart) : null
), [E, M] = l(
e.roundEnd ? c(e.roundEnd) : null
), [y, j] = l(
e.totalSubmissionLimit
), [g, L] = l(!1), [R, U] = l(null), [z, G] = l(null), {
list: v,
handleListRemove: J,
handleListChange: H,
appendToList: I
} = ee(e.otherLimits), K = (...r) => (s(!0), H(...r)), W = (...r) => (s(!0), I(...r)), Y = (r) => {
const p = J(r);
return () => {
s(!0), p(), v.length === 1 && L(!1);
};
}, C = () => {
S(!1);
let r;
try {
r = P(
e,
T,
E,
y,
v
);
} catch (p) {
f(p);
}
r && (r.id ? Q(r, i) : V(r, i)).then((x) => {
const q = me(
x,
e.reactListKey
);
f(void 0), S(!0), s(!1), o(q);
}).catch((x) => f(x));
}, $ = () => {
e.id ? X(
e.evaluationId,
e.id,
i
).then(() => n()).catch((r) => f(r)) : n();
}, D = c().isSameOrAfter(
e.roundStart
);
return /* @__PURE__ */ t("div", { className: "evaluation-round-editor", children: /* @__PURE__ */ t(te, { children: /* @__PURE__ */ t(re, { sx: { p: 3 }, children: /* @__PURE__ */ h("form", { "aria-label": "Evaluation Round Form", children: [
/* @__PURE__ */ h(u, { sx: { display: "flex", justifyContent: "space-between" }, children: [
/* @__PURE__ */ h("h5", { children: [
"ROUND STATUS",
e.id && " (" + e.id + ")"
] }),
/* @__PURE__ */ t(
ce,
{
onDelete: $,
onSave: C
}
)
] }),
/* @__PURE__ */ t(u, { className: "round-status", sx: { mb: 2 }, children: B(
e.roundStart,
e.roundEnd
) }),
/* @__PURE__ */ t("h5", { children: "DURATION" }),
/* @__PURE__ */ h(b, { container: !0, children: [
/* @__PURE__ */ t(b, { size: 6, children: /* @__PURE__ */ t(
O,
{
label: "Round Start",
value: T,
onChange: (r) => {
F(r), s(!0);
},
onError: (r) => U(r),
disabled: D,
disablePast: !D,
slotProps: {
textField: {
helperText: w("start", R)
}
}
}
) }),
/* @__PURE__ */ t(b, { size: 6, children: /* @__PURE__ */ t(
O,
{
label: "Round End",
value: E,
onChange: (r) => {
M(r), s(!0);
},
onError: (r) => G(r),
disablePast: !c(E).isSame(e.roundEnd),
slotProps: {
textField: {
helperText: w("end", z)
}
}
}
) })
] }),
/* @__PURE__ */ t("h5", { style: { marginTop: "20px" }, children: "SUBMISSION LIMITS" }),
/* @__PURE__ */ t(
se,
{
fullWidth: !0,
label: "Total Submissions / Round",
value: y,
onChange: (r) => {
j(r.target.value), s(!0);
},
autoComplete: "new-password",
slotProps: {
htmlInput: {
pattern: "[0-9]*"
}
}
}
),
/* @__PURE__ */ t(u, { sx: { my: 2 }, children: /* @__PURE__ */ t(
N,
{
variant: "outlined",
color: "primary",
size: "small",
onClick: () => L(!g),
children: "Advanced Limits"
}
) }),
g && /* @__PURE__ */ t(
ue,
{
limitInputs: v,
handleChange: K,
handleDeleteLimit: Y,
onAddNewLimit: W
}
),
m && /* @__PURE__ */ t(u, { sx: { my: 3 }, children: /* @__PURE__ */ t(de, { error: m }) }),
k && /* @__PURE__ */ t(u, { sx: { my: 3 }, children: /* @__PURE__ */ t(
ie,
{
className: "save-success-alert",
severity: "success",
onClose: () => S(!1),
sx: { mb: "20px" },
children: "Successfully saved."
}
) }),
/* @__PURE__ */ t(u, { sx: { mt: 3, textAlign: "right" }, children: /* @__PURE__ */ t(
N,
{
variant: "contained",
color: "primary",
onClick: C,
children: "Save"
}
) })
] }) }) }) });
}
const Pe = {
disallowCalendarDateBefore: he,
determineRoundStatus: B,
convertInputsToEvaluationRound: P
};
export {
Be as EvaluationRoundEditor,
Pe as HelpersToTest
};
//# sourceMappingURL=EvaluationRoundEditor.js.map