import React , { useCallback , useMemo } from 'react' ; import { getAnalysisType } from '../../../../common/analytics' ; import { useMlLocator , useNavigateToPath } from '../../../../../contexts/kibana' ; import { DataFrameAnalyticsListAction , DataFrameAnalyticsListRow } from '../analytics_list/common' ; import { getViewLinkStatus } from './get_view_link_status' ; import { viewActionButtonText , ViewButton } from './view_button' ; import { DataFrameAnalysisConfigType } from '../../../../../../../common/types/data_frame_analytics' ; import { ML_PAGES } from '../../../../../../../common/constants/locator' ; export type ViewAction = ReturnType < typeof useViewAction > ; export const useViewAction = ( ) => { const mlLocator = useMlLocator ( ) ! ; const navigateToPath = useNavigateToPath ( ) ; const redirectToTab = async ( jobId , analysisType ) => { const path = await mlLocator . getUrl ( { page : ML_PAGES . DATA_FRAME_ANALYTICS_EXPLORATION , pageState : { jobId , analysisType } , } ) ; await navigateToPath ( path , false ) ; } ; const clickHandler = useCallback ( ( item ) => { const analysisType = getAnalysisType ( item . config . analysis ) as DataFrameAnalysisConfigType ; redirectToTab ( item . id , analysisType ) ; } , [ ] ) ; const action = useMemo ( ( ) => ( { isPrimary : true , name : ( item ) => < ViewButton item = { item } / > , enabled : ( item ) => ! getViewLinkStatus ( item ) . disabled , description : viewActionButtonText , icon : 'visTable' , type : 'icon' , onClick : clickHandler , 'data-test-subj' : 'mlAnalyticsJobViewButton' , } ) , [ clickHandler ] ) ; return { action } ; } ;