import { Meta , Story } from '@storybook/react' ; import React , { useState } from 'react' ; import { RuleParams , ErrorCountAlertTrigger } from '.' ; import { CoreStart } from '../../../../../../../src/core/public' ; import { createKibanaReactContext } from '../../../../../../../src/plugins/kibana_react/public' ; import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values' ; import { createCallApmApi } from '../../../services/rest/createCallApmApi' ; import { AlertMetadata } from '../helper' ; const coreMock = { http : { get : async ( ) => ( { } ) } , notifications : { toasts : { add : ( ) => { } } } , uiSettings : { get : ( ) => { } } , } as unknown as CoreStart ; const KibanaReactContext = createKibanaReactContext ( coreMock ) ; interface Args { ruleParams : RuleParams ; metadata ? : AlertMetadata ; } const stories = { title : 'alerting/ErrorCountAlertTrigger' , component : ErrorCountAlertTrigger , decorators : [ ( StoryComponent ) => { createCallApmApi ( coreMock ) ; return ( < KibanaReactContext . Provider > < div style = { { width : 400 } } > < StoryComponent /> < /div> < /KibanaReactContext.Provider>); } , ] , } ; export default stories ; export const CreatingInApmFromInventory = ( { ruleParams , metadata , } ) => { const [ params , setParams ] = useState < RuleParams > ( ruleParams ) ; function setRuleParams ( property , value ) { setParams ( { ... params , [ property ] : value } ) ; } return ( < ErrorCountAlertTrigger ruleParams = { params } metadata = { metadata } setRuleParams = { setRuleParams } setRuleProperty = { ( ) => { } } />); } ; CreatingInApmFromInventory . args = { ruleParams : { } , metadata : { end : '2021-09-10T14:14:04.789Z' , environment : ENVIRONMENT_ALL . value , serviceName : undefined , start : '2021-09-10T13:59:00.000Z' , } , } ; export const CreatingInApmFromService = ( { ruleParams , metadata , } ) => { const [ params , setParams ] = useState < RuleParams > ( ruleParams ) ; function setRuleParams ( property , value ) { setParams ( { ... params , [ property ] : value } ) ; } return ( < ErrorCountAlertTrigger ruleParams = { params } metadata = { metadata } setRuleParams = { setRuleParams } setRuleProperty = { ( ) => { } } />); } ; CreatingInApmFromService . args = { ruleParams : { } , metadata : { end : '2021-09-10T14:14:04.789Z' , environment : 'testEnvironment' , serviceName : 'testServiceName' , start : '2021-09-10T13:59:00.000Z' , } , } ; export const EditingInStackManagement = ( { ruleParams , metadata , } ) => { const [ params , setParams ] = useState < RuleParams > ( ruleParams ) ; function setRuleParams ( property , value ) { setParams ( { ... params , [ property ] : value } ) ; } return ( < ErrorCountAlertTrigger ruleParams = { params } metadata = { metadata } setRuleParams = { setRuleParams } setRuleProperty = { ( ) => { } } />); } ; EditingInStackManagement . args = { ruleParams : { environment : 'testEnvironment' , serviceName : 'testServiceName' , threshold : 25 , windowSize : 1 , windowUnit : 'm' , } , metadata : undefined , } ; export const CreatingInStackManagement = ( { ruleParams , metadata , } ) => { const [ params , setParams ] = useState < RuleParams > ( ruleParams ) ; function setRuleParams ( property , value ) { setParams ( { ... params , [ property ] : value } ) ; } return ( < ErrorCountAlertTrigger ruleParams = { params } metadata = { metadata } setRuleParams = { setRuleParams } setRuleProperty = { ( ) => { } } />); } ; CreatingInStackManagement . args = { ruleParams : { } , metadata : undefined , } ;