[Enterprise Search] Change minute values to preset intervals (#161082)

## Summary


b9b7d66d-6368-4da4-90f6-2547193c07b6


Change minute values to the preset intervals
5, 10, 15 and 30 minutes presets are set.



### Checklist

Delete any items that are not applicable to this PR.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [x] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
This commit is contained in:
Efe Gürkan YALAMAN 2023-07-03 18:24:51 +02:00 committed by GitHub
parent 44c7091507
commit 0aea720fb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 815 deletions

View file

@ -135,7 +135,7 @@ function cronToFrequency(cron: string): Frequency {
if (fields.length < 4) {
return 'YEAR';
}
if (fields[1] === '*' || fields[1].startsWith('*/')) {
if (fields[1] === '*' || fields[1].includes(',')) {
return 'MINUTE';
}
if (fields[2] === '*') {

View file

@ -3391,241 +3391,21 @@ exports[`CronEditor is rendered with a MINUTE frequency 1`] = `
minute="10"
minuteOptions={
Array [
Object {
"text": "1",
"value": "*/1",
},
Object {
"text": "2",
"value": "*/2",
},
Object {
"text": "3",
"value": "*/3",
},
Object {
"text": "4",
"value": "*/4",
},
Object {
"text": "5",
"value": "*/5",
},
Object {
"text": "6",
"value": "*/6",
},
Object {
"text": "7",
"value": "*/7",
},
Object {
"text": "8",
"value": "*/8",
},
Object {
"text": "9",
"value": "*/9",
"value": "0,5,10,15,20,25,30,35,40,45,50,55",
},
Object {
"text": "10",
"value": "*/10",
},
Object {
"text": "11",
"value": "*/11",
},
Object {
"text": "12",
"value": "*/12",
},
Object {
"text": "13",
"value": "*/13",
},
Object {
"text": "14",
"value": "*/14",
"value": "0,10,20,30,40,50",
},
Object {
"text": "15",
"value": "*/15",
},
Object {
"text": "16",
"value": "*/16",
},
Object {
"text": "17",
"value": "*/17",
},
Object {
"text": "18",
"value": "*/18",
},
Object {
"text": "19",
"value": "*/19",
},
Object {
"text": "20",
"value": "*/20",
},
Object {
"text": "21",
"value": "*/21",
},
Object {
"text": "22",
"value": "*/22",
},
Object {
"text": "23",
"value": "*/23",
},
Object {
"text": "24",
"value": "*/24",
},
Object {
"text": "25",
"value": "*/25",
},
Object {
"text": "26",
"value": "*/26",
},
Object {
"text": "27",
"value": "*/27",
},
Object {
"text": "28",
"value": "*/28",
},
Object {
"text": "29",
"value": "*/29",
"value": "0,15,30,45",
},
Object {
"text": "30",
"value": "*/30",
},
Object {
"text": "31",
"value": "*/31",
},
Object {
"text": "32",
"value": "*/32",
},
Object {
"text": "33",
"value": "*/33",
},
Object {
"text": "34",
"value": "*/34",
},
Object {
"text": "35",
"value": "*/35",
},
Object {
"text": "36",
"value": "*/36",
},
Object {
"text": "37",
"value": "*/37",
},
Object {
"text": "38",
"value": "*/38",
},
Object {
"text": "39",
"value": "*/39",
},
Object {
"text": "40",
"value": "*/40",
},
Object {
"text": "41",
"value": "*/41",
},
Object {
"text": "42",
"value": "*/42",
},
Object {
"text": "43",
"value": "*/43",
},
Object {
"text": "44",
"value": "*/44",
},
Object {
"text": "45",
"value": "*/45",
},
Object {
"text": "46",
"value": "*/46",
},
Object {
"text": "47",
"value": "*/47",
},
Object {
"text": "48",
"value": "*/48",
},
Object {
"text": "49",
"value": "*/49",
},
Object {
"text": "50",
"value": "*/50",
},
Object {
"text": "51",
"value": "*/51",
},
Object {
"text": "52",
"value": "*/52",
},
Object {
"text": "53",
"value": "*/53",
},
Object {
"text": "54",
"value": "*/54",
},
Object {
"text": "55",
"value": "*/55",
},
Object {
"text": "56",
"value": "*/56",
},
Object {
"text": "57",
"value": "*/57",
},
Object {
"text": "58",
"value": "*/58",
},
Object {
"text": "59",
"value": "*/59",
"value": "0,30",
},
]
}
@ -3690,241 +3470,21 @@ exports[`CronEditor is rendered with a MINUTE frequency 1`] = `
onFocus={[Function]}
options={
Array [
Object {
"text": "1",
"value": "*/1",
},
Object {
"text": "2",
"value": "*/2",
},
Object {
"text": "3",
"value": "*/3",
},
Object {
"text": "4",
"value": "*/4",
},
Object {
"text": "5",
"value": "*/5",
},
Object {
"text": "6",
"value": "*/6",
},
Object {
"text": "7",
"value": "*/7",
},
Object {
"text": "8",
"value": "*/8",
},
Object {
"text": "9",
"value": "*/9",
"value": "0,5,10,15,20,25,30,35,40,45,50,55",
},
Object {
"text": "10",
"value": "*/10",
},
Object {
"text": "11",
"value": "*/11",
},
Object {
"text": "12",
"value": "*/12",
},
Object {
"text": "13",
"value": "*/13",
},
Object {
"text": "14",
"value": "*/14",
"value": "0,10,20,30,40,50",
},
Object {
"text": "15",
"value": "*/15",
},
Object {
"text": "16",
"value": "*/16",
},
Object {
"text": "17",
"value": "*/17",
},
Object {
"text": "18",
"value": "*/18",
},
Object {
"text": "19",
"value": "*/19",
},
Object {
"text": "20",
"value": "*/20",
},
Object {
"text": "21",
"value": "*/21",
},
Object {
"text": "22",
"value": "*/22",
},
Object {
"text": "23",
"value": "*/23",
},
Object {
"text": "24",
"value": "*/24",
},
Object {
"text": "25",
"value": "*/25",
},
Object {
"text": "26",
"value": "*/26",
},
Object {
"text": "27",
"value": "*/27",
},
Object {
"text": "28",
"value": "*/28",
},
Object {
"text": "29",
"value": "*/29",
"value": "0,15,30,45",
},
Object {
"text": "30",
"value": "*/30",
},
Object {
"text": "31",
"value": "*/31",
},
Object {
"text": "32",
"value": "*/32",
},
Object {
"text": "33",
"value": "*/33",
},
Object {
"text": "34",
"value": "*/34",
},
Object {
"text": "35",
"value": "*/35",
},
Object {
"text": "36",
"value": "*/36",
},
Object {
"text": "37",
"value": "*/37",
},
Object {
"text": "38",
"value": "*/38",
},
Object {
"text": "39",
"value": "*/39",
},
Object {
"text": "40",
"value": "*/40",
},
Object {
"text": "41",
"value": "*/41",
},
Object {
"text": "42",
"value": "*/42",
},
Object {
"text": "43",
"value": "*/43",
},
Object {
"text": "44",
"value": "*/44",
},
Object {
"text": "45",
"value": "*/45",
},
Object {
"text": "46",
"value": "*/46",
},
Object {
"text": "47",
"value": "*/47",
},
Object {
"text": "48",
"value": "*/48",
},
Object {
"text": "49",
"value": "*/49",
},
Object {
"text": "50",
"value": "*/50",
},
Object {
"text": "51",
"value": "*/51",
},
Object {
"text": "52",
"value": "*/52",
},
Object {
"text": "53",
"value": "*/53",
},
Object {
"text": "54",
"value": "*/54",
},
Object {
"text": "55",
"value": "*/55",
},
Object {
"text": "56",
"value": "*/56",
},
Object {
"text": "57",
"value": "*/57",
},
Object {
"text": "58",
"value": "*/58",
},
Object {
"text": "59",
"value": "*/59",
"value": "0,30",
},
]
}
@ -3970,358 +3530,28 @@ exports[`CronEditor is rendered with a MINUTE frequency 1`] = `
>
<option
key="0"
value="*/1"
>
1
</option>
<option
key="1"
value="*/2"
>
2
</option>
<option
key="2"
value="*/3"
>
3
</option>
<option
key="3"
value="*/4"
>
4
</option>
<option
key="4"
value="*/5"
value="0,5,10,15,20,25,30,35,40,45,50,55"
>
5
</option>
<option
key="5"
value="*/6"
>
6
</option>
<option
key="6"
value="*/7"
>
7
</option>
<option
key="7"
value="*/8"
>
8
</option>
<option
key="8"
value="*/9"
>
9
</option>
<option
key="9"
value="*/10"
key="1"
value="0,10,20,30,40,50"
>
10
</option>
<option
key="10"
value="*/11"
>
11
</option>
<option
key="11"
value="*/12"
>
12
</option>
<option
key="12"
value="*/13"
>
13
</option>
<option
key="13"
value="*/14"
>
14
</option>
<option
key="14"
value="*/15"
key="2"
value="0,15,30,45"
>
15
</option>
<option
key="15"
value="*/16"
>
16
</option>
<option
key="16"
value="*/17"
>
17
</option>
<option
key="17"
value="*/18"
>
18
</option>
<option
key="18"
value="*/19"
>
19
</option>
<option
key="19"
value="*/20"
>
20
</option>
<option
key="20"
value="*/21"
>
21
</option>
<option
key="21"
value="*/22"
>
22
</option>
<option
key="22"
value="*/23"
>
23
</option>
<option
key="23"
value="*/24"
>
24
</option>
<option
key="24"
value="*/25"
>
25
</option>
<option
key="25"
value="*/26"
>
26
</option>
<option
key="26"
value="*/27"
>
27
</option>
<option
key="27"
value="*/28"
>
28
</option>
<option
key="28"
value="*/29"
>
29
</option>
<option
key="29"
value="*/30"
key="3"
value="0,30"
>
30
</option>
<option
key="30"
value="*/31"
>
31
</option>
<option
key="31"
value="*/32"
>
32
</option>
<option
key="32"
value="*/33"
>
33
</option>
<option
key="33"
value="*/34"
>
34
</option>
<option
key="34"
value="*/35"
>
35
</option>
<option
key="35"
value="*/36"
>
36
</option>
<option
key="36"
value="*/37"
>
37
</option>
<option
key="37"
value="*/38"
>
38
</option>
<option
key="38"
value="*/39"
>
39
</option>
<option
key="39"
value="*/40"
>
40
</option>
<option
key="40"
value="*/41"
>
41
</option>
<option
key="41"
value="*/42"
>
42
</option>
<option
key="42"
value="*/43"
>
43
</option>
<option
key="43"
value="*/44"
>
44
</option>
<option
key="44"
value="*/45"
>
45
</option>
<option
key="45"
value="*/46"
>
46
</option>
<option
key="46"
value="*/47"
>
47
</option>
<option
key="47"
value="*/48"
>
48
</option>
<option
key="48"
value="*/49"
>
49
</option>
<option
key="49"
value="*/50"
>
50
</option>
<option
key="50"
value="*/51"
>
51
</option>
<option
key="51"
value="*/52"
>
52
</option>
<option
key="52"
value="*/53"
>
53
</option>
<option
key="53"
value="*/54"
>
54
</option>
<option
key="54"
value="*/55"
>
55
</option>
<option
key="55"
value="*/56"
>
56
</option>
<option
key="56"
value="*/57"
>
57
</option>
<option
key="57"
value="*/58"
>
58
</option>
<option
key="58"
value="*/59"
>
59
</option>
</select>
</EuiValidatableControl>
<EuiFormControlLayoutIcons

View file

@ -24,10 +24,24 @@ function makeSequence(min: number, max: number): number[] {
return values;
}
export const EVERY_MINUTE_OPTIONS = makeSequence(1, 59).map((value) => ({
value: '*/' + value.toString(),
text: value.toString(),
}));
export const EVERY_MINUTE_OPTIONS = [
{
text: '5',
value: '0,5,10,15,20,25,30,35,40,45,50,55',
},
{
text: '10',
value: '0,10,20,30,40,50',
},
{
text: '15',
value: '0,15,30,45',
},
{
text: '30',
value: '0,30',
},
];
export const MINUTE_OPTIONS = makeSequence(0, 59).map((value) => ({
value: value.toString(),
@ -111,7 +125,7 @@ export const frequencyToFieldsMap: Record<Frequency, FieldFlags> = {
export const frequencyToBaselineFieldsMap: Record<Frequency, FieldToValueMap> = {
MINUTE: {
second: '0',
minute: '*/1',
minute: '0,5,10,15,20,25,30,35,40,45,50,55',
hour: '*',
date: '*',
month: '*',

View file

@ -29,7 +29,6 @@ import { CronMonthly } from './cron_monthly';
import { CronWeekly } from './cron_weekly';
import { CronYearly } from './cron_yearly';
import { cronExpressionToParts, cronPartsToExpression } from './services';
import { convertFromEveryXMinute, convertToEveryXMinute } from './services/cron';
import { Frequency, Field, FieldToValueMap } from './types';
const excludeBlockListedFrequencies = (
@ -80,20 +79,14 @@ export class CronEditor extends Component<Props, State> {
}
onChangeFrequency = (frequency: Frequency) => {
const { onChange, fieldToPreferredValueMap, frequency: oldFrequency } = this.props;
const { onChange, fieldToPreferredValueMap } = this.props;
// Update fields which aren't editable with acceptable baseline values.
const editableFields = Object.keys(frequencyToFieldsMap[frequency]) as Field[];
const inheritedFields = editableFields.reduce<FieldToValueMap>(
(fieldBaselines, field) => {
if (fieldToPreferredValueMap[field] != null) {
if (oldFrequency === 'MINUTE') {
fieldBaselines[field] = convertFromEveryXMinute(fieldToPreferredValueMap[field]);
} else if (frequency === 'MINUTE') {
fieldBaselines[field] = convertToEveryXMinute(fieldToPreferredValueMap[field]);
} else {
fieldBaselines[field] = fieldToPreferredValueMap[field];
}
fieldBaselines[field] = fieldToPreferredValueMap[field];
}
return fieldBaselines;
},

View file

@ -56,18 +56,3 @@ export function cronPartsToExpression({
}: FieldToValueMap): string {
return `${second} ${minute} ${hour} ${date} ${month} ${day}`;
}
export function convertToEveryXMinute(
minute: FieldToValueMap['minute']
): FieldToValueMap['minute'] {
if (!minute) return minute;
if (minute.startsWith('*/')) return minute;
return '*/' + minute;
}
export function convertFromEveryXMinute(
minute: FieldToValueMap['minute']
): FieldToValueMap['minute'] {
if (!minute) return minute;
return minute.startsWith('*/') ? minute.slice(2) : minute;
}