UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

94 lines (93 loc) 2.7 kB
import { jsxs as f, jsx as r } from "react/jsx-runtime"; import g from "./components/GridSessionSelectionField.js"; import S from "./useInitializeGridConnection.js"; import { parseQueryInput as y } from "./utils/DataGridUtils.js"; import { Grid as s, Button as I } from "@mui/material"; import d from "lodash-es/noop"; import { forwardRef as h, useState as G, useImperativeHandle as w } from "react"; import { displayToast as C } from "../ToastMessage/ToastMessage.js"; const E = h((o, t) => { const { show: l = !1, onSessionChange: a = d, onReplicaChange: c = d } = o, [p, m] = G(""), { mutate: n } = S({ onMutate(e) { console.debug("Starting grid session with args:", e); }, onSuccess({ session: e, replica: i }) { a(e), c(i.replicaId); }, onError(e) { const i = e && typeof e == "object" && "message" in e && typeof e.message == "string" ? e.message : "An error occurred"; C(i, "danger"); } }), u = function(e) { n(q(e)); }; return w( t, () => ({ handleStartSession: (e) => { n({ createGridRequest: e }); }, handleLoadSession: (e) => { n({ sessionId: e }); } }), [n] ), l ? /* @__PURE__ */ f(s, { container: !0, spacing: 2, sx: { mb: 2 }, children: [ /* @__PURE__ */ r(s, { size: { xs: 12 }, sx: { position: "relative" }, children: /* @__PURE__ */ r( g, { inputValue: p, onInputValueChange: m, onConfirmInput: u, onSessionChange: a, onReplicaChange: c } ) }), /* @__PURE__ */ r(s, { container: !0, size: 12, justifyContent: "flex-end", children: /* @__PURE__ */ r( I, { color: "primary", variant: "contained", onClick: () => { u(p); }, children: "Start Grid Session" } ) }) ] }) : null; }); function q(o) { const t = y(o); if (t.type == "unknown") throw new Error( "Unknown input type, please provide a valid SQL query, Synapse ID, or session ID." ); switch (t.type) { case "empty": throw new Error("Input cannot be empty."); case "sql": return { createGridRequest: { initialQuery: { sql: t.input }, concreteType: "org.sagebionetworks.repo.model.grid.CreateGridRequest" } }; case "sessionId": return { sessionId: t.input }; case "recordSetId": return { createGridRequest: { recordSetId: t.input, concreteType: "org.sagebionetworks.repo.model.grid.CreateGridRequest" } }; } } export { E as StartGridSession }; //# sourceMappingURL=StartGridSession.js.map