synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
187 lines (186 loc) • 6.31 kB
JavaScript
import { getEvaluations as S, getEntityHeaders as U, getGroupHeadersBatch as y } 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 "@sage-bionetworks/synapse-types";
import "../functions/EntityTypeUtils.js";
import { VALUE_NOT_SET as O, EVALUATIONS_STORAGE_KEY as T, ENTITY_HEADER_STORAGE_KEY as R, USER_PROFILE_STORAGE_KEY as _ } from "../SynapseConstants.js";
import { uniq as h, without as k, chunk as A } from "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import { useState as F, useEffect as N } from "react";
import D from "use-deep-compare-effect";
import { useSynapseContext as b } from "../context/SynapseContext.js";
import "../PermissionLevelToAccessType.js";
import "@tanstack/react-query";
import "@tanstack/query-core";
import "lodash-es/isEmpty";
import "lodash-es/isEqual";
import "lodash-es/xorWith";
import "@mui/material";
import "@sage-bionetworks/synapse-client";
import "../types/IsType.js";
import "react/jsx-runtime";
import "./useCookiePreferences.js";
import "./useSourceAppConfigs.js";
import "universal-cookie";
import "../AppUtils/session/ApplicationSessionContext.js";
import "../context/FullContextProvider.js";
import "../context/DocumentMetadataContext.js";
import '../../style/components/_spinner.css';/* empty css */
import "react-router";
const v = {
ownerId: "",
// A foreign key to the ID of the 'principal' object for the user
firstName: "Unknown",
// This person's given name (forename)
lastName: "Unknown",
// This person's family name (surname)
userName: "Unknown",
// A name chosen by the user that uniquely identifies them
isIndividual: !1
}, H = {
name: "Unknown",
// The name of the entity
id: "unknown",
// The id of the entity
type: "org.sagebionetworks.repo.model.FileEntity",
// The type of the entity
versionNumber: 0,
// The version number of the entity
versionLabel: "placeholder",
// The user defined version label of the entity
benefactorId: 0,
// The ID of the entity that this Entity's ACL is inherited from.
createdOn: "null",
// The date this entity was created.
modifiedOn: "null",
// The date this entity was last modified.
createdBy: "null",
// The ID of the user that created this entity.
modifiedBy: "null",
// The ID of the user that last modified this entity.
isLatestVersion: !0
// If this version is the latest version of the entity
}, L = {
id: "unknown",
// The unique immutable ID for this Evaluation.
etag: "Unknown",
// Synapse employs an Optimistic Concurrency Control (OCC) scheme to handle concurrent updates. The eTag changes every time an Evaluation is updated; it is used to detect when a client's copy of an Evaluation is out-of-date.
name: "Unknown",
// The name of this Evaluation
description: "Unknown",
// A text description of this Evaluation.
ownerId: "null",
// The ID of the Synapse user who created this Evaluation.
createdOn: "null",
// The date on which Evaluation was created.
contentSource: "Unknown",
// The Synapse ID of the Entity to which this Evaluation belongs, e.g. a reference to a Synapse project.
submissionInstructionsMessage: "Unknown",
// Message to display to users detailing acceptable formatting for Submissions to this Evaluation.
submissionReceiptMessage: "Unknown"
// Message to display to users upon successful submission to this Evaluation.
}, G = async (n, a) => {
const t = await U(n, a), o = n.filter(
(e) => t.results.map((r) => r.id).indexOf(e.targetId) === -1
).map((e) => ({
...H,
id: e.targetId,
name: `${e.targetId}`
}));
return [...t.results, ...o];
}, K = async (n, a) => {
const t = (await y(n, a)).children, o = n.filter(
(e) => t.map((r) => r.ownerId).indexOf(e) === -1
).map((e) => ({
...v,
ownerId: e,
name: `Unknown User (${e})`
}));
return [...t, ...o];
}, P = async (n, a) => {
const t = await S(
{ evaluationIds: n },
a
), o = n.filter(
(e) => t.results.map((r) => r.id).indexOf(e) === -1
).map((e) => ({
...L,
id: e,
name: e
}));
return [...t.results, ...o];
};
function we(n) {
const { ids: a, type: t } = n, { accessToken: i } = b(), [o, e] = F([]), r = t === "USER_PROFILE" ? "ownerId" : "id", p = ((s) => {
switch (s) {
case "USER_PROFILE":
return _;
case "ENTITY_HEADER":
return R;
case "EVALUATION_QUEUE":
return T;
default:
return "";
}
})(t), g = o.map((s) => s[r]), I = a.filter((s) => s !== O), f = h(k(I, ...g));
return N(() => {
((l) => {
if (!l.length)
return;
const c = sessionStorage.getItem(p);
try {
const u = c ? JSON.parse(c) : [], w = u.map((m) => m[r]);
for (const m of l)
w.includes(m[r]) || u.push(m);
sessionStorage.setItem(
p,
JSON.stringify(u)
);
} catch {
sessionStorage.setItem(p, JSON.stringify(l));
}
})(o);
}, [o, r, p]), D(() => {
let s = !1;
return (async () => {
if (f.length > 0)
try {
const c = Array.from(f), u = t === "ENTITY_HEADER" ? c.map((d) => ({ targetId: d })) : c, w = A(u, 45), m = [];
for (const d of w) {
let E = [];
switch (t) {
case "USER_PROFILE":
E = await K(
d,
i
);
break;
case "ENTITY_HEADER":
E = await G(
d,
i
);
break;
case "EVALUATION_QUEUE":
E = await P(
d,
i
);
break;
}
m.push(...E);
}
s || e((d) => d.concat(...m));
} catch (c) {
console.error("Error on data retrieval", c);
}
})(), () => {
s = !0;
};
}, [i, t, f]), o;
}
export {
we as default
};
//# sourceMappingURL=useGetInfoFromIds.js.map