From 37a178cf75823c136d0a90b18b4598abe23c8d77 Mon Sep 17 00:00:00 2001 From: Hendrik Heil Date: Thu, 6 Nov 2025 23:39:25 +0100 Subject: [PATCH] fix: handle prefix in source --- src/app/src/composables/useContext.ts | 21 ++++++--------------- src/app/src/composables/useTree.ts | 4 ++-- src/app/src/types/tree.ts | 1 + src/app/src/utils/tree.ts | 3 +++ src/module/src/runtime/utils/collection.ts | 11 +++++------ 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/app/src/composables/useContext.ts b/src/app/src/composables/useContext.ts index 329e91a5..1a0dc3b6 100644 --- a/src/app/src/composables/useContext.ts +++ b/src/app/src/composables/useContext.ts @@ -139,19 +139,14 @@ export const useContext = createSharedComposable(( } }, [StudioItemActionId.RevertItem]: async (item: TreeItem) => { - // Get collections from document item or use default media collection - for (const collection of item.collections) { - const id = generateIdFromFsPath(item.fsPath, collection) - await activeTree.value.draft.revert(id) - } + await activeTree.value.draft.revert(item.id) }, [StudioItemActionId.RenameItem]: async (params: TreeItem | RenameFileParams) => { const { item, newFsPath } = params as RenameFileParams // Revert file if (item.type === 'file') { - const id = generateIdFromFsPath(item.fsPath, item.collections[0]) - await activeTree.value.draft.rename([{ id, newFsPath }]) + await activeTree.value.draft.rename([{ id: item.id, newFsPath }]) return } @@ -160,7 +155,7 @@ export const useContext = createSharedComposable(( if (descendants.length > 0) { const itemsToRename = descendants.map((descendant) => { return { - id: generateIdFromFsPath(descendant.fsPath, descendant.collections[0]), + id: descendant.id, newFsPath: descendant.fsPath.replace(item.fsPath, newFsPath), } }) @@ -171,25 +166,21 @@ export const useContext = createSharedComposable(( [StudioItemActionId.DeleteItem]: async (item: TreeItem) => { // Delete file if (item.type === 'file') { - const id = generateIdFromFsPath(item.fsPath, item.collections![0]) - await activeTree.value.draft.remove([id]) + await activeTree.value.draft.remove([item.id]) return } // Delete folder const descendants = findDescendantsFileItemsFromFsPath(activeTree.value.root.value, item.fsPath) if (descendants.length > 0) { - const ids: string[] = descendants.map((descendant) => { - return generateIdFromFsPath(descendant.fsPath, descendant.collections![0]) - }) + const ids: string[] = descendants.map(descendant => descendant.id) await activeTree.value.draft.remove(ids) } }, [StudioItemActionId.DuplicateItem]: async (item: TreeItem) => { // Duplicate file if (item.type === 'file') { - const id = generateIdFromFsPath(item.fsPath, item.collections![0]) - const draftItem = await activeTree.value.draft.duplicate(id) + const draftItem = await activeTree.value.draft.duplicate(item.id) await activeTree.value.selectItemByFsPath(draftItem!.id) return } diff --git a/src/app/src/composables/useTree.ts b/src/app/src/composables/useTree.ts index fdf493a9..22d1efab 100644 --- a/src/app/src/composables/useTree.ts +++ b/src/app/src/composables/useTree.ts @@ -2,7 +2,7 @@ import { StudioFeature, TreeStatus, type StudioHost, type TreeItem, DraftStatus import { ref, computed } from 'vue' import type { useDraftDocuments } from './useDraftDocuments' import type { useDraftMedias } from './useDraftMedias' -import { buildTree, findItemFromFsPath, findItemFromRoute, findParentFromFsPath, generateIdFromFsPath } from '../utils/tree' +import { buildTree, findItemFromFsPath, findItemFromRoute, findParentFromFsPath } from '../utils/tree' import type { RouteLocationNormalized } from 'vue-router' import { useHooks } from './useHooks' import { useStudioState } from './useStudioState' @@ -53,7 +53,7 @@ export const useTree = (type: StudioFeature, host: StudioHost, draft: ReturnType setLocation(type, currentItem.value.fsPath) if (item?.type === 'file') { - await draft.selectById(generateIdFromFsPath(item.fsPath, item.collections![0])) + await draft.selectById(item.id) if ( !preferences.value.syncEditorAndRoute diff --git a/src/app/src/types/tree.ts b/src/app/src/types/tree.ts index aa4a6fd8..09ad9181 100644 --- a/src/app/src/types/tree.ts +++ b/src/app/src/types/tree.ts @@ -21,4 +21,5 @@ export interface TreeItem { routePath?: string children?: TreeItem[] hide?: boolean + id: string } diff --git a/src/app/src/utils/tree.ts b/src/app/src/utils/tree.ts index d2ba7fca..0e9ce2bf 100644 --- a/src/app/src/utils/tree.ts +++ b/src/app/src/utils/tree.ts @@ -81,6 +81,7 @@ TreeItem[] { type: 'file', prefix, collections: [dbItem.id.split('/')[0]], + id: dbItem.id, } if (dbItem.fsPath.endsWith('.gitkeep')) { @@ -122,6 +123,7 @@ TreeItem[] { children: [], prefix: dirPrefix, collections: [dbItem.id.split('/')[0]], + id: dirFsPath, } directoryMap.set(dirFsPath, directory) @@ -150,6 +152,7 @@ TreeItem[] { type: 'file', prefix, collections: [dbItem.id.split('/')[0]], + id: dbItem.id, } if (dbItem.fsPath.endsWith('.gitkeep')) { diff --git a/src/module/src/runtime/utils/collection.ts b/src/module/src/runtime/utils/collection.ts index 3f4b6ec9..31ae06a5 100644 --- a/src/module/src/runtime/utils/collection.ts +++ b/src/module/src/runtime/utils/collection.ts @@ -63,12 +63,11 @@ export function getCollection(collectionName: string, collections: Record { - const include = minimatch(path, source.include, { dot: true }) - const exclude = source.exclude?.some(exclude => minimatch(path, exclude)) + const filePath = generateFsPathFromId(id, source) + + const include = minimatch(filePath, source.include, { dot: true }) + const exclude = source.exclude?.some(exclude => minimatch(filePath, exclude)) return include && !exclude }) @@ -82,7 +81,7 @@ export function generateFsPathFromId(id: string, source: CollectionInfo['source' const { fixed } = parseSourceBase(source) - const pathWithoutFixed = path.substring(fixed.length) + const pathWithoutFixed = source.prefix === '/' ? path : path.substring(fixed.length) return join(fixed, pathWithoutFixed) }