import { VISUALIZE_FIELD_TRIGGER , VISUALIZE_GEO_FIELD_TRIGGER , visualizeFieldTrigger , visualizeGeoFieldTrigger , } from '../../../../../../ui_actions/public' ; import { getUiActions } from '../../../../opensearch_dashboards_services' ; import { IndexPatternField , OSD_FIELD_TYPES } from '../../../../../../data/public' ; function getTriggerConstant ( type ) { return type === OSD_FIELD_TYPES . GEO_POINT || type === OSD_FIELD_TYPES . GEO_SHAPE ? VISUALIZE_GEO_FIELD_TRIGGER : VISUALIZE_FIELD_TRIGGER ; } function getTrigger ( type ) { return type === OSD_FIELD_TYPES . GEO_POINT || type === OSD_FIELD_TYPES . GEO_SHAPE ? visualizeGeoFieldTrigger : visualizeFieldTrigger ; } async function getCompatibleActions ( fieldName , indexPatternId , contextualFields , trigger ) { const compatibleActions = await getUiActions ( ) . getTriggerCompatibleActions ( trigger , { indexPatternId , fieldName , contextualFields , } ) ; return compatibleActions ; } export async function getVisualizeHref ( field , indexPatternId , contextualFields ) { if ( ! indexPatternId ) return undefined ; const triggerOptions = { indexPatternId , fieldName : field . name , contextualFields , trigger : getTrigger ( field . type ) , } ; const compatibleActions = await getCompatibleActions ( field . name , indexPatternId , contextualFields , getTriggerConstant ( field . type ) ) ; return compatibleActions . length === 1 ? compatibleActions [ 0 ] . getHref ?. ( triggerOptions ) : undefined ; } export function triggerVisualizeActions ( field , indexPatternId , contextualFields ) { if ( ! indexPatternId ) return ; const trigger = getTriggerConstant ( field . type ) ; const triggerOptions = { indexPatternId , fieldName : field . name , contextualFields , } ; getUiActions ( ) . getTrigger ( trigger ) . exec ( triggerOptions ) ; } export async function isFieldVisualizable ( field , indexPatternId , contextualFields ) { if ( field . name === '_id' || ! indexPatternId ) { return false ; } const trigger = getTriggerConstant ( field . type ) ; const compatibleActions = await getCompatibleActions ( field . name , indexPatternId , contextualFields , trigger ) ; return compatibleActions . length > 0 && field . visualizable ; }