fix: admin/fs: after moving, item was unselected
Massimo Melina committed
Apr 7, 2023 at 18:12 UTC
06834eccd9e61039072f0438333183142b75cfd1
3 files changed
+5
-23
admin/src/VfsTree.ts
+2
-2
@@ -9,7 +9,7 @@ import {
9
} from '@mui/icons-material'
10
import { Box } from '@mui/material'
11
import { reloadVfs, VfsNode, Who } from './VfsPage'
12
-import { iconTooltip, isWindowsDrive, onlyTruthy, pathJoin, basename } from './misc'
12
+import { iconTooltip, isWindowsDrive, onlyTruthy } from './misc'
13
import { apiCall } from './api'
14
import { alertDialog, confirmDialog } from './dialog'
15
@@ -73,7 +73,7 @@ export default function VfsTree({ id2node }:{ id2node: Map<string, VfsNode> }) {
73
if (!from) return
74
if (await confirmDialog(`Moving ${from} under ${id}`))
75
apiCall('move_vfs', { from, parent: id }).then(() => {
76
- reloadVfs([ pathJoin(id, basename(from)) ])
76
+ reloadVfs([ id + from.slice(1 + from.lastIndexOf('/', from.length-2)) ])
77
}, alertDialog)
78
},
79
sx: {
admin/src/misc.ts
-18
@@ -93,24 +93,6 @@ export function typedKeys<T extends {}>(o: T) {
93
return Object.keys(o) as (keyof T)[]
94
}
95
96
-export function basename(s: string) {
97
- let i = s.lastIndexOf('/')
98
- if (i < 0)
99
- i = s.lastIndexOf('\\')
100
- return i < 0 ? s : s.slice(i)
101
-}
102
-
103
-export function isAbsolutePath(s: string) {
104
- return s && (s[0] === '/' || isWindowsDrive(s.slice(0,2)))
105
-}
106
-
107
-export function pathJoin(...args: any[]) {
108
- const delimiter = findFirst(args, x => /\\|\//.exec('\\a/b')?.[0])
109
- const good = onlyTruthy(args.map(x => x == null ? '' : String(x)))
110
- return good.map((x, i) => i === good.length-1 || x.endsWith('\\') || x.endsWith('/') ? x : x + delimiter)
111
- .join('')
112
-}
113
-
96
export function xlate(input: any, table: Record<string, any>) {
97
return table[input] ?? input
98
}
shared/index.ts
+3
-3
@@ -95,9 +95,9 @@ export function domOn<K extends keyof WindowEventMap>(eventName: K, cb: (ev: Win
95
}
96
97
98
-export function findFirst<I=any, O=any>(a: I[], cb:(v:I)=>O): any {
99
- for (const x of a) {
100
- const ret = cb(x)
98
+export function findFirst<I, O>(a: I[] | Record<string, I>, cb:(v:I, k: string | number)=>O): any {
99
+ if (a) for (const k in a) {
100
+ const ret = cb((a as any)[k] as I, k)
101
if (ret !== undefined)
102
return ret
103
}