fix: save new views in default workspace
This commit is contained in:
29
src/utils/viewTargetVault.test.ts
Normal file
29
src/utils/viewTargetVault.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { viewCreationVaultPath } from './viewTargetVault'
|
||||
|
||||
describe('viewCreationVaultPath', () => {
|
||||
it('creates new views in the default workspace when multiple workspaces are mounted', () => {
|
||||
expect(viewCreationVaultPath({
|
||||
fallbackVaultPath: '/portent',
|
||||
graphDefaultWorkspacePath: '/laputa',
|
||||
multiWorkspaceEnabled: true,
|
||||
})).toBe('/laputa')
|
||||
})
|
||||
|
||||
it('keeps edited views in their owning vault', () => {
|
||||
expect(viewCreationVaultPath({
|
||||
editingRootPath: '/refactoring',
|
||||
fallbackVaultPath: '/portent',
|
||||
graphDefaultWorkspacePath: '/laputa',
|
||||
multiWorkspaceEnabled: true,
|
||||
})).toBe('/refactoring')
|
||||
})
|
||||
|
||||
it('uses the active vault when workspace mounting is disabled', () => {
|
||||
expect(viewCreationVaultPath({
|
||||
fallbackVaultPath: '/portent',
|
||||
graphDefaultWorkspacePath: '/laputa',
|
||||
multiWorkspaceEnabled: false,
|
||||
})).toBe('/portent')
|
||||
})
|
||||
})
|
||||
22
src/utils/viewTargetVault.ts
Normal file
22
src/utils/viewTargetVault.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
interface ViewCreationVaultPathOptions {
|
||||
editingRootPath?: string
|
||||
fallbackVaultPath: string
|
||||
graphDefaultWorkspacePath: string
|
||||
multiWorkspaceEnabled: boolean
|
||||
}
|
||||
|
||||
function usablePath(path: string | null | undefined): string | null {
|
||||
const trimmed = path?.trim()
|
||||
return trimmed ? trimmed : null
|
||||
}
|
||||
|
||||
export function viewCreationVaultPath({
|
||||
editingRootPath,
|
||||
fallbackVaultPath,
|
||||
graphDefaultWorkspacePath,
|
||||
multiWorkspaceEnabled,
|
||||
}: ViewCreationVaultPathOptions): string {
|
||||
return usablePath(editingRootPath)
|
||||
?? (multiWorkspaceEnabled ? usablePath(graphDefaultWorkspacePath) : null)
|
||||
?? fallbackVaultPath
|
||||
}
|
||||
Reference in New Issue
Block a user