import React from 'react' ; import { EuiCode , EuiTitle } from '@elastic/eui' ; import { i18n } from '@osd/i18n' ; import { ShardFailure } from './shard_failure_types' ; export function getFailurePropsForSummary ( failure ) { const failureDetailProps = [ 'shard' , 'index' , 'node' ] ; return failureDetailProps . filter ( ( key ) => typeof failure [ key ] === 'number' || typeof failure [ key ] === 'string' ) . map ( ( key ) => ( { key , value : String ( failure [ key ] ) } ) ) ; } export function getFailureSummaryText ( failure , failureDetails ? ) { const failureName = failure . reason . type ; const displayDetails = typeof failureDetails === 'string' ? failureDetails : getFailureSummaryDetailsText ( failure ) ; return i18n . translate ( 'data.search.searchSource.fetch.shardsFailedModal.failureHeader' , { defaultMessage : '{failureName} at {failureDetails}' , values : { failureName , failureDetails : displayDetails } , description : 'Summary of shard failures, e.g. "IllegalArgumentException at shard 0 node xyz"' , } ) ; } export function getFailureSummaryDetailsText ( failure ) { return getFailurePropsForSummary ( failure ) . map ( ( { key , value } ) => `${ key }: ${ value }` ) . join ( ', ' ) ; } export function ShardFailureDescriptionHeader ( props ) { const failureDetails = getFailurePropsForSummary ( props ) . map ( ( kv ) => ( < span className = "shardFailureModal__keyValueTitle" key = { kv . key } > < EuiCode > { kv . key } < /EuiCode> {kv.value} < /span>)); return ( < EuiTitle size = "xs" > < h2 > { getFailureSummaryText ( props , '' ) } { failureDetails } < /h2> < /EuiTitle>); }