File size: 1,064 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import { RecordActionParams, ViewHelpers } from '../../../backend/utils/view-helpers/index.js'
import { DifferentActionParams } from '../../hooks/index.js'
import { ActionJSON } from './action-json.interface.js'
const h = new ViewHelpers()
export const actionHref = (
action: ActionJSON,
params: DifferentActionParams,
): string | null => {
const actionName = action.name
if (!action.component && !action.hasHandler) {
return null
}
if (params.recordIds?.length) {
params.recordIds = [...new Set(params.recordIds)]
}
const hrefMap = {
record: (): string => h.recordActionUrl({
...params as RecordActionParams,
actionName,
}),
resource: (): string => h.resourceActionUrl({
resourceId: params.resourceId,
actionName,
search: params.search,
}),
bulk: (): string => h.bulkActionUrl({
...params,
actionName,
}),
}
if (hrefMap[action.actionType]) {
return hrefMap[action.actionType]()
}
throw new Error('"actionType" should be either record, resource or bulk')
}
|