Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

add throttle on action level #45

Merged
merged 11 commits into from
May 14, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ const FormikFieldNumber = ({
/>
);

const FieldNumber = ({ name, form, field, inputProps: { onChange, isInvalid, ...rest } }) => (
const FieldNumber = ({ name, form, field, inputProps: { onChange, isInvalid, disabled, ...rest } }) => (
<EuiFieldNumber
{...field}
{...rest}
onChange={e => (typeof onChange === 'function' ? onChange(e, field, form) : field.onChange(e))}
isInvalid={typeof isInvalid === 'function' ? isInvalid(name, form) : isInvalid}
disabled={ disabled? "disabled":"" }
ylwu-amzn marked this conversation as resolved.
Show resolved Hide resolved
/>
);

Expand Down
1 change: 0 additions & 1 deletion public/pages/CreateTrigger/components/Action/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const Action = ({
helpText: 'Choose destination for an action.',
isInvalid,
error: hasError,
style: { marginTop: '0px' },
}}
inputProps={{
placeholder: 'Select a destination',
Expand Down
45 changes: 43 additions & 2 deletions public/pages/CreateTrigger/components/Action/actions/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import React from 'react';
import _ from 'lodash';
import Mustache from 'mustache';
import {
EuiFlexGroup,
Expand All @@ -25,8 +26,8 @@ import {
EuiTextArea,
} from '@elastic/eui';

import { FormikTextArea, FormikFieldText } from '../../../../../components/FormControls';
import { isInvalid, hasError, required } from '../../../../../utils/validate';
import { FormikTextArea, FormikFieldText, FormikSwitch, FormikFieldNumber } from '../../../../../components/FormControls';
import { isInvalid, validateActionThrottle, validateInterval, hasError, required } from '../../../../../utils/validate';
import { URL } from '../../../../../../utils/constants';

const messageHelpText = (index, sendTestMessage) => (
Expand Down Expand Up @@ -122,6 +123,46 @@ const Message = ({
</EuiFormRow>

<EuiSpacer size="s" />

<EuiFormRow
label={
<div>
<span>Action throttling</span>
<EuiButtonEmpty
size="s"
onClick={() => { setFlyout({ type: 'messageFrequency' }); }}
ylwu-amzn marked this conversation as resolved.
Show resolved Hide resolved
>
Info
</EuiButtonEmpty>
</div>
}
style={{ maxWidth: '100%' }}
>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false} style={{ marginRight: '0px' }}>
<FormikSwitch
name={`actions.${index}.throttle_enabled`}
inputProps={{ label: 'Maximum Frequency' }}
/>
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ marginLeft: '4px', marginRight: '4px' }}>
<FormikFieldNumber
name={`actions.${index}.throttle.value`}
ylwu-amzn marked this conversation as resolved.
Show resolved Hide resolved
fieldProps={{ validate: validateActionThrottle(action) }}
inputProps={{
ylwu-amzn marked this conversation as resolved.
Show resolved Hide resolved
style: { width: '100px' },
min: 1,
compressed: true,
disabled: !_.get(action, `throttle_enabled`),
isInvalid: (name, form) => _.get(form.values, `actions.${index}.throttle_enabled`) && (!_.get(form.values, name))
}}
/>
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ marginLeft: '0px' }}>
<EuiText size="s">minutes.</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import React from 'react';
import { render,shallow,mount } from 'enzyme';
import { Formik } from 'formik'
import Message from './Message';
import Mustache from 'mustache';

jest.mock('@elastic/eui/lib/components/form/form_row/make_id', () => () => 'testing-id');

function getRenderWrapper(customProps = {}) {
return render(
<Formik
render={() => <Message
action={{
"message_template": {
"source": "Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n- Trigger: {{ctx.trigger.name}}\n- Severity: {{ctx.trigger.severity}}\n- Period start: {{ctx.periodStart}}\n- Period end: {{ctx.periodEnd}}",
"lang": "mustache"
}
}}
context={{}}
index={0}
sendTestMessage={jest.fn()}
setFlyout={jest.fn()}
/>}
/>
);
}

describe('Message', () => {
test('renders', () => {
const wrapper = getRenderWrapper();
expect(wrapper).toMatchSnapshot();
});

});
Loading