diff --git a/.i18nrc.json b/.i18nrc.json
index 29d4bb6f0fa29..81f043a42e259 100644
--- a/.i18nrc.json
+++ b/.i18nrc.json
@@ -27,7 +27,8 @@
"tsvb": "src/legacy/core_plugins/metrics",
"kbnESQuery": "packages/kbn-es-query",
"inspector": "src/plugins/inspector",
- "kibana-react": "src/plugins/kibana_react"
+ "kibana-react": "src/plugins/kibana_react",
+ "esUi": "src/plugins/es_ui_shared"
},
"exclude": ["src/legacy/ui/ui_render/ui_render_mixin.js"],
"translations": []
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_daily.js b/src/plugins/es_ui_shared/public/components/cron_editor/cron_daily.js
similarity index 60%
rename from x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_daily.js
rename to src/plugins/es_ui_shared/public/components/cron_editor/cron_daily.js
index 8199ea8bf0b21..de14cd43165c2 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_daily.js
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/cron_daily.js
@@ -1,7 +1,20 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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, { Fragment } from 'react';
@@ -27,12 +40,12 @@ export const CronDaily = ({
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
@@ -45,13 +58,13 @@ export const CronDaily = ({
)}
- data-test-subj="rollupJobCreateFrequencyDailyHourSelect"
+ data-test-subj="cronFrequencyDailyHourSelect"
/>
@@ -68,7 +81,7 @@ export const CronDaily = ({
)}
- data-test-subj="rollupJobCreateFrequencyDailyMinuteSelect"
+ data-test-subj="cronFrequencyDailyMinuteSelect"
/>
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_editor.js b/src/plugins/es_ui_shared/public/components/cron_editor/cron_editor.js
similarity index 88%
rename from x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_editor.js
rename to src/plugins/es_ui_shared/public/components/cron_editor/cron_editor.js
index c0eb5bb624487..64d6405603dd7 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_editor.js
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/cron_editor.js
@@ -1,7 +1,20 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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, { Component, Fragment } from 'react';
@@ -27,7 +40,7 @@ import {
WEEK,
MONTH,
YEAR,
-} from '../../../../../services';
+} from './services';
import { CronHourly } from './cron_hourly';
import { CronDaily } from './cron_daily';
@@ -331,7 +344,7 @@ export class CronEditor extends Component {
)}
@@ -346,13 +359,13 @@ export class CronEditor extends Component {
)}
- data-test-subj="rollupJobCreateFrequencySelect"
+ data-test-subj="cronFrequencySelect"
/>
diff --git a/src/plugins/es_ui_shared/public/components/cron_editor/cron_hourly.js b/src/plugins/es_ui_shared/public/components/cron_editor/cron_hourly.js
new file mode 100644
index 0000000000000..a207998a7f73b
--- /dev/null
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/cron_hourly.js
@@ -0,0 +1,71 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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, { Fragment } from 'react';
+import PropTypes from 'prop-types';
+import { FormattedMessage } from '@kbn/i18n/react';
+
+import {
+ EuiFormRow,
+ EuiSelect,
+ EuiText,
+} from '@elastic/eui';
+
+export const CronHourly = ({
+ minute,
+ minuteOptions,
+ onChange,
+}) => (
+
+
+ )}
+ fullWidth
+ data-test-subj="cronFrequencyConfiguration"
+ >
+ onChange({ minute: e.target.value })}
+ fullWidth
+ prepend={(
+
+
+
+
+
+ )}
+ data-test-subj="cronFrequencyHourlyMinuteSelect"
+ />
+
+
+);
+
+CronHourly.propTypes = {
+ minute: PropTypes.string.isRequired,
+ minuteOptions: PropTypes.array.isRequired,
+ onChange: PropTypes.func.isRequired,
+};
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_monthly.js b/src/plugins/es_ui_shared/public/components/cron_editor/cron_monthly.js
similarity index 63%
rename from x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_monthly.js
rename to src/plugins/es_ui_shared/public/components/cron_editor/cron_monthly.js
index 52a7701e4422e..e90a194d83d93 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_monthly.js
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/cron_monthly.js
@@ -1,7 +1,20 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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, { Fragment } from 'react';
@@ -29,12 +42,12 @@ export const CronMonthly = ({
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
)}
- data-test-subj="rollupJobCreateFrequencyMonthlyDateSelect"
+ data-test-subj="cronFrequencyMonthlyDateSelect"
/>
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
@@ -76,13 +89,13 @@ export const CronMonthly = ({
)}
- data-test-subj="rollupJobCreateFrequencyMonthlyHourSelect"
+ data-test-subj="cronFrequencyMonthlyHourSelect"
/>
@@ -99,7 +112,7 @@ export const CronMonthly = ({
)}
- data-test-subj="rollupJobCreateFrequencyMonthlyMinuteSelect"
+ data-test-subj="cronFrequencyMonthlyMinuteSelect"
/>
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_weekly.js b/src/plugins/es_ui_shared/public/components/cron_editor/cron_weekly.js
similarity index 63%
rename from x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_weekly.js
rename to src/plugins/es_ui_shared/public/components/cron_editor/cron_weekly.js
index 8c41f366bb2be..fbf9e37e46b48 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_weekly.js
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/cron_weekly.js
@@ -1,7 +1,20 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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, { Fragment } from 'react';
@@ -29,12 +42,12 @@ export const CronWeekly = ({
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
)}
- data-test-subj="rollupJobCreateFrequencyWeeklyDaySelect"
+ data-test-subj="cronFrequencyWeeklyDaySelect"
/>
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
@@ -76,13 +89,13 @@ export const CronWeekly = ({
)}
- data-test-subj="rollupJobCreateFrequencyWeeklyHourSelect"
+ data-test-subj="cronFrequencyWeeklyHourSelect"
/>
@@ -99,7 +112,7 @@ export const CronWeekly = ({
)}
- data-test-subj="rollupJobCreateFrequencyWeeklyMinuteSelect"
+ data-test-subj="cronFrequencyWeeklyMinuteSelect"
/>
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_yearly.js b/src/plugins/es_ui_shared/public/components/cron_editor/cron_yearly.js
similarity index 65%
rename from x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_yearly.js
rename to src/plugins/es_ui_shared/public/components/cron_editor/cron_yearly.js
index 900e77f63accb..5e19ec7b35b0c 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_yearly.js
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/cron_yearly.js
@@ -1,7 +1,20 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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, { Fragment } from 'react';
@@ -31,12 +44,12 @@ export const CronYearly = ({
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
)}
- data-test-subj="rollupJobCreateFrequencyYearlyMonthSelect"
+ data-test-subj="cronFrequencyYearlyMonthSelect"
/>
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
)}
- data-test-subj="rollupJobCreateFrequencyYearlyDateSelect"
+ data-test-subj="cronFrequencyYearlyDateSelect"
/>
)}
fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
+ data-test-subj="cronFrequencyConfiguration"
>
@@ -107,13 +120,13 @@ export const CronYearly = ({
)}
- data-test-subj="rollupJobCreateFrequencyYearlyHourSelect"
+ data-test-subj="cronFrequencyYearlyHourSelect"
/>
@@ -130,7 +143,7 @@ export const CronYearly = ({
)}
- data-test-subj="rollupJobCreateFrequencyYearlyMinuteSelect"
+ data-test-subj="cronFrequencyYearlyMinuteSelect"
/>
diff --git a/src/plugins/es_ui_shared/public/components/cron_editor/index.d.ts b/src/plugins/es_ui_shared/public/components/cron_editor/index.d.ts
new file mode 100644
index 0000000000000..b318587057c76
--- /dev/null
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/index.d.ts
@@ -0,0 +1,26 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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.
+ */
+
+export declare const MINUTE: string;
+export declare const HOUR: string;
+export declare const DAY: string;
+export declare const WEEK: string;
+export declare const MONTH: string;
+export declare const YEAR: string;
+export declare const CronEditor: any;
diff --git a/src/plugins/es_ui_shared/public/components/cron_editor/index.js b/src/plugins/es_ui_shared/public/components/cron_editor/index.js
new file mode 100644
index 0000000000000..6c4539a6c3f75
--- /dev/null
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/index.js
@@ -0,0 +1,21 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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.
+ */
+
+export { CronEditor } from './cron_editor';
+export { MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from './services';
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/cron.js b/src/plugins/es_ui_shared/public/components/cron_editor/services/cron.js
similarity index 55%
rename from x-pack/legacy/plugins/rollup/public/crud_app/services/cron.js
rename to src/plugins/es_ui_shared/public/components/cron_editor/services/cron.js
index 97e474f8df27c..71f6253375ef1 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/services/cron.js
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/services/cron.js
@@ -1,7 +1,20 @@
/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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.
*/
export const MINUTE = 'MINUTE';
diff --git a/src/plugins/es_ui_shared/public/components/cron_editor/services/humanized_numbers.js b/src/plugins/es_ui_shared/public/components/cron_editor/services/humanized_numbers.js
new file mode 100644
index 0000000000000..b3cb58bea24e5
--- /dev/null
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/services/humanized_numbers.js
@@ -0,0 +1,91 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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 { i18n } from '@kbn/i18n';
+
+// The international ISO standard dictates Monday as the first day of the week, but cron patterns
+// use Sunday as the first day, so we're going with the cron way.
+const dayOrdinalToDayNameMap = {
+ 0: i18n.translate('esUi.cronEditor.day.sunday', { defaultMessage: 'Sunday' }),
+ 1: i18n.translate('esUi.cronEditor.day.monday', { defaultMessage: 'Monday' }),
+ 2: i18n.translate('esUi.cronEditor.day.tuesday', { defaultMessage: 'Tuesday' }),
+ 3: i18n.translate('esUi.cronEditor.day.wednesday', { defaultMessage: 'Wednesday' }),
+ 4: i18n.translate('esUi.cronEditor.day.thursday', { defaultMessage: 'Thursday' }),
+ 5: i18n.translate('esUi.cronEditor.day.friday', { defaultMessage: 'Friday' }),
+ 6: i18n.translate('esUi.cronEditor.day.saturday', { defaultMessage: 'Saturday' }),
+};
+
+const monthOrdinalToMonthNameMap = {
+ 0: i18n.translate('esUi.cronEditor.month.january', { defaultMessage: 'January' }),
+ 1: i18n.translate('esUi.cronEditor.month.february', { defaultMessage: 'February' }),
+ 2: i18n.translate('esUi.cronEditor.month.march', { defaultMessage: 'March' }),
+ 3: i18n.translate('esUi.cronEditor.month.april', { defaultMessage: 'April' }),
+ 4: i18n.translate('esUi.cronEditor.month.may', { defaultMessage: 'May' }),
+ 5: i18n.translate('esUi.cronEditor.month.june', { defaultMessage: 'June' }),
+ 6: i18n.translate('esUi.cronEditor.month.july', { defaultMessage: 'July' }),
+ 7: i18n.translate('esUi.cronEditor.month.august', { defaultMessage: 'August' }),
+ 8: i18n.translate('esUi.cronEditor.month.september', { defaultMessage: 'September' }),
+ 9: i18n.translate('esUi.cronEditor.month.october', { defaultMessage: 'October' }),
+ 10: i18n.translate('esUi.cronEditor.month.november', { defaultMessage: 'November' }),
+ 11: i18n.translate('esUi.cronEditor.month.december', { defaultMessage: 'December' }),
+};
+
+export function getOrdinalValue(number) {
+ // TODO: This is breaking reporting pdf generation. Possibly due to phantom not setting locale,
+ // which is needed by i18n (formatjs). Need to verify, fix, and restore i18n in place of static stings.
+ // return i18n.translate('esUi.cronEditor.number.ordinal', {
+ // defaultMessage: '{number, selectordinal, one{#st} two{#nd} few{#rd} other{#th}}',
+ // values: { number },
+ // });
+ // TODO: https://github.com/elastic/kibana/issues/27136
+
+ // Protects against falsey (including 0) values
+ const num = number && number.toString();
+ let lastDigit = num && num.substr(-1);
+ let ordinal;
+
+ if(!lastDigit) {
+ return number;
+ }
+ lastDigit = parseFloat(lastDigit);
+
+ switch(lastDigit) {
+ case 1:
+ ordinal = 'st';
+ break;
+ case 2:
+ ordinal = 'nd';
+ break;
+ case 3:
+ ordinal = 'rd';
+ break;
+ default:
+ ordinal = 'th';
+ }
+
+ return `${num}${ordinal}`;
+}
+
+export function getDayName(dayOrdinal) {
+ return dayOrdinalToDayNameMap[dayOrdinal];
+}
+
+export function getMonthName(monthOrdinal) {
+ return monthOrdinalToMonthNameMap[monthOrdinal];
+}
diff --git a/src/plugins/es_ui_shared/public/components/cron_editor/services/index.js b/src/plugins/es_ui_shared/public/components/cron_editor/services/index.js
new file mode 100644
index 0000000000000..cb4af15bf1945
--- /dev/null
+++ b/src/plugins/es_ui_shared/public/components/cron_editor/services/index.js
@@ -0,0 +1,21 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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.
+ */
+
+export * from './cron';
+export * from './humanized_numbers';
diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js
index 82911650bf37a..f392f16abc31d 100644
--- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js
+++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from '../../public/crud_app/services';
+import { MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from '../../../../../../src/plugins/es_ui_shared/public/components/cron_editor';
import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../../../src/legacy/ui/public/index_patterns';
import { setupEnvironment, pageHelpers } from './helpers';
@@ -162,7 +162,7 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('rollup cron', () => {
const changeFrequency = (value) => {
- find('rollupJobCreateFrequencySelect').simulate('change', { target: { value } });
+ find('cronFrequencySelect').simulate('change', { target: { value } });
};
const generateStringSequenceOfNumbers = (total) => (
@@ -171,7 +171,7 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('frequency', () => {
it('should allow "minute", "hour", "day", "week", "month", "year"', () => {
- const frequencySelect = find('rollupJobCreateFrequencySelect');
+ const frequencySelect = find('cronFrequencySelect');
const options = frequencySelect.find('option').map(option => option.text());
expect(options).toEqual(['minute', 'hour', 'day', 'week', 'month', 'year']);
});
@@ -179,7 +179,7 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('every minute', () => {
it('should not have any additional configuration', () => {
changeFrequency(MINUTE);
- expect(find('rollupCronFrequencyConfiguration').length).toBe(0);
+ expect(find('cronFrequencyConfiguration').length).toBe(0);
});
});
@@ -189,12 +189,12 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 1 additional configuration', () => {
- expect(find('rollupCronFrequencyConfiguration').length).toBe(1);
- expect(exists('rollupJobCreateFrequencyHourlyMinuteSelect')).toBe(true);
+ expect(find('cronFrequencyConfiguration').length).toBe(1);
+ expect(exists('cronFrequencyHourlyMinuteSelect')).toBe(true);
});
it('should allow to select any minute from 00 -> 59', () => {
- const minutSelect = find('rollupJobCreateFrequencyHourlyMinuteSelect');
+ const minutSelect = find('cronFrequencyHourlyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@@ -206,19 +206,19 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 1 additional configuration with hour and minute selects', () => {
- expect(find('rollupCronFrequencyConfiguration').length).toBe(1);
- expect(exists('rollupJobCreateFrequencyDailyHourSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyDailyMinuteSelect')).toBe(true);
+ expect(find('cronFrequencyConfiguration').length).toBe(1);
+ expect(exists('cronFrequencyDailyHourSelect')).toBe(true);
+ expect(exists('cronFrequencyDailyMinuteSelect')).toBe(true);
});
it('should allow to select any hour from 00 -> 23', () => {
- const hourSelect = find('rollupJobCreateFrequencyDailyHourSelect');
+ const hourSelect = find('cronFrequencyDailyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
- const minutSelect = find('rollupJobCreateFrequencyDailyMinuteSelect');
+ const minutSelect = find('cronFrequencyDailyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@@ -230,14 +230,14 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 2 additional configurations with day, hour and minute selects', () => {
- expect(find('rollupCronFrequencyConfiguration').length).toBe(2);
- expect(exists('rollupJobCreateFrequencyWeeklyDaySelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyWeeklyHourSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyWeeklyMinuteSelect')).toBe(true);
+ expect(find('cronFrequencyConfiguration').length).toBe(2);
+ expect(exists('cronFrequencyWeeklyDaySelect')).toBe(true);
+ expect(exists('cronFrequencyWeeklyHourSelect')).toBe(true);
+ expect(exists('cronFrequencyWeeklyMinuteSelect')).toBe(true);
});
it('should allow to select any day of the week', () => {
- const hourSelect = find('rollupJobCreateFrequencyWeeklyDaySelect');
+ const hourSelect = find('cronFrequencyWeeklyDaySelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual([
'Sunday',
@@ -251,13 +251,13 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should allow to select any hour from 00 -> 23', () => {
- const hourSelect = find('rollupJobCreateFrequencyWeeklyHourSelect');
+ const hourSelect = find('cronFrequencyWeeklyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
- const minutSelect = find('rollupJobCreateFrequencyWeeklyMinuteSelect');
+ const minutSelect = find('cronFrequencyWeeklyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@@ -269,26 +269,26 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 2 additional configurations with date, hour and minute selects', () => {
- expect(find('rollupCronFrequencyConfiguration').length).toBe(2);
- expect(exists('rollupJobCreateFrequencyMonthlyDateSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyMonthlyHourSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyMonthlyMinuteSelect')).toBe(true);
+ expect(find('cronFrequencyConfiguration').length).toBe(2);
+ expect(exists('cronFrequencyMonthlyDateSelect')).toBe(true);
+ expect(exists('cronFrequencyMonthlyHourSelect')).toBe(true);
+ expect(exists('cronFrequencyMonthlyMinuteSelect')).toBe(true);
});
it('should allow to select any date of the month from 1st to 31st', () => {
- const dateSelect = find('rollupJobCreateFrequencyMonthlyDateSelect');
+ const dateSelect = find('cronFrequencyMonthlyDateSelect');
const options = dateSelect.find('option').map(option => option.text());
expect(options.length).toEqual(31);
});
it('should allow to select any hour from 00 -> 23', () => {
- const hourSelect = find('rollupJobCreateFrequencyMonthlyHourSelect');
+ const hourSelect = find('cronFrequencyMonthlyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
- const minutSelect = find('rollupJobCreateFrequencyMonthlyMinuteSelect');
+ const minutSelect = find('cronFrequencyMonthlyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@@ -300,15 +300,15 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 3 additional configurations with month, date, hour and minute selects', () => {
- expect(find('rollupCronFrequencyConfiguration').length).toBe(3);
- expect(exists('rollupJobCreateFrequencyYearlyMonthSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyYearlyDateSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyYearlyHourSelect')).toBe(true);
- expect(exists('rollupJobCreateFrequencyYearlyMinuteSelect')).toBe(true);
+ expect(find('cronFrequencyConfiguration').length).toBe(3);
+ expect(exists('cronFrequencyYearlyMonthSelect')).toBe(true);
+ expect(exists('cronFrequencyYearlyDateSelect')).toBe(true);
+ expect(exists('cronFrequencyYearlyHourSelect')).toBe(true);
+ expect(exists('cronFrequencyYearlyMinuteSelect')).toBe(true);
});
it('should allow to select any month of the year', () => {
- const monthSelect = find('rollupJobCreateFrequencyYearlyMonthSelect');
+ const monthSelect = find('cronFrequencyYearlyMonthSelect');
const options = monthSelect.find('option').map(option => option.text());
expect(options).toEqual([
'January',
@@ -327,19 +327,19 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should allow to select any date of the month from 1st to 31st', () => {
- const dateSelect = find('rollupJobCreateFrequencyYearlyDateSelect');
+ const dateSelect = find('cronFrequencyYearlyDateSelect');
const options = dateSelect.find('option').map(option => option.text());
expect(options.length).toEqual(31);
});
it('should allow to select any hour from 00 -> 23', () => {
- const hourSelect = find('rollupJobCreateFrequencyYearlyHourSelect');
+ const hourSelect = find('cronFrequencyYearlyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
- const minutSelect = find('rollupJobCreateFrequencyYearlyMinuteSelect');
+ const minutSelect = find('cronFrequencyYearlyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_hourly.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_hourly.js
deleted file mode 100644
index bab1704d4e721..0000000000000
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/cron_editor/cron_hourly.js
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-import React, { Fragment } from 'react';
-import PropTypes from 'prop-types';
-import { FormattedMessage } from '@kbn/i18n/react';
-
-import {
- EuiFormRow,
- EuiSelect,
- EuiText,
-} from '@elastic/eui';
-
-export const CronHourly = ({
- minute,
- minuteOptions,
- onChange,
-}) => (
-
-
- )}
- fullWidth
- data-test-subj="rollupCronFrequencyConfiguration"
- >
- onChange({ minute: e.target.value })}
- fullWidth
- prepend={(
-
-
-
-
-
- )}
- data-test-subj="rollupJobCreateFrequencyHourlyMinuteSelect"
- />
-
-
-);
-
-CronHourly.propTypes = {
- minute: PropTypes.string.isRequired,
- minuteOptions: PropTypes.array.isRequired,
- onChange: PropTypes.func.isRequired,
-};
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/index.js
index e5c8eb2e2e17f..1efdcb7caec92 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/index.js
+++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/components/index.js
@@ -5,5 +5,4 @@
*/
export { FieldChooser } from './field_chooser';
-export { CronEditor } from './cron_editor';
export { StepError } from './step_error';
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js
index 382d1b7ccca47..62b0045395099 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js
+++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js
@@ -24,10 +24,12 @@ import {
EuiTitle,
} from '@elastic/eui';
+// eslint-disable-next-line @kbn/eslint/no-restricted-paths
+import { CronEditor } from '../../../../../../../../../src/plugins/es_ui_shared/public/components/cron_editor';
import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/index_patterns';
import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices';
import { logisticalDetailsUrl, cronUrl } from '../../../services';
-import { CronEditor, StepError } from './components';
+import { StepError } from './components';
const indexPatternIllegalCharacters = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.join(' ');
const indexIllegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' ');
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/index.js
index 09c427a49f028..db77844dcfe35 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/index.js
+++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/index.js
@@ -8,7 +8,8 @@ import cloneDeep from 'lodash/lang/cloneDeep';
import get from 'lodash/object/get';
import pick from 'lodash/object/pick';
-import { WEEK } from '../../../services';
+// eslint-disable-next-line @kbn/eslint/no-restricted-paths
+import { WEEK } from '../../../../../../../../../src/plugins/es_ui_shared/public/components/cron_editor';
import { validateId } from './validate_id';
import { validateIndexPattern } from './validate_index_pattern';
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/humanized_numbers.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/humanized_numbers.js
deleted file mode 100644
index ce779e62df926..0000000000000
--- a/x-pack/legacy/plugins/rollup/public/crud_app/services/humanized_numbers.js
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-import { i18n } from '@kbn/i18n';
-
-// The international ISO standard dictates Monday as the first day of the week, but cron patterns
-// use Sunday as the first day, so we're going with the cron way.
-const dayOrdinalToDayNameMap = {
- 0: i18n.translate('xpack.rollupJobs.util.day.sunday', { defaultMessage: 'Sunday' }),
- 1: i18n.translate('xpack.rollupJobs.util.day.monday', { defaultMessage: 'Monday' }),
- 2: i18n.translate('xpack.rollupJobs.util.day.tuesday', { defaultMessage: 'Tuesday' }),
- 3: i18n.translate('xpack.rollupJobs.util.day.wednesday', { defaultMessage: 'Wednesday' }),
- 4: i18n.translate('xpack.rollupJobs.util.day.thursday', { defaultMessage: 'Thursday' }),
- 5: i18n.translate('xpack.rollupJobs.util.day.friday', { defaultMessage: 'Friday' }),
- 6: i18n.translate('xpack.rollupJobs.util.day.saturday', { defaultMessage: 'Saturday' }),
-};
-
-const monthOrdinalToMonthNameMap = {
- 0: i18n.translate('xpack.rollupJobs.util.month.january', { defaultMessage: 'January' }),
- 1: i18n.translate('xpack.rollupJobs.util.month.february', { defaultMessage: 'February' }),
- 2: i18n.translate('xpack.rollupJobs.util.month.march', { defaultMessage: 'March' }),
- 3: i18n.translate('xpack.rollupJobs.util.month.april', { defaultMessage: 'April' }),
- 4: i18n.translate('xpack.rollupJobs.util.month.may', { defaultMessage: 'May' }),
- 5: i18n.translate('xpack.rollupJobs.util.month.june', { defaultMessage: 'June' }),
- 6: i18n.translate('xpack.rollupJobs.util.month.july', { defaultMessage: 'July' }),
- 7: i18n.translate('xpack.rollupJobs.util.month.august', { defaultMessage: 'August' }),
- 8: i18n.translate('xpack.rollupJobs.util.month.september', { defaultMessage: 'September' }),
- 9: i18n.translate('xpack.rollupJobs.util.month.october', { defaultMessage: 'October' }),
- 10: i18n.translate('xpack.rollupJobs.util.month.november', { defaultMessage: 'November' }),
- 11: i18n.translate('xpack.rollupJobs.util.month.december', { defaultMessage: 'December' }),
-};
-
-export function getOrdinalValue(number) {
- // TODO: This is breaking reporting pdf generation. Possibly due to phantom not setting locale,
- // which is needed by i18n (formatjs). Need to verify, fix, and restore i18n in place of static stings.
- // return i18n.translate('xpack.rollupJobs.util.number.ordinal', {
- // defaultMessage: '{number, selectordinal, one{#st} two{#nd} few{#rd} other{#th}}',
- // values: { number },
- // });
- // TODO: https://github.com/elastic/kibana/issues/27136
-
- // Protects against falsey (including 0) values
- const num = number && number.toString();
- let lastDigit = num && num.substr(-1);
- let ordinal;
-
- if(!lastDigit) {
- return number;
- }
- lastDigit = parseFloat(lastDigit);
-
- switch(lastDigit) {
- case 1:
- ordinal = 'st';
- break;
- case 2:
- ordinal = 'nd';
- break;
- case 3:
- ordinal = 'rd';
- break;
- default:
- ordinal = 'th';
- }
-
- return `${num}${ordinal}`;
-}
-
-export function getDayName(dayOrdinal) {
- return dayOrdinalToDayNameMap[dayOrdinal];
-}
-
-export function getMonthName(monthOrdinal) {
- return monthOrdinalToMonthNameMap[monthOrdinal];
-}
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js
index b3a7cdb9a286d..c52c9064b8d76 100644
--- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js
+++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js
@@ -23,17 +23,6 @@ export {
createBreadcrumb,
} from './breadcrumbs';
-export {
- cronExpressionToParts,
- cronPartsToExpression,
- MINUTE,
- HOUR,
- DAY,
- WEEK,
- MONTH,
- YEAR,
-} from './cron';
-
export {
logisticalDetailsUrl,
dateHistogramDetailsUrl,
@@ -61,12 +50,6 @@ export {
getHttp,
} from './http_provider';
-export {
- getOrdinalValue,
- getDayName,
- getMonthName,
-} from './humanized_numbers';
-
export {
serializeJob,
deserializeJob,
diff --git a/x-pack/legacy/plugins/snapshot_restore/common/constants.ts b/x-pack/legacy/plugins/snapshot_restore/common/constants.ts
index d876c6ffd581d..a881bf3081c5e 100644
--- a/x-pack/legacy/plugins/snapshot_restore/common/constants.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/common/constants.ts
@@ -53,3 +53,4 @@ export const APP_REQUIRED_CLUSTER_PRIVILEGES = [
'cluster:admin/repository',
];
export const APP_RESTORE_INDEX_PRIVILEGES = ['monitor'];
+export const APP_SLM_CLUSTER_PRIVILEGES = ['manage_slm'];
diff --git a/x-pack/legacy/plugins/snapshot_restore/common/lib/index.ts b/x-pack/legacy/plugins/snapshot_restore/common/lib/index.ts
index 0092d37b74a20..bede2689bb855 100644
--- a/x-pack/legacy/plugins/snapshot_restore/common/lib/index.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/common/lib/index.ts
@@ -8,3 +8,9 @@ export {
deserializeRestoreSettings,
serializeRestoreSettings,
} from './restore_settings_serialization';
+export {
+ deserializeSnapshotDetails,
+ deserializeSnapshotConfig,
+ serializeSnapshotConfig,
+} from './snapshot_serialization';
+export { deserializePolicy, serializePolicy } from './policy_serialization';
diff --git a/x-pack/legacy/plugins/snapshot_restore/server/lib/policy_serialization.test.ts b/x-pack/legacy/plugins/snapshot_restore/common/lib/policy_serialization.test.ts
similarity index 100%
rename from x-pack/legacy/plugins/snapshot_restore/server/lib/policy_serialization.test.ts
rename to x-pack/legacy/plugins/snapshot_restore/common/lib/policy_serialization.test.ts
diff --git a/x-pack/legacy/plugins/snapshot_restore/server/lib/policy_serialization.ts b/x-pack/legacy/plugins/snapshot_restore/common/lib/policy_serialization.ts
similarity index 70%
rename from x-pack/legacy/plugins/snapshot_restore/server/lib/policy_serialization.ts
rename to x-pack/legacy/plugins/snapshot_restore/common/lib/policy_serialization.ts
index 5abbc4270ec2f..dc52765670540 100644
--- a/x-pack/legacy/plugins/snapshot_restore/server/lib/policy_serialization.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/common/lib/policy_serialization.ts
@@ -3,8 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import { SlmPolicy, SlmPolicyEs } from '../../common/types';
-import { deserializeSnapshotConfig } from './';
+import { SlmPolicy, SlmPolicyEs, SlmPolicyPayload } from '../types';
+import { deserializeSnapshotConfig, serializeSnapshotConfig } from './';
export const deserializePolicy = (name: string, esPolicy: SlmPolicyEs): SlmPolicy => {
const {
@@ -16,6 +16,7 @@ export const deserializePolicy = (name: string, esPolicy: SlmPolicyEs): SlmPolic
next_execution_millis: nextExecutionMillis,
last_failure: lastFailure,
last_success: lastSuccess,
+ in_progress: inProgress,
} = esPolicy;
const policy: SlmPolicy = {
@@ -26,11 +27,14 @@ export const deserializePolicy = (name: string, esPolicy: SlmPolicyEs): SlmPolic
snapshotName,
schedule,
repository,
- config: deserializeSnapshotConfig(config),
nextExecution,
nextExecutionMillis,
};
+ if (config) {
+ policy.config = deserializeSnapshotConfig(config);
+ }
+
if (lastFailure) {
const {
snapshot_name: failureSnapshotName,
@@ -70,5 +74,28 @@ export const deserializePolicy = (name: string, esPolicy: SlmPolicyEs): SlmPolic
};
}
+ if (inProgress) {
+ const { name: inProgressSnapshotName } = inProgress;
+
+ policy.inProgress = {
+ snapshotName: inProgressSnapshotName,
+ };
+ }
+
return policy;
};
+
+export const serializePolicy = (policy: SlmPolicyPayload): SlmPolicyEs['policy'] => {
+ const { snapshotName: name, schedule, repository, config } = policy;
+ const policyEs: SlmPolicyEs['policy'] = {
+ name,
+ schedule,
+ repository,
+ };
+
+ if (config) {
+ policyEs.config = serializeSnapshotConfig(config);
+ }
+
+ return policyEs;
+};
diff --git a/x-pack/legacy/plugins/snapshot_restore/server/lib/snapshot_serialization.test.ts b/x-pack/legacy/plugins/snapshot_restore/common/lib/snapshot_serialization.test.ts
similarity index 100%
rename from x-pack/legacy/plugins/snapshot_restore/server/lib/snapshot_serialization.test.ts
rename to x-pack/legacy/plugins/snapshot_restore/common/lib/snapshot_serialization.test.ts
diff --git a/x-pack/legacy/plugins/snapshot_restore/server/lib/snapshot_serialization.ts b/x-pack/legacy/plugins/snapshot_restore/common/lib/snapshot_serialization.ts
similarity index 80%
rename from x-pack/legacy/plugins/snapshot_restore/server/lib/snapshot_serialization.ts
rename to x-pack/legacy/plugins/snapshot_restore/common/lib/snapshot_serialization.ts
index 608d85cf8840b..b1f6d2005a2e3 100644
--- a/x-pack/legacy/plugins/snapshot_restore/server/lib/snapshot_serialization.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/common/lib/snapshot_serialization.ts
@@ -6,12 +6,7 @@
import { sortBy } from 'lodash';
-import {
- SnapshotDetails,
- SnapshotDetailsEs,
- SnapshotConfig,
- SnapshotConfigEs,
-} from '../../common/types';
+import { SnapshotDetails, SnapshotDetailsEs, SnapshotConfig, SnapshotConfigEs } from '../types';
export function deserializeSnapshotDetails(
repository: string,
@@ -114,3 +109,22 @@ export function deserializeSnapshotConfig(snapshotConfigEs: SnapshotConfigEs): S
return config;
}, {});
}
+
+export function serializeSnapshotConfig(snapshotConfig: SnapshotConfig): SnapshotConfigEs {
+ const { indices, ignoreUnavailable, includeGlobalState, partial, metadata } = snapshotConfig;
+
+ const snapshotConfigEs: SnapshotConfigEs = {
+ indices,
+ ignore_unavailable: ignoreUnavailable,
+ include_global_state: includeGlobalState,
+ partial,
+ metadata,
+ };
+
+ return Object.entries(snapshotConfigEs).reduce((config: any, [key, value]) => {
+ if (value !== undefined) {
+ config[key] = value;
+ }
+ return config;
+ }, {});
+}
diff --git a/x-pack/legacy/plugins/snapshot_restore/common/types/policy.ts b/x-pack/legacy/plugins/snapshot_restore/common/types/policy.ts
index 54d17e853cc87..888cad13d213b 100644
--- a/x-pack/legacy/plugins/snapshot_restore/common/types/policy.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/common/types/policy.ts
@@ -6,15 +6,18 @@
import { SnapshotConfig, SnapshotConfigEs } from './snapshot';
-export interface SlmPolicy {
+export interface SlmPolicyPayload {
name: string;
- version: number;
- modifiedDate: string;
- modifiedDateMillis: number;
snapshotName: string;
schedule: string;
repository: string;
- config: SnapshotConfig;
+ config?: SnapshotConfig;
+}
+
+export interface SlmPolicy extends SlmPolicyPayload {
+ version: number;
+ modifiedDate: string;
+ modifiedDateMillis: number;
nextExecution: string;
nextExecutionMillis: number;
lastSuccess?: {
@@ -28,6 +31,9 @@ export interface SlmPolicy {
time: number;
details: object | string;
};
+ inProgress?: {
+ snapshotName: string;
+ };
}
export interface SlmPolicyEs {
@@ -38,7 +44,7 @@ export interface SlmPolicyEs {
name: string;
schedule: string;
repository: string;
- config: SnapshotConfigEs;
+ config?: SnapshotConfigEs;
};
next_execution: string;
next_execution_millis: number;
@@ -53,4 +59,11 @@ export interface SlmPolicyEs {
time: number;
details: string;
};
+ in_progress?: {
+ name: string;
+ uuid: string;
+ state: string;
+ start_time: string;
+ start_time_millis: number;
+ };
}
diff --git a/x-pack/legacy/plugins/snapshot_restore/common/types/snapshot.ts b/x-pack/legacy/plugins/snapshot_restore/common/types/snapshot.ts
index c896336cc943b..dd561bd50d352 100644
--- a/x-pack/legacy/plugins/snapshot_restore/common/types/snapshot.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/common/types/snapshot.ts
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
export interface SnapshotConfig {
- indices?: string[];
+ indices?: string | string[];
ignoreUnavailable?: boolean;
includeGlobalState?: boolean;
partial?: boolean;
@@ -14,7 +14,7 @@ export interface SnapshotConfig {
}
export interface SnapshotConfigEs {
- indices?: string[];
+ indices?: string | string[];
ignore_unavailable?: boolean;
include_global_state?: boolean;
partial?: boolean;
diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/app.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/app.tsx
index 207044c4692fd..764c50bc47721 100644
--- a/x-pack/legacy/plugins/snapshot_restore/public/app/app.tsx
+++ b/x-pack/legacy/plugins/snapshot_restore/public/app/app.tsx
@@ -8,9 +8,17 @@ import React, { useContext } from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
import { EuiPageContent } from '@elastic/eui';
+import { APP_REQUIRED_CLUSTER_PRIVILEGES } from '../../common/constants';
import { SectionLoading, SectionError } from './components';
import { BASE_PATH, DEFAULT_SECTION, Section } from './constants';
-import { RepositoryAdd, RepositoryEdit, RestoreSnapshot, SnapshotRestoreHome } from './sections';
+import {
+ RepositoryAdd,
+ RepositoryEdit,
+ RestoreSnapshot,
+ SnapshotRestoreHome,
+ PolicyAdd,
+ PolicyEdit,
+} from './sections';
import { useAppDependencies } from './index';
import { AuthorizationContext, WithPrivileges, NotAuthorizedSection } from './lib/authorization';
@@ -36,7 +44,7 @@ export const App: React.FunctionComponent = () => {
error={apiError}
/>
) : (
-
+ `cluster.${name}`)}>
{({ isLoading, hasPrivileges, privilegesMissing }) =>
isLoading ? (
@@ -69,6 +77,8 @@ export const App: React.FunctionComponent = () => {
path={`${BASE_PATH}/restore/:repositoryName/:snapshotId*`}
component={RestoreSnapshot}
/>
+
+
diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts b/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts
index a017299a78914..a367e529cf63b 100644
--- a/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts
+++ b/x-pack/legacy/plugins/snapshot_restore/public/app/components/index.ts
@@ -16,3 +16,4 @@ export { SnapshotDeleteProvider } from './snapshot_delete_provider';
export { RestoreSnapshotForm } from './restore_snapshot_form';
export { PolicyExecuteProvider } from './policy_execute_provider';
export { PolicyDeleteProvider } from './policy_delete_provider';
+export { PolicyForm } from './policy_form';
diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/components/policy_execute_provider.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/components/policy_execute_provider.tsx
index 3df081e9c9dba..c43ab02801e4e 100644
--- a/x-pack/legacy/plugins/snapshot_restore/public/app/components/policy_execute_provider.tsx
+++ b/x-pack/legacy/plugins/snapshot_restore/public/app/components/policy_execute_provider.tsx
@@ -87,7 +87,7 @@ export const PolicyExecuteProvider: React.FunctionComponent = ({ children
title={
}
@@ -102,18 +102,11 @@ export const PolicyExecuteProvider: React.FunctionComponent = ({ children
confirmButtonText={
}
data-test-subj="srExecutePolicyConfirmationModal"
- >
-