admin/fs: better error dialog adding files
Massimo Melina committed
Feb 3, 2023 at 11:43 UTC
0c4626d830296a073975e85d731a93fb593cb386
3 files changed
+18
-13
admin/src/FileForm.ts
+1
-1
@@ -57,7 +57,7 @@ export default function FileForm({ file, defaultPerms, addToBar }: { file: VfsNo
57
icon: Delete,
58
title: "Delete",
59
confirm: "Delete?",
60
- onClick: () => apiCall('del_vfs', { uris: [file.id] }).then(() => reloadVfs()),
60
+ onClick: () => apiCall('del_vfs', { uris: [file.id] }).then(() => reloadVfs()),
61
}),
62
addToBar
63
],
admin/src/VfsPage.ts
+7
-7
@@ -33,14 +33,16 @@ export default function VfsPage() {
33
const sideBreakpoint = 'md'
34
const isSideBreakpoint = useBreakpoint(sideBreakpoint)
35
36
+ function close() {
37
+ state.selectedFiles = []
38
+ }
39
+
40
const sideContent = !selectedFiles.length ? null
41
: selectedFiles.length === 1 ? h(FileForm, {
42
addToBar: isSideBreakpoint && h(IconBtn, { // not really useful, but users misled in thinking it's a dialog will find satisfaction in dismissing the form
43
icon: Close,
44
title: "Close",
41
- onClick(){
42
- state.selectedFiles = []
43
- }
45
+ onClick: close
46
}),
47
defaultPerms: data?.defaultPerms as VfsPerms,
48
file: selectedFiles[0] as VfsNode // it's actually Snapshot<VfsNode> but it's easier this way
@@ -59,11 +61,9 @@ export default function VfsPage() {
61
useEffect(() => {
62
if (isSideBreakpoint || !sideContent) return
63
return newDialog({
62
- title: selectedFiles[0].name,
64
+ title: selectedFiles.length > 1 ? "Multiple selection" : selectedFiles[0].name,
65
Content: () => sideContent,
64
- onClose() {
65
- state.selectedFiles = []
66
- },
66
+ onClose: close,
67
})
68
},[isSideBreakpoint, selectedFiles])
69
admin/src/addFiles.ts
+10
-5
@@ -20,11 +20,16 @@ export default function addFiles() {
20
"Selected elements will be added to virtual path " + (under || '(home)')),
21
h(FilePicker, {
22
async onSelect(sel) {
23
- let failed = await Promise.all(sel.map(source =>
24
- apiCall('add_vfs', { under, source }).then(() => '', () => source) ))
25
- failed = onlyTruthy(failed)
26
- if (failed.length)
27
- await alertDialog("Some elements have been rejected: "+failed.join(', '), 'error')
23
+ const errs = onlyTruthy(await Promise.all(sel.map(source =>
24
+ apiCall('add_vfs', { under, source }).then(() => null, e => [source,e.message]) )))
25
+ if (errs.length)
26
+ await alertDialog(h(Box, {},
27
+ "Some elements have been rejected",
28
+ h('ul', {},
29
+ errs.map(([file, err]) =>
30
+ h('li', { key: file }, file, ': ', err))
31
+ )
32
+ ), 'error')
33
reloadVfs()
34
close()
35
}