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

321 lines (320 loc) 9.43 kB
import { jsxs as d, Fragment as y, jsx 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 { ENTITY_VIEW_TYPE_MASK_FILE as me, ENTITY_VIEW_TYPE_MASK_PROJECT as ce } from "@sage-bionetworks/synapse-types"; import { convertToConcreteEntityType as pe } from "../../utils/functions/EntityTypeUtils.js"; import "../../utils/SynapseConstants.js"; import { omitBy as Ee, isUndefined as ue } from "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import { useState as r, useRef as de, useMemo as S, useCallback as p } from "react"; import "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import { Alert as P, Box as Y, Button as x } 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 '../../style/components/_spinner.css';/* empty css */ import "@tanstack/query-core"; import "lodash-es/isEmpty"; import "lodash-es/isEqual"; import "lodash-es/xorWith"; import "react-router"; import { EntityType as u } from "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import { useCreateEntity as Se } from "../../synapse-queries/entity/useEntity.js"; import { useGetDefaultColumnModels as Te, useCreateColumnModels as fe } from "../../synapse-queries/table/useColumnModel.js"; import { useValidateDefiningSql as Ce } from "../../synapse-queries/table/useDefiningSql.js"; import { DialogBase as _e } from "../DialogBase.js"; import ye from "../EntityViewScopeEditor/EntityViewMaskEditor.js"; import Ie from "../EntityViewScopeEditor/EntityViewScopeEditor.js"; import he from "../SqlDefinedTableEditor/SqlDefinedTableEditor.js"; import Oe from "../SubmissionViewScopeEditor/SubmissionViewScopeEditor.js"; import ve from "../TableColumnSchemaEditor/TableColumnSchemaForm.js"; import { getStepAfterTypeSelection as Ve, maybeSetColumnIds as Be, maybeSetScopeIds as we, maybeSetViewTypeMask as Me, maybeSetDefiningSQL as be, getPreviousStep as ge, isLastStep as z, getModalTitle as Le } from "./CreateTableViewWizardUtils.js"; import Ae from "./TableNameForm.js"; import Ne from "./TableTypeSelection.js"; import Pe from "./ViewTypeSelection.js"; function vt(K) { const { open: G, parentId: W, onComplete: J, onCancel: k } = K, [t, m] = r("CHOOSE_TABLE_TYPE"), [T, X] = r(""), [f, Z] = r(void 0), [e, $] = r( void 0 ), [s, ee] = r([]), [a, te] = r([]), [n, D] = r( me ), I = n === ce, [c, h] = r([]), O = de(null), [E, oe] = r(""), C = S(() => { if (e === u.entityview) return { scope: s, viewTypeMask: n, viewEntityType: e }; if (e === u.submissionview) return { scope: a, viewEntityType: e }; }, [e, s, a, n]), { data: v, isLoading: V, isError: B } = Te( C?.viewEntityType, C?.viewTypeMask, { // Fetch the default columns when the user is determining scope // This way we can pre-fill the columns right before they go to the columns step // We will prevent clicking "Next" before this is loaded enabled: t === "ENTITY_VIEW_SCOPE" || t === "SUBMISSION_VIEW_SCOPE", staleTime: 1 / 0 // The default column models will never change } ), { mutateAsync: H, error: w } = Se({ onSuccess: (o) => { J(o.id); } }), { mutate: F, data: _, error: M } = Ce({ onSuccess: (o) => { o && o.isValid && m("TABLE_NAME"); } }), b = S(() => M ? M.reason : _ && _.invalidReason ? _.invalidReason : null, [M, _]), { mutateAsync: U, error: g } = fe(), L = p( (o, l) => { $(o), l != null && D(l), m(Ve(o)); }, [] ), q = p(() => { m("CHOOSE_VIEW_TYPE"); }, []), R = p(async () => { if (!e) { console.error("entityType was not defined!"), m("CHOOSE_TABLE_TYPE"); return; } let o = []; if (c && // Do not create columns if this is a SQL-defined view e !== u.materializedview && e !== u.virtualtable) try { o = await U( c.map((N) => Ee(N, ue)) ); } catch { return; } const l = { name: T, description: f, parentId: W, concreteType: pe(e) }; Be(l, e, o), we( l, e, e === u.submissionview ? a : s ), Me(l, e, n), be(l, e, E); try { await H(l); } catch { return; } }, [ c, U, H, f, e, T, W, s, a, E, n ]), j = p( (o) => { h(o), m("TABLE_NAME"); }, [] ), Q = p(() => { O.current != null && O.current.submit(); }, []), ie = t !== "CHOOSE_TABLE_TYPE", ne = t !== "CHOOSE_TABLE_TYPE" && t !== "CHOOSE_VIEW_TYPE", re = p(() => { const o = ge(t, e); ["CHOOSE_TABLE_TYPE", "CHOOSE_VIEW_TYPE"].includes(o) && h([]), m(o); }, [t, e]), se = p(() => { z(t) ? R() : t === "TABLE_SQL" && e ? F({ sql: E, entityType: e }) : t === "TABLE_COLUMNS" ? Q() : (t === "ENTITY_VIEW_SCOPE" || t === "SUBMISSION_VIEW_SCOPE") && (c.length == 0 && v && h( v.map((o) => ({ ...o, id: void 0 })) ), m("TABLE_COLUMNS")); }, [ t, R, Q, c.length, v, F, e, E ]), ae = S(() => t === "ENTITY_VIEW_SCOPE" ? s.length === 0 || n === 0 || V && !B : t === "SUBMISSION_VIEW_SCOPE" ? a.length === 0 || n === 0 || V && !B : !1, [ s.length, a.length, t, n, V, B ]), A = S(() => /* @__PURE__ */ d(y, { children: [ w && /* @__PURE__ */ i(P, { sx: { my: 2 }, severity: "error", children: w.message }), g && /* @__PURE__ */ i(P, { sx: { my: 2 }, severity: "error", children: g.message }), b && /* @__PURE__ */ i(P, { sx: { my: 2 }, severity: "error", children: b }) ] }), [g, w, b]), le = S(() => { switch (t) { case "CHOOSE_TABLE_TYPE": return /* @__PURE__ */ i( Ne, { onTableSelected: () => { L(u.table); }, onViewSelected: q } ); case "CHOOSE_VIEW_TYPE": return /* @__PURE__ */ i(Pe, { onTypeSelected: L }); case "ENTITY_VIEW_SCOPE": return /* @__PURE__ */ d(y, { children: [ /* @__PURE__ */ i( Ie, { scopeIds: s, onChange: ee, isProjectView: I } ), !I && /* @__PURE__ */ i( ye, { value: n, onChange: D } ) ] }); case "SUBMISSION_VIEW_SCOPE": return /* @__PURE__ */ i( Oe, { evaluationIds: a, onChange: te } ); case "TABLE_SQL": return /* @__PURE__ */ d(y, { children: [ /* @__PURE__ */ i( Y, { sx: { mt: 1.25 }, children: /* @__PURE__ */ i( he, { value: E, onChange: (o) => oe(o.target.value), entityType: e } ) } ), A ] }); case "TABLE_COLUMNS": return /* @__PURE__ */ i( ve, { initialData: c, entityType: e, ref: O, onSubmit: j, viewScope: C } ); case "TABLE_NAME": return /* @__PURE__ */ d(y, { children: [ /* @__PURE__ */ i( Ae, { name: T, setName: X, description: f, setDescription: Z } ), A ] }); } }, [ t, q, L, s, I, n, a, T, f, E, e, A, c, j, C ]); return /* @__PURE__ */ i( _e, { open: G, onCancel: k, maxWidth: "md", title: Le(t, e), content: le, actions: /* @__PURE__ */ d( Y, { sx: { display: "flex", width: "100%", gap: 2.25, mt: 2 }, children: [ ie && /* @__PURE__ */ i(x, { variant: "outlined", onClick: re, children: "Back" }), /* @__PURE__ */ i( Y, { sx: { m: "auto" } } ), /* @__PURE__ */ i(x, { variant: "outlined", onClick: k, children: "Cancel" }), ne && /* @__PURE__ */ i( x, { variant: "contained", onClick: se, disabled: ae, children: z(t) ? "Finish" : "Next" } ) ] } ) } ); } export { vt as default }; //# sourceMappingURL=CreateTableViewWizard.js.map