import { i18n } from '@kbn/i18n' ; import { NotificationsStart } from 'kibana/public' ; import { Filter , CustomLink , } from '../../../../../../common/custom_link/custom_link_types' ; import { callApmApi } from '../../../../../services/rest/createCallApmApi' ; export async function saveCustomLink ( { id , label , url , filters , toasts , } ) { try { const customLink = { label , url , filters : filters . filter ( ( { key , value } ) => key && value ) , } ; if ( id ) { await callApmApi ( { endpoint : 'PUT /internal/apm/settings/custom_links/{id}' , signal : null , params : { path : { id } , body : customLink , } , } ) ; } else { await callApmApi ( { endpoint : 'POST /internal/apm/settings/custom_links' , signal : null , params : { body : customLink , } , } ) ; } toasts . addSuccess ( { iconType : 'check' , title : i18n . translate ( 'xpack.apm.settings.customLink.create.successed' , { defaultMessage : 'Link saved!' , } ) , } ) ; } catch ( error ) { toasts . addDanger ( { title : i18n . translate ( 'xpack.apm.settings.customLink.create.failed' , { defaultMessage : 'Link could not be saved!' , } ) , text : i18n . translate ( 'xpack.apm.settings.customLink.create.failed.message' , { defaultMessage : 'Something went wrong when saving the link. Error: "{errorMessage}"' , values : { errorMessage : error . message , } , } ) , } ) ; } }