Skip to content

Commit

Permalink
refactor: utilize getDefaultAction for getDefaultEditorAction
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed May 19, 2023
1 parent 98ef7dd commit 727fda9
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import {
export const EDITOR_MODE_EDIT = 'edit'
export const EDITOR_MODE_CREATE = 'create'

interface GetFileActionsOptions extends FileActionOptions {
omitSystemActions?: boolean
}

export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
store = store || useStore()
const router = useRouter()
Expand Down Expand Up @@ -215,14 +219,10 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
}

const getDefaultEditorAction = (options: FileActionOptions): Action | null => {
const defaultAction = getDefaultAction(options)

return defaultAction && defaultAction.name !== unref(downloadFileActions)[0].name
? defaultAction
: null
return getDefaultAction({ ...options, omitSystemActions: true })
}

const getDefaultAction = (options: FileActionOptions): Action => {
const getDefaultAction = (options: GetFileActionsOptions): Action | null => {
const filterCallback = (action) =>
action.canBeDefault &&
action.isEnabled({
Expand All @@ -244,7 +244,7 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
}

// fallback: system actions
return unref(systemActions).filter(filterCallback)[0]
return options.omitSystemActions ? null : unref(systemActions).filter(filterCallback)[0]
}

const getAllAvailableActions = (options: FileActionOptions) => {
Expand Down

0 comments on commit 727fda9

Please sign in to comment.