Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented ability to clear and properly validate alert interval #60571

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('alert_form', () => {
uiSettings: deps!.uiSettings,
}}
>
<AlertForm alert={initialAlert} dispatch={() => {}} errors={{ name: [] }} />
<AlertForm alert={initialAlert} dispatch={() => {}} errors={{ name: [], interval: [] }} />
</AlertsContextProvider>
);

Expand Down Expand Up @@ -165,7 +165,7 @@ describe('alert_form', () => {
uiSettings: deps!.uiSettings,
}}
>
<AlertForm alert={initialAlert} dispatch={() => {}} errors={{ name: [] }} />
<AlertForm alert={initialAlert} dispatch={() => {}} errors={{ name: [], interval: [] }} />
</AlertsContextProvider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function validateBaseProperties(alertObject: Alert) {
})
);
}
if (!alertObject.schedule.interval) {
if (alertObject.schedule.interval.length < 2) {
errors.interval.push(
i18n.translate('xpack.triggersActionsUI.sections.alertForm.error.requiredIntervalText', {
defaultMessage: 'Check interval is required.',
Expand Down Expand Up @@ -81,11 +81,15 @@ export const AlertForm = ({ alert, canChangeTrigger = true, dispatch, errors }:
);

const [alertTypesIndex, setAlertTypesIndex] = useState<AlertTypeIndex | undefined>(undefined);
const [alertInterval, setAlertInterval] = useState<number>(
alert.schedule.interval ? parseInt(alert.schedule.interval.replace(/^[A-Za-z]+$/, ''), 0) : 1
const [alertInterval, setAlertInterval] = useState<number | undefined>(
alert.schedule.interval
? parseInt(alert.schedule.interval.replace(/^[A-Za-z]+$/, ''), 0)
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
: undefined
);
const [alertIntervalUnit, setAlertIntervalUnit] = useState<string>(
alert.schedule.interval ? alert.schedule.interval.replace(alertInterval.toString(), '') : 'm'
alert.schedule.interval
? alert.schedule.interval.replace((alertInterval ?? '').toString(), '')
: 'm'
);
const [alertThrottle, setAlertThrottle] = useState<number | null>(
alert.throttle ? parseInt(alert.throttle.replace(/^[A-Za-z]+$/, ''), 0) : null
Expand Down Expand Up @@ -344,19 +348,27 @@ export const AlertForm = ({ alert, canChangeTrigger = true, dispatch, errors }:
<EuiSpacer size="m" />
<EuiFlexGrid columns={2}>
<EuiFlexItem>
<EuiFormRow fullWidth compressed label={labelForAlertChecked}>
<EuiFormRow
fullWidth
compressed
label={labelForAlertChecked}
isInvalid={errors.interval.length > 0}
error={errors.interval}
>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem>
<EuiFieldNumber
fullWidth
min={1}
isInvalid={errors.interval.length > 0}
compressed
value={alertInterval}
value={alertInterval || ''}
name="interval"
data-test-subj="intervalInput"
onChange={e => {
const interval = e.target.value !== '' ? parseInt(e.target.value, 10) : null;
setAlertInterval(interval ?? 1);
const interval =
e.target.value !== '' ? parseInt(e.target.value, 10) : undefined;
setAlertInterval(interval);
setScheduleProperty('interval', `${e.target.value}${alertIntervalUnit}`);
}}
/>
Expand All @@ -366,7 +378,7 @@ export const AlertForm = ({ alert, canChangeTrigger = true, dispatch, errors }:
fullWidth
compressed
value={alertIntervalUnit}
options={getTimeOptions(alertInterval)}
options={getTimeOptions(alertInterval ?? 1)}
onChange={e => {
setAlertIntervalUnit(e.target.value);
setScheduleProperty('interval', `${alertInterval}${e.target.value}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await fieldOptions[1].click();
// need this two out of popup clicks to close them
await nameInput.click();
await testSubjects.click('intervalInput');
const intervalInput = await testSubjects.find('intervalInput');
await intervalInput.click();
await intervalInput.clearValue();
const validationError = await find.byCssSelector(`.euiFormErrorText`);
expect(validationError.isDisplayed).to.be(true);
await intervalInput.type(1);

await testSubjects.click('.slack-ActionTypeSelectOption');
await testSubjects.click('createActionConnectorButton');
Expand Down