admin/fs: add from disk now starts from the parent source, if any

Massimo Melina committed Apr 17, 2023 at 12:52 UTC 22403f15d8fa52af58fcf8649031cd4b1f7376b9
1 file changed +8 -11
admin/src/addFiles.ts
+8 -11
@@ -3,7 +3,7 @@
3 import { alertDialog, newDialog, promptDialog } from './dialog'
4 import { createElement as h, Fragment } from 'react'
5 import { Box } from '@mui/material'
6 -import { VfsNode, reloadVfs } from './VfsPage'
6 +import { reloadVfs } from './VfsPage'
7 import { state } from './state'
8 import { apiCall } from './api'
9 import FilePicker from './FilePicker'
@@ -17,11 +17,12 @@ export default function addFiles() {
17 const parent = getParent()
18 return h(Fragment, {},
19 h(Box, { sx:{ typography: 'body1', px: 1, py: 2 } },
20 - "Selected elements will be added under " + (parent || '(home)')),
20 + "Selected elements will be added under " + (parent.isRoot ? '(home)' : parent.id)),
21 h(FilePicker, {
22 + from: parent.source,
23 async onSelect(sel) {
24 const errs = onlyTruthy(await Promise.all(sel.map(source =>
24 - apiCall('add_vfs', { parent, source }).then(() => null, e => [source,e.message]) )))
25 + apiCall('add_vfs', { parent: parent.id, source }).then(() => null, e => [source, e.message]))))
26 if (errs.length)
27 await alertDialog(h(Box, {},
28 "Some elements have been rejected",
@@ -43,9 +44,9 @@ export async function addVirtual() {
44 try {
45 const name = await promptDialog("Enter folder name")
46 if (!name) return
46 - const parent = getParent()
47 + const { id: parent } = getParent()
48 await apiCall('add_vfs', { parent, name })
48 - reloadVfs([ (parent||'') + '/' + name ])
49 + reloadVfs([ parent + name ])
50 await alertDialog(`Folder "${name}" created`, 'success')
51 }
52 catch(e) {
@@ -54,10 +55,6 @@ export async function addVirtual() {
55 }
56
57 function getParent() {
57 - let f: VfsNode | undefined = state.selectedFiles[0]
58 - if (!f || f.isRoot)
59 - return ''
60 - if (f.type !== 'folder')
61 - f = f.parent
62 - return f?.id || ''
58 + const f = state.selectedFiles[0] || state.vfs
59 + return f.type === 'folder' ? f : f.parent!
60 }