synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
310 lines (309 loc) • 9 kB
JavaScript
import { jsxs as $, jsx as p } 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 { ALL_ENTITY_BUNDLE_FIELDS as W } from "@sage-bionetworks/synapse-types";
import { SYNAPSE_ENTITY_ID_REGEX as X } from "../../../utils/functions/RegularExpressions.js";
import "../../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../../utils/PermissionLevelToAccessType.js";
import { useState as q, useEffect as g, useCallback as b, useMemo as w } from "react";
import "../../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import "@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 { SynapseSpinner as K } from "../../LoadingScreen/LoadingScreen.js";
import "@tanstack/query-core";
import "lodash-es/isEmpty";
import "lodash-es/isEqual";
import "lodash-es/xorWith";
import "react-router";
import { EntityType as D } from "@sage-bionetworks/synapse-client";
import "../../../utils/types/IsType.js";
import { useGetEntityPath as Q } from "../../../synapse-queries/entity/useEntity.js";
import Z from "../../../synapse-queries/entity/useEntityBundle.js";
import { useGetEntityHeader as ee } from "../../../synapse-queries/entity/useGetEntityHeaders.js";
import { convertToEntityType as te } from "../../../utils/functions/EntityTypeUtils.js";
import { useGetFavorites as re } from "../../../synapse-queries/user/useFavorites.js";
import { useGetProjectsInfinite as oe } from "../../../synapse-queries/user/useProjects.js";
import ie from "../../DropdownSelect/DropdownSelect.js";
import { displayToast as se } from "../../ToastMessage/ToastMessage.js";
import { toEntityHeader as ae } from "../details/configurations/ProjectListDetails.js";
import { EntityDetailsListDataConfigurationType as n } from "../details/EntityDetailsList.js";
import { VirtualizedTree as ne, EntityTreeNodeType as ce } from "./VirtualizedTree.js";
const le = (o, C) => {
for (const i of C.path)
if (o === i.id)
return !0;
return !1;
};
var x = /* @__PURE__ */ ((o) => (o.CURRENT_PROJECT = "Current Project", o.ALL_PROJECTS = "All Projects", o.CREATED_BY_ME = "Projects Created By Me", o.FAVORITES = "My Favorites", o))(x || {});
function pe(o) {
switch (o) {
case "My Favorites":
return "root";
case "Current Project":
case "All Projects":
case "Projects Created By Me":
return null;
}
}
function de(o) {
switch (o) {
case "Current Project":
case "All Projects":
case "Projects Created By Me":
return "Projects";
case "My Favorites":
return "Favorites";
}
}
function Ze(o) {
const {
initialScope: C = "Current Project",
projectId: i,
initialContainer: h = null,
currentContainer: s,
setCurrentContainer: a,
visibleTypes: v = [D.project, D.folder],
toggleSelection: y,
selectedEntities: B,
setDetailsViewConfiguration: c,
setBreadcrumbItems: m,
showScopeAsRootNode: A = !0,
treeNodeType: I,
selectableTypes: F,
hideScopeSelector: k = !1
} = o, G = {
type: n.PROMPT
}, [t, R] = q(C);
g(() => {
c && c(G);
}, []);
const U = b(
(e) => {
y && y({ targetId: e }), a(e);
},
[a, y]
), T = t === "All Projects" || t === "Projects Created By Me", {
data: j,
fetchNextPage: L,
hasNextPage: M,
isLoading: u
} = oe(
t === "Projects Created By Me" ? { filter: "CREATED", sort: "PROJECT_NAME", sortDirection: "ASC" } : { sort: "PROJECT_NAME", sortDirection: "ASC" },
{
enabled: T,
// Don't refetch the projects. Updating the entity headers will drop all the children that VirtualizedTree has fetched
refetchInterval: 1 / 0
}
), { data: N, isSuccess: H } = Z(s, void 0, W, {
enabled: !!s && s !== "root",
throwOnError: !0
}), { data: O, isLoading: _ } = re(
"NAME",
"ASC",
{
select: (e) => e.filter((r) => v.includes(te(r.type))),
// Don't refetch the projects. Updating the entity headers will drop all the children that VirtualizedTree has fetched
refetchInterval: 1 / 0,
throwOnError: !0
}
), { data: f } = Q(h, {
enabled: !!(i && h && h.match(X)),
refetchInterval: 1 / 0,
throwOnError: !0
}), { data: d, isLoading: E } = ee(i, void 0, {
enabled: !!(i ?? f?.path[1]?.id),
refetchInterval: 1 / 0
});
g(() => {
t === "Current Project" && i && !E && !d && (se(
`You don't have access to the current project (${i}).`,
"warning"
), R(
"Projects Created By Me"
/* CREATED_BY_ME */
));
}, [E, d, i, t]);
const {
topLevelEntities: P,
isLoading: J
} = w(() => {
let e = [], r = !1;
switch (t) {
case "All Projects":
case "Projects Created By Me":
j && (e = j.pages.flatMap((l) => l.results).map(ae)), r = u;
break;
case "My Favorites": {
e = O ?? [], r = _;
break;
}
case "Current Project":
d && (e = [d], r = E);
break;
default:
throw new Error("No scope selected");
}
return { topLevelEntities: e, isLoading: r };
}, [
O,
_,
E,
u,
j,
d,
t
]);
g(() => {
if (c || m) {
let e, r = [];
if (s === null)
e = {
type: n.PROMPT
}, r = [];
else if (s === "root") {
switch (t) {
case "All Projects":
e = {
type: n.USER_PROJECTS
};
break;
case "Projects Created By Me":
e = {
type: n.USER_PROJECTS,
getProjectParams: {
filter: "CREATED"
}
};
break;
case "Current Project":
e = {
type: n.HEADER_LIST,
headerList: P
};
break;
case "My Favorites":
e = {
type: n.USER_FAVORITES
};
break;
}
r = [
{
name: t,
isCurrent: !0,
action: () => {
a("root");
}
}
];
} else
e = {
type: n.PARENT_CONTAINER,
parentContainerId: s
}, N && (r = [
{
name: t,
isCurrent: !1,
action: () => {
a("root");
}
},
...N.path.path.slice(1).map((l) => ({
name: l.name ?? l.id,
isCurrent: l.id === s,
action: () => {
a(l.id);
}
}))
]);
c && c(e), m && m(r);
}
}, [
t,
s,
P,
c,
m,
N,
H,
a
]);
const V = w(
() => ({
show: A,
nodeText: de(t),
children: P,
fetchNextPage: async () => {
await L();
},
hasNextPage: T && M && !u
}),
[
A,
t,
P,
T,
M,
u,
L
]
), Y = b(
(e) => e === "root" ? !0 : !!(t === "Current Project" && f && le(e, f)),
[t, f]
), S = Object.values(x).filter(
(e) => !(e === "Current Project" && i == null)
), z = S.indexOf(t);
return /* @__PURE__ */ $(
"div",
{
className: `TreeView ${I === ce.SINGLE_PANE ? "SelectTree" : "BrowseTree"}`,
children: [
!k && /* @__PURE__ */ p("div", { className: "Header", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ p(
ie,
{
variant: "outlined",
options: S,
selectedIndex: z,
setSelectedIndex: (e) => {
const r = S[e];
t !== r && (R(r), a(
pe(r)
));
},
size: "small",
fullWidth: !0
}
) }),
J ? /* @__PURE__ */ p("div", { className: "Placeholder", children: /* @__PURE__ */ p(K, { size: 30 }) }) : /* @__PURE__ */ p("div", { className: "Tree", role: "tree", children: /* @__PURE__ */ p(
ne,
{
selected: B,
visibleTypes: v,
autoExpand: Y,
rootNodeConfiguration: V,
treeNodeType: I,
selectableTypes: F,
currentContainer: s,
setSelectedId: U
}
) })
]
}
);
}
export {
Ze as EntityTree,
x as FinderScope
};
//# sourceMappingURL=EntityTree.js.map