@burdenoff/microfe-cosmicintersection 2026.1110.2 → 2026.1111.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cosmicintersection/components/FileUploadField.d.ts +5 -1
- package/dist/cosmicintersection/components/FileUploadField.js +79 -74
- package/dist/cosmicintersection/components/FileUploadField.js.map +1 -1
- package/dist/cosmicintersection/lib/uploadAudience.d.ts +4 -0
- package/dist/cosmicintersection/lib/uploadAudience.js +17 -0
- package/dist/cosmicintersection/lib/uploadAudience.js.map +1 -0
- package/dist/cosmicintersection/pages/analyses/AnalysesPage.js +1 -0
- package/dist/cosmicintersection/pages/analyses/AnalysesPage.js.map +1 -1
- package/dist/cosmicintersection/pages/datasets/DatasetFormPage.js +129 -116
- package/dist/cosmicintersection/pages/datasets/DatasetFormPage.js.map +1 -1
- package/dist/cosmicintersection/pages/notebooks/NotebookFormPage.js +128 -125
- package/dist/cosmicintersection/pages/notebooks/NotebookFormPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useQuery } from '@apollo/client/react';
|
|
2
|
+
import { ArtifactVisibility } from '../lib/uploadAudience';
|
|
2
3
|
export declare const GET_FILE_DOWNLOAD_URL: import('graphql').DocumentNode;
|
|
3
4
|
interface DownloadUrlResponse {
|
|
4
5
|
getFileDownloadUrl?: string | null;
|
|
@@ -24,10 +25,13 @@ export interface FileUploadFieldProps {
|
|
|
24
25
|
hint?: string;
|
|
25
26
|
/** Optional wspace-files folder id; when omitted the file lands in the root. */
|
|
26
27
|
folderId?: string;
|
|
28
|
+
/** Captured at initiation; completion never changes the session audience. */
|
|
29
|
+
visibility?: ArtifactVisibility;
|
|
30
|
+
onUploadingChange?: (uploading: boolean) => void;
|
|
27
31
|
/** `accept` attribute for the file input; defaults to any file type. */
|
|
28
32
|
accept?: string;
|
|
29
33
|
disabled?: boolean;
|
|
30
34
|
className?: string;
|
|
31
35
|
}
|
|
32
|
-
export declare function FileUploadField({ value, onChange, label, hint, folderId, accept, disabled, className, }: FileUploadFieldProps): import('react').JSX.Element;
|
|
36
|
+
export declare function FileUploadField({ value, onChange, label, hint, folderId, visibility, onUploadingChange, accept, disabled, className, }: FileUploadFieldProps): import('react').JSX.Element;
|
|
33
37
|
export default FileUploadField;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { notify as e } from "../lib/toast.js";
|
|
2
2
|
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { artifactVisibility as n } from "../lib/uploadAudience.js";
|
|
4
|
+
import { useId as r, useRef as i, useState as a } from "react";
|
|
5
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
6
|
+
import { Button as c } from "@burdenoff/fe-libs/ui";
|
|
7
|
+
import { Download as l, FileUp as u, Loader2 as d, Paperclip as f, X as p } from "lucide-react";
|
|
8
|
+
import { gql as m } from "@apollo/client";
|
|
9
|
+
import { useApolloClient as h, useQuery as g } from "@apollo/client/react";
|
|
9
10
|
// src/cosmicintersection/components/FileUploadField.tsx
|
|
10
|
-
var
|
|
11
|
+
var _ = m`
|
|
11
12
|
mutation CosInitiateUpload($input: InitiateUploadInput!) {
|
|
12
13
|
initiateUpload(input: $input) {
|
|
13
14
|
session {
|
|
@@ -16,7 +17,7 @@ var g = p`
|
|
|
16
17
|
uploadUrl
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
`,
|
|
20
|
+
`, v = m`
|
|
20
21
|
mutation CosCompleteUpload($input: CompleteUploadInput!) {
|
|
21
22
|
completeUpload(input: $input) {
|
|
22
23
|
fileId
|
|
@@ -25,123 +26,127 @@ var g = p`
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
|
-
`,
|
|
29
|
+
`, y = m`
|
|
29
30
|
query CosGetFileDownloadUrl($id: ID!, $expiresIn: Int) {
|
|
30
31
|
getFileDownloadUrl(id: $id, expiresIn: $expiresIn)
|
|
31
32
|
}
|
|
32
|
-
`,
|
|
33
|
-
function
|
|
34
|
-
return
|
|
33
|
+
`, b = 3600;
|
|
34
|
+
function x(e) {
|
|
35
|
+
return g(y, {
|
|
35
36
|
variables: {
|
|
36
37
|
id: e ?? "",
|
|
37
|
-
expiresIn:
|
|
38
|
+
expiresIn: b
|
|
38
39
|
},
|
|
39
40
|
skip: !e,
|
|
40
41
|
fetchPolicy: "no-cache"
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
let
|
|
45
|
-
let
|
|
46
|
-
if (t.target.value = "",
|
|
47
|
-
|
|
44
|
+
function S({ value: m, onChange: g, label: y, hint: b, folderId: S, visibility: C = "PRIVATE", onUploadingChange: w, accept: T, disabled: E = !1, className: D }) {
|
|
45
|
+
let O = t(), k = h(), A = i(null), j = r(), [M, N] = a(!1), [P, F] = a(null), I = i(!1), L = x(M ? null : m).data?.getFileDownloadUrl ?? null, R = async (t) => {
|
|
46
|
+
let r = t.target.files?.[0];
|
|
47
|
+
if (t.target.value = "", !(!r || E || I.current)) {
|
|
48
|
+
I.current = !0;
|
|
48
49
|
try {
|
|
49
|
-
let t = n
|
|
50
|
-
|
|
50
|
+
let t = n(C);
|
|
51
|
+
N(!0), w?.(!0);
|
|
52
|
+
let i = r.name.includes(".") ? r.name.substring(r.name.lastIndexOf(".") + 1) : "", a = r.type || "application/octet-stream", o = await k.mutate({
|
|
53
|
+
mutation: _,
|
|
51
54
|
variables: { input: {
|
|
52
|
-
fileName:
|
|
53
|
-
fileSize: String(
|
|
54
|
-
extension:
|
|
55
|
-
mimeType:
|
|
56
|
-
|
|
55
|
+
fileName: r.name,
|
|
56
|
+
fileSize: String(r.size),
|
|
57
|
+
extension: i,
|
|
58
|
+
mimeType: a,
|
|
59
|
+
visibility: t,
|
|
60
|
+
...S ? { folderId: S } : {}
|
|
57
61
|
} }
|
|
58
|
-
}),
|
|
59
|
-
if (!
|
|
62
|
+
}), s = o.data?.initiateUpload?.session, c = o.data?.initiateUpload?.uploadUrl;
|
|
63
|
+
if (!s || !c) throw Error(o.error?.message ?? O("cosmicintersection.common.uploadStartError", "Could not start the upload."));
|
|
60
64
|
await new Promise((e, t) => {
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}),
|
|
65
|
+
let n = new XMLHttpRequest();
|
|
66
|
+
n.addEventListener("load", () => {
|
|
67
|
+
n.status >= 200 && n.status < 300 ? e() : t(/* @__PURE__ */ Error(`Upload failed with status ${n.status}`));
|
|
68
|
+
}), n.addEventListener("error", () => t(/* @__PURE__ */ Error("Upload network error"))), n.addEventListener("abort", () => t(/* @__PURE__ */ Error("Upload aborted"))), n.open("PUT", c), n.setRequestHeader("Content-Type", a), n.send(r);
|
|
65
69
|
});
|
|
66
|
-
let
|
|
67
|
-
mutation:
|
|
70
|
+
let l = await k.mutate({
|
|
71
|
+
mutation: v,
|
|
68
72
|
variables: { input: {
|
|
69
|
-
sessionId:
|
|
70
|
-
fileSize: String(
|
|
71
|
-
...
|
|
73
|
+
sessionId: s.id,
|
|
74
|
+
fileSize: String(r.size),
|
|
75
|
+
...S ? { folderId: S } : {}
|
|
72
76
|
} }
|
|
73
|
-
}),
|
|
74
|
-
if (!
|
|
75
|
-
|
|
77
|
+
}), u = l.data?.completeUpload?.fileId ?? l.data?.completeUpload?.file?.id;
|
|
78
|
+
if (!u) throw Error(l.error?.message ?? O("cosmicintersection.common.uploadConfirmError", "The file was uploaded but not confirmed."));
|
|
79
|
+
F(r.name), await g(u), e.success(O("cosmicintersection.common.uploadSuccess", "File uploaded"));
|
|
76
80
|
} catch (t) {
|
|
77
|
-
e.error(
|
|
81
|
+
e.error(O("cosmicintersection.common.uploadFailed", "Upload failed"), t instanceof Error ? t.message : O("cosmicintersection.common.uploadTryAgain", "Please try again."));
|
|
78
82
|
} finally {
|
|
79
|
-
|
|
83
|
+
I.current = !1, N(!1), w?.(!1);
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
|
-
},
|
|
83
|
-
|
|
86
|
+
}, z = async () => {
|
|
87
|
+
F(null), await g("");
|
|
84
88
|
};
|
|
85
|
-
return /* @__PURE__ */
|
|
86
|
-
className:
|
|
87
|
-
children: [/* @__PURE__ */
|
|
89
|
+
return /* @__PURE__ */ s("div", {
|
|
90
|
+
className: D,
|
|
91
|
+
children: [/* @__PURE__ */ s("div", {
|
|
88
92
|
className: "flex flex-wrap items-center gap-3",
|
|
89
|
-
children: [/* @__PURE__ */
|
|
93
|
+
children: [/* @__PURE__ */ o("div", {
|
|
90
94
|
className: "flex size-12 shrink-0 items-center justify-center rounded-card border border-dashed border-border-default bg-bg-sunken text-text-secondary",
|
|
91
|
-
children: /* @__PURE__ */
|
|
95
|
+
children: /* @__PURE__ */ o(f, {
|
|
92
96
|
className: "size-5",
|
|
93
97
|
"aria-hidden": "true"
|
|
94
98
|
})
|
|
95
|
-
}), /* @__PURE__ */
|
|
99
|
+
}), /* @__PURE__ */ s("div", {
|
|
96
100
|
className: "space-y-1",
|
|
97
|
-
children: [/* @__PURE__ */
|
|
101
|
+
children: [/* @__PURE__ */ s("div", {
|
|
98
102
|
className: "flex items-center gap-2",
|
|
99
|
-
children: [/* @__PURE__ */
|
|
103
|
+
children: [/* @__PURE__ */ s(c, {
|
|
100
104
|
type: "button",
|
|
101
105
|
variant: "secondary",
|
|
102
106
|
size: "sm",
|
|
103
|
-
disabled:
|
|
104
|
-
onClick: () =>
|
|
105
|
-
children: [
|
|
106
|
-
}),
|
|
107
|
+
disabled: E || M,
|
|
108
|
+
onClick: () => A.current?.click(),
|
|
109
|
+
children: [M ? /* @__PURE__ */ o(d, { className: "size-4 animate-spin" }) : /* @__PURE__ */ o(u, { className: "size-4" }), M ? O("cosmicintersection.common.uploading", "Uploading…") : m ? O("cosmicintersection.common.replaceFile", "Replace file") : y]
|
|
110
|
+
}), m && !M ? /* @__PURE__ */ s(c, {
|
|
107
111
|
type: "button",
|
|
108
112
|
variant: "ghost",
|
|
109
113
|
size: "sm",
|
|
110
|
-
onClick: () => void
|
|
111
|
-
disabled:
|
|
112
|
-
children: [/* @__PURE__ */
|
|
114
|
+
onClick: () => void z(),
|
|
115
|
+
disabled: E,
|
|
116
|
+
children: [/* @__PURE__ */ o(p, { className: "size-4" }), O("cosmicintersection.common.remove", "Remove")]
|
|
113
117
|
}) : null]
|
|
114
|
-
}),
|
|
118
|
+
}), m ? /* @__PURE__ */ s("div", {
|
|
115
119
|
className: "flex flex-wrap items-center gap-2 text-xs text-text-secondary",
|
|
116
|
-
children: [/* @__PURE__ */
|
|
120
|
+
children: [/* @__PURE__ */ o("span", {
|
|
117
121
|
className: "max-w-[16rem] truncate",
|
|
118
|
-
children:
|
|
119
|
-
}),
|
|
120
|
-
href:
|
|
122
|
+
children: P ?? `File ${m}`
|
|
123
|
+
}), L ? /* @__PURE__ */ s("a", {
|
|
124
|
+
href: L,
|
|
121
125
|
target: "_blank",
|
|
122
126
|
rel: "noopener noreferrer",
|
|
123
127
|
className: "inline-flex items-center gap-1 text-text-primary underline-offset-2 hover:underline",
|
|
124
|
-
children: [/* @__PURE__ */
|
|
128
|
+
children: [/* @__PURE__ */ o(l, {
|
|
125
129
|
className: "size-3.5",
|
|
126
130
|
"aria-hidden": "true"
|
|
127
|
-
}),
|
|
131
|
+
}), O("cosmicintersection.common.download", "Download")]
|
|
128
132
|
}) : null]
|
|
129
|
-
}) :
|
|
133
|
+
}) : b ? /* @__PURE__ */ o("p", {
|
|
130
134
|
className: "text-xs text-text-secondary",
|
|
131
|
-
children:
|
|
135
|
+
children: b
|
|
132
136
|
}) : null]
|
|
133
137
|
})]
|
|
134
|
-
}), /* @__PURE__ */
|
|
135
|
-
ref:
|
|
136
|
-
id:
|
|
138
|
+
}), /* @__PURE__ */ o("input", {
|
|
139
|
+
ref: A,
|
|
140
|
+
id: j,
|
|
137
141
|
type: "file",
|
|
138
|
-
accept:
|
|
142
|
+
accept: T,
|
|
143
|
+
disabled: E || M,
|
|
139
144
|
className: "sr-only",
|
|
140
|
-
"aria-label":
|
|
141
|
-
onChange: (e) => void
|
|
145
|
+
"aria-label": y,
|
|
146
|
+
onChange: (e) => void R(e)
|
|
142
147
|
})]
|
|
143
148
|
});
|
|
144
149
|
}
|
|
145
|
-
export {
|
|
150
|
+
export { S as FileUploadField, S as default, y as GET_FILE_DOWNLOAD_URL, x as useFileDownloadUrl };
|
|
146
151
|
|
|
147
152
|
//# sourceMappingURL=FileUploadField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileUploadField.js","names":["INITIATE_UPLOAD","COMPLETE_UPLOAD","GET_FILE_DOWNLOAD_URL","DOWNLOAD_URL_TTL_SECONDS","useFileDownloadUrl","useQuery","fileId","FileUploadField","tr","useTr","client","useApolloClient","inputRef","useRef","inputId","useId","uploading","setUploading","useState","fileName","setFileName","downloadUrl","value","handleSelect","file","event","extension","mimeType","initiate","folderId","session","uploadUrl","xhr","resolve","reject","complete","uploadedId","onChange","notify","error","clear","Paperclip","Button","disabled","Loader2","FileUp","label","X","Download","hint"],"sources":["../../../src/cosmicintersection/components/FileUploadField.tsx"],"sourcesContent":["import { gql } from '@apollo/client';\nimport { useApolloClient, useQuery } from '@apollo/client/react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { Download, FileUp, Loader2, Paperclip, X } from 'lucide-react';\nimport { useId, useRef, useState } from 'react';\n\nimport { notify } from '../lib/toast';\nimport { useTr } from '../../shared/hooks/useTr';\n\n/**\n * Generic artifact uploader backed by wspace-files-svc.\n *\n * Dataset/notebook/analysis blobs are NOT stored by this MFE — they live in\n * wspace-files as `File` records, and the Cos entities only hold the returned\n * `fileId` (CosDataset.fileId / CosNotebook.fileId / cosCompleteAnalysis.outputFileId).\n * This control performs the shared 3-step presigned upload (initiateUpload → PUT\n * → completeUpload) inline — the same protocol microfe-files uses — and hands the\n * resulting `fileId` back via `onChange`. It never keeps a local blob store and\n * accepts any file type.\n */\n\n// initiateUpload returns a presigned PUT URL + the upload session id.\nconst INITIATE_UPLOAD = gql`\n mutation CosInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) {\n session {\n id\n }\n uploadUrl\n }\n }\n`;\n\n// completeUpload finalizes the session and returns the committed File id.\nconst COMPLETE_UPLOAD = gql`\n mutation CosCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) {\n fileId\n file {\n id\n }\n }\n }\n`;\n\n// Presigned, time-limited download URL for a stored File — used to render a\n// \"Download\" affordance for an already-attached artifact.\nexport const GET_FILE_DOWNLOAD_URL = gql`\n query CosGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }\n`;\n\n// One hour — artifact links are resolved on demand when a detail page renders.\nconst DOWNLOAD_URL_TTL_SECONDS = 3_600;\n\ninterface InitiateUploadResponse {\n initiateUpload?: { session?: { id: string } | null; uploadUrl?: string | null } | null;\n}\n\ninterface CompleteUploadResponse {\n completeUpload?: { fileId?: string | null; file?: { id: string } | null } | null;\n}\n\ninterface DownloadUrlResponse {\n getFileDownloadUrl?: string | null;\n}\n\n/**\n * Resolve a presigned download URL for an attached File id. Skips when no id is\n * present. Detail pages use this to render a \"Download\" link for a dataset/\n * notebook/analysis artifact.\n */\nexport function useFileDownloadUrl(fileId: string | null | undefined) {\n return useQuery<DownloadUrlResponse, { id: string; expiresIn: number }>(GET_FILE_DOWNLOAD_URL, {\n variables: { id: fileId ?? '', expiresIn: DOWNLOAD_URL_TTL_SECONDS },\n skip: !fileId,\n fetchPolicy: 'no-cache',\n });\n}\n\nexport interface FileUploadFieldProps {\n /** Current attached wspace-files File id, if any. */\n value?: string | null;\n /** Called with the new File id once an upload completes, or '' when cleared. */\n onChange: (fileId: string) => void | Promise<void>;\n label: string;\n hint?: string;\n /** Optional wspace-files folder id; when omitted the file lands in the root. */\n folderId?: string;\n /** `accept` attribute for the file input; defaults to any file type. */\n accept?: string;\n disabled?: boolean;\n className?: string;\n}\n\nexport function FileUploadField({\n value,\n onChange,\n label,\n hint,\n folderId,\n accept,\n disabled = false,\n className,\n}: FileUploadFieldProps) {\n const tr = useTr();\n const client = useApolloClient();\n const inputRef = useRef<HTMLInputElement | null>(null);\n const inputId = useId();\n const [uploading, setUploading] = useState(false);\n const [fileName, setFileName] = useState<string | null>(null);\n\n const download = useFileDownloadUrl(uploading ? null : value);\n const downloadUrl = download.data?.getFileDownloadUrl ?? null;\n\n const handleSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {\n const file = event.target.files?.[0];\n // Reset the input so selecting the same file again re-triggers change.\n event.target.value = '';\n if (!file) {\n return;\n }\n\n setUploading(true);\n try {\n const extension = file.name.includes('.')\n ? file.name.substring(file.name.lastIndexOf('.') + 1)\n : '';\n const mimeType = file.type || 'application/octet-stream';\n\n const initiate = await client.mutate<InitiateUploadResponse>({\n mutation: INITIATE_UPLOAD,\n variables: {\n input: {\n fileName: file.name,\n fileSize: String(file.size),\n extension,\n mimeType,\n ...(folderId ? { folderId } : {}),\n },\n },\n });\n const session = initiate.data?.initiateUpload?.session;\n const uploadUrl = initiate.data?.initiateUpload?.uploadUrl;\n if (!session || !uploadUrl) {\n throw new Error(\n initiate.error?.message ??\n tr('cosmicintersection.common.uploadStartError', 'Could not start the upload.')\n );\n }\n\n await new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n xhr.addEventListener('load', () => {\n if (xhr.status >= 200 && xhr.status < 300) {\n resolve();\n } else {\n reject(new Error(`Upload failed with status ${xhr.status}`));\n }\n });\n xhr.addEventListener('error', () => reject(new Error('Upload network error')));\n xhr.addEventListener('abort', () => reject(new Error('Upload aborted')));\n xhr.open('PUT', uploadUrl);\n xhr.setRequestHeader('Content-Type', mimeType);\n xhr.send(file);\n });\n\n const complete = await client.mutate<CompleteUploadResponse>({\n mutation: COMPLETE_UPLOAD,\n variables: {\n input: {\n sessionId: session.id,\n fileSize: String(file.size),\n ...(folderId ? { folderId } : {}),\n },\n },\n });\n const uploadedId =\n complete.data?.completeUpload?.fileId ?? complete.data?.completeUpload?.file?.id;\n if (!uploadedId) {\n throw new Error(\n complete.error?.message ??\n tr(\n 'cosmicintersection.common.uploadConfirmError',\n 'The file was uploaded but not confirmed.'\n )\n );\n }\n\n setFileName(file.name);\n await onChange(uploadedId);\n notify.success(tr('cosmicintersection.common.uploadSuccess', 'File uploaded'));\n } catch (error) {\n notify.error(\n tr('cosmicintersection.common.uploadFailed', 'Upload failed'),\n error instanceof Error\n ? error.message\n : tr('cosmicintersection.common.uploadTryAgain', 'Please try again.')\n );\n } finally {\n setUploading(false);\n }\n };\n\n const clear = async () => {\n setFileName(null);\n await onChange('');\n };\n\n return (\n <div className={className}>\n <div className=\"flex flex-wrap items-center gap-3\">\n <div className=\"flex size-12 shrink-0 items-center justify-center rounded-card border border-dashed border-border-default bg-bg-sunken text-text-secondary\">\n <Paperclip className=\"size-5\" aria-hidden=\"true\" />\n </div>\n <div className=\"space-y-1\">\n <div className=\"flex items-center gap-2\">\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n disabled={disabled || uploading}\n onClick={() => inputRef.current?.click()}\n >\n {uploading ? (\n <Loader2 className=\"size-4 animate-spin\" />\n ) : (\n <FileUp className=\"size-4\" />\n )}\n {uploading\n ? tr('cosmicintersection.common.uploading', 'Uploading…')\n : value\n ? tr('cosmicintersection.common.replaceFile', 'Replace file')\n : label}\n </Button>\n {value && !uploading ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => void clear()}\n disabled={disabled}\n >\n <X className=\"size-4\" />\n {tr('cosmicintersection.common.remove', 'Remove')}\n </Button>\n ) : null}\n </div>\n {value ? (\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-text-secondary\">\n <span className=\"max-w-[16rem] truncate\">{fileName ?? `File ${value}`}</span>\n {downloadUrl ? (\n <a\n href={downloadUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"inline-flex items-center gap-1 text-text-primary underline-offset-2 hover:underline\"\n >\n <Download className=\"size-3.5\" aria-hidden=\"true\" />\n {tr('cosmicintersection.common.download', 'Download')}\n </a>\n ) : null}\n </div>\n ) : hint ? (\n <p className=\"text-xs text-text-secondary\">{hint}</p>\n ) : null}\n </div>\n </div>\n <input\n ref={inputRef}\n id={inputId}\n type=\"file\"\n accept={accept}\n className=\"sr-only\"\n aria-label={label}\n onChange={(event) => void handleSelect(event)}\n />\n </div>\n );\n}\n\nexport default FileUploadField;\n"],"mappings":";;;;;;;;;AAsBA,IAAMA,IAAkB,CAAG;;;;;;;;;GAYrBC,IAAkB,CAAG;;;;;;;;;GAadC,IAAwB,CAAG;;;;GAOlCC,IAA2B;AAmBjC,SAAgBC,EAAmB,GAAmC;CACpE,OAAOC,EAAiEH,GAAuB;EAC7F,WAAW;GAAE,IAAII,KAAU;GAAI,WAAWH;EAAyB;EACnE,MAAM,CAACG;EACP,aAAa;CACf,CAAC;AACH;AAiBA,SAAgBC,EAAgB,EAC9B,UACA,aACA,UACA,SACA,aACA,WACA,cAAW,IACX,gBACuB;CACvB,IAAMC,IAAKC,EAAM,GACXC,IAASC,EAAgB,GACzBC,IAAWC,EAAgC,IAAI,GAC/CC,IAAUC,EAAM,GAChB,CAACC,GAAWC,KAAgBC,EAAS,EAAK,GAC1C,CAACC,GAAUC,KAAeF,EAAwB,IAAI,GAGtDG,IADWjB,EAAmBY,IAAY,OAAOM,CACnC,CAAA,CAAS,MAAM,sBAAsB,MAEnDC,IAAe,OAAO,MAA+C;EACzE,IAAMC,IAAOC,EAAM,OAAO,QAAQ;EAGlC,IADA,EAAM,OAAO,QAAQ,IAChBD,GAIL;KAAa,EAAI;GACjB,IAAI;IACF,IAAME,IAAYF,EAAK,KAAK,SAAS,GAAG,IACpCA,EAAK,KAAK,UAAUA,EAAK,KAAK,YAAY,GAAG,IAAI,CAAC,IAClD,IACEG,IAAWH,EAAK,QAAQ,4B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CAAA,GAC3ED,IACC,kBAAC,KAAD;MACE,MAAMA;MACN,QAAO;MACP,KAAI;MACJ,WAAU;MAJZ,UAAA,CAME,kBAAC2B,GAAD;OAAU,WAAU;OAAW,eAAY;MAAQ,CAAA,GAClDxC,EAAG,sCAAsC,UAAU,CACnD;KACD,CAAA,IAAA,IACD;IACH,CAAA,IAAAyC,IACF,kBAAC,KAAD;KAAG,WAAU;KAA+B,UAAAA;IAAQ,CAAA,IAClD,IACD;GACF,CAAA,CAAA;EACL,CAAA,GAAA,kBAAC,SAAD;GACE,KAAKrC;GACL,IAAIE;GACJ,MAAK;GACG;GACR,WAAU;GACV,cAAYgC;GACZ,WAAW,MAAU,KAAKvB,EAAaE,CAAK;EAC7C,CAAA,CACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"FileUploadField.js","names":["INITIATE_UPLOAD","COMPLETE_UPLOAD","GET_FILE_DOWNLOAD_URL","DOWNLOAD_URL_TTL_SECONDS","useFileDownloadUrl","useQuery","fileId","FileUploadField","tr","useTr","client","useApolloClient","inputRef","useRef","inputId","useId","uploading","setUploading","useState","fileName","setFileName","inFlight","downloadUrl","value","handleSelect","file","event","disabled","audience","artifactVisibility","visibility","onUploadingChange","extension","mimeType","initiate","folderId","session","uploadUrl","xhr","resolve","reject","complete","uploadedId","onChange","notify","error","clear","Paperclip","Button","Loader2","FileUp","label","X","Download","hint"],"sources":["../../../src/cosmicintersection/components/FileUploadField.tsx"],"sourcesContent":["import { gql } from '@apollo/client';\nimport { useApolloClient, useQuery } from '@apollo/client/react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { Download, FileUp, Loader2, Paperclip, X } from 'lucide-react';\nimport { useId, useRef, useState } from 'react';\n\nimport { notify } from '../lib/toast';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { artifactVisibility, type ArtifactVisibility } from '../lib/uploadAudience';\n\n/**\n * Generic artifact uploader backed by wspace-files-svc.\n *\n * Dataset/notebook/analysis blobs are NOT stored by this MFE — they live in\n * wspace-files as `File` records, and the Cos entities only hold the returned\n * `fileId` (CosDataset.fileId / CosNotebook.fileId / cosCompleteAnalysis.outputFileId).\n * This control performs the shared 3-step presigned upload (initiateUpload → PUT\n * → completeUpload) inline — the same protocol microfe-files uses — and hands the\n * resulting `fileId` back via `onChange`. It never keeps a local blob store and\n * accepts any file type.\n */\n\n// initiateUpload returns a presigned PUT URL + the upload session id.\nconst INITIATE_UPLOAD = gql`\n mutation CosInitiateUpload($input: InitiateUploadInput!) {\n initiateUpload(input: $input) {\n session {\n id\n }\n uploadUrl\n }\n }\n`;\n\n// completeUpload finalizes the session and returns the committed File id.\nconst COMPLETE_UPLOAD = gql`\n mutation CosCompleteUpload($input: CompleteUploadInput!) {\n completeUpload(input: $input) {\n fileId\n file {\n id\n }\n }\n }\n`;\n\n// Presigned, time-limited download URL for a stored File — used to render a\n// \"Download\" affordance for an already-attached artifact.\nexport const GET_FILE_DOWNLOAD_URL = gql`\n query CosGetFileDownloadUrl($id: ID!, $expiresIn: Int) {\n getFileDownloadUrl(id: $id, expiresIn: $expiresIn)\n }\n`;\n\n// One hour — artifact links are resolved on demand when a detail page renders.\nconst DOWNLOAD_URL_TTL_SECONDS = 3_600;\n\ninterface InitiateUploadResponse {\n initiateUpload?: { session?: { id: string } | null; uploadUrl?: string | null } | null;\n}\n\ninterface CompleteUploadResponse {\n completeUpload?: { fileId?: string | null; file?: { id: string } | null } | null;\n}\n\ninterface DownloadUrlResponse {\n getFileDownloadUrl?: string | null;\n}\n\n/**\n * Resolve a presigned download URL for an attached File id. Skips when no id is\n * present. Detail pages use this to render a \"Download\" link for a dataset/\n * notebook/analysis artifact.\n */\nexport function useFileDownloadUrl(fileId: string | null | undefined) {\n return useQuery<DownloadUrlResponse, { id: string; expiresIn: number }>(GET_FILE_DOWNLOAD_URL, {\n variables: { id: fileId ?? '', expiresIn: DOWNLOAD_URL_TTL_SECONDS },\n skip: !fileId,\n fetchPolicy: 'no-cache',\n });\n}\n\nexport interface FileUploadFieldProps {\n /** Current attached wspace-files File id, if any. */\n value?: string | null;\n /** Called with the new File id once an upload completes, or '' when cleared. */\n onChange: (fileId: string) => void | Promise<void>;\n label: string;\n hint?: string;\n /** Optional wspace-files folder id; when omitted the file lands in the root. */\n folderId?: string;\n /** Captured at initiation; completion never changes the session audience. */\n visibility?: ArtifactVisibility;\n onUploadingChange?: (uploading: boolean) => void;\n /** `accept` attribute for the file input; defaults to any file type. */\n accept?: string;\n disabled?: boolean;\n className?: string;\n}\n\nexport function FileUploadField({\n value,\n onChange,\n label,\n hint,\n folderId,\n visibility = 'PRIVATE',\n onUploadingChange,\n accept,\n disabled = false,\n className,\n}: FileUploadFieldProps) {\n const tr = useTr();\n const client = useApolloClient();\n const inputRef = useRef<HTMLInputElement | null>(null);\n const inputId = useId();\n const [uploading, setUploading] = useState(false);\n const [fileName, setFileName] = useState<string | null>(null);\n const inFlight = useRef(false);\n\n const download = useFileDownloadUrl(uploading ? null : value);\n const downloadUrl = download.data?.getFileDownloadUrl ?? null;\n\n const handleSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {\n const file = event.target.files?.[0];\n // Reset the input so selecting the same file again re-triggers change.\n event.target.value = '';\n if (!file || disabled || inFlight.current) {\n return;\n }\n\n inFlight.current = true;\n try {\n const audience = artifactVisibility(visibility);\n setUploading(true);\n onUploadingChange?.(true);\n const extension = file.name.includes('.')\n ? file.name.substring(file.name.lastIndexOf('.') + 1)\n : '';\n const mimeType = file.type || 'application/octet-stream';\n\n const initiate = await client.mutate<InitiateUploadResponse>({\n mutation: INITIATE_UPLOAD,\n variables: {\n input: {\n fileName: file.name,\n fileSize: String(file.size),\n extension,\n mimeType,\n visibility: audience,\n ...(folderId ? { folderId } : {}),\n },\n },\n });\n const session = initiate.data?.initiateUpload?.session;\n const uploadUrl = initiate.data?.initiateUpload?.uploadUrl;\n if (!session || !uploadUrl) {\n throw new Error(\n initiate.error?.message ??\n tr('cosmicintersection.common.uploadStartError', 'Could not start the upload.')\n );\n }\n\n await new Promise<void>((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n xhr.addEventListener('load', () => {\n if (xhr.status >= 200 && xhr.status < 300) {\n resolve();\n } else {\n reject(new Error(`Upload failed with status ${xhr.status}`));\n }\n });\n xhr.addEventListener('error', () => reject(new Error('Upload network error')));\n xhr.addEventListener('abort', () => reject(new Error('Upload aborted')));\n xhr.open('PUT', uploadUrl);\n xhr.setRequestHeader('Content-Type', mimeType);\n xhr.send(file);\n });\n\n const complete = await client.mutate<CompleteUploadResponse>({\n mutation: COMPLETE_UPLOAD,\n variables: {\n input: {\n sessionId: session.id,\n fileSize: String(file.size),\n ...(folderId ? { folderId } : {}),\n },\n },\n });\n const uploadedId =\n complete.data?.completeUpload?.fileId ?? complete.data?.completeUpload?.file?.id;\n if (!uploadedId) {\n throw new Error(\n complete.error?.message ??\n tr(\n 'cosmicintersection.common.uploadConfirmError',\n 'The file was uploaded but not confirmed.'\n )\n );\n }\n\n setFileName(file.name);\n await onChange(uploadedId);\n notify.success(tr('cosmicintersection.common.uploadSuccess', 'File uploaded'));\n } catch (error) {\n notify.error(\n tr('cosmicintersection.common.uploadFailed', 'Upload failed'),\n error instanceof Error\n ? error.message\n : tr('cosmicintersection.common.uploadTryAgain', 'Please try again.')\n );\n } finally {\n inFlight.current = false;\n setUploading(false);\n onUploadingChange?.(false);\n }\n };\n\n const clear = async () => {\n setFileName(null);\n await onChange('');\n };\n\n return (\n <div className={className}>\n <div className=\"flex flex-wrap items-center gap-3\">\n <div className=\"flex size-12 shrink-0 items-center justify-center rounded-card border border-dashed border-border-default bg-bg-sunken text-text-secondary\">\n <Paperclip className=\"size-5\" aria-hidden=\"true\" />\n </div>\n <div className=\"space-y-1\">\n <div className=\"flex items-center gap-2\">\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n disabled={disabled || uploading}\n onClick={() => inputRef.current?.click()}\n >\n {uploading ? (\n <Loader2 className=\"size-4 animate-spin\" />\n ) : (\n <FileUp className=\"size-4\" />\n )}\n {uploading\n ? tr('cosmicintersection.common.uploading', 'Uploading…')\n : value\n ? tr('cosmicintersection.common.replaceFile', 'Replace file')\n : label}\n </Button>\n {value && !uploading ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => void clear()}\n disabled={disabled}\n >\n <X className=\"size-4\" />\n {tr('cosmicintersection.common.remove', 'Remove')}\n </Button>\n ) : null}\n </div>\n {value ? (\n <div className=\"flex flex-wrap items-center gap-2 text-xs text-text-secondary\">\n <span className=\"max-w-[16rem] truncate\">{fileName ?? `File ${value}`}</span>\n {downloadUrl ? (\n <a\n href={downloadUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"inline-flex items-center gap-1 text-text-primary underline-offset-2 hover:underline\"\n >\n <Download className=\"size-3.5\" aria-hidden=\"true\" />\n {tr('cosmicintersection.common.download', 'Download')}\n </a>\n ) : null}\n </div>\n ) : hint ? (\n <p className=\"text-xs text-text-secondary\">{hint}</p>\n ) : null}\n </div>\n </div>\n <input\n ref={inputRef}\n id={inputId}\n type=\"file\"\n accept={accept}\n disabled={disabled || uploading}\n className=\"sr-only\"\n aria-label={label}\n onChange={(event) => void handleSelect(event)}\n />\n </div>\n );\n}\n\nexport default FileUploadField;\n"],"mappings":";;;;;;;;;;AAuBA,IAAMA,IAAkB,CAAG;;;;;;;;;GAYrBC,IAAkB,CAAG;;;;;;;;;GAadC,IAAwB,CAAG;;;;GAOlCC,IAA2B;AAmBjC,SAAgBC,EAAmB,GAAmC;CACpE,OAAOC,EAAiEH,GAAuB;EAC7F,WAAW;GAAE,IAAII,KAAU;GAAI,WAAWH;EAAyB;EACnE,MAAM,CAACG;EACP,aAAa;CACf,CAAC;AACH;AAoBA,SAAgBC,EAAgB,EAC9B,UACA,aACA,UACA,SACA,aACA,gBAAa,WACb,sBACA,WACA,cAAW,IACX,gBACuB;CACvB,IAAMC,IAAKC,EAAM,GACXC,IAASC,EAAgB,GACzBC,IAAWC,EAAgC,IAAI,GAC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ata does not authorize publishing its underlying bytes. */
|
|
3
|
+
export declare function artifactVisibility(value?: unknown): ArtifactVisibility;
|
|
4
|
+
export declare function datasetArtifactVisibility(accessLevel: unknown): ArtifactVisibility;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/cosmicintersection/lib/uploadAudience.ts
|
|
2
|
+
function e(e = "PRIVATE") {
|
|
3
|
+
if (e !== "PRIVATE" && e !== "WORKSPACE") throw Error("Upload visibility must be PRIVATE or WORKSPACE");
|
|
4
|
+
return e;
|
|
5
|
+
}
|
|
6
|
+
function t(e) {
|
|
7
|
+
switch (e) {
|
|
8
|
+
case "WORKSPACE": return "WORKSPACE";
|
|
9
|
+
case "PUBLIC":
|
|
10
|
+
case "RESTRICTED":
|
|
11
|
+
case "EMBARGOED": return "PRIVATE";
|
|
12
|
+
default: throw Error("Unknown dataset access level");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export { e as artifactVisibility, t as datasetArtifactVisibility };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=uploadAudience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadAudience.js","names":["artifactVisibility","value","datasetArtifactVisibility","accessLevel"],"sources":["../../../src/cosmicintersection/lib/uploadAudience.ts"],"sourcesContent":["export type ArtifactVisibility = 'PRIVATE' | 'WORKSPACE';\n\n/** Public science metadata does not authorize publishing its underlying bytes. */\nexport function artifactVisibility(value: unknown = 'PRIVATE'): ArtifactVisibility {\n if (value !== 'PRIVATE' && value !== 'WORKSPACE') {\n throw new Error('Upload visibility must be PRIVATE or WORKSPACE');\n }\n return value;\n}\n\nexport function datasetArtifactVisibility(accessLevel: unknown): ArtifactVisibility {\n switch (accessLevel) {\n case 'WORKSPACE':\n return 'WORKSPACE';\n case 'PUBLIC':\n case 'RESTRICTED':\n case 'EMBARGOED':\n return 'PRIVATE';\n default:\n throw new Error('Unknown dataset access level');\n }\n}\n"],"mappings":";AAGA,SAAgBA,EAAmB,IAAiB,WAA+B;CACjF,IAAIC,MAAU,aAAaA,MAAU,aACnC,MAAU,MAAM,gDAAgD;CAElE,OAAOA;AACT;AAEA,SAAgBC,EAA0B,GAA0C;CAClF,QAAQC,GAAR;EACE,KAAK,aACH,OAAO;EACT,KAAK;EACL,KAAK;EACL,KAAK,aACH,OAAO;EACT,SACE,MAAU,MAAM,8BAA8B;CAClD;AACF"}
|