synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
188 lines (187 loc) • 5.49 kB
JavaScript
import { SYNAPSE_STORAGE_LOCATION_ID as T } 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 "../../SynapseConstants.js";
import { noop as b } from "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../PermissionLevelToAccessType.js";
import { useCallback as l, useMemo as c } from "react";
import { useSynapseContext as M } from "../../context/SynapseContext.js";
import "use-deep-compare-effect";
import "react/jsx-runtime";
import "@mui/material";
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 "@tanstack/query-core";
import "lodash-es/isEmpty";
import "lodash-es/isEqual";
import "lodash-es/xorWith";
import "react-router";
import "@sage-bionetworks/synapse-client";
import "../../types/IsType.js";
import { useCreateEntity as W, useUpdateEntity as G } from "../../../synapse-queries/entity/useEntity.js";
import { useGetDefaultUploadDestination as B } from "../../../synapse-queries/file/useUploadDestination.js";
import { useUploadFiles as j } from "./useUploadFiles.js";
import q from "../useConfirmItems.js";
import { usePrepareFileEntityUpload as H } from "./usePrepareFileEntityUpload.js";
import { willUploadsExceedStorageLimit as J } from "./willUploadsExceedStorageLimit.js";
function Dt(f, v = "", x = "", g = b) {
const { synapseClient: u } = M(), { mutateAsync: y } = W(), { mutateAsync: I } = G(), L = l(
async function(t, o) {
if ("existingEntityId" in t && t.existingEntityId) {
const d = await u.entityServicesClient.getRepoV1EntityId({
id: t.existingEntityId
});
await I({
...d,
dataFileHandleId: o
});
} else if ("parentId" in t) {
const d = {
parentId: t.parentId,
name: t.file.name,
concreteType: "org.sagebionetworks.repo.model.FileEntity",
dataFileHandleId: o
};
await y(d);
} else
throw new Error(
`Can't upload file without a parent ID or existing entity ID. File was: ${JSON.stringify(
t
)}`
);
},
[
y,
u.entityServicesClient,
I
]
), {
data: e,
isLoading: U,
error: V
} = B(f, {
// Storage location usage is eventually consistent. We will keep track of the sum of uploaded files client-side
// to determine if subsequent uploads will exceed the storage limit.
// Do not refetch the storage location usage to avoid double-counting the size of new uploads against the limit.
staleTime: 1 / 0
}), E = !!(f && e), _ = e?.storageLocationId || T, s = V?.message, {
pendingItems: p,
confirmItem: r,
addItemsPendingConfirmation: C,
removePendingItems: w,
clear: a
} = q(), k = l(() => {
a();
}, [a]), {
state: h,
startUpload: n,
activeUploadCount: N,
uploadProgress: F,
bytesPendingUpload: R
} = j({
onBeforeUpload: k,
storageLocationId: _,
uploadDestination: e,
accessKey: v,
secretKey: x,
onUploadComplete: L
}), S = l(
(i) => {
const { filesReadyForUpload: t, filesToPromptForNewVersion: o } = i;
t.length > 0 && o.length == 0 && n(...t), o.length > 0 && (r(...t), C(...o));
},
[
C,
r,
n
]
), { mutateAsync: P, isPending: A } = H(), D = l(
async (i) => {
if (e == null) {
console.error(
"Upload destination was not loaded, or failed to load! Aborting upload."
);
return;
}
if (J(
i.map((o) => o.file),
e.projectStorageLocationUsage,
R
)) {
g();
return;
}
const t = await P(i);
S(t);
},
[
R,
g,
S,
P,
e
]
), m = c(() => p.map((i) => ({
info: {
type: "CONFIRM_NEW_VERSION",
fileName: i.file.name,
existingEntityId: i.existingEntityId
},
onConfirm: () => {
const { confirmedItems: t, pendingItems: o } = r(i);
t.length > 0 && o.length == 0 && n(...t);
},
onConfirmAll: () => {
const { confirmedItems: t } = r(
...p
);
n(...t);
},
onSkip: () => {
const { confirmedItems: t, pendingItems: o } = w(i);
t.length > 0 && o.length == 0 && n(...t);
},
onCancelAll: () => {
a();
}
})), [
a,
r,
p,
w,
n
]), O = c(() => s ? "ERROR" : U ? "LOADING" : m.length > 0 ? "PROMPT_USER" : h, [m.length, s, U, h]);
return c(() => ({
state: O,
errorMessage: s,
isPrecheckingUpload: A,
activeUploadCount: N,
initiateUpload: D,
activePrompts: m,
uploadProgress: F,
isUploadReady: E
}), [
O,
s,
A,
N,
D,
m,
F,
E
]);
}
export {
Dt as useUploadFileEntities
};
//# sourceMappingURL=useUploadFileEntities.js.map