@terreno/admin-frontend 0.3.2 → 0.4.2
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/README.md +5 -0
- package/dist/AdminFieldRenderer.d.ts +36 -0
- package/dist/AdminFieldRenderer.js +41 -1
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminModelForm.d.ts +51 -0
- package/dist/AdminModelForm.js +55 -4
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +26 -0
- package/dist/AdminModelList.js +35 -5
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +29 -0
- package/dist/AdminModelTable.js +45 -16
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminRefField.d.ts +35 -0
- package/dist/AdminRefField.js +36 -1
- package/dist/AdminRefField.js.map +1 -1
- package/dist/AdminScriptList.d.ts +10 -0
- package/dist/AdminScriptList.js +31 -0
- package/dist/AdminScriptList.js.map +1 -0
- package/dist/AdminScriptRunModal.d.ts +11 -0
- package/dist/AdminScriptRunModal.js +87 -0
- package/dist/AdminScriptRunModal.js.map +1 -0
- package/dist/ConfigurationScreen.d.ts +30 -0
- package/dist/ConfigurationScreen.js +128 -0
- package/dist/ConfigurationScreen.js.map +1 -0
- package/dist/DocumentStorageBrowser.d.ts +3 -0
- package/dist/DocumentStorageBrowser.js +317 -0
- package/dist/DocumentStorageBrowser.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +52 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +43 -0
- package/dist/useAdminApi.js +44 -1
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.d.ts +29 -0
- package/dist/useAdminConfig.js +30 -1
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.d.ts +32 -0
- package/dist/useAdminScripts.js +36 -0
- package/dist/useAdminScripts.js.map +1 -0
- package/dist/useConfigurationApi.d.ts +34 -0
- package/dist/useConfigurationApi.js +53 -0
- package/dist/useConfigurationApi.js.map +1 -0
- package/dist/useDocumentStorageApi.d.ts +9 -0
- package/dist/useDocumentStorageApi.js +89 -0
- package/dist/useDocumentStorageApi.js.map +1 -0
- package/package.json +17 -3
- package/src/AdminFieldRenderer.tsx +57 -1
- package/src/AdminModelForm.tsx +69 -16
- package/src/AdminModelList.tsx +107 -21
- package/src/AdminModelTable.tsx +98 -68
- package/src/AdminRefField.tsx +36 -1
- package/src/AdminScriptList.test.tsx +124 -0
- package/src/AdminScriptList.tsx +96 -0
- package/src/AdminScriptRunModal.test.tsx +69 -0
- package/src/AdminScriptRunModal.tsx +188 -0
- package/src/ConfigurationScreen.tsx +319 -0
- package/src/DocumentStorageBrowser.tsx +641 -0
- package/src/index.tsx +12 -0
- package/src/types.ts +59 -0
- package/src/useAdminApi.ts +44 -1
- package/src/useAdminConfig.ts +30 -1
- package/src/useAdminScripts.ts +48 -0
- package/src/useConfigurationApi.ts +70 -0
- package/src/useDocumentStorageApi.ts +96 -0
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
Button,
|
|
4
|
+
DataTable,
|
|
5
|
+
type DataTableCellData,
|
|
6
|
+
type DataTableColumn,
|
|
7
|
+
type DataTableCustomComponentMap,
|
|
8
|
+
IconButton,
|
|
9
|
+
Link,
|
|
10
|
+
Modal,
|
|
11
|
+
Page,
|
|
12
|
+
Spinner,
|
|
13
|
+
Text,
|
|
14
|
+
TextField,
|
|
15
|
+
} from "@terreno/ui";
|
|
16
|
+
import {DateTime} from "luxon";
|
|
17
|
+
import React, {useCallback, useEffect, useMemo, useRef, useState} from "react";
|
|
18
|
+
import {Platform, Image as RNImage, useWindowDimensions} from "react-native";
|
|
19
|
+
import {WebView} from "react-native-webview";
|
|
20
|
+
|
|
21
|
+
import type {DocumentFile, DocumentListResponse, DocumentStorageBrowserProps} from "./types";
|
|
22
|
+
import {useDocumentStorageApi} from "./useDocumentStorageApi";
|
|
23
|
+
|
|
24
|
+
const ACTIONS_COLUMN_TYPE = "documentActions";
|
|
25
|
+
const NAME_COLUMN_TYPE = "documentName";
|
|
26
|
+
|
|
27
|
+
const formatFileSize = (bytes: number): string => {
|
|
28
|
+
if (bytes === 0) {
|
|
29
|
+
return "0 B";
|
|
30
|
+
}
|
|
31
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
32
|
+
const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
|
|
33
|
+
const value = bytes / 1024 ** index;
|
|
34
|
+
return `${value.toFixed(index === 0 ? 0 : 1)} ${units[index]}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const formatDate = (isoDate: string): string => {
|
|
38
|
+
const dt = DateTime.fromISO(isoDate);
|
|
39
|
+
return dt.isValid ? dt.toLocaleString(DateTime.DATETIME_SHORT) : isoDate;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
|
|
43
|
+
api,
|
|
44
|
+
basePath,
|
|
45
|
+
title = "Documents",
|
|
46
|
+
allowDelete = true,
|
|
47
|
+
allowUpload = true,
|
|
48
|
+
onFileSelect,
|
|
49
|
+
onSettingsPress,
|
|
50
|
+
}) => {
|
|
51
|
+
const [currentPrefix, setCurrentPrefix] = useState("");
|
|
52
|
+
const [isNotConfigured, setIsNotConfigured] = useState(false);
|
|
53
|
+
const [skipFetch, setSkipFetch] = useState(false);
|
|
54
|
+
const [showNewFolderModal, setShowNewFolderModal] = useState(false);
|
|
55
|
+
const [newFolderName, setNewFolderName] = useState("");
|
|
56
|
+
const [isCreatingFolder, setIsCreatingFolder] = useState(false);
|
|
57
|
+
const [viewerFile, setViewerFile] = useState<DocumentFile | null>(null);
|
|
58
|
+
const [viewerBlobUrl, setViewerBlobUrl] = useState<string | null>(null);
|
|
59
|
+
const [isViewLoading, setIsViewLoading] = useState(false);
|
|
60
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
61
|
+
const viewerBlobUrlRef = useRef<string | null>(null);
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
useListQuery,
|
|
65
|
+
useUploadMutation,
|
|
66
|
+
useDeleteMutation,
|
|
67
|
+
useDeleteFolderMutation,
|
|
68
|
+
useCreateFolderMutation,
|
|
69
|
+
useLazyDownloadQuery,
|
|
70
|
+
} = useDocumentStorageApi(api, basePath);
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
data: listData,
|
|
74
|
+
isLoading,
|
|
75
|
+
isError,
|
|
76
|
+
error,
|
|
77
|
+
refetch,
|
|
78
|
+
} = useListQuery(currentPrefix || undefined, {skip: skipFetch}) as {
|
|
79
|
+
data: DocumentListResponse | undefined;
|
|
80
|
+
isLoading: boolean;
|
|
81
|
+
isError: boolean;
|
|
82
|
+
error: any;
|
|
83
|
+
refetch: () => void;
|
|
84
|
+
};
|
|
85
|
+
const [uploadFile, {isLoading: isUploading}] = useUploadMutation();
|
|
86
|
+
const [deleteFile] = useDeleteMutation();
|
|
87
|
+
const [deleteFolder] = useDeleteFolderMutation();
|
|
88
|
+
const [createFolder] = useCreateFolderMutation();
|
|
89
|
+
const [downloadFile] = useLazyDownloadQuery();
|
|
90
|
+
|
|
91
|
+
// Revoke blob URL on unmount
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
return () => {
|
|
94
|
+
if (viewerBlobUrlRef.current) {
|
|
95
|
+
URL.revokeObjectURL(viewerBlobUrlRef.current);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
99
|
+
|
|
100
|
+
// Detect 503 "not configured" responses
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (isError && error) {
|
|
103
|
+
const status = error?.status ?? error?.originalStatus;
|
|
104
|
+
if (status === 503) {
|
|
105
|
+
setIsNotConfigured(true);
|
|
106
|
+
setSkipFetch(true);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, [isError, error]);
|
|
110
|
+
|
|
111
|
+
const handleRefresh = useCallback(() => {
|
|
112
|
+
if (skipFetch) {
|
|
113
|
+
setIsNotConfigured(false);
|
|
114
|
+
setSkipFetch(false);
|
|
115
|
+
} else {
|
|
116
|
+
refetch();
|
|
117
|
+
}
|
|
118
|
+
}, [skipFetch, refetch]);
|
|
119
|
+
|
|
120
|
+
const handleFolderClick = useCallback((folder: string) => {
|
|
121
|
+
setCurrentPrefix(folder);
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
const handleBreadcrumbClick = useCallback((prefix: string) => {
|
|
125
|
+
setCurrentPrefix(prefix);
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
128
|
+
const handleViewFile = useCallback(
|
|
129
|
+
async (file: DocumentFile) => {
|
|
130
|
+
setViewerFile(file);
|
|
131
|
+
setViewerBlobUrl(null);
|
|
132
|
+
setIsViewLoading(true);
|
|
133
|
+
try {
|
|
134
|
+
const blob = await downloadFile(file.fullPath).unwrap();
|
|
135
|
+
if (Platform.OS === "web") {
|
|
136
|
+
const url = URL.createObjectURL(blob as Blob);
|
|
137
|
+
viewerBlobUrlRef.current = url;
|
|
138
|
+
setViewerBlobUrl(url);
|
|
139
|
+
} else {
|
|
140
|
+
// Convert to base64 data URI for React Native
|
|
141
|
+
const dataUri = await new Promise<string>((resolve, reject) => {
|
|
142
|
+
const reader = new FileReader();
|
|
143
|
+
reader.onloadend = () => resolve(reader.result as string);
|
|
144
|
+
reader.onerror = reject;
|
|
145
|
+
reader.readAsDataURL(blob as Blob);
|
|
146
|
+
});
|
|
147
|
+
setViewerBlobUrl(dataUri);
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
console.error("Failed to load file preview:", err);
|
|
151
|
+
} finally {
|
|
152
|
+
setIsViewLoading(false);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
[downloadFile]
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const handleViewerClose = useCallback(() => {
|
|
159
|
+
// Only blob: URLs need revocation; base64 data URIs do not
|
|
160
|
+
if (Platform.OS === "web" && viewerBlobUrlRef.current) {
|
|
161
|
+
URL.revokeObjectURL(viewerBlobUrlRef.current);
|
|
162
|
+
viewerBlobUrlRef.current = null;
|
|
163
|
+
}
|
|
164
|
+
setViewerFile(null);
|
|
165
|
+
setViewerBlobUrl(null);
|
|
166
|
+
}, []);
|
|
167
|
+
|
|
168
|
+
const handleDownload = useCallback(
|
|
169
|
+
async (filePath: string) => {
|
|
170
|
+
console.info("[DocumentStorageBrowser] handleDownload filePath:", filePath);
|
|
171
|
+
try {
|
|
172
|
+
const blob = await downloadFile(filePath).unwrap();
|
|
173
|
+
console.info("[DocumentStorageBrowser] got blob:", blob);
|
|
174
|
+
if (Platform.OS === "web" && blob) {
|
|
175
|
+
const blobObj = blob as Blob;
|
|
176
|
+
const url = URL.createObjectURL(blobObj);
|
|
177
|
+
const filename = filePath.split("/").filter(Boolean).pop() ?? "download";
|
|
178
|
+
console.info(
|
|
179
|
+
"[DocumentStorageBrowser] creating download link, filename:",
|
|
180
|
+
filename,
|
|
181
|
+
"blobSize:",
|
|
182
|
+
blobObj.size,
|
|
183
|
+
"blobType:",
|
|
184
|
+
blobObj.type,
|
|
185
|
+
"url:",
|
|
186
|
+
url
|
|
187
|
+
);
|
|
188
|
+
const a = document.createElement("a");
|
|
189
|
+
a.href = url;
|
|
190
|
+
a.download = filename;
|
|
191
|
+
document.body.appendChild(a);
|
|
192
|
+
a.click();
|
|
193
|
+
document.body.removeChild(a);
|
|
194
|
+
URL.revokeObjectURL(url);
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
console.error("Failed to download file:", err);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
[downloadFile]
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const handleDelete = useCallback(
|
|
204
|
+
async (filePath: string) => {
|
|
205
|
+
try {
|
|
206
|
+
await deleteFile(filePath).unwrap();
|
|
207
|
+
} catch (err) {
|
|
208
|
+
console.error("Failed to delete file:", err);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
[deleteFile]
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
const handleDeleteFolder = useCallback(
|
|
215
|
+
async (folderPath: string) => {
|
|
216
|
+
try {
|
|
217
|
+
await deleteFolder(folderPath).unwrap();
|
|
218
|
+
} catch (err) {
|
|
219
|
+
console.error("Failed to delete folder:", err);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[deleteFolder]
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const handleUploadClick = useCallback(() => {
|
|
226
|
+
fileInputRef.current?.click();
|
|
227
|
+
}, []);
|
|
228
|
+
|
|
229
|
+
const handleFileChange = useCallback(
|
|
230
|
+
async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
231
|
+
const file = event.target.files?.[0];
|
|
232
|
+
if (!file) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const formData = new FormData();
|
|
237
|
+
formData.append("file", file);
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
await uploadFile({formData, prefix: currentPrefix || undefined}).unwrap();
|
|
241
|
+
} catch (err) {
|
|
242
|
+
console.error("Failed to upload file:", err);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (fileInputRef.current) {
|
|
246
|
+
fileInputRef.current.value = "";
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
[uploadFile, currentPrefix]
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const handleCreateFolder = useCallback(async () => {
|
|
253
|
+
const name = newFolderName.trim();
|
|
254
|
+
if (!name) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
setIsCreatingFolder(true);
|
|
258
|
+
try {
|
|
259
|
+
await createFolder({folderName: name, prefix: currentPrefix || undefined}).unwrap();
|
|
260
|
+
setNewFolderName("");
|
|
261
|
+
setShowNewFolderModal(false);
|
|
262
|
+
} catch (err) {
|
|
263
|
+
console.error("Failed to create folder:", err);
|
|
264
|
+
} finally {
|
|
265
|
+
setIsCreatingFolder(false);
|
|
266
|
+
}
|
|
267
|
+
}, [createFolder, newFolderName, currentPrefix]);
|
|
268
|
+
|
|
269
|
+
const handleNewFolderModalDismiss = useCallback(() => {
|
|
270
|
+
setShowNewFolderModal(false);
|
|
271
|
+
setNewFolderName("");
|
|
272
|
+
}, []);
|
|
273
|
+
|
|
274
|
+
// Build breadcrumb segments
|
|
275
|
+
const breadcrumbs = useMemo(() => {
|
|
276
|
+
const segments: {label: string; prefix: string}[] = [{label: "Root", prefix: ""}];
|
|
277
|
+
if (currentPrefix) {
|
|
278
|
+
const parts = currentPrefix.split("/").filter(Boolean);
|
|
279
|
+
let accumulated = "";
|
|
280
|
+
for (const part of parts) {
|
|
281
|
+
accumulated += `${part}/`;
|
|
282
|
+
segments.push({label: part, prefix: accumulated});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return segments;
|
|
286
|
+
}, [currentPrefix]);
|
|
287
|
+
|
|
288
|
+
const DocumentNameCell: React.FC<{
|
|
289
|
+
column: DataTableColumn;
|
|
290
|
+
cellData: DataTableCellData;
|
|
291
|
+
}> = useCallback(
|
|
292
|
+
({cellData}: {column: DataTableColumn; cellData: DataTableCellData}) => {
|
|
293
|
+
const {
|
|
294
|
+
name,
|
|
295
|
+
isFolder: isFolderItem,
|
|
296
|
+
folder,
|
|
297
|
+
file,
|
|
298
|
+
} = cellData.value as {
|
|
299
|
+
name: string;
|
|
300
|
+
isFolder: boolean;
|
|
301
|
+
folder?: string;
|
|
302
|
+
file?: DocumentFile;
|
|
303
|
+
};
|
|
304
|
+
if (isFolderItem && folder) {
|
|
305
|
+
return <Link onClick={() => handleFolderClick(folder)} text={name} />;
|
|
306
|
+
}
|
|
307
|
+
if (file && onFileSelect) {
|
|
308
|
+
return <Link onClick={() => onFileSelect(file)} text={name} />;
|
|
309
|
+
}
|
|
310
|
+
// TODO: re-enable file preview in a follow-up PR
|
|
311
|
+
// if (file && Platform.OS === "web" && isViewable(file.contentType)) {
|
|
312
|
+
// return <Link onClick={() => handleViewFile(file)} text={name} />;
|
|
313
|
+
// }
|
|
314
|
+
return <Text>{name}</Text>;
|
|
315
|
+
},
|
|
316
|
+
[handleFolderClick, handleViewFile, onFileSelect]
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const DocumentActionsCell: React.FC<{
|
|
320
|
+
column: DataTableColumn;
|
|
321
|
+
cellData: DataTableCellData;
|
|
322
|
+
}> = useCallback(
|
|
323
|
+
({cellData}: {column: DataTableColumn; cellData: DataTableCellData}) => {
|
|
324
|
+
const {filePath, isFolder: isFolderItem} = cellData.value as {
|
|
325
|
+
filePath: string;
|
|
326
|
+
isFolder: boolean;
|
|
327
|
+
};
|
|
328
|
+
if (isFolderItem) {
|
|
329
|
+
if (!allowDelete) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
return (
|
|
333
|
+
<Box alignItems="center" direction="row" gap={1} justifyContent="end">
|
|
334
|
+
<IconButton
|
|
335
|
+
accessibilityLabel="Delete folder"
|
|
336
|
+
confirmationText="Delete this folder and all its contents?"
|
|
337
|
+
iconName="trash"
|
|
338
|
+
onClick={() => handleDeleteFolder(filePath)}
|
|
339
|
+
tooltipText="Delete folder"
|
|
340
|
+
variant="destructive"
|
|
341
|
+
withConfirmation
|
|
342
|
+
/>
|
|
343
|
+
</Box>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return (
|
|
347
|
+
<Box alignItems="center" direction="row" gap={1} justifyContent="end">
|
|
348
|
+
{Platform.OS === "web" && (
|
|
349
|
+
<IconButton
|
|
350
|
+
accessibilityLabel="Download"
|
|
351
|
+
iconName="download"
|
|
352
|
+
onClick={() => handleDownload(filePath)}
|
|
353
|
+
tooltipText="Download"
|
|
354
|
+
variant="muted"
|
|
355
|
+
/>
|
|
356
|
+
)}
|
|
357
|
+
{allowDelete && (
|
|
358
|
+
<IconButton
|
|
359
|
+
accessibilityLabel="Delete"
|
|
360
|
+
confirmationText="Are you sure you want to delete this file?"
|
|
361
|
+
iconName="trash"
|
|
362
|
+
onClick={() => handleDelete(filePath)}
|
|
363
|
+
tooltipText="Delete"
|
|
364
|
+
variant="destructive"
|
|
365
|
+
withConfirmation
|
|
366
|
+
/>
|
|
367
|
+
)}
|
|
368
|
+
</Box>
|
|
369
|
+
);
|
|
370
|
+
},
|
|
371
|
+
[handleDownload, handleDelete, handleDeleteFolder, allowDelete]
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
const customColumnComponentMap: DataTableCustomComponentMap = useMemo(
|
|
375
|
+
() => ({
|
|
376
|
+
[ACTIONS_COLUMN_TYPE]: DocumentActionsCell,
|
|
377
|
+
[NAME_COLUMN_TYPE]: DocumentNameCell,
|
|
378
|
+
}),
|
|
379
|
+
[DocumentActionsCell, DocumentNameCell]
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
const columns: DataTableColumn[] = useMemo(
|
|
383
|
+
() => [
|
|
384
|
+
{columnType: NAME_COLUMN_TYPE, sortable: false, title: "Name", width: 300},
|
|
385
|
+
{columnType: "text", sortable: false, title: "Size", width: 100},
|
|
386
|
+
{columnType: "text", sortable: false, title: "Type", width: 150},
|
|
387
|
+
{columnType: "text", sortable: false, title: "Updated", width: 180},
|
|
388
|
+
{columnType: ACTIONS_COLUMN_TYPE, sortable: false, title: "", width: 100},
|
|
389
|
+
],
|
|
390
|
+
[]
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
const tableData = useMemo(() => {
|
|
394
|
+
const rows: any[][] = [];
|
|
395
|
+
|
|
396
|
+
for (const folder of listData?.folders ?? []) {
|
|
397
|
+
const folderName = folder.split("/").filter(Boolean).pop() ?? folder;
|
|
398
|
+
rows.push([
|
|
399
|
+
{value: {folder, isFolder: true, name: `${folderName}/`}},
|
|
400
|
+
{value: "\u2014"},
|
|
401
|
+
{value: "Folder"},
|
|
402
|
+
{value: ""},
|
|
403
|
+
{value: {filePath: folder, isFolder: true}},
|
|
404
|
+
]);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
for (const file of listData?.files ?? []) {
|
|
408
|
+
rows.push([
|
|
409
|
+
{value: {file, isFolder: false, name: file.name}},
|
|
410
|
+
{value: formatFileSize(file.size)},
|
|
411
|
+
{value: file.contentType ?? "Unknown"},
|
|
412
|
+
{value: file.updated ? formatDate(file.updated) : ""},
|
|
413
|
+
{value: {filePath: file.fullPath, isFolder: false}},
|
|
414
|
+
]);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return rows;
|
|
418
|
+
}, [listData]);
|
|
419
|
+
|
|
420
|
+
const {height: windowHeight} = useWindowDimensions();
|
|
421
|
+
const nativeViewerHeight = Math.floor(windowHeight * 0.6);
|
|
422
|
+
|
|
423
|
+
const renderViewerContent = () => {
|
|
424
|
+
if (isViewLoading) {
|
|
425
|
+
return (
|
|
426
|
+
<Box alignItems="center" justifyContent="center" padding={6}>
|
|
427
|
+
<Spinner />
|
|
428
|
+
</Box>
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
if (!viewerBlobUrl) {
|
|
432
|
+
return (
|
|
433
|
+
<Box alignItems="center" padding={4}>
|
|
434
|
+
<Text color="error">Failed to load preview.</Text>
|
|
435
|
+
</Box>
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const contentType = viewerFile?.contentType ?? "";
|
|
440
|
+
|
|
441
|
+
if (Platform.OS === "web") {
|
|
442
|
+
if (contentType.startsWith("image/")) {
|
|
443
|
+
return (
|
|
444
|
+
<Box alignItems="center">
|
|
445
|
+
<img
|
|
446
|
+
alt={viewerFile?.name}
|
|
447
|
+
src={viewerBlobUrl}
|
|
448
|
+
style={{maxHeight: "70vh", maxWidth: "100%", objectFit: "contain"}}
|
|
449
|
+
/>
|
|
450
|
+
</Box>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
if (contentType.startsWith("video/")) {
|
|
454
|
+
return (
|
|
455
|
+
<Box alignItems="center">
|
|
456
|
+
<video controls src={viewerBlobUrl} style={{maxHeight: "70vh", maxWidth: "100%"}}>
|
|
457
|
+
<track kind="captions" />
|
|
458
|
+
</video>
|
|
459
|
+
</Box>
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
// PDF and text/plain — render in iframe
|
|
463
|
+
return (
|
|
464
|
+
<iframe
|
|
465
|
+
src={viewerBlobUrl}
|
|
466
|
+
style={{border: "none", height: "70vh", width: "100%"}}
|
|
467
|
+
title={viewerFile?.name}
|
|
468
|
+
/>
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// React Native
|
|
473
|
+
if (contentType.startsWith("image/")) {
|
|
474
|
+
return (
|
|
475
|
+
<RNImage
|
|
476
|
+
resizeMode="contain"
|
|
477
|
+
source={{uri: viewerBlobUrl}}
|
|
478
|
+
style={{height: nativeViewerHeight, width: "100%"}}
|
|
479
|
+
/>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
// PDFs, videos, and text — use WebView with the data URI
|
|
483
|
+
return (
|
|
484
|
+
<WebView source={{uri: viewerBlobUrl}} style={{height: nativeViewerHeight, width: "100%"}} />
|
|
485
|
+
);
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const headerRow = (
|
|
489
|
+
<Box alignItems="center" direction="row" padding={2}>
|
|
490
|
+
{/* Breadcrumbs */}
|
|
491
|
+
<Box alignItems="center" direction="row" flex="grow" gap={1} wrap>
|
|
492
|
+
{breadcrumbs.map((crumb, index) => (
|
|
493
|
+
<Box direction="row" gap={1} key={crumb.prefix || "root"}>
|
|
494
|
+
{index > 0 && <Text color="secondaryDark">/</Text>}
|
|
495
|
+
{index === breadcrumbs.length - 1 ? (
|
|
496
|
+
<Text bold>{crumb.label}</Text>
|
|
497
|
+
) : (
|
|
498
|
+
<Link onClick={() => handleBreadcrumbClick(crumb.prefix)} text={crumb.label} />
|
|
499
|
+
)}
|
|
500
|
+
</Box>
|
|
501
|
+
))}
|
|
502
|
+
</Box>
|
|
503
|
+
|
|
504
|
+
{/* Action buttons */}
|
|
505
|
+
<Box alignItems="center" direction="row" gap={1}>
|
|
506
|
+
{Platform.OS === "web" && allowUpload && (
|
|
507
|
+
<>
|
|
508
|
+
<input
|
|
509
|
+
accept="*/*"
|
|
510
|
+
onChange={handleFileChange as any}
|
|
511
|
+
ref={fileInputRef as any}
|
|
512
|
+
style={{display: "none"}}
|
|
513
|
+
type="file"
|
|
514
|
+
/>
|
|
515
|
+
<IconButton
|
|
516
|
+
accessibilityLabel="Upload file"
|
|
517
|
+
iconName="cloud-arrow-up"
|
|
518
|
+
loading={isUploading}
|
|
519
|
+
onClick={handleUploadClick}
|
|
520
|
+
testID="document-upload-button"
|
|
521
|
+
tooltipText="Upload file"
|
|
522
|
+
variant="muted"
|
|
523
|
+
/>
|
|
524
|
+
</>
|
|
525
|
+
)}
|
|
526
|
+
{allowUpload && (
|
|
527
|
+
<IconButton
|
|
528
|
+
accessibilityLabel="New folder"
|
|
529
|
+
iconName="folder-plus"
|
|
530
|
+
onClick={() => setShowNewFolderModal(true)}
|
|
531
|
+
testID="document-new-folder-button"
|
|
532
|
+
tooltipText="New folder"
|
|
533
|
+
variant="muted"
|
|
534
|
+
/>
|
|
535
|
+
)}
|
|
536
|
+
<IconButton
|
|
537
|
+
accessibilityLabel="Refresh"
|
|
538
|
+
iconName="rotate"
|
|
539
|
+
onClick={handleRefresh}
|
|
540
|
+
testID="document-refresh-button"
|
|
541
|
+
tooltipText="Refresh"
|
|
542
|
+
variant="muted"
|
|
543
|
+
/>
|
|
544
|
+
{onSettingsPress && (
|
|
545
|
+
<IconButton
|
|
546
|
+
accessibilityLabel="Storage settings"
|
|
547
|
+
iconName="gear"
|
|
548
|
+
onClick={onSettingsPress}
|
|
549
|
+
variant="muted"
|
|
550
|
+
/>
|
|
551
|
+
)}
|
|
552
|
+
</Box>
|
|
553
|
+
</Box>
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
const renderContent = () => {
|
|
557
|
+
if (isNotConfigured) {
|
|
558
|
+
return (
|
|
559
|
+
<Box alignItems="center" gap={3} padding={6}>
|
|
560
|
+
<Text color="error">Storage is not configured.</Text>
|
|
561
|
+
{onSettingsPress && (
|
|
562
|
+
<Button
|
|
563
|
+
iconName="gear"
|
|
564
|
+
onClick={onSettingsPress}
|
|
565
|
+
text="Open Settings"
|
|
566
|
+
variant="secondary"
|
|
567
|
+
/>
|
|
568
|
+
)}
|
|
569
|
+
</Box>
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
if (isLoading) {
|
|
573
|
+
return (
|
|
574
|
+
<Box alignItems="center" justifyContent="center" padding={6}>
|
|
575
|
+
<Spinner />
|
|
576
|
+
</Box>
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
if (isError) {
|
|
580
|
+
return (
|
|
581
|
+
<Box alignItems="center" padding={6}>
|
|
582
|
+
<Text color="error">Failed to load files. Please try again.</Text>
|
|
583
|
+
</Box>
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
if (tableData.length === 0) {
|
|
587
|
+
return (
|
|
588
|
+
<Box alignItems="center" padding={6}>
|
|
589
|
+
<Text color="secondaryDark">No files found.</Text>
|
|
590
|
+
</Box>
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
return (
|
|
594
|
+
<DataTable
|
|
595
|
+
columns={columns}
|
|
596
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
597
|
+
data={tableData}
|
|
598
|
+
/>
|
|
599
|
+
);
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
return (
|
|
603
|
+
<Page maxWidth="100%" title={title}>
|
|
604
|
+
{headerRow}
|
|
605
|
+
{renderContent()}
|
|
606
|
+
|
|
607
|
+
<Modal
|
|
608
|
+
onDismiss={handleViewerClose}
|
|
609
|
+
primaryButtonOnClick={handleViewerClose}
|
|
610
|
+
primaryButtonText="Close"
|
|
611
|
+
size="lg"
|
|
612
|
+
title={viewerFile?.name ?? "Preview"}
|
|
613
|
+
visible={viewerFile !== null}
|
|
614
|
+
>
|
|
615
|
+
{renderViewerContent()}
|
|
616
|
+
</Modal>
|
|
617
|
+
|
|
618
|
+
<Modal
|
|
619
|
+
onDismiss={handleNewFolderModalDismiss}
|
|
620
|
+
primaryButtonOnClick={handleCreateFolder}
|
|
621
|
+
primaryButtonText="Create"
|
|
622
|
+
secondaryButtonOnClick={handleNewFolderModalDismiss}
|
|
623
|
+
secondaryButtonText="Cancel"
|
|
624
|
+
size="sm"
|
|
625
|
+
title="New Folder"
|
|
626
|
+
visible={showNewFolderModal}
|
|
627
|
+
>
|
|
628
|
+
<Box gap={3}>
|
|
629
|
+
<TextField
|
|
630
|
+
disabled={isCreatingFolder}
|
|
631
|
+
onChange={setNewFolderName}
|
|
632
|
+
placeholder="folder-name"
|
|
633
|
+
testID="new-folder-name-input"
|
|
634
|
+
title="Folder Name"
|
|
635
|
+
value={newFolderName}
|
|
636
|
+
/>
|
|
637
|
+
</Box>
|
|
638
|
+
</Modal>
|
|
639
|
+
</Page>
|
|
640
|
+
);
|
|
641
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -3,12 +3,24 @@ export {AdminModelForm} from "./AdminModelForm";
|
|
|
3
3
|
export {AdminModelList} from "./AdminModelList";
|
|
4
4
|
export {AdminModelTable} from "./AdminModelTable";
|
|
5
5
|
export {AdminRefField} from "./AdminRefField";
|
|
6
|
+
export {AdminScriptList} from "./AdminScriptList";
|
|
7
|
+
export {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
8
|
+
export {ConfigurationScreen} from "./ConfigurationScreen";
|
|
9
|
+
export {DocumentStorageBrowser} from "./DocumentStorageBrowser";
|
|
6
10
|
export type {
|
|
7
11
|
AdminConfigResponse,
|
|
8
12
|
AdminFieldConfig,
|
|
9
13
|
AdminModelConfig,
|
|
10
14
|
AdminScreenProps,
|
|
15
|
+
AdminScriptConfig,
|
|
16
|
+
BackgroundTask,
|
|
17
|
+
DocumentFile,
|
|
18
|
+
DocumentListResponse,
|
|
19
|
+
DocumentStorageBrowserProps,
|
|
11
20
|
} from "./types";
|
|
12
21
|
export {SYSTEM_FIELDS} from "./types";
|
|
13
22
|
export {useAdminApi} from "./useAdminApi";
|
|
14
23
|
export {useAdminConfig} from "./useAdminConfig";
|
|
24
|
+
export {useAdminScripts} from "./useAdminScripts";
|
|
25
|
+
export {useConfigurationApi} from "./useConfigurationApi";
|
|
26
|
+
export {useDocumentStorageApi} from "./useDocumentStorageApi";
|