-
Notifications
You must be signed in to change notification settings - Fork 19
feat(tree): compute tree based on fsPath #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
| const rootDocumentDraftItem = await activeTree.value.draft.create(rootDocument) | ||
|
|
||
| await activeTree.value.selectItemById(rootDocumentDraftItem.id) | ||
| await activeTree.value.selectItemByFsPath(rootDocumentDraftItem.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing id (with collection prefix like docs/file.md) to selectItemByFsPath() and selectParentByFsPath() which expect fsPath (like file.md). This causes tree lookups to fail and root items to be selected instead of the intended items after create and duplicate operations.
View Details
📝 Patch Details
diff --git a/src/app/src/composables/useContext.ts b/src/app/src/composables/useContext.ts
index 15d6881..5285a12 100644
--- a/src/app/src/composables/useContext.ts
+++ b/src/app/src/composables/useContext.ts
@@ -100,7 +100,7 @@ export const useContext = createSharedComposable((
const rootDocumentDraftItem = await activeTree.value.draft.create(rootDocument)
- await activeTree.value.selectItemByFsPath(rootDocumentDraftItem.id)
+ await activeTree.value.selectItemByFsPath(rootDocumentDraftItem.fsPath)
},
[StudioItemActionId.CreateMediaFolder]: async (params: CreateFolderParams) => {
const { fsPath } = params
@@ -117,13 +117,13 @@ export const useContext = createSharedComposable((
unsetActionInProgress()
- await activeTree.value.selectParentByFsPath(gitKeepMedia.id)
+ await activeTree.value.selectParentByFsPath(gitKeepMedia.fsPath)
},
[StudioItemActionId.CreateDocument]: async (params: CreateFileParams) => {
const { fsPath, content } = params
const document = await host.document.create(fsPath, content)
const draftItem = await activeTree.value.draft.create(document as DatabaseItem)
- await activeTree.value.selectItemByFsPath(draftItem.id)
+ await activeTree.value.selectItemByFsPath(draftItem.fsPath)
},
[StudioItemActionId.UploadMedia]: async ({ parentFsPath, files }: UploadMediaParams) => {
// Remove .gitkeep draft in folder if exists
@@ -191,7 +191,7 @@ export const useContext = createSharedComposable((
if (item.type === 'file') {
const id = generateIdFromFsPath(item.fsPath, item.collections![0])
const draftItem = await activeTree.value.draft.duplicate(id)
- await activeTree.value.selectItemByFsPath(draftItem!.id)
+ await activeTree.value.selectItemByFsPath(draftItem!.fsPath)
return
}
},
Analysis
Incorrect ID vs fsPath usage causes tree selection failures after create and duplicate operations
What fails: selectItemByFsPath() and selectParentByFsPath() in useContext.ts receive full IDs with collection prefixes (e.g., "docs/file.md", "public-assets/.gitkeep") instead of fsPath values ("file.md", ".gitkeep"), causing tree lookups to fail and root items to be selected instead of the intended items
How to reproduce:
- Create a new document or media folder through the Studio UI
- The item should auto-select after creation, but root is selected instead
- Occurs in CreateDocumentFolder (line 103), CreateMediaFolder (line 120), CreateDocument (line 126), and DuplicateItem (line 194) actions
Result: Tree search functions findItemFromFsPath() and findParentFromFsPath() fail to match items because they compare item.fsPath (without prefix) against the provided ID parameter (with "docs/" or "public-assets/" prefix). Functions return null and select root item instead of newly created/duplicated item.
Expected: After create/duplicate operations, the new item should be auto-selected in the tree for immediate editing.
No description provided.