Separate resource-related editor actions for external widgets#3099
Separate resource-related editor actions for external widgets#3099nighca wants to merge 1 commit intogoplus:devfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the resource renaming and navigation logic by moving these responsibilities from UI components to the ResourceProvider. It extends the IResourceProvider interface with optional renameResource and goToResource methods and introduces a useModalInvoker hook for dynamic modal management. The review feedback suggests calling provider methods directly rather than using .call() for more idiomatic and readable code.
| const { goToResource } = provider | ||
| if (goToResource != null) { | ||
| this.registerCommand(builtInCommandGoToResource, { | ||
| icon: 'goto', | ||
| title: { en: 'View detail', zh: '查看详情' }, | ||
| handler: async (resource) => { | ||
| await goToResource.call(provider, resource) | ||
| } | ||
| }) |
There was a problem hiding this comment.
Instead of destructuring the goToResource method and using .call(), it is cleaner and more idiomatic to call the method directly on the provider instance. This avoids the need for explicit context binding and improves readability.
if (provider.goToResource != null) {
this.registerCommand(builtInCommandGoToResource, {
icon: 'goto',
title: { en: 'View detail', zh: '查看详情' },
handler: async (resource) => {
await provider.goToResource!(resource)
}
})
}| const { renameResource } = provider | ||
| if (renameResource != null) { | ||
| this.registerCommand(builtInCommandRenameResource, { | ||
| icon: 'rename', | ||
| title: { en: 'Rename', zh: '重命名' }, | ||
| handler: async (resource) => { | ||
| await renameResource.call(provider, resource, this.codeEditor) | ||
| } | ||
| }) |
There was a problem hiding this comment.
Similar to goToResource, calling renameResource directly on the provider instance is preferred over destructuring and using .call(). This follows standard TypeScript practices for method invocation when the object context is available.
if (provider.renameResource != null) {
this.registerCommand(builtInCommandRenameResource, {
icon: 'rename',
title: { en: 'Rename', zh: '重命名' },
handler: async (resource) => {
await provider.renameResource!(resource, this.codeEditor)
}
})
}
Summary
Separate resource-related editor actions from the generic XGo code editor UI and route spx-specific resource behavior through the resource provider boundary.
Changes
SpxResourceProvider.useModalInvokerso modal invocation can be passed as a dependency to shared helpers.Closes #3086