import React from 'react' ; import { getFlattenedObject } from '@osd/std' ; import { EuiCodeBlock , EuiDescriptionList , EuiSpacer } from '@elastic/eui' ; import { ShardFailure } from './shard_failure_types' ; import { ShardFailureDescriptionHeader } from './shard_failure_description_header' ; param key export function formatKey ( key ) { const nameCapitalized = key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 ) ; return nameCapitalized . replace ( /[\._]/g , ' ' ) ; } param value param key export function formatValueByKey ( value , key ) { if ( key === 'script' || key === 'script_stack' ) { const valueScript = Array . isArray ( value ) ? value . join ( '\n' ) : String ( value ) ; return ( < EuiCodeBlock language = "java" paddingSize = "s" isCopyable > { valueScript } < /EuiCodeBlock>); } else { return String ( value ) ; } } export function ShardFailureDescription ( props ) { const flattendReason = getFlattenedObject ( props . reason ) ; const listItems = Object . entries ( flattendReason ) . map ( ( [ key , value ] ) => ( { title : formatKey ( key ) , description : formatValueByKey ( value , key ) , } ) ) ; return ( < div > < ShardFailureDescriptionHeader { ... props } / > < EuiSpacer size = "m" / > < EuiDescriptionList listItems = { listItems } type = "column" compressed className = "shardFailureModal__desc" titleProps = { { className : 'shardFailureModal__descTitle' } } descriptionProps = { { className : 'shardFailureModal__descValue' } } /> < /div>); }