synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
248 lines (247 loc) • 8.15 kB
JavaScript
import { jsx as e, jsxs as y, Fragment as I } 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 "@sage-bionetworks/synapse-types";
import "../../utils/functions/EntityTypeUtils.js";
import { BUNDLE_MASK_QUERY_RESULTS as O } from "../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../utils/PermissionLevelToAccessType.js";
import { useState as q, useEffect as k } from "react";
import "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import { Typography as c, Stack as S, FormControl as U, TextField as G, Collapse as W, FormControlLabel as D, Checkbox as P } 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 { SynapseSpinner as Q } from "../LoadingScreen/LoadingScreen.js";
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 { useGetFullTableQueryResults as Y } from "../../synapse-queries/entity/useGetQueryResultBundle.js";
import { Set as X } from "immutable";
import { ConfirmationDialog as z } from "../ConfirmationDialog/ConfirmationDialog.js";
import { ErrorBanner as J } from "../error/ErrorBanner.js";
import K from "../FullWidthAlert/FullWidthAlert.js";
import $ from "../IconSvg/IconSvg.js";
const b = "category", H = "category email prompt", V = "rejection reason", Z = "email text";
function ee(d) {
const {
category: u,
rows: a,
selectedRowIds: s,
setSelectedRowIds: m,
rejectionReasonFormTextIndex: i,
initialIsExpanded: R = !1
} = d, [l, x] = q(R);
return /* @__PURE__ */ y(I, { children: [
/* @__PURE__ */ y(
c,
{
variant: "body1",
onClick: () => x(!l),
sx: { fontWeight: 700, cursor: "pointer", my: 1 },
children: [
/* @__PURE__ */ e(
$,
{
icon: l ? "expandMore" : "chevronRight",
sx: { color: "grey.700" },
wrap: !1
}
),
u
]
}
),
/* @__PURE__ */ e(W, { in: l, children: /* @__PURE__ */ e(S, { sx: { ml: 3 }, children: (a ?? []).map((n) => /* @__PURE__ */ e(
D,
{
control: /* @__PURE__ */ e(
P,
{
checked: s.has(n.rowId),
size: "small",
onChange: (o) => {
o.target.checked ? m(s.add(n.rowId)) : m(s.remove(n.rowId));
}
}
),
label: /* @__PURE__ */ e(c, { variant: "smallText1", children: n.values[i] })
},
n.rowId
)) }) })
] });
}
function te(d) {
const {
tableQuery: u,
selectedRowIds: a,
setSelectedRowIds: s,
rejectionFormPromptCopy: m
} = d, { data: i, isLoading: R, error: l } = u, x = i?.queryResult?.queryResults.headers.findIndex(
(r) => r.name.toLowerCase() === b
), n = i?.queryResult?.queryResults.headers.findIndex(
(r) => r.name.toLowerCase() === V
), o = i && i.queryResult && i.queryResult.queryResults.rows.reduce(
(r, g) => {
const E = g.values[x];
return r[E] = [...r[E] || [], g], r;
},
{}
);
return /* @__PURE__ */ y(I, { children: [
/* @__PURE__ */ e(c, { variant: "headline3", gutterBottom: !0, children: "Reasons for rejecting" }),
m && /* @__PURE__ */ e(c, { variant: "body1", gutterBottom: !0, children: m }),
R && /* @__PURE__ */ e(S, { sx: { my: 2 }, children: /* @__PURE__ */ e(Q, { size: 30 }) }),
l && /* @__PURE__ */ e(J, { error: l }),
o && /* @__PURE__ */ e(U, { children: Object.keys(o).map((r) => /* @__PURE__ */ e(
ee,
{
category: r,
rows: o[r],
selectedRowIds: a,
setSelectedRowIds: s,
rejectionReasonFormTextIndex: n,
initialIsExpanded: Object.keys(o).length === 1
},
r
)) }),
/* @__PURE__ */ e(c, { variant: "headline3", sx: { mt: 1 }, gutterBottom: !0, children: "We’ll generate a response email message based on your selections." }),
/* @__PURE__ */ e(c, { variant: "body1", gutterBottom: !0, children: "If your reasons for rejecting are not shown here, that’s okay! You can edit the complete text of the message on the next screen before sending it." })
] });
}
function oe(d) {
const { emailText: u, setEmailText: a } = d;
return /* @__PURE__ */ y(I, { children: [
/* @__PURE__ */ e(c, { variant: "headline3", gutterBottom: !0, children: "Edit the text of the rejection message" }),
/* @__PURE__ */ e(c, { variant: "body1", gutterBottom: !0, children: "This message will be sent to the requester. You may edit it, or add custom text to the message." }),
/* @__PURE__ */ e(
G,
{
multiline: !0,
fullWidth: !0,
rows: 15,
value: u,
onChange: (s) => {
a(s.target.value);
}
}
)
] });
}
function Ue(d) {
const {
open: u,
tableId: a,
onClose: s,
onConfirm: m,
defaultMessagePrefix: i = "",
defaultMessageAppend: R = "",
rejectionFormPromptCopy: l,
children: x,
error: n
} = d, [o, r] = q(1), [g, E] = q(""), [w, j] = q(X()), M = Y({
entityId: a,
query: {
sql: `SELECT * FROM ${a}`
},
partMask: O,
concreteType: "org.sagebionetworks.repo.model.table.QueryBundleRequest"
}), { data: f } = M, L = f?.queryResult?.queryResults.headers.findIndex(
(t) => t.name.toLowerCase() === b
), N = f?.queryResult?.queryResults.headers.findIndex(
(t) => t.name.toLowerCase() === H
), A = f?.queryResult?.queryResults.headers.findIndex(
(t) => t.name.toLowerCase() === Z
), C = f && f.queryResult && w.reduce((t, T) => {
const h = f.queryResult.queryResults.rows.find(
(F) => F.rowId === T
), p = h.values[L], B = h.values[N], v = h.values[A];
return t[p] ? t[p].reasons = [
...t[p].reasons,
v
] : t[p] = {
sectionText: B,
reasons: [v]
}, t;
}, {}), _ = C && i + Object.keys(C).reduce((t, T) => {
t += `
`;
const h = C[T].sectionText;
h && (t += h + `
`);
for (const p of C[T].reasons)
p != null && (t += `
* ` + p.replaceAll("\\n", `
`) + `
`);
return t;
}, "") + R;
return k(() => {
_ && E(_);
}, [w]), /* @__PURE__ */ e(
z,
{
open: u,
onCancel: () => {
o === 1 && s(), o === 2 && r(1);
},
maxWidth: "md",
fullWidth: !0,
title: "Reject Request?",
content: /* @__PURE__ */ y(I, { children: [
o === 1 && /* @__PURE__ */ e(
te,
{
tableQuery: M,
selectedRowIds: w,
setSelectedRowIds: j,
rejectionFormPromptCopy: l
}
),
o === 2 && /* @__PURE__ */ y(I, { children: [
/* @__PURE__ */ e(
oe,
{
emailText: g,
setEmailText: E
}
),
x
] }),
n && /* @__PURE__ */ e(
K,
{
variant: "danger",
description: n.reason,
isGlobal: !1
}
)
] }),
onConfirm: () => {
o === 1 && r(2), o === 2 && m(g);
},
confirmButtonProps: {
children: o === 1 ? "Generate Email" : "Reject and Notify Requester"
},
cancelButtonProps: {
children: o === 1 ? "Cancel" : "Back"
}
}
);
}
export {
Ue as CannedRejectionDialog
};
//# sourceMappingURL=CannedRejectionDialog.js.map