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

Prevents negative values for Snapshot retention policies #51295

Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ export const PolicyStepRetention: React.FunctionComponent<StepProps> = ({
<EuiFieldNumber
value={retention.expireAfterValue || ''}
onBlur={() => setTouched({ ...touched, expireAfterValue: true })}
onKeyDown={e => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than preventing the user from entering the - symbol, I think it might be better to add a new validation rule that prevents negative numbers. This way, a validation error message will appear as well, and the user will not be able to proceed to the next step until it is corrected.

For example, there is currently validation in place so that a user cannot set the min_count greater than max_count.

Screen Shot 2019-11-25 at 1 47 48 PM

You should be able to modify this file: https://github.com/elastic/kibana/blob/cda7eba4c9dbb3739c726a194ceed155111f15fc/x-pack/legacy/plugins/snapshot_restore/public/app/services/validation/validate_policy.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alisonelizabeth thanks for the tip. It surely looks better as a validation.
I did some testing and it looks like the image below.

I also tryied to add a Jest test, but I don't know eactly how to run it locally (do you? I mean, doyou know how I could have run specifically the x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts test locally before pushing?)

Let me know what do you think!

Bildschirmfoto vom 2019-11-25 20-17-19

if (e.which === 189) {
e.preventDefault();
}
}}
onChange={e => {
const value = e.target.value;
updatePolicyRetention({
expireAfterValue: value !== '' ? Number(value) : value,
});
}}
data-test-subj="expireAfterValueInput"
min="0"
/>
</EuiFlexItem>
<EuiFlexItem>
Expand Down Expand Up @@ -160,13 +166,19 @@ export const PolicyStepRetention: React.FunctionComponent<StepProps> = ({
fullWidth
value={retention.minCount || ''}
onBlur={() => setTouched({ ...touched, minCount: true })}
onKeyDown={e => {
if (e.which === 189) {
e.preventDefault();
}
}}
onChange={e => {
const value = e.target.value;
updatePolicyRetention({
minCount: value !== '' ? Number(value) : value,
});
}}
data-test-subj="minCountInput"
min="0"
/>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -186,13 +198,19 @@ export const PolicyStepRetention: React.FunctionComponent<StepProps> = ({
fullWidth
value={retention.maxCount || ''}
onBlur={() => setTouched({ ...touched, maxCount: true })}
onKeyDown={e => {
if (e.which === 189) {
e.preventDefault();
}
}}
onChange={e => {
const value = e.target.value;
updatePolicyRetention({
maxCount: value !== '' ? Number(value) : value,
});
}}
data-test-subj="maxCountInput"
min="0"
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down