UNPKG

@valiantys/atlassian-app-frontend

Version:

This library provides an Atlassian Forge Custom UI wrapper component that handles all the setup necessary to support an app that can run deployed or in standalone mode

140 lines (139 loc) 4.08 kB
import { jsx as o } from "react/jsx-runtime"; import { requestConfluence as h, requestBitbucket as v, requestJira as f, showFlag as k, view as m, invoke as w, invokeRemote as F, router as y, Modal as P } from "@forge/bridge"; import { useReducer as b, useCallback as R } from "react"; import { route as x, AppFlagsDispatchContext as C, AppFlagsProviderAtlasKit as q, FeatureChosenWorkspaceCheck as A, RemoteAdapterProvider as S, BackendAdapterProvider as g, HostRouterProvider as j, RequestBitbucketProvider as E, RequestConfluenceProvider as J, RequestJiraProvider as B, ViewContextProvider as $, ModalServiceProvider as I } from "./index.mjs"; import "@atlaskit/flag"; import "@atlaskit/icon/glyph/check-circle"; import "@atlaskit/icon/glyph/error"; import "@atlaskit/icon/glyph/info"; import "@atlaskit/icon/glyph/warning"; import "@atlaskit/tokens"; import "@atlaskit/button/new"; import "@atlaskit/heading"; import "@atlaskit/primitives"; import "@atlaskit/button"; import "@atlaskit/form"; import "@atlaskit/section-message"; import "@atlaskit/select"; import "@atlaskit/spinner"; import "@atlaskit/app-provider"; import "react-router-dom"; function M(e) { return async ({ url: t, method: r, responseType: c = "json", allowExperimental: u = !1 }, s) => { const n = { Accept: c === "json" ? "application/json" : "text/html" }; s && (n["Content-Type"] = "application/json"), u && (n["X-ExperimentalApi"] = "opt-in"); const a = JSON.stringify(s), i = await e(t, { method: r, headers: n, body: a }); if (i.ok) return r === "DELETE" || i.status === 204 ? void 0 : c === "text" ? p(i) : T(i); { const d = `${r} ${t.value} - ${i.status} ${i.statusText} Request Body: ${a} Response Body: ${await p(i)}`; throw console.error(d), new Error(d); } }; } async function p(e) { try { return await e.text(); } catch { return ""; } } async function T(e) { try { return await e.json(); } catch { return p(e); } } function _(e) { switch (e) { case "jira": return f; case "bitbucket": return v; case "confluence": return h; } } function l(e) { const t = _(e); return { productType: e, fetch: M( (r, c) => t(r.value, c) ), route: x, // @ts-expect-error slight difference in typing, null vs undefined rawFetch: t }; } function D({ children: e }) { const [t, r] = b(N, {}); return /* @__PURE__ */ o(C.Provider, { value: r, children: e }); } function N(e, t) { var r; switch (t.type) { case "add": return t.props ? { ...e, [t.props.id]: k(t.props) } : (console.error("invalid flag action: ", JSON.stringify(t)), e); case "remove": return (r = e[t.id]) == null || r.close(), { ...e, [t.id]: void 0 }; default: throw Error("Unknown action: " + t.type); } } m.theme.enable(); const O = l("jira"), W = l("bitbucket"), H = l("confluence"), K = { open(e) { return new P(e).open(); } }; function le({ appName: e, doCheckWorkspace: t, invokeRemoteImpl: r, useAtlasKitFlags: c, children: u }) { const s = R( async (a, i) => w(a, { ...i }), [] ); let n = u; return t && (n = /* @__PURE__ */ o(A, { appName: e, children: n })), n = /* @__PURE__ */ o( S, { invokeRemoteImplementation: r || F, children: /* @__PURE__ */ o(g, { invokeImplementation: s, children: /* @__PURE__ */ o(j, { hostRouter: y, children: /* @__PURE__ */ o( E, { requestBitbucketImplementation: W, children: /* @__PURE__ */ o( J, { requestConfluenceImplementation: H, children: /* @__PURE__ */ o(B, { requestJiraImplementation: O, children: /* @__PURE__ */ o($, { viewContext: m, children: /* @__PURE__ */ o(I, { modalService: K, children: n }) }) }) } ) } ) }) }) } ), c ? /* @__PURE__ */ o(q, { children: n }) : /* @__PURE__ */ o(D, { children: n }); } export { le as AtlassianAppForge, le as default };