/* * SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. * * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ import ContentPanel from '../../../../components/ContentPanel/ContentPanel'; import { EuiFlexGrid, EuiFlexItem, EuiButton, EuiCallOut, EuiLoadingSpinner, EuiFlexGroup, EuiText, } from '@elastic/eui'; import React from 'react'; import { get, isEqual } from 'lodash'; import { Detector, ValidationSettingResponse, } from '../../../../models/interfaces'; import { FilterDisplayList } from '../FilterDisplayList'; import { ConfigCell, FixedWidthRow } from '../../../../components/ConfigCell'; import { toStringConfigCell } from '../../utils/helpers'; interface DetectorDefinitionFieldsProps { detector: Detector; onEditDetectorDefinition(): void; isCreate: boolean; validationError?: boolean; validDetectorSettings?: boolean; validationResponse?: ValidationSettingResponse; isLoading?: boolean; isCreatingDetector?: boolean; } export const DetectorDefinitionFields = ( props: DetectorDefinitionFieldsProps ) => { const filterInputs = { uiMetadata: get(props, 'detector.uiMetadata', {}), filterQuery: JSON.stringify( get(props, 'detector.filterQuery', {}) || {}, null, 4 ), }; const getValidationCallout = () => { //When validation response is loading then displaying loading spinner, don't display // after clicking on "create detector" button as isLoading will be true from that request if (props.isLoading && !props.isCreatingDetector) { return (

Validating detector configurations

} style={{ marginBottom: '10px' }} size="s" color="primary" /> ); } // Callouts only displayed based on if validDetectorSettings is true or not, referring to // to response content from validation API (empty body or response issue body). // validationError refers to if there was an exception from validation API // such as a security exception or error establishing network connection on request. // This means no callout will be displayed since validation wasn't able to say if settings are valid or not. if (props.validationResponse != undefined && !props.validationError) { if (props.validDetectorSettings) { return ( ); } else if ( !props.validDetectorSettings && props.validationResponse.hasOwnProperty('message') ) { if ( isEqual(get(props, 'validationResponse.validationType', ''), 'model') ) { return ( {JSON.stringify(props.validationResponse.message).replace( /\"/g, '' )} ); } else { return ( ); } } else { return null; } } }; return ( Edit , ]} > {props.isCreate ? getValidationCallout() : null} {props.isCreate ? null : ( )} {props.isCreate ? null : ( )} ); };