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

147 lines (146 loc) 4.85 kB
import { jsx as t, jsxs as r, Fragment as l } from "react/jsx-runtime"; import * as d from "../../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 { parseEntityIdFromSqlStatement as F } from "../../utils/functions/SqlFunctions.js"; import "../../utils/functions/EntityTypeUtils.js"; import "../../utils/SynapseConstants.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import { SynapseContext as D } from "../../utils/context/SynapseContext.js"; import { Button as c } from "@mui/material"; import b from "@rjsf/core"; import q from "@rjsf/validator-ajv8"; import { Component as R, Fragment as x } from "react"; import { DialogBase as T } from "../DialogBase.js"; import k from "../SynapseForm/SynapseFormCheckboxesWidget.js"; import v from "../SynapseForm/SynapseFormCheckboxWidget.js"; import I from "../SynapseForm/SynapseFormRadioWidget.js"; import { writeHeaderOption as m, includeRowIdAndRowVersionOption as p, csvOption as h, formSchemaUIArray as L, formSchemaArray as W } from "./ModalDownload.FormSchema.js"; class _ extends R { static contextType = D; constructor(e) { super(e), this.state = { isLoading: !1, step: 0, formData: { "File Type": h, Contents: [m, p] } }; } handleSubmit = (e) => { this.state.step === 0 ? this.handleDownloadSetup(e) : this.onDownload(); }; handleDownloadSetup = (e) => { this.setState({ isLoading: !0 }); const { formData: o } = e, u = o["File Type"], i = o.Contents, { queryBundleRequest: f, getLastQueryRequest: g } = this.props, y = u === h ? "," : " ", w = i.includes(m), C = i.includes( p ), s = f ?? g(), a = s.query.sql, S = { sql: a, entityId: F(a), selectedFacets: s.query.selectedFacets, concreteType: "org.sagebionetworks.repo.model.table.DownloadFromTableRequest", writeHeader: w, includeRowIdAndRowVersion: C, csvTableDescriptor: { separator: y }, additionalFilters: s.query.additionalFilters }; d.createTableCsvForDownload( S, this.context.accessToken ).then((n) => { this.setState({ isLoading: !1, step: 1, data: n }); }).catch((n) => { console.log("Error getDownloadFromTableRequest: ", n); }); }; onDownload = () => { const { data: e } = this.state; d.getFileHandleByIdURL( e.resultsFileHandleId, this.context.accessToken ).then((o) => { window.location.href = o, this.props.onClose(); }); }; handleChange = (e) => { const { formData: o } = e; this.setState({ formData: o }); }; render() { const e = { height: 50, width: 50, backgroundSize: 50 }; return /* @__PURE__ */ t( T, { open: !0, onCancel: this.props.onClose, title: "Download query results", content: /* @__PURE__ */ t(l, { children: /* @__PURE__ */ r( b, { validator: q, id: "modal-download-form", schema: W[this.state.step], uiSchema: L[this.state.step], onChange: this.handleChange, formData: this.state.formData, onSubmit: this.handleSubmit, widgets: { CheckboxWidget: v, CheckboxesWidget: k, RadioWidget: I }, children: [ this.state.isLoading && /* @__PURE__ */ t("div", { className: "SRC-centerAndJustifyContent", children: /* @__PURE__ */ r("div", { className: "SRC-center-text", children: [ /* @__PURE__ */ t("p", { children: " Creating the File " }), /* @__PURE__ */ t("div", { style: e, className: "spinner" }), /* @__PURE__ */ t("p", { children: " Loading... " }) ] }) }), /* @__PURE__ */ t(x, {}) ] } ) }), actions: /* @__PURE__ */ r(l, { children: [ /* @__PURE__ */ t( c, { variant: "outlined", color: "primary", onClick: this.props.onClose, children: "Cancel" } ), /* @__PURE__ */ t( c, { form: "modal-download-form", type: "submit", variant: "contained", color: "primary", children: this.state.step === 0 ? "Next" : "Download" } ) ] }) } ); } } export { _ as ModalDownload, _ as default }; //# sourceMappingURL=ModalDownload.js.map