taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
288 lines (287 loc) • 13.3 kB
JavaScript
import { jsxs as d, jsx as t, Fragment as B } from "react/jsx-runtime";
import { useState as m, useEffect as W, Suspense as L } from "react";
import { m as y, T as S, o as v, u as l, c as x, bR as J, a as b, P as F, bS as I, an as G, bG as E, a4 as M, bp as R, t as H, bb as O, bE as $, B as N, bD as V, bA as _, bT as q } from "./JBrowsePanel-BNE3gNW1.js";
import { M as A } from "./MenuItem-DAMdxuDJ.js";
import { D as z } from "./Delete-CRntlDho.js";
import { C as K, a as Y } from "./CardContent-CBvdvL5S.js";
import { L as P } from "./ListItem-hho_hfbE.js";
import { F as Q } from "./FormControlLabel-CfHqydvH.js";
import { C as X } from "./Checkbox-D7_LksK2.js";
import { S as Z, a as ee, b as te, c as ae } from "./Stepper-CYaq8zXr.js";
const ne = y()((e) => ({
spacing: {
marginBottom: e.spacing(3)
}
}));
function se({ trackAdapter: e, trackType: a }) {
const { classes: o } = ne(), { type: s, subadapter: n } = e;
return s === "SNPCoverageAdapter" ? d(S, { className: o.spacing, children: ["Selected ", t("code", { children: a }), ". Using adapter ", t("code", { children: s }), " with subadapter ", t("code", { children: n == null ? void 0 : n.type }), ". Please enter a track name and, if necessary, update the track type."] }) : d(S, { className: o.spacing, children: ["Using adapter ", t("code", { children: s }), " and guessing track type", " ", t("code", { children: a }), ". Please enter a track name and, if necessary, update the track type."] });
}
function re(e) {
var a;
const o = {};
for (const s of e) {
const n = ((a = s.adapterMetadata) === null || a === void 0 ? void 0 : a.category) || "Default";
o[n] || (o[n] = []), o[n].push(s);
}
return o;
}
const j = v(({ model: e }) => {
const { trackAdapter: a } = e, { pluginManager: o } = l.getEnv(e);
return t(x, { value: (a == null ? void 0 : a.type) !== "UNKNOWN" ? a == null ? void 0 : a.type : "", label: "Adapter type", variant: "outlined", select: !0, fullWidth: !0, onChange: (s) => {
e.setAdapterHint(s.target.value);
}, slotProps: {
select: {
SelectDisplayProps: {
"data-testid": "adapterTypeSelect"
}
}
}, children: Object.entries(re(o.getAdapterElements().filter((s) => {
var n;
return !(!((n = s.adapterMetadata) === null || n === void 0) && n.hiddenFromGUI);
}))).map(([s, n]) => [
t(J, { children: s }, s),
n.map((c) => t(A, { value: c.name, children: c.displayName }, c.name))
]) });
}), oe = y()((e) => ({
spacing: {
marginBottom: e.spacing(3)
}
}));
function ce({ model: e }) {
const { classes: a } = oe();
return d(B, { children: [d(S, { className: a.spacing, children: ["JBrowse was not able to guess the adapter type for this data, but it may be in the list below. If not, you can", " ", t(b.ExternalLink, { href: "https://github.com/GMOD/jbrowse-components/releases", children: "check for new releases" }), " ", "of JBrowse to see if they support this data type or", " ", t(b.ExternalLink, { href: "https://github.com/GMOD/jbrowse-components/issues/new", children: "file an issue" }), " ", "and add a feature request for this data type."] }), t(j, { model: e })] });
}
const ie = y()((e) => ({
paper: {
display: "flex",
flexDirection: "column",
padding: e.spacing(1)
},
card: {
marginTop: e.spacing(1)
}
})), le = v(function({ model: e }) {
const { classes: a } = ie(), [o, s] = m(""), [n, c] = m(""), [r, p] = m(["Name", "ID"]), [i, h] = m(["CDS", "exon"]), T = [
{
label: "Indexing attributes",
values: r
},
{
label: "Feature types to exclude",
values: i
}
];
return W(() => {
e.setTextIndexingConf({ attributes: r, exclude: i });
}, [e, r, i]), d(F, { className: a.paper, children: [t(I, { children: "Indexing configuration" }), T.map((u, f) => t(K, { raised: !0, className: a.card, children: d(Y, { children: [t(I, { children: u.label }), d(G, { disablePadding: !0, children: [u.values.map((g, C) => t(P, { disableGutters: !0, children: t(x, { value: g, slotProps: {
input: {
endAdornment: t(E, { position: "end", children: t(M, { onClick: () => {
const k = u.values.filter((D, U) => U !== C);
f === 0 ? p(k) : h(k);
}, children: t(z, {}) }) })
}
} }) }, `${g}-${C}`)), t(P, { disableGutters: !0, children: t(x, { value: f === 0 ? o : n, placeholder: "add new", onChange: (g) => {
f === 0 ? s(g.target.value) : c(g.target.value);
}, slotProps: {
input: {
endAdornment: t(E, { position: "end", children: t(M, { onClick: () => {
f === 0 ? (p([...r, o]), s("")) : (h([...i, n]), c(""));
}, disabled: f === 0 ? o === "" : n === "", "data-testid": "stringArrayAdd-Feat", children: t(R, {}) }) })
}
} }) })] })] }) }, u.label))] });
}), de = v(function({ model: e }) {
const { pluginManager: a } = l.getEnv(e), { trackType: o } = e, s = a.getTrackElements();
return t(x, { value: o, variant: "outlined", label: "Track type", select: !0, fullWidth: !0, onChange: (n) => {
e.setTrackType(n.target.value);
}, slotProps: {
select: {
SelectDisplayProps: {
"data-testid": "trackTypeSelect"
}
}
}, children: s.map(({ name: n, displayName: c }) => t(A, { value: n, children: c }, n)) });
}), pe = y()((e) => ({
spacing: {
marginBottom: e.spacing(3)
}
}));
function ue() {
const { classes: e } = pe();
return d(S, { className: e.spacing, children: ["This version of JBrowse cannot display data of this type. It is possible, however, that there is a newer version that can display them. You can", " ", t(b.ExternalLink, { href: "https://github.com/GMOD/jbrowse-components/releases", children: "check for new releases" }), " ", "of JBrowse or", " ", t(b.ExternalLink, { href: "https://github.com/GMOD/jbrowse-components/issues/new", children: "file an issue" }), " ", "and add a feature request for this data type."] });
}
const he = y()((e) => ({
spacing: {
marginBottom: e.spacing(3)
}
})), fe = v(function({ model: a }) {
const { classes: o } = he(), [s, n] = m(!0), c = l.getSession(a), { trackName: r, unsupported: p, trackAdapter: i, trackType: h, warningMessage: T, adapterHint: u } = a;
if (W(() => {
u === "" && i && a.setAdapterHint(i.type);
}, [u, i, i == null ? void 0 : i.type, a]), p)
return t(ue, {});
if ((i == null ? void 0 : i.type) === H.UNKNOWN)
return t(ce, { model: a });
if (i != null && i.type) {
const f = l.isSupportedIndexingAdapter(i.type), { pluginManager: g } = l.getEnv(a), C = g.evaluateExtensionPoint("Core-addTrackComponent", ({ model: k }) => t(b.AssemblySelector, { session: c, helperText: "Select assembly to add track to", selected: k.assembly, onChange: (D) => {
k.setAssembly(D);
}, TextFieldProps: {
fullWidth: !0,
SelectProps: {
SelectDisplayProps: {
"data-testid": "assemblyNameSelect"
}
}
} }), { model: a });
return d("div", { children: [t(se, { trackAdapter: i, trackType: h }), T ? t(S, { color: "warning", children: T }) : null, t(x, { className: o.spacing, label: "trackName", helperText: "A name for this track", fullWidth: !0, value: r, onChange: (k) => {
a.setTrackName(k.target.value);
}, slotProps: {
htmlInput: {
"data-testid": "trackNameInput"
}
} }), d("div", { style: {
display: "flex",
flexDirection: "column",
gap: 10
}, children: [t(j, { model: a }), t(de, { model: a }), t(L, { fallback: null, children: t(C, { model: a }) })] }), l.isElectron && f && t(O, { children: t(Q, { label: "Index track for text searching?", control: t(X, { checked: s, onChange: (k) => {
n(k.target.checked), a.setTextIndexTrack(k.target.checked);
} }) }) }), l.isElectron && s && f ? t(le, { model: a }) : null] });
} else
return t(S, { children: "Could not recognize this data type." });
}), ge = y()((e) => ({
paper: {
padding: e.spacing(2)
},
spacer: {
height: e.spacing(8)
}
})), ke = v(function({ model: e }) {
const { classes: a } = ge(), o = $(e);
return d(F, { className: a.paper, children: [t(b.FileSelector, { name: "Main file", description: "", location: e.trackData, setLocation: e.setTrackData, setName: e.setTrackName, rootModel: o }), t("div", { className: a.spacer }), t(b.FileSelector, { name: "Index file", description: "(Optional) The URL of the index file is automatically inferred from the URL of the main file if it is not supplied.", location: e.indexTrackData, setLocation: e.setIndexTrackData, setName: e.setTrackName, rootModel: o })] });
});
function me({ trackId: e, model: a }) {
const { textIndexingConf: o, trackName: s, assembly: n } = a, { jobsManager: c } = $(a), r = o || {
attributes: ["Name", "ID"],
exclude: ["CDS", "exon"]
}, p = `${s}-index`;
c.queueJob({
indexingParams: {
...r,
assemblies: [n],
tracks: [e],
indexType: "perTrack",
name: p,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
},
name: p,
cancelCallback: () => c.abortJob()
});
}
function be({ model: e }) {
var a;
const { textIndexTrack: o, trackAdapter: s, view: n } = e, c = l.getSession(e), r = e.getTrackConfig(Date.now());
if (l.isSessionWithAddTracks(c))
if (r && s) {
const { trackId: p } = r;
c.addTrackConf(r), (a = n == null ? void 0 : n.showTrack) === null || a === void 0 || a.call(n, p), l.isElectron && o && l.isSupportedIndexingAdapter(s.type) && me({
model: e,
trackId: p
}), e.clearData(), l.isSessionModelWithWidgets(c) && c.hideWidget(e);
} else
throw new Error(`Failed to add track.
The configuration of this file is not currently supported.`);
else throw new Error("Can't add tracks to this session");
}
const ye = y()((e) => ({
root: {
marginTop: e.spacing(1)
},
stepper: {
backgroundColor: e.palette.background.default
},
button: {
marginRight: e.spacing(1)
},
actionsContainer: {
marginTop: e.spacing(10),
marginBottom: e.spacing(2)
},
alertContainer: {
padding: `${e.spacing(2)}px 0px ${e.spacing(2)}px 0px`
}
})), w = ["Enter track data", "Confirm track type"], ve = v(function({ model: e }) {
const [a, o] = m(0), { classes: s } = ye(), { assembly: n, trackAdapter: c, trackData: r, trackName: p, trackType: i } = e;
function h(u) {
switch (u) {
case 0:
return t(ke, { model: e });
case 1:
return t(fe, { model: e });
default:
return t(S, { children: "Unknown step" });
}
}
function T() {
switch (a) {
case 0:
return !r;
case 1:
return !(p && i && (c != null && c.type) && n);
default:
return !0;
}
}
return t("div", { className: s.root, children: t(Z, { className: s.stepper, activeStep: a, orientation: "vertical", children: w.map((u, f) => d(ee, { children: [t(te, { children: u }), d(ae, { children: [h(f), d("div", { className: s.actionsContainer, children: [t(N, { disabled: a === 0, className: s.button, onClick: () => {
o(a - 1);
}, "data-testid": "addTrackBackButton", children: "Back" }), t(N, { disabled: T(), variant: "contained", color: "primary", onClick: () => {
if (a !== w.length - 1)
o(a + 1);
else
try {
be({ model: e });
} catch (g) {
l.getSession(e).notifyError(`${g}`, g);
}
}, className: s.button, "data-testid": "addTrackNextButton", children: a === w.length - 1 ? "Add" : "Next" })] })] })] }, u)) }) });
}), Se = y()({
textbox: {
width: "100%"
},
submit: {
marginTop: 25,
marginBottom: 100,
display: "block"
}
}), Te = v(function({ model: e }) {
const { classes: a } = Se(), [o, s] = m(""), [n, c] = m();
return d("div", { children: [n ? t(b.ErrorMessage, { error: n }) : null, t(x, { multiline: !0, rows: 10, value: o, placeholder: "Paste track config or array of track configs in JSON format", variant: "outlined", className: a.textbox, onChange: (r) => {
s(r.target.value);
} }), t(N, { variant: "contained", className: a.submit, onClick: () => {
try {
c(void 0);
const r = l.getSession(e), p = JSON.parse(o), i = Array.isArray(p) ? p : [p];
l.isSessionWithAddTracks(r) && l.isSessionModelWithWidgets(r) && (V(() => {
for (const h of i)
r.addTrackConf(h);
for (const h of i)
e.view.showTrack(h.trackId);
e.clearData();
}), r.hideWidget(e));
} catch (r) {
console.error(r), c(r);
}
}, children: "Submit" })] });
}), Be = v(function({ model: e }) {
const [a, o] = m("Default add track workflow"), s = {
"Default add track workflow": ve,
"Add track JSON": Te,
...Object.fromEntries(l.getEnv(e).pluginManager.getAddTrackWorkflowElements().map((r) => [r.name, r.ReactComponent]))
}, n = s[a] ? a : "Default add track workflow", c = s[n];
return d(B, { children: [d(O, { children: [t(_, { value: n, onChange: (r) => {
o(r.target.value);
}, children: Object.keys(s).map((r) => t(A, { value: r, children: r }, r)) }), t(q, { children: "Type of add track workflow" })] }), t(L, { fallback: null, children: t(c, { model: e }) })] });
});
export {
Be as default
};
//# sourceMappingURL=AddTrackWidget-DwyNVeRJ.js.map