synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
149 lines (148 loc) • 4.32 kB
JavaScript
import { jsxs as b, Fragment as K, jsx as o } 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 "../../utils/SynapseConstants.js";
import { defaults as E } from "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../utils/PermissionLevelToAccessType.js";
import { useState as O, useMemo as k } from "react";
import "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import { Box as C, Button as R, Alert as _ } 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 x } 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 { useGetRootWikiPageKey as F, useCreateWikiPage as M, useGetWikiPage as j } from "../../synapse-queries/wiki/useWiki.js";
import { Markdown as v } from "../Markdown/MarkdownSynapse.js";
import { WikiMarkdownEditor as A } from "../WikiMarkdownEditor/WikiMarkdownEditor.js";
const f = "Failed to load the wiki page: ", B = "Edit Wiki Page", D = {
children: B,
color: "primary",
variant: "contained"
};
function yi(g) {
const {
ownerObjectType: i,
ownerObjectId: e,
wikiPageId: a,
displayWikiMarkdown: W = !1
} = g, y = E(
{},
g.buttonProps,
D
), [c, n] = O(!1), {
data: s,
isLoading: l,
error: d
} = F(i, e, {
enabled: a === void 0
}), {
mutate: I,
isPending: h,
error: m
} = M({
onSuccess: () => n(!0)
}), P = k(() => {
const t = a || s?.wikiPageId || "";
return {
ownerObjectType: i,
ownerObjectId: e,
wikiPageId: t
};
}, [a, s, e, i]), {
data: r,
isLoading: u,
error: p
} = j(P, {
enabled: P.wikiPageId !== "",
// Set staleTime to infinity to prevent re-fetching while editing
staleTime: 1 / 0
}), w = k(() => d ? f + d.reason : p ? f + p.reason : m ? m.reason : null, [d, p, m]), T = () => {
r ? n(!0) : s === null ? I({
ownerObjectId: e,
ownerObjectType: i,
wikiPage: {
parentWikiId: void 0,
title: "",
markdown: "",
attachmentFileHandleIds: []
}
}) : console.warn(
"There was an error fetching the root WikiPageKey or WikiPage - address that error first."
);
}, L = k(() => {
const t = {
showPlaceholderIfNoWikiContent: !0
};
return r ? {
...t,
ownerId: e,
objectType: i,
wikiId: r.id
} : { ...t, markdown: "" };
}, [e, i, r]);
return /* @__PURE__ */ b(K, { children: [
W && /* @__PURE__ */ o(
C,
{
sx: {
mb: 1
},
children: u || l ? /* @__PURE__ */ o(x, {}) : (
// TODO - remove key once MarkdownSynapse uses tanstack-query
/* @__PURE__ */ o(
v,
{
...L
},
r?.markdown
)
)
}
),
/* @__PURE__ */ o(
R,
{
onClick: T,
disabled: u || l || h,
...y
}
),
w && /* @__PURE__ */ o(_, { severity: "error", sx: { marginTop: 2 }, children: w }),
r && /* @__PURE__ */ o(
A,
{
open: c,
ownerObjectType: i,
ownerObjectId: e,
wikiPage: r,
onSave: () => n(!1),
onCancel: () => n(!1)
},
c.toString()
)
] });
}
export {
B as DEFAULT_BUTTON_TEXT,
f as ERROR_LOADING_WIKI_FAILED,
yi as WikiMarkdownEditorButton,
yi as default
};
//# sourceMappingURL=WikiMarkdownEditorButton.js.map