fix: (regression 0.32.0) admin/fs: new items always created under root instead of selected item

Massimo Melina committed Mar 12, 2023 at 11:05 UTC a4ba637eec287fc8cb690d83c5c2e3a719130143
2 files changed +9 -9
admin/src/VfsMenuBar.ts
+2 -2
@@ -2,11 +2,11 @@
2
3 import { createElement as h } from 'react'
4 import { Box } from '@mui/material'
5 -import { Add, Refresh } from '@mui/icons-material'
5 +import { Add } from '@mui/icons-material'
6 import { reloadVfs } from './VfsPage'
7 import addFiles, { addVirtual } from './addFiles'
8 import MenuButton from './MenuButton'
9 -import { IconBtn, reloadBtn } from './misc'
9 +import { reloadBtn } from './misc'
10
11 export default function VfsMenuBar() {
12 return h(Box, {
admin/src/addFiles.ts
+7 -7
@@ -14,14 +14,14 @@ export default function addFiles() {
14 title: "Add files or folders",
15 dialogProps: { sx:{ minWidth: 'min(90vw, 40em)', minHeight: 'calc(100vh - 9em)' } },
16 Content() {
17 - const under = getUnder()
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 " + (under || '(home)')),
20 + "Selected elements will be added under " + (parent || '(home)')),
21 h(FilePicker, {
22 async onSelect(sel) {
23 const errs = onlyTruthy(await Promise.all(sel.map(source =>
24 - apiCall('add_vfs', { under, source }).then(() => null, e => [source,e.message]) )))
24 + apiCall('add_vfs', { parent, source }).then(() => null, e => [source,e.message]) )))
25 if (errs.length)
26 await alertDialog(h(Box, {},
27 "Some elements have been rejected",
@@ -43,9 +43,9 @@ export async function addVirtual() {
43 try {
44 const name = await promptDialog("Enter folder name")
45 if (!name) return
46 - const under = getUnder()
47 - await apiCall('add_vfs', { under, name })
48 - reloadVfs([ (under||'') + '/' + name ])
46 + const parent = getParent()
47 + await apiCall('add_vfs', { parent, name })
48 + reloadVfs([ (parent||'') + '/' + name ])
49 await alertDialog(`Folder "${name}" created`, 'success')
50 }
51 catch(e) {
@@ -53,7 +53,7 @@ export async function addVirtual() {
53 }
54 }
55
56 -function getUnder() {
56 +function getParent() {
57 let f: VfsNode | undefined = state.selectedFiles[0]
58 if (!f)
59 return ''