import { navigateToComponent } from "fastball-mobile-common"; import type { ActionInfo, ApiActionInfo, Displayable, PopupActionInfo } from "../../types/basic"; import { doApiAction } from "../api/component"; export const doViewAction = async (actionInfo: PopupActionInfo) => { const componentPath = actionInfo?.popupInfo?.popupComponent?.componentInfo?.componentPath if (componentPath) { navigateToComponent(componentPath, actionInfo.data) } else { throw new Error(`PopupActionInfo popupComponent is not defined`) } } export const doAction = (actionInfo: ActionInfo) => { if (actionInfo.type === 'API') { const apiActionInfo = actionInfo as ApiActionInfo if (apiActionInfo.needArrayWrapper !== false) { apiActionInfo.needArrayWrapper = true; } doApiAction(apiActionInfo) } else if (actionInfo.type === 'Popup') { doViewAction(actionInfo as PopupActionInfo) } else { throw new Error(`ActionInfo type ${actionInfo.type} is not supported`) } if(actionInfo.callback) { actionInfo.callback() } } export const filterVisibled = (item: Displayable) => item.display !== 'Disabled' && item.display !== 'Hidden'