Skip to content
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

[full-ci] refactor: define either handler or route in editor actions, not both #11857

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions packages/web-pkg/src/composables/actions/files/useFileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const useFileActions = () => {
return appsStore.fileExtensions
.map((fileExtension): FileAction => {
const appInfo = appsStore.apps[fileExtension.app]
const hasRoute = router.hasRoute(fileExtension.routeName || fileExtension.app)

return {
name: `editor-${fileExtension.app}`,
Expand All @@ -121,16 +122,24 @@ export const useFileActions = () => {
iconFillType: appInfo.iconFillType
}),
img: appInfo.img,
route: ({ space, resources }) => {
return getEditorRoute({
appFileExtension: fileExtension,
space,
resource: resources[0],
mode: EDITOR_MODE_EDIT
})
},
handler: (options) =>
openEditor(fileExtension, options.space, options.resources[0], EDITOR_MODE_EDIT),
...(hasRoute && {
route: ({ space, resources }) => {
const remoteItemId = isShareSpaceResource(space) ? space.id : undefined
const routeName = fileExtension.routeName || fileExtension.app
const routeOpts = getEditorRouteOpts(
routeName,
space,
resources[0],
EDITOR_MODE_EDIT,
remoteItemId
)
return router.resolve(routeOpts)
}
}),
...(!hasRoute && {
handler: (options) =>
openEditor(fileExtension, options.space, options.resources[0], EDITOR_MODE_EDIT)
}),
isVisible: ({ resources }) => {
if (resources.length !== 1) {
return false
Expand Down Expand Up @@ -171,22 +180,6 @@ export const useFileActions = () => {
})
})

const getEditorRoute = ({
appFileExtension,
space,
resource,
mode
}: {
appFileExtension: ApplicationFileExtension
space: SpaceResource
resource: Resource
mode: string
}) => {
const remoteItemId = isShareSpaceResource(space) ? space.id : undefined
const routeName = appFileExtension.routeName || appFileExtension.app
const routeOpts = getEditorRouteOpts(routeName, space, resource, mode, remoteItemId)
return router.resolve(routeOpts)
}
const getEditorRouteOpts = (
routeName: RouteRecordName,
space: SpaceResource,
Expand Down