diff --git a/kibana-reports/public/components/report_definitions/report_settings/__tests__/report_settings_helpers.test.tsx b/kibana-reports/public/components/report_definitions/report_settings/__tests__/report_settings_helpers.test.tsx index ff41762e..cd9dd46f 100644 --- a/kibana-reports/public/components/report_definitions/report_settings/__tests__/report_settings_helpers.test.tsx +++ b/kibana-reports/public/components/report_definitions/report_settings/__tests__/report_settings_helpers.test.tsx @@ -24,6 +24,8 @@ import { parseInContextUrl, } from '../report_settings_helpers'; +const TEST_DEFINITION_ID = '12345'; + describe('report_settings_helpers tests', () => { test('parseInContextUrl', () => { const urlString = @@ -43,26 +45,42 @@ describe('report_settings_helpers tests', () => { }); test('getDashboardBaseUrlCreate', () => { - const baseUrl = getDashboardBaseUrlCreate(true, '12345', true); + const baseUrl = getDashboardBaseUrlCreate(true, TEST_DEFINITION_ID, true); expect(baseUrl).toBe('/app/dashboards#/view/'); - const baseUrlNotFromEdit = getDashboardBaseUrlCreate(false, '12345', true); + const baseUrlNotFromEdit = getDashboardBaseUrlCreate( + false, + TEST_DEFINITION_ID, + true + ); expect(baseUrlNotFromEdit).toBe('/app/dashboards#/view/'); }); test('getVisualizationBaseUrlCreate', () => { - const baseUrl = getVisualizationBaseUrlCreate(true, true); + const baseUrl = getVisualizationBaseUrlCreate( + true, + TEST_DEFINITION_ID, + true + ); expect(baseUrl).toBe('/app/visualize#/edit/'); - const baseUrlNotFromEdit = getVisualizationBaseUrlCreate(false, true); + const baseUrlNotFromEdit = getVisualizationBaseUrlCreate( + false, + TEST_DEFINITION_ID, + true + ); expect(baseUrlNotFromEdit).toBe('/app/visualize#/edit/'); }); test('getSavedSearchBaseUrlCreate', () => { - const baseUrl = getSavedSearchBaseUrlCreate(true, true); + const baseUrl = getSavedSearchBaseUrlCreate(true, TEST_DEFINITION_ID, true); expect(baseUrl).toBe('/app/discover#/view/'); - const baseUrlNotFromEdit = getSavedSearchBaseUrlCreate(false, true); + const baseUrlNotFromEdit = getSavedSearchBaseUrlCreate( + false, + TEST_DEFINITION_ID, + true + ); expect(baseUrlNotFromEdit).toBe('/app/discover#/view/'); }); diff --git a/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx b/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx index 740134de..54911246 100644 --- a/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx +++ b/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx @@ -140,7 +140,7 @@ export function ReportSettings(props: ReportSettingProps) { } else if (e === 'visualizationReportSource') { reportDefinitionRequest.report_params.report_source = 'Visualization'; reportDefinitionRequest.report_params.core_params.base_url = - getVisualizationBaseUrlCreate(edit, fromInContext) + + getVisualizationBaseUrlCreate(edit, editDefinitionId, fromInContext) + visualizations[0].value; // set params to visual report params after switch from saved search @@ -150,7 +150,7 @@ export function ReportSettings(props: ReportSettingProps) { } else if (e === 'savedSearchReportSource') { reportDefinitionRequest.report_params.report_source = 'Saved search'; reportDefinitionRequest.report_params.core_params.base_url = - getSavedSearchBaseUrlCreate(edit, fromInContext) + + getSavedSearchBaseUrlCreate(edit, editDefinitionId, fromInContext) + savedSearches[0].value; reportDefinitionRequest.report_params.core_params.saved_search_id = savedSearches[0].value; @@ -182,7 +182,8 @@ export function ReportSettings(props: ReportSettingProps) { fromInContext = true; } reportDefinitionRequest.report_params.core_params.base_url = - getVisualizationBaseUrlCreate(edit, fromInContext) + e.target.value; + getVisualizationBaseUrlCreate(edit, editDefinitionId, fromInContext) + + e.target.value; }; const handleSavedSearchSelect = (e: { @@ -191,6 +192,14 @@ export function ReportSettings(props: ReportSettingProps) { setSavedSearchSourceSelect(e.target.value); reportDefinitionRequest.report_params.core_params.saved_search_id = e.target.value; + + let fromInContext = false; + if (window.location.href.includes('?')) { + fromInContext = true; + } + reportDefinitionRequest.report_params.core_params.base_url = + getSavedSearchBaseUrlCreate(edit, editDefinitionId, fromInContext) + + e.target.value; }; const handleFileFormat = (e: React.SetStateAction) => { @@ -457,7 +466,7 @@ export function ReportSettings(props: ReportSettingProps) { REPORT_SOURCE_RADIOS[1].label; setVisualizationSourceSelect(id); reportDefinitionRequest.report_params.core_params.base_url = - getVisualizationBaseUrlCreate(edit, true) + id; + getVisualizationBaseUrlCreate(edit, editDefinitionId, true) + id; } else if (url.includes('discover')) { setReportSourceId('savedSearchReportSource'); reportDefinitionRequest.report_params.core_params.report_format = 'csv'; @@ -466,7 +475,7 @@ export function ReportSettings(props: ReportSettingProps) { REPORT_SOURCE_RADIOS[2].label; setSavedSearchSourceSelect(id); reportDefinitionRequest.report_params.core_params.base_url = - getSavedSearchBaseUrlCreate(edit, true) + id; + getSavedSearchBaseUrlCreate(edit, editDefinitionId, true) + id; } }; diff --git a/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx b/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx index f32708c0..98982718 100644 --- a/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx +++ b/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx @@ -52,6 +52,7 @@ export const getDashboardBaseUrlCreate = ( export const getVisualizationBaseUrlCreate = ( edit: boolean, + editDefinitionId: string, fromInContext: boolean ) => { let baseUrl; @@ -62,7 +63,7 @@ export const getVisualizationBaseUrlCreate = ( } if (edit) { return baseUrl.replace( - 'opendistro_kibana_reports#/edit', + `opendistro_kibana_reports#/edit/${editDefinitionId}`, 'visualize#/edit/' ); } else if (fromInContext) { @@ -76,6 +77,7 @@ export const getVisualizationBaseUrlCreate = ( export const getSavedSearchBaseUrlCreate = ( edit: boolean, + editDefinitionId: string, fromInContext: boolean ) => { let baseUrl; @@ -86,7 +88,7 @@ export const getSavedSearchBaseUrlCreate = ( } if (edit) { return baseUrl.replace( - 'opendistro_kibana_reports#/edit', + `opendistro_kibana_reports#/edit/${editDefinitionId}`, 'discover#/view/' ); } else if (fromInContext) { diff --git a/kibana-reports/target/public/.kbn-optimizer-cache b/kibana-reports/target/public/.kbn-optimizer-cache index bf4c0f62..f3630dbe 100644 --- a/kibana-reports/target/public/.kbn-optimizer-cache +++ b/kibana-reports/target/public/.kbn-optimizer-cache @@ -90,7 +90,7 @@ "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/context_menu/context_menu.js": 1605143590359.2415, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/main_utils.tsx": 1605048331306.86, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/main.tsx": 1605200994044.0496, - "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_definition_details/report_definition_details.tsx": 1605211619125.6868, + "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_definition_details/report_definition_details.tsx": 1605213302571.7976, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_definitions_table.tsx": 1605047966680.2158, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_details/report_details.tsx": 1605138071515.7131, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/reports_table.tsx": 1605047966683.0679, @@ -99,11 +99,11 @@ "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/delivery/delivery.tsx": 1605047966689.483, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/delivery/email.tsx": 1605048331312.1157, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/delivery/index.ts": 1605047966691.1199, - "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/edit/edit_report_definition.tsx": 1605138071517.7808, + "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/edit/edit_report_definition.tsx": 1605221773260.5664, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/index.ts": 1605047966697.278, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_constants.tsx": 1605047966698.8801, - "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx": 1605125632993.7512, - "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx": 1605047966698.138, + "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx": 1605224950291.7615, + "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx": 1605224964873.8975, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/time_range.tsx": 1605047966700.3855, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_trigger/index.ts": 1605047966702.629, "/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_trigger/report_trigger_constants.tsx": 1605125243795.44, diff --git a/kibana-reports/target/public/1.plugin.js b/kibana-reports/target/public/1.plugin.js index d8682942..02113053 100644 --- a/kibana-reports/target/public/1.plugin.js +++ b/kibana-reports/target/public/1.plugin.js @@ -2231,6 +2231,7 @@ function EditReportDefinition(props) { }; const editReportDefinition = async metadata => { + console.log('metadata is', metadata); const { httpClient } = props; @@ -2473,13 +2474,13 @@ function ReportSettings(props) { setFileFormat('pdf'); } else if (e === 'visualizationReportSource') { reportDefinitionRequest.report_params.report_source = 'Visualization'; - reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getVisualizationBaseUrlCreate"])(edit, fromInContext) + visualizations[0].value; // set params to visual report params after switch from saved search + reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getVisualizationBaseUrlCreate"])(edit, editDefinitionId, fromInContext) + visualizations[0].value; // set params to visual report params after switch from saved search Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["handleDataToVisualReportSourceChange"])(reportDefinitionRequest); setFileFormat('pdf'); } else if (e === 'savedSearchReportSource') { reportDefinitionRequest.report_params.report_source = 'Saved search'; - reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getSavedSearchBaseUrlCreate"])(edit, fromInContext) + savedSearches[0].value; + reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getSavedSearchBaseUrlCreate"])(edit, editDefinitionId, fromInContext) + savedSearches[0].value; reportDefinitionRequest.report_params.core_params.saved_search_id = savedSearches[0].value; reportDefinitionRequest.report_params.core_params.report_format = 'csv'; reportDefinitionRequest.report_params.core_params.limit = 10000; @@ -2506,12 +2507,19 @@ function ReportSettings(props) { fromInContext = true; } - reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getVisualizationBaseUrlCreate"])(edit, fromInContext) + e.target.value; + reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getVisualizationBaseUrlCreate"])(edit, editDefinitionId, fromInContext) + e.target.value; }; const handleSavedSearchSelect = e => { setSavedSearchSourceSelect(e.target.value); reportDefinitionRequest.report_params.core_params.saved_search_id = e.target.value; + let fromInContext = false; + + if (window.location.href.includes('?')) { + fromInContext = true; + } + + reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getSavedSearchBaseUrlCreate"])(edit, editDefinitionId, fromInContext) + e.target.value; }; const handleFileFormat = e => { @@ -2725,14 +2733,14 @@ function ReportSettings(props) { setReportSourceId('visualizationReportSource'); reportDefinitionRequest.report_params.report_source = _report_settings_constants__WEBPACK_IMPORTED_MODULE_2__["REPORT_SOURCE_RADIOS"][1].label; setVisualizationSourceSelect(id); - reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getVisualizationBaseUrlCreate"])(edit, true) + id; + reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getVisualizationBaseUrlCreate"])(edit, editDefinitionId, true) + id; } else if (url.includes('discover')) { setReportSourceId('savedSearchReportSource'); reportDefinitionRequest.report_params.core_params.report_format = 'csv'; reportDefinitionRequest.report_params.core_params.saved_search_id = id; reportDefinitionRequest.report_params.report_source = _report_settings_constants__WEBPACK_IMPORTED_MODULE_2__["REPORT_SOURCE_RADIOS"][2].label; setSavedSearchSourceSelect(id); - reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getSavedSearchBaseUrlCreate"])(edit, true) + id; + reportDefinitionRequest.report_params.core_params.base_url = Object(_report_settings_helpers__WEBPACK_IMPORTED_MODULE_5__["getSavedSearchBaseUrlCreate"])(edit, editDefinitionId, true) + id; } }; @@ -2998,7 +3006,7 @@ const getDashboardBaseUrlCreate = (edit, editDefinitionId, fromInContext) => { return baseUrl.replace('opendistro_kibana_reports#/create', 'dashboards#/view/'); }; -const getVisualizationBaseUrlCreate = (edit, fromInContext) => { +const getVisualizationBaseUrlCreate = (edit, editDefinitionId, fromInContext) => { let baseUrl; if (!fromInContext) { @@ -3008,14 +3016,14 @@ const getVisualizationBaseUrlCreate = (edit, fromInContext) => { } if (edit) { - return baseUrl.replace('opendistro_kibana_reports#/edit', 'visualize#/edit/'); + return baseUrl.replace(`opendistro_kibana_reports#/edit/${editDefinitionId}`, 'visualize#/edit/'); } else if (fromInContext) { return baseUrl; } return baseUrl.replace('opendistro_kibana_reports#/create', 'visualize#/edit/'); }; -const getSavedSearchBaseUrlCreate = (edit, fromInContext) => { +const getSavedSearchBaseUrlCreate = (edit, editDefinitionId, fromInContext) => { let baseUrl; if (!fromInContext) { @@ -3025,7 +3033,7 @@ const getSavedSearchBaseUrlCreate = (edit, fromInContext) => { } if (edit) { - return baseUrl.replace('opendistro_kibana_reports#/edit', 'discover#/view/'); + return baseUrl.replace(`opendistro_kibana_reports#/edit/${editDefinitionId}`, 'discover#/view/'); } else if (fromInContext) { return baseUrl; } diff --git a/kibana-reports/target/public/1.plugin.js.map b/kibana-reports/target/public/1.plugin.js.map index f226b6dd..cae06de2 100644 --- a/kibana-reports/target/public/1.plugin.js.map +++ b/kibana-reports/target/public/1.plugin.js.map @@ -1 +1 @@ -{"version":3,"file":"1.plugin.js","sources":["/plugin:opendistroKibanaReports/plugins/kibana-reports/public/application.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/app.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/main.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/report_definition_details/report_definition_details.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/report_definitions_table.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/report_details/report_details.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/reports_table.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/create/create_report_definition.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/delivery.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/delivery_constants.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/email.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/index.ts","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/edit/edit_report_definition.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/index.ts","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_constants.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/time_range.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/index.ts","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/report_trigger_constants.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/timezone.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/utils/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport { OpendistroKibanaReportsApp } from './components/app';\nexport const renderApp = ({\n notifications,\n http,\n chrome\n}, {\n navigation\n}, {\n appBasePath,\n element\n}) => {\n ReactDOM.render( /*#__PURE__*/React.createElement(OpendistroKibanaReportsApp, {\n basename: appBasePath,\n notifications: notifications,\n http: http,\n navigation: navigation,\n chrome: chrome\n }), element);\n return () => ReactDOM.unmountComponentAtNode(element);\n};","function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\n/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React from 'react';\nimport { I18nProvider } from '@kbn/i18n/react';\nimport { HashRouter as Router, Route, Switch } from 'react-router-dom';\nimport { EuiPage, EuiPageBody, EuiPageContentBody, EuiPageContentHeader, EuiPageContentHeaderSection } from '@elastic/eui';\nimport { CreateReport } from './report_definitions/create/create_report_definition';\nimport { Main } from './main/main';\nimport { ReportDetails } from './main/report_details/report_details';\nimport { ReportDefinitionDetails } from './main/report_definition_details/report_definition_details';\nimport { EditReportDefinition } from './report_definitions/edit/edit_report_definition';\nconst styles = {\n float: 'left',\n width: \"100%\",\n maxWidth: '1600px'\n};\nexport const OpendistroKibanaReportsApp = ({\n basename,\n notifications,\n http,\n navigation,\n chrome\n}) => {\n // Render the application DOM.\n return /*#__PURE__*/React.createElement(Router, {\n basename: '/' + basename\n }, /*#__PURE__*/React.createElement(I18nProvider, null, /*#__PURE__*/React.createElement(\"div\", {\n style: styles\n }, /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiPageContentHeader, null, /*#__PURE__*/React.createElement(EuiPageContentHeaderSection, null)), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(Switch, null, /*#__PURE__*/React.createElement(Route, {\n path: \"/report_details/:reportId\",\n render: props => /*#__PURE__*/React.createElement(ReportDetails, _extends({\n title: \"Report Details\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/report_definition_details/:reportDefinitionId\",\n render: props => /*#__PURE__*/React.createElement(ReportDefinitionDetails, _extends({\n title: \"Report Definition Details\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/create\",\n render: props => /*#__PURE__*/React.createElement(CreateReport, _extends({\n title: \"Create Report\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/edit/:reportDefinitionId\",\n render: props => /*#__PURE__*/React.createElement(EditReportDefinition, _extends({\n title: \"Edit Report Definition\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/\",\n render: props => /*#__PURE__*/React.createElement(Main, _extends({\n title: \"Reporting Homepage\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }))))))));\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useState, useEffect } from 'react';\nimport { EuiFlexGroup, EuiFlexItem, EuiButton, EuiTitle // @ts-ignore\n, EuiHorizontalRule, EuiSpacer, EuiPanel, EuiGlobalToastList } from '@elastic/eui';\nimport { ReportsTable } from './reports_table';\nimport { ReportDefinitions } from './report_definitions_table';\nimport { addReportsTableContent, addReportDefinitionsTableContent } from './main_utils';\nconst reportCountStyles = {\n color: 'gray',\n display: 'inline'\n};\nexport function Main(props) {\n const [reportsTableContent, setReportsTableContent] = useState([]);\n const [reportDefinitionsTableContent, setReportDefinitionsTableContent] = useState([]);\n const [toasts, setToasts] = useState([]);\n\n const addReportsTableContentErrorToastHandler = () => {\n const errorToast = {\n title: 'Error generating reports table.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportsTableErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleReportsTableContentErrorToast = () => {\n addReportsTableContentErrorToastHandler();\n };\n\n const addReportDefinitionsTableErrorToastHandler = () => {\n const errorToast = {\n title: 'Error generating report definitions table.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportDefinitionsTableErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleReportDefinitionsTableErrorToast = () => {\n addReportDefinitionsTableErrorToastHandler();\n };\n\n const addErrorOnDemandDownloadToastHandler = () => {\n const errorToast = {\n title: 'Error downloading report.',\n color: 'danger',\n iconType: 'alert',\n id: 'onDemandDownloadErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleOnDemandDownloadErrorToast = () => {\n addErrorOnDemandDownloadToastHandler();\n };\n\n const addSuccessOnDemandDownloadToastHandler = () => {\n const successToast = {\n title: 'Successfully downloaded report.',\n color: 'success',\n iconType: 'check',\n id: 'onDemandDownloadSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleOnDemandDownloadSuccessToast = () => {\n addSuccessOnDemandDownloadToastHandler();\n };\n\n const addCreateReportDefinitionSuccessToastHandler = () => {\n const successToast = {\n title: 'Successfully created report definition.',\n color: 'success',\n iconType: 'check',\n id: 'createReportDefinitionSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleCreateReportDefinitionSuccessToast = () => {\n addCreateReportDefinitionSuccessToastHandler();\n };\n\n const addEditReportDefinitionSuccessToastHandler = () => {\n const successToast = {\n title: 'Successfully updated report definition.',\n color: 'success',\n iconType: 'check',\n id: 'editReportDefinitionSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleEditReportDefinitionSuccessToast = () => {\n addEditReportDefinitionSuccessToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const pagination = {\n initialPageSize: 10,\n pageSizeOptions: [8, 10, 13]\n };\n useEffect(() => {\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }]);\n refreshReportsTable();\n refreshReportsDefinitionsTable();\n\n if (window.location.href.includes('create=success')) {\n handleCreateReportDefinitionSuccessToast(); // refresh might not fetch the latest changes when coming from create or edit page\n // workaround to wait 1 second and refresh again\n\n setTimeout(() => {\n refreshReportsTable();\n refreshReportsDefinitionsTable();\n }, 1000);\n } else if (window.location.href.includes('edit=success')) {\n handleEditReportDefinitionSuccessToast();\n setTimeout(() => {\n refreshReportsTable();\n refreshReportsDefinitionsTable();\n }, 1000);\n }\n\n window.location.href = 'opendistro_kibana_reports#/';\n }, []);\n\n const refreshReportsTable = async () => {\n const {\n httpClient\n } = props;\n await httpClient.get('../api/reporting/reports').then(response => {\n setReportsTableContent(addReportsTableContent(response.data));\n }).catch(error => {\n console.log('error when fetching all reports: ', error);\n handleReportsTableContentErrorToast();\n });\n };\n\n const refreshReportsDefinitionsTable = async () => {\n const {\n httpClient\n } = props;\n await httpClient.get('../api/reporting/reportDefinitions').then(response => {\n setReportDefinitionsTableContent(addReportDefinitionsTableContent(response.data));\n }).catch(error => {\n console.log('error when fetching all report definitions: ', error);\n handleReportDefinitionsTableErrorToast();\n });\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiPanel, {\n paddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"spaceEvenly\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Reports\", ' ', /*#__PURE__*/React.createElement(\"p\", {\n style: reportCountStyles\n }, \" (\", reportsTableContent.length, \")\")))), /*#__PURE__*/React.createElement(EuiFlexItem, {\n component: \"span\",\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n size: \"m\",\n onClick: refreshReportsTable\n }, \"Refresh\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(ReportsTable, {\n pagination: pagination,\n reportsTableItems: reportsTableContent,\n httpClient: props['httpClient'],\n handleSuccessToast: handleOnDemandDownloadSuccessToast,\n handleErrorToast: handleOnDemandDownloadErrorToast\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiPanel, {\n paddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"spaceEvenly\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Report definitions\", /*#__PURE__*/React.createElement(\"p\", {\n style: reportCountStyles\n }, ' ', \"(\", reportDefinitionsTableContent.length, \")\")))), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n onClick: refreshReportsDefinitionsTable\n }, \"Refresh\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n component: \"span\",\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => {\n window.location.assign('opendistro_kibana_reports#/create');\n },\n id: 'createReportHomepageButton'\n }, \"Create\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(ReportDefinitions, {\n pagination: pagination,\n reportDefinitionsTableContent: reportDefinitionsTableContent\n })), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n }));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiFlexGroup, EuiFlexItem, EuiPage, EuiPageHeader, EuiTitle, EuiPageBody, EuiPageContent, EuiHorizontalRule, EuiSpacer, EuiPageHeaderSection, EuiButton, EuiIcon, EuiLink, EuiGlobalToastList, EuiOverlayMask, EuiConfirmModal } from '@elastic/eui';\nimport { ReportDetailsComponent, formatEmails, trimAndRenderAsText } from '../report_details/report_details';\nimport { fileFormatsUpper, generateReport } from '../main_utils';\nimport moment from 'moment';\nimport { converter } from '../../report_definitions/utils';\nconst ON_DEMAND = 'On demand';\nexport function ReportDefinitionDetails(props) {\n const [reportDefinitionDetails, setReportDefinitionDetails] = useState({});\n const [reportDefinitionRawResponse, setReportDefinitionRawResponse] = useState({});\n const [toasts, setToasts] = useState([]);\n const [showDeleteModal, setShowDeleteModal] = useState(false);\n const reportDefinitionId = props.match['params']['reportDefinitionId'];\n\n const handleShowDeleteModal = e => {\n setShowDeleteModal(e);\n };\n\n const addErrorLoadingDetailsToastHandler = () => {\n const errorToast = {\n title: 'Error loading report definition details.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportDefinitionDetailsErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleDetailsErrorToast = () => {\n addErrorLoadingDetailsToastHandler();\n };\n\n const addSuccessGeneratingReportToastHandler = () => {\n const successToast = {\n title: 'Successfully generated report.',\n color: 'success',\n iconType: 'check',\n id: 'generateReportSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessGeneratingReportToast = () => {\n addSuccessGeneratingReportToastHandler();\n };\n\n const addErrorGeneratingReportToastHandler = () => {\n const errorToast = {\n title: 'Error generating report.',\n color: 'danger',\n iconType: 'alert',\n id: 'generateReportErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorGeneratingReportToast = () => {\n addErrorGeneratingReportToastHandler();\n };\n\n const addSuccessEnablingScheduleToastHandler = () => {\n const successToast = {\n title: 'Successfully enabled schedule.',\n color: 'success',\n iconType: 'check',\n id: 'successEnableToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessEnablingScheduleToast = () => {\n addSuccessEnablingScheduleToastHandler();\n };\n\n const addErrorEnablingScheduleToastHandler = () => {\n const errorToast = {\n title: 'Error enabling schedule.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorEnablingScheduleToast = () => {\n addErrorEnablingScheduleToastHandler();\n };\n\n const addSuccessDisablingScheduleToastHandler = () => {\n const successToast = {\n title: 'Successfully disabled schedule.',\n color: 'success',\n iconType: 'check',\n id: 'successDisableToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessDisablingScheduleToast = () => {\n addSuccessDisablingScheduleToastHandler();\n };\n\n const addErrorDisablingScheduleToastHandler = () => {\n const errorToast = {\n title: 'Error disabling schedule.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorDisableToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorDisablingScheduleToast = () => {\n addErrorDisablingScheduleToastHandler();\n };\n\n const addErrorDeletingReportDefinitionToastHandler = () => {\n const errorToast = {\n title: 'Error deleting report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorDeleteToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorDeletingReportDefinitionToast = () => {\n addErrorDeletingReportDefinitionToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const handleReportDefinitionDetails = e => {\n setReportDefinitionDetails(e);\n };\n\n const handleReportDefinitionRawResponse = e => {\n setReportDefinitionRawResponse(e);\n };\n\n const DeleteConfirmationModal = () => {\n const closeModal = () => {\n setShowDeleteModal(false);\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiOverlayMask, null, /*#__PURE__*/React.createElement(EuiConfirmModal, {\n title: \"Delete report definition\",\n onCancel: closeModal,\n onConfirm: deleteReportDefinition,\n cancelButtonText: \"Cancel\",\n confirmButtonText: \"Delete\",\n buttonColor: \"danger\",\n defaultFocusedButton: \"confirm\"\n }, /*#__PURE__*/React.createElement(\"p\", null, \"Are you sure you want to delete \\\"\", reportDefinitionDetails.name, \"\\\"?\"))));\n };\n\n const humanReadableScheduleDetails = trigger => {\n let scheduleDetails = '';\n\n if (trigger.trigger_type === 'Schedule') {\n if (trigger.trigger_params.schedule_type === 'Recurring') {\n // Daily\n if (trigger.trigger_params.schedule.interval.unit === 'DAYS' && trigger.trigger_params.schedule.interval.period === 1) {\n const date = new Date(trigger.trigger_params.schedule.interval.start_time);\n scheduleDetails = 'Daily @ ' + date.toTimeString();\n } // By interval\n else {\n const date = new Date(trigger.trigger_params.schedule.interval.start_time);\n scheduleDetails = 'By interval, every ' + trigger.trigger_params.schedule.interval.period + ' ' + trigger.trigger_params.schedule.interval.unit.toLowerCase() + ', starting @ ' + date.toTimeString();\n }\n } // Cron\n else if (trigger.trigger_params.schedule_type === 'Cron based') {\n scheduleDetails = 'Cron based: ' + trigger.trigger_params.schedule.cron.expression + ' (' + trigger.trigger_params.schedule.cron.timezone + ')';\n }\n }\n\n return scheduleDetails;\n };\n\n const getReportDefinitionDetailsMetadata = data => {\n const reportDefinition = data.report_definition;\n const {\n report_params: reportParams,\n trigger,\n delivery,\n time_created: timeCreated,\n last_updated: lastUpdated\n } = reportDefinition;\n const {\n trigger_type: triggerType,\n trigger_params: triggerParams\n } = trigger;\n const {\n delivery_type: deliveryType,\n delivery_params: deliveryParams\n } = delivery;\n const {\n core_params: {\n base_url: baseUrl,\n report_format: reportFormat,\n time_duration: timeDuration\n }\n } = reportParams;\n let readableDate = new Date(timeCreated);\n let displayCreatedDate = readableDate.toDateString() + ' ' + readableDate.toLocaleTimeString();\n let readableUpdatedDate = new Date(lastUpdated);\n let displayUpdatedDate = readableUpdatedDate.toDateString() + ' ' + readableUpdatedDate.toLocaleTimeString();\n let reportDefinitionDetails = {\n name: reportParams.report_name,\n description: reportParams.description === '' ? `\\u2014` : reportParams.description,\n created: displayCreatedDate,\n lastUpdated: displayUpdatedDate,\n source: reportParams.report_source,\n baseUrl: baseUrl,\n // TODO: need better display\n timePeriod: moment.duration(timeDuration).humanize(),\n fileFormat: reportFormat,\n reportHeader: reportParams.core_params.hasOwnProperty('header') ? converter.makeMarkdown(reportParams.core_params.header) : `\\u2014`,\n reportFooter: reportParams.core_params.hasOwnProperty('footer') ? converter.makeMarkdown(reportParams.core_params.footer) : `\\u2014`,\n triggerType: triggerType,\n scheduleDetails: triggerParams ? humanReadableScheduleDetails(data.report_definition.trigger) : `\\u2014`,\n channel: deliveryType,\n status: reportDefinition.status,\n kibanaRecipients: deliveryParams.kibana_recipients ? deliveryParams.kibana_recipients : `\\u2014`,\n emailRecipients: deliveryType === 'Channel' ? deliveryParams.recipients : `\\u2014`,\n emailSubject: deliveryType === 'Channel' ? deliveryParams.title : `\\u2014`,\n emailBody: deliveryType === 'Channel' ? deliveryParams.textDescription : `\\u2014`\n };\n return reportDefinitionDetails;\n };\n\n useEffect(() => {\n const {\n httpClient\n } = props;\n httpClient.get(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(response => {\n handleReportDefinitionRawResponse(response);\n handleReportDefinitionDetails(getReportDefinitionDetailsMetadata(response));\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: `Report definition details: ${response.report_definition.report_params.report_name}`\n }]);\n }).catch(error => {\n console.error('error when getting report definition details:', error);\n handleDetailsErrorToast();\n });\n }, []);\n\n const fileFormatDownload = data => {\n let formatUpper = data['fileFormat'];\n formatUpper = fileFormatsUpper[formatUpper];\n return /*#__PURE__*/React.createElement(EuiLink, {\n onClick: generateReportFromDetails\n }, formatUpper + ' ', /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n }));\n };\n\n const sourceURL = data => {\n return /*#__PURE__*/React.createElement(EuiLink, {\n href: `${data.baseUrl}`,\n target: \"_blank\"\n }, data['source']);\n };\n\n const getRelativeStartDate = duration => {\n duration = moment.duration(duration);\n let time_difference = moment.now() - duration;\n return new Date(time_difference);\n };\n\n const changeScheduledReportDefinitionStatus = statusChange => {\n let updatedReportDefinition = reportDefinitionRawResponse.report_definition;\n\n if (statusChange === 'Disable') {\n updatedReportDefinition.trigger.trigger_params.enabled = false;\n updatedReportDefinition.status = 'Disabled';\n } else if (statusChange === 'Enable') {\n updatedReportDefinition.trigger.trigger_params.enabled = true;\n updatedReportDefinition.status = 'Active';\n }\n\n const {\n httpClient\n } = props;\n httpClient.put(`../api/reporting/reportDefinitions/${reportDefinitionId}`, {\n body: JSON.stringify(updatedReportDefinition),\n params: reportDefinitionId.toString()\n }).then(() => {\n const updatedRawResponse = {\n report_definition: {}\n };\n updatedRawResponse.report_definition = updatedReportDefinition;\n handleReportDefinitionRawResponse(updatedRawResponse);\n setReportDefinitionDetails(getReportDefinitionDetailsMetadata(updatedRawResponse));\n\n if (statusChange === 'Enable') {\n handleSuccessEnablingScheduleToast();\n } else if (statusChange === 'Disable') {\n handleSuccessDisablingScheduleToast();\n }\n }).catch(error => {\n console.error('error in updating report definition status:', error);\n\n if (statusChange === 'Enable') {\n handleErrorEnablingScheduleToast();\n } else if (statusChange === 'Disable') {\n handleErrorDisablingScheduleToast();\n }\n });\n };\n\n const ScheduledDefinitionStatus = () => {\n const status = reportDefinitionDetails.status === 'Active' ? 'Disable' : 'Enable';\n return /*#__PURE__*/React.createElement(EuiButton, {\n onClick: () => changeScheduledReportDefinitionStatus(status),\n id: 'changeStatusFromDetailsButton'\n }, status);\n };\n\n const generateReportFromDetails = async () => {\n let duration = reportDefinitionRawResponse.report_definition.report_params.core_params.time_duration;\n const fromDate = getRelativeStartDate(duration);\n let onDemandDownloadMetadata = {\n query_url: `${reportDefinitionDetails.baseUrl}?_g=(time:(from:'${fromDate.toISOString()}',to:'${moment().toISOString()}'))`,\n time_from: fromDate.valueOf(),\n time_to: moment().valueOf(),\n report_definition: reportDefinitionRawResponse.report_definition\n };\n const {\n httpClient\n } = props;\n let generateReportSuccess = await generateReport(onDemandDownloadMetadata, httpClient);\n\n if (generateReportSuccess) {\n handleSuccessGeneratingReportToast();\n } else {\n handleErrorGeneratingReportToast();\n }\n };\n\n const deleteReportDefinition = () => {\n const {\n httpClient\n } = props;\n httpClient.delete(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(() => {\n window.location.assign(`opendistro_kibana_reports#/`);\n }).catch(error => {\n console.log('error when deleting report definition:', error);\n handleErrorDeletingReportDefinitionToast();\n });\n };\n\n const showActionButton = reportDefinitionDetails.triggerType === ON_DEMAND ? /*#__PURE__*/React.createElement(EuiButton, {\n onClick: () => generateReportFromDetails(),\n id: 'generateReportFromDetailsButton'\n }, \"Generate report\") : /*#__PURE__*/React.createElement(ScheduledDefinitionStatus, null);\n const triggerSection = reportDefinitionDetails.triggerType === ON_DEMAND ? /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Trigger type',\n reportDetailsComponentContent: reportDefinitionDetails.triggerType\n }) : /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Trigger type',\n reportDetailsComponentContent: reportDefinitionDetails.triggerType\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Schedule details',\n reportDetailsComponentContent: reportDefinitionDetails.scheduleDetails\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Status',\n reportDetailsComponentContent: reportDefinitionDetails.status\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null));\n const showDeleteConfirmationModal = showDeleteModal ? /*#__PURE__*/React.createElement(DeleteConfirmationModal, null) : null;\n return /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, {\n size: \"l\"\n }, /*#__PURE__*/React.createElement(\"h1\", null, \"Report definition details\")), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"m\"\n }), /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiPageHeaderSection, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, reportDefinitionDetails.name))))), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"flexEnd\",\n alignItems: \"flexEnd\",\n gutterSize: \"l\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n color: 'danger',\n onClick: handleShowDeleteModal,\n id: 'deleteReportDefinitionButton'\n }, \"Delete\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, showActionButton), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => {\n window.location.assign(`opendistro_kibana_reports#/edit/${reportDefinitionId}`);\n },\n id: 'editReportDefinitionButton'\n }, \"Edit\")))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Name',\n reportDetailsComponentContent: reportDefinitionDetails.name\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Description',\n reportDetailsComponentContent: reportDefinitionDetails.description\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Created',\n reportDetailsComponentContent: reportDefinitionDetails.created\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Last updated',\n reportDetailsComponentContent: reportDefinitionDetails.lastUpdated\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Source',\n reportDetailsComponentContent: sourceURL(reportDefinitionDetails)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Time period',\n reportDetailsComponentContent: `Last ${reportDefinitionDetails.timePeriod}`\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'File format',\n reportDetailsComponentContent: fileFormatDownload(reportDefinitionDetails)\n }), /*#__PURE__*/React.createElement(EuiFlexItem, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report header',\n reportDetailsComponentContent: trimAndRenderAsText(reportDefinitionDetails.reportHeader)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report footer',\n reportDetailsComponentContent: trimAndRenderAsText(reportDefinitionDetails.reportFooter)\n }), /*#__PURE__*/React.createElement(EuiFlexItem, null), /*#__PURE__*/React.createElement(EuiFlexItem, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report trigger\")), /*#__PURE__*/React.createElement(EuiSpacer, null), triggerSection, /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Notification settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email recipients',\n reportDetailsComponentContent: formatEmails(reportDefinitionDetails.emailRecipients)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email subject',\n reportDetailsComponentContent: reportDefinitionDetails.emailSubject\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Optional message',\n reportDetailsComponentContent: trimAndRenderAsText(reportDefinitionDetails.emailBody)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n }), showDeleteConfirmationModal));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useState } from 'react';\nimport { EuiLink, EuiInMemoryTable, EuiButton, EuiEmptyPrompt, EuiText, EuiIcon } from '@elastic/eui';\nimport { humanReadableDate } from './main_utils';\nconst emptyMessageReportDefinitions = /*#__PURE__*/React.createElement(EuiEmptyPrompt, {\n title: /*#__PURE__*/React.createElement(\"h3\", null, \"No report definitions to display\"),\n titleSize: \"xs\",\n body: /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiText, null, \"Create a new report definition to get started\"), /*#__PURE__*/React.createElement(EuiText, null, \"To learn more, see\", ' ', /*#__PURE__*/React.createElement(EuiLink, null, \"Get started with Kibana reporting \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"popout\"\n })))),\n actions: /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiButton, {\n onClick: () => {\n window.location.assign('opendistro_kibana_reports#/create');\n }\n }, \"Create report definition\"))\n});\nconst reportDefinitionsSearch = {\n box: {\n incremental: true\n },\n filters: []\n};\nexport function ReportDefinitions(props) {\n const {\n pagination,\n reportDefinitionsTableContent\n } = props;\n const [sortField, setSortField] = useState('lastUpdated');\n const [sortDirection, setSortDirection] = useState('des');\n const sorting = {\n sort: {\n field: sortField,\n direction: sortDirection\n }\n };\n\n const getDefinitionTableItemId = name => {\n let index;\n\n for (index = 0; index < props.reportDefinitionsTableContent.length; ++index) {\n if (name === reportDefinitionsTableContent[index].reportName) {\n return reportDefinitionsTableContent[index].id;\n }\n }\n };\n\n const navigateToDefinitionDetails = name => {\n let id = getDefinitionTableItemId(name);\n window.location.assign(`opendistro_kibana_reports#/report_definition_details/${id}`);\n };\n\n const reportDefinitionsColumns = [{\n field: 'reportName',\n name: 'Name',\n render: name => /*#__PURE__*/React.createElement(EuiLink, {\n onClick: () => navigateToDefinitionDetails(name),\n id: 'reportDefinitionDetailsLink'\n }, name)\n }, {\n field: 'source',\n name: 'Source',\n render: (value, item) => /*#__PURE__*/React.createElement(EuiLink, {\n href: item.baseUrl,\n target: \"_blank\"\n }, value)\n }, {\n field: 'type',\n name: 'Type',\n sortable: true,\n truncateText: false\n }, {\n field: 'details',\n name: 'Schedule details',\n sortable: false,\n truncateText: true\n }, {\n field: 'lastUpdated',\n name: 'Last Updated',\n render: date => {\n let readable = humanReadableDate(date);\n return /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, readable);\n }\n }, {\n field: 'status',\n name: 'Status',\n sortable: true,\n truncateText: false\n }];\n const displayMessage = reportDefinitionsTableContent.length === 0 ? emptyMessageReportDefinitions : '0 report definitions match the search criteria. Search again.';\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiInMemoryTable, {\n items: reportDefinitionsTableContent,\n itemId: \"id\",\n loading: false,\n message: displayMessage,\n columns: reportDefinitionsColumns,\n search: reportDefinitionsSearch,\n pagination: pagination,\n sorting: sorting,\n isSelectable: true,\n tableLayout: 'auto'\n }));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiFlexGroup, EuiFlexItem, EuiPage, EuiPageHeader, EuiTitle, EuiPageBody, EuiPageContent, EuiHorizontalRule, EuiSpacer, EuiDescriptionList, EuiDescriptionListTitle, EuiDescriptionListDescription, EuiPageHeaderSection, EuiLink, EuiIcon, EuiGlobalToastList } from '@elastic/eui';\nimport { fileFormatsUpper, generateReportById } from '../main_utils';\nimport { converter } from '../../report_definitions/utils';\nimport dateMath from '@elastic/datemath';\nexport const ReportDetailsComponent = props => {\n const {\n reportDetailsComponentTitle,\n reportDetailsComponentContent\n } = props;\n return /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiDescriptionList, null, /*#__PURE__*/React.createElement(EuiDescriptionListTitle, null, reportDetailsComponentTitle), /*#__PURE__*/React.createElement(EuiDescriptionListDescription, null, reportDetailsComponentContent)));\n}; // convert markdown to plain text, trim it if it's longer than 3 lines\n\nexport const trimAndRenderAsText = markdown => {\n if (!markdown) return markdown;\n const lines = markdown.split('\\n').filter(line => line);\n const elements = lines.slice(0, 3).map((line, i) => /*#__PURE__*/React.createElement(\"p\", {\n key: i\n }, line));\n return lines.length <= 3 ? elements : elements.concat( /*#__PURE__*/React.createElement(\"p\", {\n key: 3\n }, \"...\"));\n};\nexport const formatEmails = emails => {\n return Array.isArray(emails) ? emails.join(', ') : emails;\n};\nexport function ReportDetails(props) {\n const [reportDetails, setReportDetails] = useState({});\n const [toasts, setToasts] = useState([]);\n const reportId = props.match['params']['reportId'];\n\n const addErrorToastHandler = () => {\n const errorToast = {\n title: 'Error loading report details.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportDetailsErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorToast = () => {\n addErrorToastHandler();\n };\n\n const addSuccessToastHandler = () => {\n const successToast = {\n title: 'Success',\n color: 'success',\n text: /*#__PURE__*/React.createElement(\"p\", null, \"Report successfully downloaded!\"),\n id: 'onDemandDownloadSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessToast = () => {\n addSuccessToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const handleReportDetails = e => {\n setReportDetails(e);\n };\n\n const convertTimestamp = timestamp => {\n let displayDate = `\\u2014`;\n\n if (timestamp) {\n let readableDate = new Date(timestamp);\n displayDate = readableDate.toLocaleString();\n }\n\n return displayDate;\n };\n\n const parseTimePeriod = queryUrl => {\n let timeString = queryUrl.substring(queryUrl.lastIndexOf('time:'), queryUrl.lastIndexOf('))'));\n let fromDateString = timeString.substring(timeString.lastIndexOf('from:') + 5, timeString.lastIndexOf(','));\n let toDateString = timeString.substring(timeString.lastIndexOf('to:') + 3, timeString.length);\n fromDateString = fromDateString.replace(/[']+/g, '');\n toDateString = toDateString.replace(/[']+/g, '');\n let fromDateParsed = dateMath.parse(fromDateString);\n let toDateParsed = dateMath.parse(toDateString);\n const fromTimePeriod = fromDateParsed === null || fromDateParsed === void 0 ? void 0 : fromDateParsed.toDate();\n const toTimePeriod = toDateParsed === null || toDateParsed === void 0 ? void 0 : toDateParsed.toDate();\n return (fromTimePeriod === null || fromTimePeriod === void 0 ? void 0 : fromTimePeriod.toLocaleString()) + ' -> ' + (toTimePeriod === null || toTimePeriod === void 0 ? void 0 : toTimePeriod.toLocaleString());\n };\n\n const getReportDetailsData = report => {\n const {\n report_definition: reportDefinition,\n last_updated: lastUpdated,\n state,\n query_url: queryUrl\n } = report;\n const {\n report_params: reportParams,\n trigger,\n delivery\n } = reportDefinition;\n const {\n trigger_type: triggerType,\n trigger_params: triggerParams\n } = trigger;\n const {\n delivery_type: deliveryType,\n delivery_params: deliveryParams\n } = delivery;\n const coreParams = reportParams.core_params; // covert timestamp to local date-time string\n\n let reportDetails = {\n reportName: reportParams.report_name,\n description: reportParams.description === '' ? `\\u2014` : reportParams.description,\n created: convertTimestamp(report.time_created),\n lastUpdated: convertTimestamp(report.last_updated),\n source: reportParams.report_source,\n // TODO: we have all data needed, time_from, time_to, time_duration,\n // think of a way to better display\n time_period: parseTimePeriod(queryUrl),\n defaultFileFormat: coreParams.report_format,\n state: state,\n reportHeader: reportParams.core_params.hasOwnProperty('header') ? converter.makeMarkdown(reportParams.core_params.header) : `\\u2014`,\n reportFooter: reportParams.core_params.hasOwnProperty('footer') ? converter.makeMarkdown(reportParams.core_params.footer) : `\\u2014`,\n triggerType: triggerType,\n scheduleType: triggerParams ? triggerParams.schedule_type : `\\u2014`,\n scheduleDetails: `\\u2014`,\n alertDetails: `\\u2014`,\n channel: deliveryType,\n emailRecipients: deliveryType === 'Channel' ? deliveryParams.recipients : `\\u2014`,\n emailSubject: deliveryType === 'Channel' ? deliveryParams.title : `\\u2014`,\n emailBody: deliveryType === 'Channel' ? deliveryParams.textDescription : `\\u2014`,\n queryUrl: queryUrl\n };\n return reportDetails;\n };\n\n useEffect(() => {\n const {\n httpClient\n } = props;\n httpClient.get('../api/reporting/reports/' + reportId).then(response => {\n handleReportDetails(getReportDetailsData(response));\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: 'Report details: ' + response.report_definition.report_params.report_name\n }]);\n }).catch(error => {\n console.log('Error when fetching report details: ', error);\n handleErrorToast();\n });\n }, []);\n\n const fileFormatDownload = data => {\n let formatUpper = data['defaultFileFormat'];\n formatUpper = fileFormatsUpper[formatUpper];\n return /*#__PURE__*/React.createElement(EuiLink, {\n onClick: () => {\n generateReportById(reportId, props.httpClient, handleSuccessToast, handleErrorToast);\n }\n }, formatUpper + ' ', /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n }));\n };\n\n const sourceURL = data => {\n return /*#__PURE__*/React.createElement(EuiLink, {\n href: `${data.queryUrl}`,\n target: \"_blank\"\n }, data['source']);\n };\n\n return /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, {\n size: \"l\"\n }, /*#__PURE__*/React.createElement(\"h1\", null, \"Report details\")), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"m\"\n }), /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiPageHeaderSection, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, reportDetails['reportName'])))))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report Settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Name',\n reportDetailsComponentContent: reportDetails['reportName']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Description',\n reportDetailsComponentContent: reportDetails['description']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Created',\n reportDetailsComponentContent: reportDetails['created']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Last updated',\n reportDetailsComponentContent: reportDetails['lastUpdated']\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Source',\n reportDetailsComponentContent: sourceURL(reportDetails)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Time period',\n reportDetailsComponentContent: reportDetails.time_period\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'File format',\n reportDetailsComponentContent: fileFormatDownload(reportDetails)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'State',\n reportDetailsComponentContent: reportDetails['state']\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report header',\n reportDetailsComponentContent: trimAndRenderAsText(reportDetails['reportHeader'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report footer',\n reportDetailsComponentContent: trimAndRenderAsText(reportDetails['reportFooter'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null), /*#__PURE__*/React.createElement(ReportDetailsComponent, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report trigger\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report type',\n reportDetailsComponentContent: reportDetails['triggerType']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Schedule type',\n reportDetailsComponentContent: reportDetails['scheduleType']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Schedule details',\n reportDetailsComponentContent: reportDetails['scheduleDetails']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Notification settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email recipient(s)',\n reportDetailsComponentContent: formatEmails(reportDetails['emailRecipients'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email subject',\n reportDetailsComponentContent: reportDetails['emailSubject']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Optional message',\n reportDetailsComponentContent: trimAndRenderAsText(reportDetails['emailBody'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { Fragment, useState } from 'react';\nimport { EuiButton // @ts-ignore\n, EuiLink, EuiText, EuiIcon, EuiEmptyPrompt, EuiInMemoryTable, EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner, EuiModal, EuiModalBody, EuiModalHeader, EuiOverlayMask, EuiSpacer, EuiTitle } from '@elastic/eui';\nimport { fileFormatsUpper, humanReadableDate, generateReportById } from './main_utils';\nconst reportStatusOptions = ['Created', 'Error', 'Pending', 'Shared', 'Archived'];\nconst reportTypeOptions = ['Schedule', 'On demand'];\nconst emptyMessageReports = /*#__PURE__*/React.createElement(EuiEmptyPrompt, {\n title: /*#__PURE__*/React.createElement(\"h3\", null, \"No reports to display\"),\n titleSize: \"xs\",\n body: /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiText, null, \"Create a report definition, or share/download a report from a dashboard, saved search or visualization.\"), /*#__PURE__*/React.createElement(EuiText, null, \"To learn more, see\", ' ', /*#__PURE__*/React.createElement(EuiLink, null, \"Get started with Kibana reporting \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"popout\"\n }))))\n});\nexport function ReportsTable(props) {\n const {\n pagination,\n reportsTableItems,\n httpClient,\n handleSuccessToast,\n handleErrorToast\n } = props;\n const [sortField, setSortField] = useState('timeCreated');\n const [sortDirection, setSortDirection] = useState('des');\n const [showLoading, setShowLoading] = useState(false);\n const [message, setMessage] = useState('');\n\n const handleLoading = e => {\n setShowLoading(e);\n };\n\n const GenerateReportLoadingModal = () => {\n const [isModalVisible, setIsModalVisible] = useState(true);\n\n const closeModal = () => {\n setIsModalVisible(false);\n setShowLoading(false);\n };\n\n const showModal = () => setIsModalVisible(true);\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiOverlayMask, null, /*#__PURE__*/React.createElement(EuiModal, {\n onClose: closeModal,\n style: {\n maxWidth: 350,\n minWidth: 300\n }\n }, /*#__PURE__*/React.createElement(EuiModalHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(EuiText, {\n textAlign: \"right\"\n }, /*#__PURE__*/React.createElement(\"h2\", null, \"Generating report\")))), /*#__PURE__*/React.createElement(EuiModalBody, null, /*#__PURE__*/React.createElement(EuiText, null, \"Preparing your file for download.\"), /*#__PURE__*/React.createElement(EuiText, null, \"You can close this dialog while we continue in the background.\"), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"center\",\n alignItems: \"center\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiLoadingSpinner, {\n size: \"xl\",\n style: {\n minWidth: 75,\n minHeight: 75\n }\n }))), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"l\"\n }), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n alignItems: \"flexEnd\",\n justifyContent: \"flexEnd\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n onClick: closeModal\n }, \"Close\")))))));\n };\n\n const onDemandDownload = async id => {\n handleLoading(true);\n await generateReportById(id, httpClient, handleSuccessToast, handleErrorToast);\n handleLoading(false);\n };\n\n const reportsTableColumns = [{\n field: 'reportName',\n name: 'Name',\n render: (reportName, item) => /*#__PURE__*/React.createElement(EuiLink, {\n disabled: item.state === 'Pending',\n onClick: () => {\n window.location.assign(`opendistro_kibana_reports#/report_details/${item.id}`);\n },\n id: 'reportDetailsLink'\n }, reportName)\n }, {\n // TODO: link to dashboard/visualization snapshot, use \"queryUrl\" field. Display dashboard name?\n field: 'reportSource',\n name: 'Source',\n render: (source, item) => item.state === 'Pending' ? /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, source) : /*#__PURE__*/React.createElement(EuiLink, {\n href: item.url,\n target: \"_blank\"\n }, source)\n }, {\n field: 'type',\n name: 'Type',\n sortable: true,\n truncateText: false\n }, {\n field: 'timeCreated',\n name: 'Creation time',\n render: date => {\n let readable = humanReadableDate(date);\n return /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, readable);\n }\n }, {\n field: 'state',\n name: 'State',\n sortable: true,\n truncateText: false\n }, {\n field: 'id',\n name: 'Generate',\n render: (id, item) => item.state === 'Pending' ? /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, fileFormatsUpper[item.format], \" \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n })) : /*#__PURE__*/React.createElement(EuiLink, {\n onClick: () => onDemandDownload(id)\n }, fileFormatsUpper[item.format], \" \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n }))\n }];\n const sorting = {\n sort: {\n field: sortField,\n direction: sortDirection\n }\n };\n const reportsListSearch = {\n box: {\n incremental: true\n },\n filters: [{\n type: 'field_value_selection',\n field: 'type',\n name: 'Type',\n multiselect: false,\n options: reportTypeOptions.map(type => ({\n value: type,\n name: type,\n view: type\n }))\n }, {\n type: 'field_value_selection',\n field: 'state',\n name: 'State',\n multiselect: false,\n options: reportStatusOptions.map(state => ({\n value: state,\n name: state,\n view: state\n }))\n }]\n };\n const displayMessage = reportsTableItems.length === 0 ? emptyMessageReports : '0 reports match the search criteria. Search again';\n const showLoadingModal = showLoading ? /*#__PURE__*/React.createElement(GenerateReportLoadingModal, null) : null;\n return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(EuiInMemoryTable, {\n items: reportsTableItems,\n itemId: \"id\",\n loading: false,\n message: displayMessage,\n columns: reportsTableColumns,\n search: reportsListSearch,\n pagination: pagination,\n sorting: sorting,\n hasActions: true,\n tableLayout: 'auto'\n }), showLoadingModal);\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiGlobalToastList, EuiButton, EuiTitle, EuiPageBody, EuiSpacer } from '@elastic/eui';\nimport { ReportSettings } from '../report_settings';\nimport { ReportDelivery } from '../delivery';\nimport { ReportTrigger } from '../report_trigger';\nimport { generateReport } from '../../main/main_utils';\nimport { isValidCron } from 'cron-validator';\nimport { converter } from '../utils';\nimport moment from 'moment';\nexport function CreateReport(props) {\n let createReportDefinitionRequest = {\n report_params: {\n report_name: '',\n report_source: '',\n description: '',\n core_params: {\n base_url: '',\n report_format: '',\n time_duration: ''\n }\n },\n delivery: {\n delivery_type: '',\n delivery_params: {}\n },\n trigger: {\n trigger_type: ''\n }\n };\n const [toasts, setToasts] = useState([]);\n const [comingFromError, setComingFromError] = useState(false);\n const [preErrorData, setPreErrorData] = useState({});\n const [showSettingsReportNameError, setShowSettingsReportNameError] = useState(false);\n const [showTriggerIntervalNaNError, setShowTriggerIntervalNaNError] = useState(false);\n const [showCronError, setShowCronError] = useState(false);\n const [showEmailRecipientsError, setShowEmailRecipientsError] = useState(false);\n const [showTimeRangeError, setShowTimeRangeError] = useState(false); // preserve the state of the request after an invalid create report definition request\n\n if (comingFromError) {\n createReportDefinitionRequest = preErrorData;\n }\n\n const addErrorToastHandler = () => {\n const errorToast = {\n title: 'Error creating report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorToast = () => {\n addErrorToastHandler();\n };\n\n const addInvalidTimeRangeToastHandler = () => {\n const errorToast = {\n title: 'Invalid time range selected.',\n color: 'danger',\n iconType: 'alert',\n id: 'timeRangeErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleInvalidTimeRangeToast = () => {\n addInvalidTimeRangeToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n let timeRange = {\n timeFrom: new Date(),\n timeTo: new Date()\n };\n\n const definitionInputValidation = async (metadata, error) => {\n // check report name\n // allow a-z, A-Z, 0-9, (), [], ',' - and _ and spaces\n let regexp = /^[\\w\\-\\s\\(\\)\\[\\]\\,\\_\\-+]+$/;\n\n if (metadata.report_params.report_name.search(regexp) === -1) {\n setShowSettingsReportNameError(true);\n error = true;\n } // if recurring by interval and input is not a number\n\n\n if (metadata.trigger.trigger_type === 'Schedule' && metadata.trigger.trigger_params.schedule_type === 'Recurring') {\n let interval = parseInt(metadata.trigger.trigger_params.schedule.interval.period);\n\n if (isNaN(interval)) {\n setShowTriggerIntervalNaNError(true);\n error = true;\n }\n } // if time range is invalid\n\n\n const nowDate = new Date(moment.now());\n\n if (timeRange.timeFrom > timeRange.timeTo || timeRange.timeTo > nowDate) {\n setShowTimeRangeError(true);\n error = true;\n } // if cron based and cron input is invalid\n\n\n if (metadata.trigger.trigger_type === 'Schedule' && metadata.trigger.trigger_params.schedule_type === 'Cron based') {\n if (!isValidCron(metadata.trigger.trigger_params.schedule.cron.expression)) {\n setShowCronError(true);\n error = true;\n }\n } // if email delivery\n\n\n if (metadata.delivery.delivery_type === 'Channel') {\n // no recipients are listed\n if (metadata.delivery.delivery_params.recipients.length === 0) {\n setShowEmailRecipientsError(true);\n error = true;\n } // recipients have invalid email addresses: regexp checks format xxxxx@yyyy.zzz\n\n\n let emailRegExp = /\\S+@\\S+\\.\\S+/;\n let index;\n let recipients = metadata.delivery.delivery_params.recipients;\n\n for (index = 0; index < recipients.length; ++index) {\n if (recipients[0].search(emailRegExp) === -1) {\n setShowEmailRecipientsError(true);\n error = true;\n }\n }\n }\n\n return error;\n };\n\n const createNewReportDefinition = async (metadata, timeRange) => {\n const {\n httpClient\n } = props; //TODO: need better handle\n\n if (metadata.trigger.trigger_type === 'On demand' && metadata.trigger.trigger_params !== undefined) {\n delete metadata.trigger.trigger_params;\n }\n\n let error = false;\n await definitionInputValidation(metadata, error).then(response => {\n error = response;\n });\n\n if (error) {\n handleErrorToast();\n setPreErrorData(metadata);\n setComingFromError(true);\n } else {\n // convert header and footer to html\n if ('header' in metadata.report_params.core_params) {\n metadata.report_params.core_params.header = converter.makeHtml(metadata.report_params.core_params.header);\n }\n\n if ('footer' in metadata.report_params.core_params) {\n metadata.report_params.core_params.footer = converter.makeHtml(metadata.report_params.core_params.footer);\n }\n\n httpClient.post('../api/reporting/reportDefinition', {\n body: JSON.stringify(metadata),\n headers: {\n 'Content-Type': 'application/json'\n }\n }).then(async resp => {\n //TODO: consider handle the on demand report generation from server side instead\n if (metadata.trigger.trigger_type === 'On demand') {\n let onDemandDownloadMetadata = {\n query_url: `${metadata.report_params.core_params.base_url}?_g=(time:(from:'${timeRange.timeFrom.toISOString()}',to:'${timeRange.timeTo.toISOString()}'))`,\n time_from: timeRange.timeFrom.valueOf(),\n time_to: timeRange.timeTo.valueOf(),\n report_definition: metadata\n };\n generateReport(onDemandDownloadMetadata, httpClient);\n }\n\n window.location.assign(`opendistro_kibana_reports#/create=success`);\n }).catch(error => {\n console.log('error in creating report definition: ' + error);\n handleErrorToast();\n });\n }\n };\n\n useEffect(() => {\n window.scrollTo(0, 0);\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: 'Create report definition',\n href: '#/create'\n }]);\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h1\", null, \"Create report definition\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportSettings, {\n edit: false,\n reportDefinitionRequest: createReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange,\n showSettingsReportNameError: showSettingsReportNameError,\n showTimeRangeError: showTimeRangeError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportTrigger, {\n edit: false,\n reportDefinitionRequest: createReportDefinitionRequest,\n showTriggerIntervalNaNError: showTriggerIntervalNaNError,\n showCronError: showCronError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportDelivery, {\n edit: false,\n reportDefinitionRequest: createReportDefinitionRequest,\n showEmailRecipientsError: showEmailRecipientsError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"flexEnd\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButtonEmpty, {\n onClick: () => {\n window.location.assign(`opendistro_kibana_reports#/`);\n }\n }, \"Cancel\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => createNewReportDefinition(createReportDefinitionRequest, timeRange),\n id: 'createNewReportDefinition'\n }, \"Create\"))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiPageHeader, EuiTitle, EuiPageContent, EuiPageContentBody, EuiHorizontalRule, EuiSpacer, EuiCheckbox } from '@elastic/eui';\nimport { DELIVERY_TYPE_OPTIONS } from './delivery_constants';\nimport 'react-mde/lib/styles/css/react-mde-all.css';\nimport { EmailDelivery } from './email';\nexport function ReportDelivery(props) {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps\n } = props;\n const [emailCheckbox, setEmailCheckbox] = useState(false);\n\n const handleEmailCheckbox = e => {\n setEmailCheckbox(e.target.checked);\n\n if (e.target.checked) {\n // if checked, set delivery type to email\n reportDefinitionRequest.delivery.delivery_type = DELIVERY_TYPE_OPTIONS[1].id;\n } else {\n // uncheck email checkbox means to use default setting, which is kibana user\n defaultCreateDeliveryParams();\n }\n };\n\n const emailDelivery = emailCheckbox ? /*#__PURE__*/React.createElement(EmailDelivery, props) : null;\n\n const defaultCreateDeliveryParams = () => {\n reportDefinitionRequest.delivery = {\n delivery_type: DELIVERY_TYPE_OPTIONS[0].id,\n delivery_params: {\n kibana_recipients: []\n }\n };\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n const isEmailSelected = response.report_definition.delivery.delivery_type === DELIVERY_TYPE_OPTIONS[1].id;\n handleEmailCheckbox({\n target: {\n checked: isEmailSelected\n }\n });\n });\n } else {\n // By default it's set to deliver to kibana user\n defaultCreateDeliveryParams();\n }\n }, []);\n return /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Notification settings\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(EuiCheckbox, {\n id: \"emailCheckboxDelivery\",\n label: \"Add email recipients\",\n checked: emailCheckbox,\n onChange: handleEmailCheckbox\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), emailDelivery));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport const EMAIL_RECIPIENT_OPTIONS = [];\nexport const DELIVERY_TYPE_OPTIONS = [{\n id: 'Kibana user',\n label: 'Kibana user'\n}, {\n id: 'Channel',\n label: 'Email'\n}];","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport { EuiComboBox, EuiFieldText, EuiFormRow, EuiSpacer } from '@elastic/eui';\nimport React, { useEffect } from 'react';\nimport { useState } from 'react';\nimport ReactMDE from 'react-mde';\nimport { converter } from '../utils';\nimport { DELIVERY_TYPE_OPTIONS } from './delivery_constants';\nexport const EmailDelivery = props => {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps,\n showEmailRecipientsError\n } = props;\n const [emailRecipients, setEmailRecipients] = useState([]);\n const [selectedEmailRecipients, setSelectedEmailRecipients] = useState([]);\n const [emailSubject, setEmailSubject] = useState('');\n const [emailBody, setEmailBody] = useState('');\n const [selectedTab, setSelectedTab] = React.useState('write');\n\n const handleCreateEmailRecipient = (searchValue, flattenedOptions = []) => {\n const normalizedSearchValue = searchValue.trim().toLowerCase();\n\n if (!normalizedSearchValue) {\n return;\n }\n\n const newOption = {\n label: searchValue\n }; // Create the option if it doesn't exist.\n\n if (flattenedOptions.findIndex(option => option.label.trim().toLowerCase() === normalizedSearchValue) === -1) {\n setEmailRecipients([...emailRecipients, newOption]);\n }\n\n handleSelectEmailRecipients([...selectedEmailRecipients, newOption]);\n };\n\n const handleSelectEmailRecipients = e => {\n setSelectedEmailRecipients(e);\n reportDefinitionRequest.delivery.delivery_params.recipients = e.map(option => option.label);\n };\n\n const handleEmailSubject = e => {\n setEmailSubject(e.target.value);\n reportDefinitionRequest.delivery.delivery_params.title = e.target.value;\n };\n\n const handleEmailBody = e => {\n setEmailBody(e);\n reportDefinitionRequest.delivery.delivery_params.textDescription = e;\n reportDefinitionRequest.delivery.delivery_params.htmlDescription = converter.makeHtml(e);\n }; // TODO: need better handling when we add full support for kibana user report delivery\n\n\n const optionalMessageLabel = `Add optional message (${selectedTab} mode)`;\n\n const defaultEditDeliveryParams = delivery => {\n //TODO: need better handle?\n // if the original notification setting is kibana user\n if (delivery.delivery_type === DELIVERY_TYPE_OPTIONS[0].id) {\n defaultCreateDeliveryParams();\n delete reportDefinitionRequest.delivery.delivery_params.kibana_recipients;\n } else {\n //@ts-ignore\n const emailParams = delivery.delivery_params;\n const {\n recipients,\n title,\n textDescription\n } = emailParams;\n const recipientsOptions = recipients.map(email => ({\n label: email\n }));\n handleSelectEmailRecipients(recipientsOptions);\n setEmailRecipients(recipientsOptions);\n setEmailSubject(title);\n reportDefinitionRequest.delivery.delivery_params.title = title;\n handleEmailBody(textDescription);\n }\n };\n\n const defaultCreateDeliveryParams = () => {\n reportDefinitionRequest.delivery.delivery_params = {\n recipients: selectedEmailRecipients.map(option => option.label),\n title: emailSubject,\n textDescription: emailBody,\n htmlDescription: converter.makeHtml(emailBody)\n };\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n defaultEditDeliveryParams(response.report_definition.delivery);\n });\n } else {\n defaultCreateDeliveryParams();\n }\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Email recipients\",\n helpText: \"Select or add users\",\n isInvalid: showEmailRecipientsError\n }, /*#__PURE__*/React.createElement(EuiComboBox, {\n placeholder: 'Add users here',\n options: emailRecipients,\n selectedOptions: selectedEmailRecipients,\n onChange: handleSelectEmailRecipients,\n onCreateOption: handleCreateEmailRecipient,\n isClearable: true,\n \"data-test-subj\": \"demoComboBox\"\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Email subject\"\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: \"Subject line\",\n value: emailSubject,\n onChange: handleEmailSubject\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: optionalMessageLabel,\n fullWidth: true\n }, /*#__PURE__*/React.createElement(ReactMDE, {\n value: emailBody,\n onChange: handleEmailBody,\n selectedTab: selectedTab,\n onTabChange: setSelectedTab,\n toolbarCommands: [['header', 'bold', 'italic', 'strikethrough'], ['unordered-list', 'ordered-list', 'checked-list']],\n generateMarkdownPreview: markdown => Promise.resolve(converter.makeHtml(markdown))\n })), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"xs\"\n }));\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport { ReportDelivery } from './delivery';","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiButton, EuiPage, EuiTitle, EuiPageBody, EuiSpacer, EuiGlobalToastList } from '@elastic/eui';\nimport { ReportSettings } from '../report_settings';\nimport { ReportDelivery } from '../delivery';\nimport { ReportTrigger } from '../report_trigger';\nimport { converter } from '../utils';\nexport function EditReportDefinition(props) {\n const [toasts, setToasts] = useState([]);\n const [comingFromError, setComingFromError] = useState(false);\n const [preErrorData, setPreErrorData] = useState({});\n\n const addErrorUpdatingReportDefinitionToast = () => {\n const errorToast = {\n title: 'Error updating report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorUpdatingReportDefinitionToast = () => {\n addErrorUpdatingReportDefinitionToast();\n };\n\n const addErrorDeletingReportDefinitionToastHandler = () => {\n const errorToast = {\n title: 'Error deleting old scheduled report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorDeleteToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorDeletingReportDefinitionToast = () => {\n addErrorDeletingReportDefinitionToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const reportDefinitionId = props['match']['params']['reportDefinitionId'];\n let reportDefinition;\n let editReportDefinitionRequest = {\n report_params: {\n report_name: '',\n report_source: '',\n description: '',\n core_params: {\n base_url: '',\n report_format: '',\n time_duration: ''\n }\n },\n delivery: {\n delivery_type: '',\n delivery_params: {}\n },\n trigger: {\n trigger_type: ''\n },\n time_created: 0,\n last_updated: 0,\n status: ''\n };\n reportDefinition = editReportDefinitionRequest; // initialize reportDefinition object\n\n let timeRange = {\n timeFrom: new Date(),\n timeTo: new Date()\n };\n\n if (comingFromError) {\n editReportDefinitionRequest = preErrorData;\n }\n\n const callUpdateAPI = async metadata => {\n const {\n httpClient\n } = props;\n httpClient.put(`../api/reporting/reportDefinitions/${reportDefinitionId}`, {\n body: JSON.stringify(metadata),\n params: reportDefinitionId.toString()\n }).then(async () => {\n window.location.assign(`opendistro_kibana_reports#/edit=success`);\n }).catch(error => {\n console.error('error in updating report definition:', error);\n handleErrorUpdatingReportDefinitionToast();\n setPreErrorData(metadata);\n setComingFromError(true);\n });\n };\n\n const editReportDefinition = async metadata => {\n const {\n httpClient\n } = props;\n\n if ('header' in metadata.report_params.core_params) {\n metadata.report_params.core_params.header = converter.makeHtml(metadata.report_params.core_params.header);\n }\n\n if ('footer' in metadata.report_params.core_params) {\n metadata.report_params.core_params.footer = converter.makeHtml(metadata.report_params.core_params.footer);\n }\n /*\n we check if this editing updates the trigger type from Schedule to On demand. \n If so, need to first delete the reportDefinition along with the scheduled job first, by calling the delete\n report definition API\n */\n\n\n const {\n trigger: {\n trigger_type: triggerType\n }\n } = reportDefinition;\n\n if (triggerType !== 'On demand' && metadata.trigger.trigger_type === 'On demand') {\n httpClient.delete(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(async () => {\n await callUpdateAPI(metadata);\n }).catch(error => {\n console.log('error when deleting old scheduled report definition:', error);\n handleErrorDeletingReportDefinitionToast();\n });\n } else {\n await callUpdateAPI(metadata);\n }\n };\n\n useEffect(() => {\n window.scrollTo(0, 0);\n const {\n httpClient\n } = props;\n httpClient.get(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(response => {\n reportDefinition = response.report_definition;\n const {\n time_created: timeCreated,\n status,\n last_updated: lastUpdated,\n report_params: {\n report_name: reportName\n }\n } = reportDefinition; // configure non-editable fields\n\n editReportDefinitionRequest.time_created = timeCreated;\n editReportDefinitionRequest.last_updated = lastUpdated;\n editReportDefinitionRequest.status = status;\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: `Report definition details: ${reportName}`,\n href: `#/report_definition_details/${reportDefinitionId}`\n }, {\n text: `Edit report definition: ${reportName}`\n }]);\n }).catch(error => {\n console.error('error when loading edit report definition page: ', error);\n });\n }, []);\n return /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h1\", null, \"Edit report definition\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportSettings, {\n edit: true,\n editDefinitionId: reportDefinitionId,\n reportDefinitionRequest: editReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportTrigger, {\n edit: true,\n editDefinitionId: reportDefinitionId,\n reportDefinitionRequest: editReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportDelivery, {\n edit: true,\n editDefinitionId: reportDefinitionId,\n reportDefinitionRequest: editReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"flexEnd\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButtonEmpty, {\n onClick: () => {\n window.location.assign('opendistro_kibana_reports#/');\n }\n }, \"Cancel\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => editReportDefinition(editReportDefinitionRequest),\n id: 'editReportDefinitionButton'\n }, \"Save Changes\"))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport { ReportSettings } from './report_settings';","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiPageHeader, EuiTitle, EuiPageContent, EuiPageContentBody, EuiHorizontalRule, EuiText, EuiSpacer, EuiRadioGroup, EuiSelect, EuiTextArea, EuiCheckboxGroup } from '@elastic/eui';\nimport { REPORT_SOURCE_RADIOS, PDF_PNG_FILE_FORMAT_OPTIONS, HEADER_FOOTER_CHECKBOX, REPORT_SOURCE_TYPES } from './report_settings_constants';\nimport ReactMde from 'react-mde';\nimport 'react-mde/lib/styles/css/react-mde-all.css';\nimport { parseInContextUrl, getSavedSearchBaseUrlCreate, getVisualizationBaseUrlCreate, getSavedSearchOptions, getVisualizationOptions, getDashboardBaseUrlCreate, getDashboardOptions, handleDataToVisualReportSourceChange } from './report_settings_helpers';\nimport { TimeRangeSelect } from './time_range';\nimport { converter } from '../utils';\nexport function ReportSettings(props) {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps,\n timeRange,\n showSettingsReportNameError,\n showTimeRangeError\n } = props;\n const [reportName, setReportName] = useState('');\n const [reportDescription, setReportDescription] = useState('');\n const [reportSourceId, setReportSourceId] = useState('dashboardReportSource');\n const [dashboardSourceSelect, setDashboardSourceSelect] = useState('');\n const [dashboards, setDashboards] = useState([]);\n const [visualizationSourceSelect, setVisualizationSourceSelect] = useState('');\n const [visualizations, setVisualizations] = useState([]);\n const [savedSearchSourceSelect, setSavedSearchSourceSelect] = useState('');\n const [savedSearches, setSavedSearches] = useState([]);\n const [fileFormat, setFileFormat] = useState('pdf');\n\n const handleDashboards = e => {\n setDashboards(e);\n };\n\n const handleVisualizations = e => {\n setVisualizations(e);\n };\n\n const handleSavedSearches = e => {\n setSavedSearches(e);\n };\n\n const handleReportName = e => {\n setReportName(e.target.value);\n reportDefinitionRequest.report_params.report_name = e.target.value.toString();\n };\n\n const handleReportDescription = e => {\n setReportDescription(e.target.value);\n reportDefinitionRequest.report_params.description = e.target.value.toString();\n };\n\n const handleReportSource = e => {\n setReportSourceId(e);\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n if (e === 'dashboardReportSource') {\n reportDefinitionRequest.report_params.report_source = 'Dashboard';\n reportDefinitionRequest.report_params.core_params.base_url = getDashboardBaseUrlCreate(edit, editDefinitionId, fromInContext) + dashboards[0].value; // set params to visual report params after switch from saved search\n\n handleDataToVisualReportSourceChange(reportDefinitionRequest);\n setFileFormat('pdf');\n } else if (e === 'visualizationReportSource') {\n reportDefinitionRequest.report_params.report_source = 'Visualization';\n reportDefinitionRequest.report_params.core_params.base_url = getVisualizationBaseUrlCreate(edit, fromInContext) + visualizations[0].value; // set params to visual report params after switch from saved search\n\n handleDataToVisualReportSourceChange(reportDefinitionRequest);\n setFileFormat('pdf');\n } else if (e === 'savedSearchReportSource') {\n reportDefinitionRequest.report_params.report_source = 'Saved search';\n reportDefinitionRequest.report_params.core_params.base_url = getSavedSearchBaseUrlCreate(edit, fromInContext) + savedSearches[0].value;\n reportDefinitionRequest.report_params.core_params.saved_search_id = savedSearches[0].value;\n reportDefinitionRequest.report_params.core_params.report_format = 'csv';\n reportDefinitionRequest.report_params.core_params.limit = 10000;\n reportDefinitionRequest.report_params.core_params.excel = true;\n }\n };\n\n const handleDashboardSelect = e => {\n setDashboardSourceSelect(e.target.value);\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n reportDefinitionRequest.report_params.core_params.base_url = getDashboardBaseUrlCreate(edit, editDefinitionId, fromInContext) + e.target.value;\n };\n\n const handleVisualizationSelect = e => {\n setVisualizationSourceSelect(e.target.value);\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n reportDefinitionRequest.report_params.core_params.base_url = getVisualizationBaseUrlCreate(edit, fromInContext) + e.target.value;\n };\n\n const handleSavedSearchSelect = e => {\n setSavedSearchSourceSelect(e.target.value);\n reportDefinitionRequest.report_params.core_params.saved_search_id = e.target.value;\n };\n\n const handleFileFormat = e => {\n setFileFormat(e);\n reportDefinitionRequest.report_params.core_params.report_format = e.toString();\n };\n\n const PDFandPNGFileFormats = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"File format\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: PDF_PNG_FILE_FORMAT_OPTIONS,\n idSelected: fileFormat,\n onChange: handleFileFormat\n })));\n };\n\n const SettingsMarkdown = () => {\n const [checkboxIdSelectHeaderFooter, setCheckboxIdSelectHeaderFooter] = useState({\n ['header']: false,\n ['footer']: false\n });\n const [footer, setFooter] = useState('');\n const [selectedTabFooter, setSelectedTabFooter] = React.useState('write');\n const [header, setHeader] = useState('');\n const [selectedTabHeader, setSelectedTabHeader] = React.useState('write');\n\n const handleHeader = e => {\n setHeader(e);\n reportDefinitionRequest.report_params.core_params.header = e;\n };\n\n const handleFooter = e => {\n setFooter(e);\n reportDefinitionRequest.report_params.core_params.footer = e;\n };\n\n const handleCheckboxHeaderFooter = optionId => {\n const newCheckboxIdToSelectedMap = { ...checkboxIdSelectHeaderFooter,\n ...{\n [optionId]: !checkboxIdSelectHeaderFooter[optionId]\n }\n };\n setCheckboxIdSelectHeaderFooter(newCheckboxIdToSelectedMap);\n };\n\n const showFooter = checkboxIdSelectHeaderFooter.footer ? /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Footer\",\n fullWidth: true\n }, /*#__PURE__*/React.createElement(ReactMde, {\n value: footer,\n onChange: handleFooter,\n selectedTab: selectedTabFooter,\n onTabChange: setSelectedTabFooter,\n toolbarCommands: [['header', 'bold', 'italic', 'strikethrough'], ['unordered-list', 'ordered-list', 'checked-list']],\n generateMarkdownPreview: markdown => Promise.resolve(converter.makeHtml(markdown))\n })) : null;\n const showHeader = checkboxIdSelectHeaderFooter.header ? /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Header\",\n fullWidth: true\n }, /*#__PURE__*/React.createElement(ReactMde, {\n value: header,\n onChange: handleHeader,\n selectedTab: selectedTabHeader,\n onTabChange: setSelectedTabHeader,\n toolbarCommands: [['header', 'bold', 'italic', 'strikethrough'], ['unordered-list', 'ordered-list', 'checked-list']],\n generateMarkdownPreview: markdown => Promise.resolve(converter.makeHtml(markdown))\n })) : null;\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n const reportDefinition = response.report_definition;\n const {\n report_params: {\n core_params: {\n header,\n footer\n }\n }\n } = reportDefinition; // set header/footer default\n\n if (header) {\n checkboxIdSelectHeaderFooter.header = true;\n\n if (!unmounted) {\n setHeader(converter.makeMarkdown(header));\n }\n }\n\n if (footer) {\n checkboxIdSelectHeaderFooter.footer = true;\n\n if (!unmounted) {\n setFooter(converter.makeMarkdown(footer));\n }\n }\n }).catch(error => {\n console.error('error in fetching report definition details:', error);\n });\n } else {\n // keeps header/footer from re-rendering empty when other fields in Report Settings are changed\n checkboxIdSelectHeaderFooter.header = 'header' in reportDefinitionRequest.report_params.core_params;\n checkboxIdSelectHeaderFooter.footer = 'footer' in reportDefinitionRequest.report_params.core_params;\n\n if (checkboxIdSelectHeaderFooter.header) {\n setHeader(reportDefinitionRequest.report_params.core_params.header);\n }\n\n if (checkboxIdSelectHeaderFooter.footer) {\n setFooter(reportDefinitionRequest.report_params.core_params.footer);\n }\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiCheckboxGroup, {\n options: HEADER_FOOTER_CHECKBOX,\n idToSelectedMap: checkboxIdSelectHeaderFooter,\n onChange: handleCheckboxHeaderFooter,\n legend: {\n children: 'Header and footer'\n }\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), showHeader, showFooter);\n };\n\n const ReportSourceDashboard = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Select dashboard\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"reportSourceDashboardSelect\",\n options: dashboards,\n value: dashboardSourceSelect,\n onChange: handleDashboardSelect\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const ReportSourceVisualization = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Select visualization\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"reportSourceVisualizationSelect\",\n options: visualizations,\n value: visualizationSourceSelect,\n onChange: handleVisualizationSelect\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const ReportSourceSavedSearch = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Select saved search\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"reportSourceSavedSearchSelect\",\n options: savedSearches,\n value: savedSearchSourceSelect,\n onChange: handleSavedSearchSelect\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const VisualReportFormatAndMarkdown = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(PDFandPNGFileFormats, null), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const setReportSourceDropdownOption = (options, reportSource, url) => {\n let index = 0;\n\n if (reportSource === REPORT_SOURCE_TYPES.dashboard) {\n for (index = 0; index < options.dashboard.length; ++index) {\n if (url.includes(options.dashboard[index].value)) {\n setDashboardSourceSelect(options.dashboard[index].value);\n }\n }\n } else if (reportSource === REPORT_SOURCE_TYPES.visualization) {\n for (index = 0; index < options.visualizations.length; ++index) {\n if (url.includes(options.visualizations[index].value)) {\n setVisualizationSourceSelect(options.visualizations[index].value);\n }\n }\n } else if (reportSource === REPORT_SOURCE_TYPES.savedSearch) {\n for (index = 0; index < options.savedSearch.length; ++index) {\n if (url.includes(options.savedSearch[index].value)) {\n setSavedSearchSourceSelect(options.savedSearch[index].value);\n }\n }\n }\n };\n\n const setDefaultFileFormat = fileFormat => {\n let index = 0;\n\n for (index = 0; index < PDF_PNG_FILE_FORMAT_OPTIONS.length; ++index) {\n if (fileFormat.toUpperCase() === PDF_PNG_FILE_FORMAT_OPTIONS[index].label) {\n setFileFormat(PDF_PNG_FILE_FORMAT_OPTIONS[index].id);\n }\n }\n };\n\n const setInContextDefaultConfiguration = () => {\n const url = window.location.href;\n const id = parseInContextUrl(url, 'id');\n\n if (url.includes('dashboard')) {\n setReportSourceId('dashboardReportSource');\n reportDefinitionRequest.report_params.report_source = REPORT_SOURCE_RADIOS[0].label;\n setDashboardSourceSelect(id);\n reportDefinitionRequest.report_params.core_params.base_url = getDashboardBaseUrlCreate(edit, id, true) + id;\n } else if (url.includes('visualize')) {\n setReportSourceId('visualizationReportSource');\n reportDefinitionRequest.report_params.report_source = REPORT_SOURCE_RADIOS[1].label;\n setVisualizationSourceSelect(id);\n reportDefinitionRequest.report_params.core_params.base_url = getVisualizationBaseUrlCreate(edit, true) + id;\n } else if (url.includes('discover')) {\n setReportSourceId('savedSearchReportSource');\n reportDefinitionRequest.report_params.core_params.report_format = 'csv';\n reportDefinitionRequest.report_params.core_params.saved_search_id = id;\n reportDefinitionRequest.report_params.report_source = REPORT_SOURCE_RADIOS[2].label;\n setSavedSearchSourceSelect(id);\n reportDefinitionRequest.report_params.core_params.base_url = getSavedSearchBaseUrlCreate(edit, true) + id;\n }\n };\n\n const setDefaultEditValues = async (response, reportSourceOptions) => {\n setReportName(response.report_definition.report_params.report_name);\n setReportDescription(response.report_definition.report_params.description);\n reportDefinitionRequest.report_params.report_name = response.report_definition.report_params.report_name;\n reportDefinitionRequest.report_params.description = response.report_definition.report_params.description;\n reportDefinitionRequest.report_params = response.report_definition.report_params;\n const reportSource = response.report_definition.report_params.report_source;\n REPORT_SOURCE_RADIOS.map(radio => {\n if (radio.label === reportSource) {\n setReportSourceId(radio.id);\n reportDefinitionRequest.report_params.report_source = reportSource;\n }\n });\n setDefaultFileFormat(response.report_definition.report_params.core_params.report_format);\n setReportSourceDropdownOption(reportSourceOptions, reportSource, response.report_definition.report_params.core_params.base_url);\n };\n\n const defaultConfigurationEdit = async httpClientProps => {\n let editData = {};\n await httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n editData = response;\n }).catch(error => {\n console.error('error in fetching report definition details:', error);\n });\n return editData;\n };\n\n const defaultConfigurationCreate = async httpClientProps => {\n let reportSourceOptions = {\n dashboard: [],\n visualizations: [],\n savedSearch: []\n };\n reportDefinitionRequest.report_params.core_params.report_format = fileFormat;\n await httpClientProps.get('../api/reporting/getReportSource/dashboard').then(async response => {\n let dashboardOptions = getDashboardOptions(response['hits']['hits']);\n reportSourceOptions.dashboard = dashboardOptions;\n handleDashboards(dashboardOptions);\n\n if (!edit) {\n setDashboardSourceSelect(dashboardOptions[0].value);\n reportDefinitionRequest.report_params.report_source = 'Dashboard';\n reportDefinitionRequest['report_params']['core_params']['base_url'] = getDashboardBaseUrlCreate(edit, editDefinitionId, false) + response['hits']['hits'][0]['_id'].substring(10);\n }\n }).catch(error => {\n console.log('error when fetching dashboards:', error);\n });\n await httpClientProps.get('../api/reporting/getReportSource/visualization').then(async response => {\n let visualizationOptions = getVisualizationOptions(response['hits']['hits']);\n reportSourceOptions.visualizations = visualizationOptions;\n await handleVisualizations(visualizationOptions);\n await setVisualizationSourceSelect(visualizationOptions[0].value);\n }).catch(error => {\n console.log('error when fetching visualizations:', error);\n });\n await httpClientProps.get('../api/reporting/getReportSource/search').then(async response => {\n let savedSearchOptions = getSavedSearchOptions(response['hits']['hits']);\n reportSourceOptions.savedSearch = savedSearchOptions;\n await handleSavedSearches(savedSearchOptions);\n await setSavedSearchSourceSelect(savedSearchOptions[0].value);\n }).catch(error => {\n console.log('error when fetching saved searches:', error);\n });\n return reportSourceOptions;\n };\n\n useEffect(() => {\n let reportSourceOptions = {};\n let editData = {};\n\n if (edit) {\n defaultConfigurationEdit(httpClientProps).then(async response => {\n editData = response;\n });\n }\n\n defaultConfigurationCreate(httpClientProps).then(async response => {\n reportSourceOptions = response; // if coming from in-context menu\n\n if (window.location.href.indexOf('?') > -1) {\n setInContextDefaultConfiguration();\n }\n\n if (edit) {\n setDefaultEditValues(editData, reportSourceOptions);\n }\n });\n }, []);\n const displayDashboardSelect = reportSourceId === 'dashboardReportSource' ? /*#__PURE__*/React.createElement(ReportSourceDashboard, null) : null;\n const displayVisualizationSelect = reportSourceId === 'visualizationReportSource' ? /*#__PURE__*/React.createElement(ReportSourceVisualization, null) : null;\n const displaySavedSearchSelect = reportSourceId === 'savedSearchReportSource' ? /*#__PURE__*/React.createElement(ReportSourceSavedSearch, null) : null;\n const displayVisualReportsFormatAndMarkdown = reportSourceId != 'savedSearchReportSource' ? /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(VisualReportFormatAndMarkdown, null), /*#__PURE__*/React.createElement(SettingsMarkdown, null)) : /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"File format\"\n }, /*#__PURE__*/React.createElement(EuiText, null, /*#__PURE__*/React.createElement(\"p\", null, \"CSV\"))));\n return /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Report Settings\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Name\",\n helpText: \"Valid characters are a-z, A-Z, 0-9, (), [], _ (underscore), - (hyphen) and (space).\",\n isInvalid: showSettingsReportNameError,\n id: 'reportSettingsName'\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: \"Report name (e.g Log Traffic Daily Report)\",\n value: reportName,\n onChange: handleReportName\n })))), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n style: {\n maxWidth: 600\n }\n }, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Description (optional)\",\n id: 'reportSettingsDescription'\n }, /*#__PURE__*/React.createElement(EuiTextArea, {\n placeholder: \"Describe this report (e.g Morning daily reports for log traffic)\",\n value: reportDescription,\n onChange: handleReportDescription\n })))), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Report source\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: REPORT_SOURCE_RADIOS,\n idSelected: reportSourceId,\n onChange: handleReportSource\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), displayDashboardSelect, displayVisualizationSelect, displaySavedSearchSelect, /*#__PURE__*/React.createElement(TimeRangeSelect, {\n timeRange: timeRange,\n reportDefinitionRequest: reportDefinitionRequest,\n edit: edit,\n id: editDefinitionId,\n httpClientProps: httpClientProps,\n showTimeRangeError: showTimeRangeError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), displayVisualReportsFormatAndMarkdown, /*#__PURE__*/React.createElement(EuiSpacer, null)));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport const REPORT_SOURCE_RADIOS = [{\n id: 'dashboardReportSource',\n label: 'Dashboard'\n}, {\n id: 'visualizationReportSource',\n label: 'Visualization'\n}, {\n id: 'savedSearchReportSource',\n label: 'Saved search'\n}];\nexport const PDF_PNG_FILE_FORMAT_OPTIONS = [{\n id: 'pdf',\n label: 'PDF'\n}, {\n id: 'png',\n label: 'PNG'\n}];\nexport const SAVED_SEARCH_FORMAT_OPTIONS = [{\n id: 'csvFormat',\n label: 'CSV'\n}, {\n id: 'xlsFormat',\n label: 'XLS'\n}];\nexport const HEADER_FOOTER_CHECKBOX = [{\n id: 'header',\n label: 'Add header'\n}, {\n id: 'footer',\n label: 'Add footer'\n}];\nexport const REPORT_SOURCE_TYPES = {\n dashboard: 'Dashboard',\n visualization: 'Visualization',\n savedSearch: 'Saved search'\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport const parseInContextUrl = (url, parameter) => {\n const info = url.split('?');\n\n if (parameter === 'id') {\n return info[1].substring(info[1].indexOf(':') + 1, info[1].length);\n } else if (parameter === 'timeFrom') {\n return info[2].substring(info[2].indexOf('=') + 1, info[2].length);\n } else if (parameter === 'timeTo') {\n return info[3].substring(info[3].indexOf('=') + 1, info[3].length);\n }\n\n return 'error: invalid parameter';\n};\nexport const getDashboardBaseUrlCreate = (edit, editDefinitionId, fromInContext) => {\n let baseUrl;\n\n if (!fromInContext) {\n baseUrl = location.pathname + location.hash;\n } else {\n baseUrl = '/app/dashboards#/view/';\n }\n\n if (edit) {\n return baseUrl.replace(`opendistro_kibana_reports#/edit/${editDefinitionId}`, 'dashboards#/view/');\n } else if (fromInContext) {\n return baseUrl;\n }\n\n return baseUrl.replace('opendistro_kibana_reports#/create', 'dashboards#/view/');\n};\nexport const getVisualizationBaseUrlCreate = (edit, fromInContext) => {\n let baseUrl;\n\n if (!fromInContext) {\n baseUrl = location.pathname + location.hash;\n } else {\n baseUrl = '/app/visualize#/edit/';\n }\n\n if (edit) {\n return baseUrl.replace('opendistro_kibana_reports#/edit', 'visualize#/edit/');\n } else if (fromInContext) {\n return baseUrl;\n }\n\n return baseUrl.replace('opendistro_kibana_reports#/create', 'visualize#/edit/');\n};\nexport const getSavedSearchBaseUrlCreate = (edit, fromInContext) => {\n let baseUrl;\n\n if (!fromInContext) {\n baseUrl = location.pathname + location.hash;\n } else {\n baseUrl = '/app/discover#/view/';\n }\n\n if (edit) {\n return baseUrl.replace('opendistro_kibana_reports#/edit', 'discover#/view/');\n } else if (fromInContext) {\n return baseUrl;\n }\n\n return baseUrl.replace('opendistro_kibana_reports#/create', 'discover#/view/');\n};\nexport const getDashboardOptions = data => {\n let index;\n let dashboard_options = [];\n\n for (index = 0; index < data.length; ++index) {\n let entry = {\n value: data[index]['_id'].substring(10),\n text: data[index]['_source']['dashboard']['title']\n };\n dashboard_options.push(entry);\n }\n\n return dashboard_options;\n};\nexport const getVisualizationOptions = data => {\n let index;\n let options = [];\n\n for (index = 0; index < data.length; ++index) {\n let entry = {\n value: data[index]['_id'].substring(14),\n text: data[index]['_source']['visualization']['title']\n };\n options.push(entry);\n }\n\n return options;\n};\nexport const getSavedSearchOptions = data => {\n let index;\n let options = [];\n\n for (index = 0; index < data.length; ++index) {\n let entry = {\n value: data[index]['_id'].substring(7),\n text: data[index]['_source']['search']['title']\n };\n options.push(entry);\n }\n\n return options;\n};\nexport const handleDataToVisualReportSourceChange = reportDefinitionRequest => {\n delete reportDefinitionRequest.report_params.core_params.saved_search_id;\n delete reportDefinitionRequest.report_params.core_params.limit;\n delete reportDefinitionRequest.report_params.core_params.excel;\n reportDefinitionRequest.report_params.core_params.report_format = 'pdf';\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport moment from 'moment';\nimport React, { useState, useEffect } from 'react';\nimport { parseInContextUrl } from './report_settings_helpers';\nimport dateMath from '@elastic/datemath';\nimport { EuiFormRow, EuiGlobalToastList, EuiSuperDatePicker } from '@elastic/eui';\nexport function TimeRangeSelect(props) {\n const {\n reportDefinitionRequest,\n timeRange,\n edit,\n id,\n httpClientProps,\n showTimeRangeError\n } = props;\n const [recentlyUsedRanges, setRecentlyUsedRanges] = useState([]);\n const [isLoading, setIsLoading] = useState(false);\n const [start, setStart] = useState('now-30m');\n const [end, setEnd] = useState('now');\n const [toasts, setToasts] = useState([]);\n\n const addInvalidTimeRangeToastHandler = () => {\n const errorToast = {\n title: 'Invalid time range selected',\n color: 'danger',\n iconType: 'alert',\n id: 'timeRangeErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleInvalidTimeRangeToast = () => {\n addInvalidTimeRangeToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const isValidTimeRange = (timeRangeMoment, limit, handleInvalidTimeRangeToast) => {\n if (limit === 'start') {\n if (!timeRangeMoment || !timeRangeMoment.isValid()) {\n handleInvalidTimeRangeToast();\n }\n } else if (limit === 'end') {\n if (!timeRangeMoment || !timeRangeMoment.isValid() || timeRangeMoment > moment()) {\n handleInvalidTimeRangeToast();\n }\n }\n };\n\n const setDefaultEditTimeRange = (duration, unmounted) => {\n let time_difference = moment.now() - duration;\n const fromDate = new Date(time_difference);\n parseTimeRange(fromDate, end, reportDefinitionRequest);\n\n if (!unmounted) {\n setStart(fromDate.toISOString());\n setEnd(end);\n }\n }; // valid time range check for absolute time end date\n\n\n const checkValidAbsoluteEndDate = end => {\n let endDate = new Date(end);\n let nowDate = new Date(moment.now());\n let valid = true;\n\n if (endDate.getTime() > nowDate.getTime()) {\n end = 'now';\n valid = false;\n }\n\n return valid;\n };\n\n useEffect(() => {\n let unmounted = false; // if we are coming from the in-context menu\n\n if (window.location.href.indexOf('?') > -1) {\n const url = window.location.href;\n const timeFrom = parseInContextUrl(url, 'timeFrom');\n const timeTo = parseInContextUrl(url, 'timeTo');\n parseTimeRange(timeFrom, timeTo, reportDefinitionRequest);\n\n if (!unmounted) {\n setStart(timeFrom);\n setEnd(timeTo);\n }\n } else {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${id}`).then(async response => {\n let duration = response.report_definition.report_params.core_params.time_duration;\n duration = moment.duration(duration);\n setDefaultEditTimeRange(duration, unmounted);\n }).catch(error => {\n console.error('error in fetching report definition details:', error);\n });\n } else {\n parseTimeRange(start, end, reportDefinitionRequest);\n }\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n\n const onTimeChange = ({\n start,\n end\n }) => {\n isValidTimeRange(dateMath.parse(start), 'start', handleInvalidTimeRangeToast);\n isValidTimeRange(dateMath.parse(end, {\n roundUp: true\n }), 'end', handleInvalidTimeRangeToast);\n const recentlyUsedRange = recentlyUsedRanges.filter(recentlyUsedRange => {\n const isDuplicate = recentlyUsedRange.start === start && recentlyUsedRange.end === end;\n return !isDuplicate;\n });\n const validEndDate = checkValidAbsoluteEndDate(end);\n\n if (!validEndDate) {\n handleInvalidTimeRangeToast();\n return;\n }\n\n recentlyUsedRange.unshift({\n start,\n end\n });\n setStart(start);\n setEnd(end);\n setRecentlyUsedRanges(recentlyUsedRange.length > 10 ? recentlyUsedRange.slice(0, 9) : recentlyUsedRange);\n setIsLoading(true);\n startLoading();\n parseTimeRange(start, end, reportDefinitionRequest);\n };\n\n const parseTimeRange = (start, end, reportDefinitionRequest) => {\n timeRange.timeFrom = dateMath.parse(start);\n timeRange.timeTo = dateMath.parse(end);\n const timeDuration = moment.duration(dateMath.parse(end).diff(dateMath.parse(start)));\n reportDefinitionRequest.report_params.core_params.time_duration = timeDuration.toISOString();\n };\n\n const startLoading = () => {\n setTimeout(stopLoading, 1000);\n };\n\n const stopLoading = () => {\n setIsLoading(false);\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Time range\",\n helpText: \"Time range is relative to the report creation date on the report trigger.\",\n isInvalid: showTimeRangeError\n }, /*#__PURE__*/React.createElement(EuiSuperDatePicker, {\n isDisabled: false,\n isLoading: isLoading,\n start: start,\n end: end,\n onTimeChange: onTimeChange,\n showUpdateButton: false\n }))), /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport { ReportTrigger } from './report_trigger';","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiPageHeader, EuiTitle, EuiPageContent, EuiPageContentBody, EuiHorizontalRule, EuiFormRow, EuiRadioGroup, EuiDatePicker, EuiSelect, EuiSpacer, EuiFlexGroup, EuiFlexItem, EuiText, EuiFieldText, EuiCheckboxGroup, EuiLink, EuiFieldNumber } from '@elastic/eui';\nimport moment from 'moment';\nimport { SCHEDULE_RECURRING_OPTIONS, INTERVAL_TIME_PERIODS, WEEKLY_CHECKBOX_OPTIONS, MONTHLY_ON_THE_OPTIONS, TRIGGER_TYPE_OPTIONS, SCHEDULE_TYPE_OPTIONS, TIMEZONE_OPTIONS } from './report_trigger_constants';\nimport { TimezoneSelect } from './timezone';\nexport function ReportTrigger(props) {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps,\n showTriggerIntervalNaNError,\n showCronError\n } = props;\n const [reportTriggerType, setReportTriggerType] = useState(TRIGGER_TYPE_OPTIONS[0].id);\n const [scheduleType, setScheduleType] = useState(SCHEDULE_TYPE_OPTIONS[0].label); //TODO: should read local timezone and display\n\n const [scheduleRecurringFrequency, setScheduleRecurringFrequency] = useState('daily');\n const [recurring, setRecurringTime] = useState(moment());\n const [weeklyCheckbox, setWeeklyCheckbox] = useState({\n ['monCheckbox']: true\n });\n const [monthlySelect, setMonthlySelect] = useState(MONTHLY_ON_THE_OPTIONS[0].value);\n\n const handleReportTriggerType = e => {\n setReportTriggerType(e);\n reportDefinitionRequest.trigger.trigger_type = e;\n\n if (e === 'On demand') {\n delete reportDefinitionRequest.trigger.trigger_params;\n }\n };\n\n const handleScheduleType = e => {\n setScheduleType(e);\n\n if (e === SCHEDULE_TYPE_OPTIONS[1].label) {\n delete reportDefinitionRequest.trigger.trigger_params.schedule.interval;\n } else if (e === SCHEDULE_TYPE_OPTIONS[0].label) {\n delete reportDefinitionRequest.trigger.trigger_params.schedule.cron;\n }\n };\n\n const handleScheduleRecurringFrequency = e => {\n setScheduleRecurringFrequency(e.target.value);\n reportDefinitionRequest.trigger.trigger_params.schedule_type = e.target.value;\n };\n\n const handleRecurringTime = e => {\n setRecurringTime(e);\n };\n\n const handleWeeklyCheckbox = e => {\n const newCheckboxIdToSelectedMap = { ...weeklyCheckbox,\n ...{\n [e]: !weeklyCheckbox[e]\n }\n };\n setWeeklyCheckbox(newCheckboxIdToSelectedMap);\n };\n\n const handleMonthlySelect = e => {\n setMonthlySelect(e.target.value);\n };\n\n const RequestTime = () => {\n useEffect(() => {\n let recurringDaily = {\n interval: {\n period: 1,\n unit: 'DAYS',\n start_time: recurring.valueOf()\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: recurring.valueOf(),\n schedule: recurringDaily\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Request time\"\n }, /*#__PURE__*/React.createElement(EuiDatePicker, {\n showTimeSelect: true,\n showTimeSelectOnly: true,\n selected: recurring,\n onChange: handleRecurringTime,\n dateFormat: \"HH:mm\",\n timeFormat: \"HH:mm\"\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const RecurringDaily = () => {\n const [recurringDailyTime, setRecurringDailyTime] = useState(moment());\n\n const handleRecurringDailyTime = e => {\n setRecurringDailyTime(e);\n reportDefinitionRequest.trigger.trigger_params.schedule.interval.start_time = e.valueOf();\n };\n\n const setDailyParams = () => {\n let recurringDaily = {\n interval: {\n period: 1,\n unit: 'DAYS',\n start_time: recurringDailyTime.valueOf()\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: recurringDailyTime.valueOf(),\n schedule: recurringDaily\n };\n };\n\n const isDailySchedule = response => {\n return response.report_definition.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id && response.report_definition.trigger.trigger_params.schedule.interval.period === 1 && response.report_definition.trigger.trigger_params.schedule.interval === 'DAYS';\n };\n\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n // if switching from on demand to schedule\n if (response.report_definition.trigger.trigger_type === 'On demand') {\n setDailyParams();\n } else if (isDailySchedule(response)) {\n const date = moment(response.report_definition.trigger.trigger_params.schedule.interval.start_time);\n\n if (!unmounted) {\n setRecurringDailyTime(date);\n }\n } // if switching from on-demand to schedule\n else if (reportDefinitionRequest.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id) {\n setDailyParams();\n }\n });\n } else {\n setDailyParams();\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Request time\"\n }, /*#__PURE__*/React.createElement(EuiDatePicker, {\n showTimeSelect: true,\n showTimeSelectOnly: true,\n selected: recurringDailyTime,\n onChange: handleRecurringDailyTime,\n dateFormat: \"HH:mm\",\n timeFormat: \"HH:mm\"\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const RecurringInterval = () => {\n const [intervalText, setIntervalText] = useState('');\n const [intervalTimePeriod, setIntervalTimePeriod] = useState(INTERVAL_TIME_PERIODS[0].value);\n const [recurringIntervalTime, setRecurringIntervalTime] = useState(moment());\n\n const handleRecurringIntervalTime = e => {\n setRecurringIntervalTime(e);\n reportDefinitionRequest.trigger.trigger_params.schedule.interval.start_time = e.valueOf();\n };\n\n const handleIntervalText = e => {\n setIntervalText(e.target.value);\n };\n\n const handleIntervalTimePeriod = e => {\n setIntervalTimePeriod(e.target.value);\n };\n\n useEffect(() => {\n let interval = {\n interval: {\n period: parseInt(intervalText, 10),\n unit: intervalTimePeriod,\n start_time: recurringIntervalTime.valueOf()\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: recurringIntervalTime.valueOf(),\n schedule: interval\n };\n }, [intervalTimePeriod, intervalText]); // second useEffect() only to be triggered before render when on Edit\n\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n if (response.report_definition.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id) {\n const date = moment(response.report_definition.trigger.trigger_params.schedule.interval.start_time);\n\n if (!unmounted) {\n setRecurringIntervalTime(date);\n setIntervalText(response.report_definition.trigger.trigger_params.schedule.interval.period.toString());\n setIntervalTimePeriod(response.report_definition.trigger.trigger_params.schedule.interval.unit);\n }\n }\n });\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Every\",\n isInvalid: showTriggerIntervalNaNError\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: \"Must be a number\",\n value: intervalText,\n onChange: handleIntervalText\n })), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiFormRow, null, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"intervalTimeUnit\",\n options: INTERVAL_TIME_PERIODS,\n value: intervalTimePeriod,\n onChange: handleIntervalTimePeriod\n }))))), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Start time\"\n }, /*#__PURE__*/React.createElement(EuiDatePicker, {\n showTimeSelect: true,\n showTimeSelectOnly: true,\n selected: recurringIntervalTime,\n onChange: handleRecurringIntervalTime,\n dateFormat: \"HH:mm\",\n timeFormat: \"HH:mm\"\n })));\n };\n\n const RecurringWeekly = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Every\"\n }, /*#__PURE__*/React.createElement(EuiCheckboxGroup, {\n options: WEEKLY_CHECKBOX_OPTIONS,\n idToSelectedMap: weeklyCheckbox,\n onChange: handleWeeklyCheckbox\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(RequestTime, null));\n };\n\n const RecurringMonthly = () => {\n const [monthlyDayNumber, setMonthlyDayNumber] = useState('');\n\n const handleMonthlyDayNumber = e => {\n setMonthlyDayNumber(e.target.value);\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"On the\"\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"monthlySelect\",\n options: MONTHLY_ON_THE_OPTIONS,\n value: monthlySelect,\n onChange: handleMonthlySelect\n })), /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiFieldNumber, {\n placeholder: 'Day of month',\n value: monthlyDayNumber,\n onChange: handleMonthlyDayNumber\n })))), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"s\"\n }), /*#__PURE__*/React.createElement(RequestTime, null));\n };\n\n const CronExpression = () => {\n const [cronExpression, setCronExpression] = useState('');\n\n const handleCronExpression = e => {\n setCronExpression(e.target.value);\n reportDefinitionRequest.trigger.trigger_params.schedule.cron.expression = e.target.value;\n };\n\n const setCronParams = () => {\n let cron = {\n cron: {\n expression: '',\n timezone: TIMEZONE_OPTIONS[0].value\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: Date.now().valueOf(),\n schedule: cron\n };\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n // if switching from on demand to schedule\n if (response.report_definition.trigger.trigger_type === 'On demand') {\n setCronParams();\n } else if (response.report_definition.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[1].id) {\n setCronExpression(response.report_definition.trigger.trigger_params.schedule.cron.expression);\n } else {\n setCronParams();\n }\n });\n } else {\n setCronParams();\n }\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Custom cron expression\",\n isInvalid: showCronError,\n labelAppend: /*#__PURE__*/React.createElement(EuiText, {\n size: \"xs\"\n }, /*#__PURE__*/React.createElement(EuiLink, {\n href: \"https://opendistro.github.io/for-elasticsearch-docs/docs/alerting/cron/\"\n }, \"Cron help\"))\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: 'Ex: 0 12 * * * (Fire at 12:00 PM (noon) every day)',\n value: cronExpression,\n onChange: handleCronExpression\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const ScheduleTriggerRecurring = () => {\n const display_daily = scheduleRecurringFrequency === 'daily' ? /*#__PURE__*/React.createElement(RecurringDaily, null) : null;\n const display_interval = scheduleRecurringFrequency === 'byInterval' ? /*#__PURE__*/React.createElement(RecurringInterval, null) : null;\n const display_weekly = scheduleRecurringFrequency === 'weekly' ? /*#__PURE__*/React.createElement(RecurringWeekly, null) : null;\n const display_monthly = scheduleRecurringFrequency === 'monthly' ? /*#__PURE__*/React.createElement(RecurringMonthly, null) : null;\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Frequency\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"recurringFrequencySelect\",\n options: SCHEDULE_RECURRING_OPTIONS,\n value: scheduleRecurringFrequency,\n onChange: handleScheduleRecurringFrequency\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), display_daily, display_interval, display_weekly, display_monthly);\n };\n\n const ScheduleTrigger = () => {\n const display_recurring = scheduleType === SCHEDULE_TYPE_OPTIONS[0].id ? /*#__PURE__*/React.createElement(ScheduleTriggerRecurring, null) : null;\n const display_cron = scheduleType === SCHEDULE_TYPE_OPTIONS[1].id ? /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(CronExpression, null), /*#__PURE__*/React.createElement(TimezoneSelect, {\n reportDefinitionRequest: reportDefinitionRequest,\n httpClientProps: httpClientProps,\n edit: edit,\n editDefinitionId: editDefinitionId\n })) : null;\n useEffect(() => {\n // Set default trigger_type\n SCHEDULE_TYPE_OPTIONS.map(item => {\n if (item.id === scheduleType) {\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n schedule_type: item.id //TODO: need better handle\n\n };\n\n if (!edit) {\n reportDefinitionRequest.trigger.trigger_params.enabled = true;\n }\n\n if (!('enabled' in reportDefinitionRequest.trigger.trigger_params)) {\n reportDefinitionRequest.trigger.trigger_params.enabled = false;\n }\n }\n });\n }, [scheduleType]);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Request time\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: SCHEDULE_TYPE_OPTIONS,\n idSelected: scheduleType,\n onChange: handleScheduleType\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), display_recurring, display_cron);\n };\n\n const schedule = reportTriggerType === 'Schedule' ? /*#__PURE__*/React.createElement(ScheduleTrigger, null) : null;\n\n const defaultEditTriggerType = trigger_type => {\n let index = 0;\n\n for (index; index < TRIGGER_TYPE_OPTIONS.length; ++index) {\n if (TRIGGER_TYPE_OPTIONS[index].id === trigger_type) {\n setReportTriggerType(TRIGGER_TYPE_OPTIONS[index].id);\n }\n }\n };\n\n const defaultEditRequestType = trigger => {\n let index = 0;\n\n for (index; index < SCHEDULE_TYPE_OPTIONS.length; ++index) {\n if (SCHEDULE_TYPE_OPTIONS[index].id === trigger.trigger_params.schedule_type) {\n setScheduleType(SCHEDULE_TYPE_OPTIONS[index].id);\n }\n }\n };\n\n const defaultEditScheduleFrequency = trigger_params => {\n if (trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id) {\n if (trigger_params.schedule.interval.unit === 'DAYS') {\n setScheduleRecurringFrequency('daily');\n } else {\n setScheduleRecurringFrequency('byInterval');\n }\n }\n };\n\n const defaultConfigurationEdit = trigger => {\n defaultEditTriggerType(trigger.trigger_type);\n\n if (trigger.trigger_type === 'Schedule') {\n defaultEditScheduleFrequency(trigger.trigger_params);\n defaultEditRequestType(trigger);\n } else if (trigger.trigger_type == 'On demand') {\n setReportTriggerType('On demand');\n reportDefinitionRequest.trigger.trigger_type = 'On demand';\n }\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n defaultConfigurationEdit(response.report_definition.trigger);\n reportDefinitionRequest.trigger = response.report_definition.trigger;\n });\n } // Set default trigger_type for create new report definition\n else {\n TRIGGER_TYPE_OPTIONS.map(item => {\n if (item.id === reportTriggerType) {\n reportDefinitionRequest.trigger.trigger_type = item.id;\n }\n });\n }\n }, []);\n return /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Report trigger\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Trigger type\",\n id: \"reportDefinitionTriggerTypes\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: TRIGGER_TYPE_OPTIONS,\n idSelected: reportTriggerType,\n onChange: handleReportTriggerType\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), schedule));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport moment from 'moment-timezone';\nexport const TRIGGER_TYPE_OPTIONS = [{\n id: 'On demand',\n label: 'On demand'\n}, {\n id: 'Schedule',\n label: 'Schedule'\n}];\nexport const SCHEDULE_TYPE_OPTIONS = [{\n id: 'Recurring',\n label: 'Recurring'\n}, {\n id: 'Cron based',\n label: 'Cron-based'\n}];\nexport const SCHEDULE_RECURRING_OPTIONS = [{\n value: 'daily',\n text: 'Daily'\n}, {\n value: 'byInterval',\n text: 'By interval'\n} // TODO: disable on UI. Add them back once we support\n// {\n// value: 'weekly',\n// text: 'Weekly',\n// },\n// {\n// value: 'monthly',\n// text: 'Monthly',\n// },\n];\nexport const INTERVAL_TIME_PERIODS = [{\n value: 'MINUTES',\n text: 'Minutes'\n}, {\n value: 'HOURS',\n text: 'Hours'\n}, {\n value: 'DAYS',\n text: 'Days'\n}];\nexport const WEEKLY_CHECKBOX_OPTIONS = [{\n id: 'monCheckbox',\n label: 'Mon'\n}, {\n id: 'tueCheckbox',\n label: 'Tue'\n}, {\n id: 'wedCheckbox',\n label: 'Wed'\n}, {\n id: 'thuCheckbox',\n label: 'Thu'\n}, {\n id: 'friCheckbox',\n label: 'Fri'\n}, {\n id: 'satCheckbox',\n label: 'Sat'\n}, {\n id: 'sunCheckbox',\n label: 'Sun'\n}];\nexport const MONTHLY_ON_THE_OPTIONS = [{\n value: 'day',\n text: 'Day'\n}];\nexport const TIMEZONE_OPTIONS = moment.tz.names().map(tz => ({\n value: tz,\n text: tz\n}));","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport { EuiFormRow, EuiSelect } from '@elastic/eui';\nimport React, { useState, useEffect } from 'react';\nimport { TIMEZONE_OPTIONS } from './report_trigger_constants';\nexport function TimezoneSelect(props) {\n const {\n reportDefinitionRequest,\n httpClientProps,\n edit,\n editDefinitionId\n } = props;\n const [timezone, setTimezone] = useState(TIMEZONE_OPTIONS[0].value);\n\n const handleTimezone = e => {\n setTimezone(e.target.value);\n\n if (reportDefinitionRequest.trigger.trigger_params.schedule_type === 'Cron based') {\n reportDefinitionRequest.trigger.trigger_params.schedule.cron.timezone = e.target.value;\n }\n };\n\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n if (!unmounted && reportDefinitionRequest.trigger.trigger_params.schedule_type === 'Cron based') {\n setTimezone(response.report_definition.trigger.trigger_params.schedule.cron.timezone);\n }\n });\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Timezone\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"setTimezone\",\n options: TIMEZONE_OPTIONS,\n value: timezone,\n onChange: handleTimezone\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport Showdown from 'showdown';\nexport const converter = new Showdown.Converter({\n tables: true,\n simplifiedAutoLink: true,\n strikethrough: true,\n tasklists: true,\n noHeaderId: true\n});"],"mappings":";;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACnCA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACnFA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzNA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACxcA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACpHA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzPA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC7LA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC3PA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC1EA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACrBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACjJA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACbA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACvNA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACbA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC1dA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACjDA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC7HA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACvLA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACbA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC1cA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACpFA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzDA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"1.plugin.js","sources":["/plugin:opendistroKibanaReports/plugins/kibana-reports/public/application.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/app.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/main.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/report_definition_details/report_definition_details.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/report_definitions_table.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/report_details/report_details.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/main/reports_table.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/create/create_report_definition.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/delivery.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/delivery_constants.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/email.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/delivery/index.ts","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/edit/edit_report_definition.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/index.ts","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_constants.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_settings/time_range.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/index.ts","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/report_trigger.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/report_trigger_constants.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/report_trigger/timezone.tsx","/plugin:opendistroKibanaReports/plugins/kibana-reports/public/components/report_definitions/utils/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport { OpendistroKibanaReportsApp } from './components/app';\nexport const renderApp = ({\n notifications,\n http,\n chrome\n}, {\n navigation\n}, {\n appBasePath,\n element\n}) => {\n ReactDOM.render( /*#__PURE__*/React.createElement(OpendistroKibanaReportsApp, {\n basename: appBasePath,\n notifications: notifications,\n http: http,\n navigation: navigation,\n chrome: chrome\n }), element);\n return () => ReactDOM.unmountComponentAtNode(element);\n};","function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\n/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React from 'react';\nimport { I18nProvider } from '@kbn/i18n/react';\nimport { HashRouter as Router, Route, Switch } from 'react-router-dom';\nimport { EuiPage, EuiPageBody, EuiPageContentBody, EuiPageContentHeader, EuiPageContentHeaderSection } from '@elastic/eui';\nimport { CreateReport } from './report_definitions/create/create_report_definition';\nimport { Main } from './main/main';\nimport { ReportDetails } from './main/report_details/report_details';\nimport { ReportDefinitionDetails } from './main/report_definition_details/report_definition_details';\nimport { EditReportDefinition } from './report_definitions/edit/edit_report_definition';\nconst styles = {\n float: 'left',\n width: \"100%\",\n maxWidth: '1600px'\n};\nexport const OpendistroKibanaReportsApp = ({\n basename,\n notifications,\n http,\n navigation,\n chrome\n}) => {\n // Render the application DOM.\n return /*#__PURE__*/React.createElement(Router, {\n basename: '/' + basename\n }, /*#__PURE__*/React.createElement(I18nProvider, null, /*#__PURE__*/React.createElement(\"div\", {\n style: styles\n }, /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiPageContentHeader, null, /*#__PURE__*/React.createElement(EuiPageContentHeaderSection, null)), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(Switch, null, /*#__PURE__*/React.createElement(Route, {\n path: \"/report_details/:reportId\",\n render: props => /*#__PURE__*/React.createElement(ReportDetails, _extends({\n title: \"Report Details\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/report_definition_details/:reportDefinitionId\",\n render: props => /*#__PURE__*/React.createElement(ReportDefinitionDetails, _extends({\n title: \"Report Definition Details\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/create\",\n render: props => /*#__PURE__*/React.createElement(CreateReport, _extends({\n title: \"Create Report\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/edit/:reportDefinitionId\",\n render: props => /*#__PURE__*/React.createElement(EditReportDefinition, _extends({\n title: \"Edit Report Definition\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }), /*#__PURE__*/React.createElement(Route, {\n path: \"/\",\n render: props => /*#__PURE__*/React.createElement(Main, _extends({\n title: \"Reporting Homepage\",\n httpClient: http\n }, props, {\n setBreadcrumbs: chrome.setBreadcrumbs\n }))\n }))))))));\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useState, useEffect } from 'react';\nimport { EuiFlexGroup, EuiFlexItem, EuiButton, EuiTitle // @ts-ignore\n, EuiHorizontalRule, EuiSpacer, EuiPanel, EuiGlobalToastList } from '@elastic/eui';\nimport { ReportsTable } from './reports_table';\nimport { ReportDefinitions } from './report_definitions_table';\nimport { addReportsTableContent, addReportDefinitionsTableContent } from './main_utils';\nconst reportCountStyles = {\n color: 'gray',\n display: 'inline'\n};\nexport function Main(props) {\n const [reportsTableContent, setReportsTableContent] = useState([]);\n const [reportDefinitionsTableContent, setReportDefinitionsTableContent] = useState([]);\n const [toasts, setToasts] = useState([]);\n\n const addReportsTableContentErrorToastHandler = () => {\n const errorToast = {\n title: 'Error generating reports table.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportsTableErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleReportsTableContentErrorToast = () => {\n addReportsTableContentErrorToastHandler();\n };\n\n const addReportDefinitionsTableErrorToastHandler = () => {\n const errorToast = {\n title: 'Error generating report definitions table.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportDefinitionsTableErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleReportDefinitionsTableErrorToast = () => {\n addReportDefinitionsTableErrorToastHandler();\n };\n\n const addErrorOnDemandDownloadToastHandler = () => {\n const errorToast = {\n title: 'Error downloading report.',\n color: 'danger',\n iconType: 'alert',\n id: 'onDemandDownloadErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleOnDemandDownloadErrorToast = () => {\n addErrorOnDemandDownloadToastHandler();\n };\n\n const addSuccessOnDemandDownloadToastHandler = () => {\n const successToast = {\n title: 'Successfully downloaded report.',\n color: 'success',\n iconType: 'check',\n id: 'onDemandDownloadSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleOnDemandDownloadSuccessToast = () => {\n addSuccessOnDemandDownloadToastHandler();\n };\n\n const addCreateReportDefinitionSuccessToastHandler = () => {\n const successToast = {\n title: 'Successfully created report definition.',\n color: 'success',\n iconType: 'check',\n id: 'createReportDefinitionSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleCreateReportDefinitionSuccessToast = () => {\n addCreateReportDefinitionSuccessToastHandler();\n };\n\n const addEditReportDefinitionSuccessToastHandler = () => {\n const successToast = {\n title: 'Successfully updated report definition.',\n color: 'success',\n iconType: 'check',\n id: 'editReportDefinitionSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleEditReportDefinitionSuccessToast = () => {\n addEditReportDefinitionSuccessToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const pagination = {\n initialPageSize: 10,\n pageSizeOptions: [8, 10, 13]\n };\n useEffect(() => {\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }]);\n refreshReportsTable();\n refreshReportsDefinitionsTable();\n\n if (window.location.href.includes('create=success')) {\n handleCreateReportDefinitionSuccessToast(); // refresh might not fetch the latest changes when coming from create or edit page\n // workaround to wait 1 second and refresh again\n\n setTimeout(() => {\n refreshReportsTable();\n refreshReportsDefinitionsTable();\n }, 1000);\n } else if (window.location.href.includes('edit=success')) {\n handleEditReportDefinitionSuccessToast();\n setTimeout(() => {\n refreshReportsTable();\n refreshReportsDefinitionsTable();\n }, 1000);\n }\n\n window.location.href = 'opendistro_kibana_reports#/';\n }, []);\n\n const refreshReportsTable = async () => {\n const {\n httpClient\n } = props;\n await httpClient.get('../api/reporting/reports').then(response => {\n setReportsTableContent(addReportsTableContent(response.data));\n }).catch(error => {\n console.log('error when fetching all reports: ', error);\n handleReportsTableContentErrorToast();\n });\n };\n\n const refreshReportsDefinitionsTable = async () => {\n const {\n httpClient\n } = props;\n await httpClient.get('../api/reporting/reportDefinitions').then(response => {\n setReportDefinitionsTableContent(addReportDefinitionsTableContent(response.data));\n }).catch(error => {\n console.log('error when fetching all report definitions: ', error);\n handleReportDefinitionsTableErrorToast();\n });\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiPanel, {\n paddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"spaceEvenly\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Reports\", ' ', /*#__PURE__*/React.createElement(\"p\", {\n style: reportCountStyles\n }, \" (\", reportsTableContent.length, \")\")))), /*#__PURE__*/React.createElement(EuiFlexItem, {\n component: \"span\",\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n size: \"m\",\n onClick: refreshReportsTable\n }, \"Refresh\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(ReportsTable, {\n pagination: pagination,\n reportsTableItems: reportsTableContent,\n httpClient: props['httpClient'],\n handleSuccessToast: handleOnDemandDownloadSuccessToast,\n handleErrorToast: handleOnDemandDownloadErrorToast\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiPanel, {\n paddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"spaceEvenly\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Report definitions\", /*#__PURE__*/React.createElement(\"p\", {\n style: reportCountStyles\n }, ' ', \"(\", reportDefinitionsTableContent.length, \")\")))), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n onClick: refreshReportsDefinitionsTable\n }, \"Refresh\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n component: \"span\",\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => {\n window.location.assign('opendistro_kibana_reports#/create');\n },\n id: 'createReportHomepageButton'\n }, \"Create\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(ReportDefinitions, {\n pagination: pagination,\n reportDefinitionsTableContent: reportDefinitionsTableContent\n })), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n }));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiFlexGroup, EuiFlexItem, EuiPage, EuiPageHeader, EuiTitle, EuiPageBody, EuiPageContent, EuiHorizontalRule, EuiSpacer, EuiPageHeaderSection, EuiButton, EuiIcon, EuiLink, EuiGlobalToastList, EuiOverlayMask, EuiConfirmModal } from '@elastic/eui';\nimport { ReportDetailsComponent, formatEmails, trimAndRenderAsText } from '../report_details/report_details';\nimport { fileFormatsUpper, generateReport } from '../main_utils';\nimport moment from 'moment';\nimport { converter } from '../../report_definitions/utils';\nconst ON_DEMAND = 'On demand';\nexport function ReportDefinitionDetails(props) {\n const [reportDefinitionDetails, setReportDefinitionDetails] = useState({});\n const [reportDefinitionRawResponse, setReportDefinitionRawResponse] = useState({});\n const [toasts, setToasts] = useState([]);\n const [showDeleteModal, setShowDeleteModal] = useState(false);\n const reportDefinitionId = props.match['params']['reportDefinitionId'];\n\n const handleShowDeleteModal = e => {\n setShowDeleteModal(e);\n };\n\n const addErrorLoadingDetailsToastHandler = () => {\n const errorToast = {\n title: 'Error loading report definition details.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportDefinitionDetailsErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleDetailsErrorToast = () => {\n addErrorLoadingDetailsToastHandler();\n };\n\n const addSuccessGeneratingReportToastHandler = () => {\n const successToast = {\n title: 'Successfully generated report.',\n color: 'success',\n iconType: 'check',\n id: 'generateReportSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessGeneratingReportToast = () => {\n addSuccessGeneratingReportToastHandler();\n };\n\n const addErrorGeneratingReportToastHandler = () => {\n const errorToast = {\n title: 'Error generating report.',\n color: 'danger',\n iconType: 'alert',\n id: 'generateReportErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorGeneratingReportToast = () => {\n addErrorGeneratingReportToastHandler();\n };\n\n const addSuccessEnablingScheduleToastHandler = () => {\n const successToast = {\n title: 'Successfully enabled schedule.',\n color: 'success',\n iconType: 'check',\n id: 'successEnableToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessEnablingScheduleToast = () => {\n addSuccessEnablingScheduleToastHandler();\n };\n\n const addErrorEnablingScheduleToastHandler = () => {\n const errorToast = {\n title: 'Error enabling schedule.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorEnablingScheduleToast = () => {\n addErrorEnablingScheduleToastHandler();\n };\n\n const addSuccessDisablingScheduleToastHandler = () => {\n const successToast = {\n title: 'Successfully disabled schedule.',\n color: 'success',\n iconType: 'check',\n id: 'successDisableToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessDisablingScheduleToast = () => {\n addSuccessDisablingScheduleToastHandler();\n };\n\n const addErrorDisablingScheduleToastHandler = () => {\n const errorToast = {\n title: 'Error disabling schedule.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorDisableToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorDisablingScheduleToast = () => {\n addErrorDisablingScheduleToastHandler();\n };\n\n const addErrorDeletingReportDefinitionToastHandler = () => {\n const errorToast = {\n title: 'Error deleting report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorDeleteToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorDeletingReportDefinitionToast = () => {\n addErrorDeletingReportDefinitionToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const handleReportDefinitionDetails = e => {\n setReportDefinitionDetails(e);\n };\n\n const handleReportDefinitionRawResponse = e => {\n setReportDefinitionRawResponse(e);\n };\n\n const DeleteConfirmationModal = () => {\n const closeModal = () => {\n setShowDeleteModal(false);\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiOverlayMask, null, /*#__PURE__*/React.createElement(EuiConfirmModal, {\n title: \"Delete report definition\",\n onCancel: closeModal,\n onConfirm: deleteReportDefinition,\n cancelButtonText: \"Cancel\",\n confirmButtonText: \"Delete\",\n buttonColor: \"danger\",\n defaultFocusedButton: \"confirm\"\n }, /*#__PURE__*/React.createElement(\"p\", null, \"Are you sure you want to delete \\\"\", reportDefinitionDetails.name, \"\\\"?\"))));\n };\n\n const humanReadableScheduleDetails = trigger => {\n let scheduleDetails = '';\n\n if (trigger.trigger_type === 'Schedule') {\n if (trigger.trigger_params.schedule_type === 'Recurring') {\n // Daily\n if (trigger.trigger_params.schedule.interval.unit === 'DAYS' && trigger.trigger_params.schedule.interval.period === 1) {\n const date = new Date(trigger.trigger_params.schedule.interval.start_time);\n scheduleDetails = 'Daily @ ' + date.toTimeString();\n } // By interval\n else {\n const date = new Date(trigger.trigger_params.schedule.interval.start_time);\n scheduleDetails = 'By interval, every ' + trigger.trigger_params.schedule.interval.period + ' ' + trigger.trigger_params.schedule.interval.unit.toLowerCase() + ', starting @ ' + date.toTimeString();\n }\n } // Cron\n else if (trigger.trigger_params.schedule_type === 'Cron based') {\n scheduleDetails = 'Cron based: ' + trigger.trigger_params.schedule.cron.expression + ' (' + trigger.trigger_params.schedule.cron.timezone + ')';\n }\n }\n\n return scheduleDetails;\n };\n\n const getReportDefinitionDetailsMetadata = data => {\n const reportDefinition = data.report_definition;\n const {\n report_params: reportParams,\n trigger,\n delivery,\n time_created: timeCreated,\n last_updated: lastUpdated\n } = reportDefinition;\n const {\n trigger_type: triggerType,\n trigger_params: triggerParams\n } = trigger;\n const {\n delivery_type: deliveryType,\n delivery_params: deliveryParams\n } = delivery;\n const {\n core_params: {\n base_url: baseUrl,\n report_format: reportFormat,\n time_duration: timeDuration\n }\n } = reportParams;\n let readableDate = new Date(timeCreated);\n let displayCreatedDate = readableDate.toDateString() + ' ' + readableDate.toLocaleTimeString();\n let readableUpdatedDate = new Date(lastUpdated);\n let displayUpdatedDate = readableUpdatedDate.toDateString() + ' ' + readableUpdatedDate.toLocaleTimeString();\n let reportDefinitionDetails = {\n name: reportParams.report_name,\n description: reportParams.description === '' ? `\\u2014` : reportParams.description,\n created: displayCreatedDate,\n lastUpdated: displayUpdatedDate,\n source: reportParams.report_source,\n baseUrl: baseUrl,\n // TODO: need better display\n timePeriod: moment.duration(timeDuration).humanize(),\n fileFormat: reportFormat,\n reportHeader: reportParams.core_params.hasOwnProperty('header') ? converter.makeMarkdown(reportParams.core_params.header) : `\\u2014`,\n reportFooter: reportParams.core_params.hasOwnProperty('footer') ? converter.makeMarkdown(reportParams.core_params.footer) : `\\u2014`,\n triggerType: triggerType,\n scheduleDetails: triggerParams ? humanReadableScheduleDetails(data.report_definition.trigger) : `\\u2014`,\n channel: deliveryType,\n status: reportDefinition.status,\n kibanaRecipients: deliveryParams.kibana_recipients ? deliveryParams.kibana_recipients : `\\u2014`,\n emailRecipients: deliveryType === 'Channel' ? deliveryParams.recipients : `\\u2014`,\n emailSubject: deliveryType === 'Channel' ? deliveryParams.title : `\\u2014`,\n emailBody: deliveryType === 'Channel' ? deliveryParams.textDescription : `\\u2014`\n };\n return reportDefinitionDetails;\n };\n\n useEffect(() => {\n const {\n httpClient\n } = props;\n httpClient.get(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(response => {\n handleReportDefinitionRawResponse(response);\n handleReportDefinitionDetails(getReportDefinitionDetailsMetadata(response));\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: `Report definition details: ${response.report_definition.report_params.report_name}`\n }]);\n }).catch(error => {\n console.error('error when getting report definition details:', error);\n handleDetailsErrorToast();\n });\n }, []);\n\n const fileFormatDownload = data => {\n let formatUpper = data['fileFormat'];\n formatUpper = fileFormatsUpper[formatUpper];\n return /*#__PURE__*/React.createElement(EuiLink, {\n onClick: generateReportFromDetails\n }, formatUpper + ' ', /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n }));\n };\n\n const sourceURL = data => {\n return /*#__PURE__*/React.createElement(EuiLink, {\n href: `${data.baseUrl}`,\n target: \"_blank\"\n }, data['source']);\n };\n\n const getRelativeStartDate = duration => {\n duration = moment.duration(duration);\n let time_difference = moment.now() - duration;\n return new Date(time_difference);\n };\n\n const changeScheduledReportDefinitionStatus = statusChange => {\n let updatedReportDefinition = reportDefinitionRawResponse.report_definition;\n\n if (statusChange === 'Disable') {\n updatedReportDefinition.trigger.trigger_params.enabled = false;\n updatedReportDefinition.status = 'Disabled';\n } else if (statusChange === 'Enable') {\n updatedReportDefinition.trigger.trigger_params.enabled = true;\n updatedReportDefinition.status = 'Active';\n }\n\n const {\n httpClient\n } = props;\n httpClient.put(`../api/reporting/reportDefinitions/${reportDefinitionId}`, {\n body: JSON.stringify(updatedReportDefinition),\n params: reportDefinitionId.toString()\n }).then(() => {\n const updatedRawResponse = {\n report_definition: {}\n };\n updatedRawResponse.report_definition = updatedReportDefinition;\n handleReportDefinitionRawResponse(updatedRawResponse);\n setReportDefinitionDetails(getReportDefinitionDetailsMetadata(updatedRawResponse));\n\n if (statusChange === 'Enable') {\n handleSuccessEnablingScheduleToast();\n } else if (statusChange === 'Disable') {\n handleSuccessDisablingScheduleToast();\n }\n }).catch(error => {\n console.error('error in updating report definition status:', error);\n\n if (statusChange === 'Enable') {\n handleErrorEnablingScheduleToast();\n } else if (statusChange === 'Disable') {\n handleErrorDisablingScheduleToast();\n }\n });\n };\n\n const ScheduledDefinitionStatus = () => {\n const status = reportDefinitionDetails.status === 'Active' ? 'Disable' : 'Enable';\n return /*#__PURE__*/React.createElement(EuiButton, {\n onClick: () => changeScheduledReportDefinitionStatus(status),\n id: 'changeStatusFromDetailsButton'\n }, status);\n };\n\n const generateReportFromDetails = async () => {\n let duration = reportDefinitionRawResponse.report_definition.report_params.core_params.time_duration;\n const fromDate = getRelativeStartDate(duration);\n let onDemandDownloadMetadata = {\n query_url: `${reportDefinitionDetails.baseUrl}?_g=(time:(from:'${fromDate.toISOString()}',to:'${moment().toISOString()}'))`,\n time_from: fromDate.valueOf(),\n time_to: moment().valueOf(),\n report_definition: reportDefinitionRawResponse.report_definition\n };\n const {\n httpClient\n } = props;\n let generateReportSuccess = await generateReport(onDemandDownloadMetadata, httpClient);\n\n if (generateReportSuccess) {\n handleSuccessGeneratingReportToast();\n } else {\n handleErrorGeneratingReportToast();\n }\n };\n\n const deleteReportDefinition = () => {\n const {\n httpClient\n } = props;\n httpClient.delete(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(() => {\n window.location.assign(`opendistro_kibana_reports#/`);\n }).catch(error => {\n console.log('error when deleting report definition:', error);\n handleErrorDeletingReportDefinitionToast();\n });\n };\n\n const showActionButton = reportDefinitionDetails.triggerType === ON_DEMAND ? /*#__PURE__*/React.createElement(EuiButton, {\n onClick: () => generateReportFromDetails(),\n id: 'generateReportFromDetailsButton'\n }, \"Generate report\") : /*#__PURE__*/React.createElement(ScheduledDefinitionStatus, null);\n const triggerSection = reportDefinitionDetails.triggerType === ON_DEMAND ? /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Trigger type',\n reportDetailsComponentContent: reportDefinitionDetails.triggerType\n }) : /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Trigger type',\n reportDetailsComponentContent: reportDefinitionDetails.triggerType\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Schedule details',\n reportDetailsComponentContent: reportDefinitionDetails.scheduleDetails\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Status',\n reportDetailsComponentContent: reportDefinitionDetails.status\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null));\n const showDeleteConfirmationModal = showDeleteModal ? /*#__PURE__*/React.createElement(DeleteConfirmationModal, null) : null;\n return /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, {\n size: \"l\"\n }, /*#__PURE__*/React.createElement(\"h1\", null, \"Report definition details\")), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"m\"\n }), /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiPageHeaderSection, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, reportDefinitionDetails.name))))), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"flexEnd\",\n alignItems: \"flexEnd\",\n gutterSize: \"l\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n color: 'danger',\n onClick: handleShowDeleteModal,\n id: 'deleteReportDefinitionButton'\n }, \"Delete\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, showActionButton), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => {\n window.location.assign(`opendistro_kibana_reports#/edit/${reportDefinitionId}`);\n },\n id: 'editReportDefinitionButton'\n }, \"Edit\")))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Name',\n reportDetailsComponentContent: reportDefinitionDetails.name\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Description',\n reportDetailsComponentContent: reportDefinitionDetails.description\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Created',\n reportDetailsComponentContent: reportDefinitionDetails.created\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Last updated',\n reportDetailsComponentContent: reportDefinitionDetails.lastUpdated\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Source',\n reportDetailsComponentContent: sourceURL(reportDefinitionDetails)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Time period',\n reportDetailsComponentContent: `Last ${reportDefinitionDetails.timePeriod}`\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'File format',\n reportDetailsComponentContent: fileFormatDownload(reportDefinitionDetails)\n }), /*#__PURE__*/React.createElement(EuiFlexItem, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report header',\n reportDetailsComponentContent: trimAndRenderAsText(reportDefinitionDetails.reportHeader)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report footer',\n reportDetailsComponentContent: trimAndRenderAsText(reportDefinitionDetails.reportFooter)\n }), /*#__PURE__*/React.createElement(EuiFlexItem, null), /*#__PURE__*/React.createElement(EuiFlexItem, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report trigger\")), /*#__PURE__*/React.createElement(EuiSpacer, null), triggerSection, /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Notification settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email recipients',\n reportDetailsComponentContent: formatEmails(reportDefinitionDetails.emailRecipients)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email subject',\n reportDetailsComponentContent: reportDefinitionDetails.emailSubject\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Optional message',\n reportDetailsComponentContent: trimAndRenderAsText(reportDefinitionDetails.emailBody)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n }), showDeleteConfirmationModal));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useState } from 'react';\nimport { EuiLink, EuiInMemoryTable, EuiButton, EuiEmptyPrompt, EuiText, EuiIcon } from '@elastic/eui';\nimport { humanReadableDate } from './main_utils';\nconst emptyMessageReportDefinitions = /*#__PURE__*/React.createElement(EuiEmptyPrompt, {\n title: /*#__PURE__*/React.createElement(\"h3\", null, \"No report definitions to display\"),\n titleSize: \"xs\",\n body: /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiText, null, \"Create a new report definition to get started\"), /*#__PURE__*/React.createElement(EuiText, null, \"To learn more, see\", ' ', /*#__PURE__*/React.createElement(EuiLink, null, \"Get started with Kibana reporting \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"popout\"\n })))),\n actions: /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiButton, {\n onClick: () => {\n window.location.assign('opendistro_kibana_reports#/create');\n }\n }, \"Create report definition\"))\n});\nconst reportDefinitionsSearch = {\n box: {\n incremental: true\n },\n filters: []\n};\nexport function ReportDefinitions(props) {\n const {\n pagination,\n reportDefinitionsTableContent\n } = props;\n const [sortField, setSortField] = useState('lastUpdated');\n const [sortDirection, setSortDirection] = useState('des');\n const sorting = {\n sort: {\n field: sortField,\n direction: sortDirection\n }\n };\n\n const getDefinitionTableItemId = name => {\n let index;\n\n for (index = 0; index < props.reportDefinitionsTableContent.length; ++index) {\n if (name === reportDefinitionsTableContent[index].reportName) {\n return reportDefinitionsTableContent[index].id;\n }\n }\n };\n\n const navigateToDefinitionDetails = name => {\n let id = getDefinitionTableItemId(name);\n window.location.assign(`opendistro_kibana_reports#/report_definition_details/${id}`);\n };\n\n const reportDefinitionsColumns = [{\n field: 'reportName',\n name: 'Name',\n render: name => /*#__PURE__*/React.createElement(EuiLink, {\n onClick: () => navigateToDefinitionDetails(name),\n id: 'reportDefinitionDetailsLink'\n }, name)\n }, {\n field: 'source',\n name: 'Source',\n render: (value, item) => /*#__PURE__*/React.createElement(EuiLink, {\n href: item.baseUrl,\n target: \"_blank\"\n }, value)\n }, {\n field: 'type',\n name: 'Type',\n sortable: true,\n truncateText: false\n }, {\n field: 'details',\n name: 'Schedule details',\n sortable: false,\n truncateText: true\n }, {\n field: 'lastUpdated',\n name: 'Last Updated',\n render: date => {\n let readable = humanReadableDate(date);\n return /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, readable);\n }\n }, {\n field: 'status',\n name: 'Status',\n sortable: true,\n truncateText: false\n }];\n const displayMessage = reportDefinitionsTableContent.length === 0 ? emptyMessageReportDefinitions : '0 report definitions match the search criteria. Search again.';\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiInMemoryTable, {\n items: reportDefinitionsTableContent,\n itemId: \"id\",\n loading: false,\n message: displayMessage,\n columns: reportDefinitionsColumns,\n search: reportDefinitionsSearch,\n pagination: pagination,\n sorting: sorting,\n isSelectable: true,\n tableLayout: 'auto'\n }));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiFlexGroup, EuiFlexItem, EuiPage, EuiPageHeader, EuiTitle, EuiPageBody, EuiPageContent, EuiHorizontalRule, EuiSpacer, EuiDescriptionList, EuiDescriptionListTitle, EuiDescriptionListDescription, EuiPageHeaderSection, EuiLink, EuiIcon, EuiGlobalToastList } from '@elastic/eui';\nimport { fileFormatsUpper, generateReportById } from '../main_utils';\nimport { converter } from '../../report_definitions/utils';\nimport dateMath from '@elastic/datemath';\nexport const ReportDetailsComponent = props => {\n const {\n reportDetailsComponentTitle,\n reportDetailsComponentContent\n } = props;\n return /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiDescriptionList, null, /*#__PURE__*/React.createElement(EuiDescriptionListTitle, null, reportDetailsComponentTitle), /*#__PURE__*/React.createElement(EuiDescriptionListDescription, null, reportDetailsComponentContent)));\n}; // convert markdown to plain text, trim it if it's longer than 3 lines\n\nexport const trimAndRenderAsText = markdown => {\n if (!markdown) return markdown;\n const lines = markdown.split('\\n').filter(line => line);\n const elements = lines.slice(0, 3).map((line, i) => /*#__PURE__*/React.createElement(\"p\", {\n key: i\n }, line));\n return lines.length <= 3 ? elements : elements.concat( /*#__PURE__*/React.createElement(\"p\", {\n key: 3\n }, \"...\"));\n};\nexport const formatEmails = emails => {\n return Array.isArray(emails) ? emails.join(', ') : emails;\n};\nexport function ReportDetails(props) {\n const [reportDetails, setReportDetails] = useState({});\n const [toasts, setToasts] = useState([]);\n const reportId = props.match['params']['reportId'];\n\n const addErrorToastHandler = () => {\n const errorToast = {\n title: 'Error loading report details.',\n color: 'danger',\n iconType: 'alert',\n id: 'reportDetailsErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorToast = () => {\n addErrorToastHandler();\n };\n\n const addSuccessToastHandler = () => {\n const successToast = {\n title: 'Success',\n color: 'success',\n text: /*#__PURE__*/React.createElement(\"p\", null, \"Report successfully downloaded!\"),\n id: 'onDemandDownloadSuccessToast'\n };\n setToasts(toasts.concat(successToast));\n };\n\n const handleSuccessToast = () => {\n addSuccessToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const handleReportDetails = e => {\n setReportDetails(e);\n };\n\n const convertTimestamp = timestamp => {\n let displayDate = `\\u2014`;\n\n if (timestamp) {\n let readableDate = new Date(timestamp);\n displayDate = readableDate.toLocaleString();\n }\n\n return displayDate;\n };\n\n const parseTimePeriod = queryUrl => {\n let timeString = queryUrl.substring(queryUrl.lastIndexOf('time:'), queryUrl.lastIndexOf('))'));\n let fromDateString = timeString.substring(timeString.lastIndexOf('from:') + 5, timeString.lastIndexOf(','));\n let toDateString = timeString.substring(timeString.lastIndexOf('to:') + 3, timeString.length);\n fromDateString = fromDateString.replace(/[']+/g, '');\n toDateString = toDateString.replace(/[']+/g, '');\n let fromDateParsed = dateMath.parse(fromDateString);\n let toDateParsed = dateMath.parse(toDateString);\n const fromTimePeriod = fromDateParsed === null || fromDateParsed === void 0 ? void 0 : fromDateParsed.toDate();\n const toTimePeriod = toDateParsed === null || toDateParsed === void 0 ? void 0 : toDateParsed.toDate();\n return (fromTimePeriod === null || fromTimePeriod === void 0 ? void 0 : fromTimePeriod.toLocaleString()) + ' -> ' + (toTimePeriod === null || toTimePeriod === void 0 ? void 0 : toTimePeriod.toLocaleString());\n };\n\n const getReportDetailsData = report => {\n const {\n report_definition: reportDefinition,\n last_updated: lastUpdated,\n state,\n query_url: queryUrl\n } = report;\n const {\n report_params: reportParams,\n trigger,\n delivery\n } = reportDefinition;\n const {\n trigger_type: triggerType,\n trigger_params: triggerParams\n } = trigger;\n const {\n delivery_type: deliveryType,\n delivery_params: deliveryParams\n } = delivery;\n const coreParams = reportParams.core_params; // covert timestamp to local date-time string\n\n let reportDetails = {\n reportName: reportParams.report_name,\n description: reportParams.description === '' ? `\\u2014` : reportParams.description,\n created: convertTimestamp(report.time_created),\n lastUpdated: convertTimestamp(report.last_updated),\n source: reportParams.report_source,\n // TODO: we have all data needed, time_from, time_to, time_duration,\n // think of a way to better display\n time_period: parseTimePeriod(queryUrl),\n defaultFileFormat: coreParams.report_format,\n state: state,\n reportHeader: reportParams.core_params.hasOwnProperty('header') ? converter.makeMarkdown(reportParams.core_params.header) : `\\u2014`,\n reportFooter: reportParams.core_params.hasOwnProperty('footer') ? converter.makeMarkdown(reportParams.core_params.footer) : `\\u2014`,\n triggerType: triggerType,\n scheduleType: triggerParams ? triggerParams.schedule_type : `\\u2014`,\n scheduleDetails: `\\u2014`,\n alertDetails: `\\u2014`,\n channel: deliveryType,\n emailRecipients: deliveryType === 'Channel' ? deliveryParams.recipients : `\\u2014`,\n emailSubject: deliveryType === 'Channel' ? deliveryParams.title : `\\u2014`,\n emailBody: deliveryType === 'Channel' ? deliveryParams.textDescription : `\\u2014`,\n queryUrl: queryUrl\n };\n return reportDetails;\n };\n\n useEffect(() => {\n const {\n httpClient\n } = props;\n httpClient.get('../api/reporting/reports/' + reportId).then(response => {\n handleReportDetails(getReportDetailsData(response));\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: 'Report details: ' + response.report_definition.report_params.report_name\n }]);\n }).catch(error => {\n console.log('Error when fetching report details: ', error);\n handleErrorToast();\n });\n }, []);\n\n const fileFormatDownload = data => {\n let formatUpper = data['defaultFileFormat'];\n formatUpper = fileFormatsUpper[formatUpper];\n return /*#__PURE__*/React.createElement(EuiLink, {\n onClick: () => {\n generateReportById(reportId, props.httpClient, handleSuccessToast, handleErrorToast);\n }\n }, formatUpper + ' ', /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n }));\n };\n\n const sourceURL = data => {\n return /*#__PURE__*/React.createElement(EuiLink, {\n href: `${data.queryUrl}`,\n target: \"_blank\"\n }, data['source']);\n };\n\n return /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, {\n size: \"l\"\n }, /*#__PURE__*/React.createElement(\"h1\", null, \"Report details\")), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"m\"\n }), /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiPageHeaderSection, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, reportDetails['reportName'])))))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report Settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Name',\n reportDetailsComponentContent: reportDetails['reportName']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Description',\n reportDetailsComponentContent: reportDetails['description']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Created',\n reportDetailsComponentContent: reportDetails['created']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Last updated',\n reportDetailsComponentContent: reportDetails['lastUpdated']\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Source',\n reportDetailsComponentContent: sourceURL(reportDetails)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Time period',\n reportDetailsComponentContent: reportDetails.time_period\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'File format',\n reportDetailsComponentContent: fileFormatDownload(reportDetails)\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'State',\n reportDetailsComponentContent: reportDetails['state']\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report header',\n reportDetailsComponentContent: trimAndRenderAsText(reportDetails['reportHeader'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report footer',\n reportDetailsComponentContent: trimAndRenderAsText(reportDetails['reportFooter'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null), /*#__PURE__*/React.createElement(ReportDetailsComponent, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Report trigger\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Report type',\n reportDetailsComponentContent: reportDetails['triggerType']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Schedule type',\n reportDetailsComponentContent: reportDetails['scheduleType']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Schedule details',\n reportDetailsComponentContent: reportDetails['scheduleDetails']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null)), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h3\", null, \"Notification settings\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email recipient(s)',\n reportDetailsComponentContent: formatEmails(reportDetails['emailRecipients'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Email subject',\n reportDetailsComponentContent: reportDetails['emailSubject']\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, {\n reportDetailsComponentTitle: 'Optional message',\n reportDetailsComponentContent: trimAndRenderAsText(reportDetails['emailBody'])\n }), /*#__PURE__*/React.createElement(ReportDetailsComponent, null))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { Fragment, useState } from 'react';\nimport { EuiButton // @ts-ignore\n, EuiLink, EuiText, EuiIcon, EuiEmptyPrompt, EuiInMemoryTable, EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner, EuiModal, EuiModalBody, EuiModalHeader, EuiOverlayMask, EuiSpacer, EuiTitle } from '@elastic/eui';\nimport { fileFormatsUpper, humanReadableDate, generateReportById } from './main_utils';\nconst reportStatusOptions = ['Created', 'Error', 'Pending', 'Shared', 'Archived'];\nconst reportTypeOptions = ['Schedule', 'On demand'];\nconst emptyMessageReports = /*#__PURE__*/React.createElement(EuiEmptyPrompt, {\n title: /*#__PURE__*/React.createElement(\"h3\", null, \"No reports to display\"),\n titleSize: \"xs\",\n body: /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiText, null, \"Create a report definition, or share/download a report from a dashboard, saved search or visualization.\"), /*#__PURE__*/React.createElement(EuiText, null, \"To learn more, see\", ' ', /*#__PURE__*/React.createElement(EuiLink, null, \"Get started with Kibana reporting \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"popout\"\n }))))\n});\nexport function ReportsTable(props) {\n const {\n pagination,\n reportsTableItems,\n httpClient,\n handleSuccessToast,\n handleErrorToast\n } = props;\n const [sortField, setSortField] = useState('timeCreated');\n const [sortDirection, setSortDirection] = useState('des');\n const [showLoading, setShowLoading] = useState(false);\n const [message, setMessage] = useState('');\n\n const handleLoading = e => {\n setShowLoading(e);\n };\n\n const GenerateReportLoadingModal = () => {\n const [isModalVisible, setIsModalVisible] = useState(true);\n\n const closeModal = () => {\n setIsModalVisible(false);\n setShowLoading(false);\n };\n\n const showModal = () => setIsModalVisible(true);\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiOverlayMask, null, /*#__PURE__*/React.createElement(EuiModal, {\n onClose: closeModal,\n style: {\n maxWidth: 350,\n minWidth: 300\n }\n }, /*#__PURE__*/React.createElement(EuiModalHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(EuiText, {\n textAlign: \"right\"\n }, /*#__PURE__*/React.createElement(\"h2\", null, \"Generating report\")))), /*#__PURE__*/React.createElement(EuiModalBody, null, /*#__PURE__*/React.createElement(EuiText, null, \"Preparing your file for download.\"), /*#__PURE__*/React.createElement(EuiText, null, \"You can close this dialog while we continue in the background.\"), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"center\",\n alignItems: \"center\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiLoadingSpinner, {\n size: \"xl\",\n style: {\n minWidth: 75,\n minHeight: 75\n }\n }))), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"l\"\n }), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n alignItems: \"flexEnd\",\n justifyContent: \"flexEnd\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n onClick: closeModal\n }, \"Close\")))))));\n };\n\n const onDemandDownload = async id => {\n handleLoading(true);\n await generateReportById(id, httpClient, handleSuccessToast, handleErrorToast);\n handleLoading(false);\n };\n\n const reportsTableColumns = [{\n field: 'reportName',\n name: 'Name',\n render: (reportName, item) => /*#__PURE__*/React.createElement(EuiLink, {\n disabled: item.state === 'Pending',\n onClick: () => {\n window.location.assign(`opendistro_kibana_reports#/report_details/${item.id}`);\n },\n id: 'reportDetailsLink'\n }, reportName)\n }, {\n // TODO: link to dashboard/visualization snapshot, use \"queryUrl\" field. Display dashboard name?\n field: 'reportSource',\n name: 'Source',\n render: (source, item) => item.state === 'Pending' ? /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, source) : /*#__PURE__*/React.createElement(EuiLink, {\n href: item.url,\n target: \"_blank\"\n }, source)\n }, {\n field: 'type',\n name: 'Type',\n sortable: true,\n truncateText: false\n }, {\n field: 'timeCreated',\n name: 'Creation time',\n render: date => {\n let readable = humanReadableDate(date);\n return /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, readable);\n }\n }, {\n field: 'state',\n name: 'State',\n sortable: true,\n truncateText: false\n }, {\n field: 'id',\n name: 'Generate',\n render: (id, item) => item.state === 'Pending' ? /*#__PURE__*/React.createElement(EuiText, {\n size: \"s\"\n }, fileFormatsUpper[item.format], \" \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n })) : /*#__PURE__*/React.createElement(EuiLink, {\n onClick: () => onDemandDownload(id)\n }, fileFormatsUpper[item.format], \" \", /*#__PURE__*/React.createElement(EuiIcon, {\n type: \"importAction\"\n }))\n }];\n const sorting = {\n sort: {\n field: sortField,\n direction: sortDirection\n }\n };\n const reportsListSearch = {\n box: {\n incremental: true\n },\n filters: [{\n type: 'field_value_selection',\n field: 'type',\n name: 'Type',\n multiselect: false,\n options: reportTypeOptions.map(type => ({\n value: type,\n name: type,\n view: type\n }))\n }, {\n type: 'field_value_selection',\n field: 'state',\n name: 'State',\n multiselect: false,\n options: reportStatusOptions.map(state => ({\n value: state,\n name: state,\n view: state\n }))\n }]\n };\n const displayMessage = reportsTableItems.length === 0 ? emptyMessageReports : '0 reports match the search criteria. Search again';\n const showLoadingModal = showLoading ? /*#__PURE__*/React.createElement(GenerateReportLoadingModal, null) : null;\n return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(EuiInMemoryTable, {\n items: reportsTableItems,\n itemId: \"id\",\n loading: false,\n message: displayMessage,\n columns: reportsTableColumns,\n search: reportsListSearch,\n pagination: pagination,\n sorting: sorting,\n hasActions: true,\n tableLayout: 'auto'\n }), showLoadingModal);\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiGlobalToastList, EuiButton, EuiTitle, EuiPageBody, EuiSpacer } from '@elastic/eui';\nimport { ReportSettings } from '../report_settings';\nimport { ReportDelivery } from '../delivery';\nimport { ReportTrigger } from '../report_trigger';\nimport { generateReport } from '../../main/main_utils';\nimport { isValidCron } from 'cron-validator';\nimport { converter } from '../utils';\nimport moment from 'moment';\nexport function CreateReport(props) {\n let createReportDefinitionRequest = {\n report_params: {\n report_name: '',\n report_source: '',\n description: '',\n core_params: {\n base_url: '',\n report_format: '',\n time_duration: ''\n }\n },\n delivery: {\n delivery_type: '',\n delivery_params: {}\n },\n trigger: {\n trigger_type: ''\n }\n };\n const [toasts, setToasts] = useState([]);\n const [comingFromError, setComingFromError] = useState(false);\n const [preErrorData, setPreErrorData] = useState({});\n const [showSettingsReportNameError, setShowSettingsReportNameError] = useState(false);\n const [showTriggerIntervalNaNError, setShowTriggerIntervalNaNError] = useState(false);\n const [showCronError, setShowCronError] = useState(false);\n const [showEmailRecipientsError, setShowEmailRecipientsError] = useState(false);\n const [showTimeRangeError, setShowTimeRangeError] = useState(false); // preserve the state of the request after an invalid create report definition request\n\n if (comingFromError) {\n createReportDefinitionRequest = preErrorData;\n }\n\n const addErrorToastHandler = () => {\n const errorToast = {\n title: 'Error creating report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorToast = () => {\n addErrorToastHandler();\n };\n\n const addInvalidTimeRangeToastHandler = () => {\n const errorToast = {\n title: 'Invalid time range selected.',\n color: 'danger',\n iconType: 'alert',\n id: 'timeRangeErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleInvalidTimeRangeToast = () => {\n addInvalidTimeRangeToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n let timeRange = {\n timeFrom: new Date(),\n timeTo: new Date()\n };\n\n const definitionInputValidation = async (metadata, error) => {\n // check report name\n // allow a-z, A-Z, 0-9, (), [], ',' - and _ and spaces\n let regexp = /^[\\w\\-\\s\\(\\)\\[\\]\\,\\_\\-+]+$/;\n\n if (metadata.report_params.report_name.search(regexp) === -1) {\n setShowSettingsReportNameError(true);\n error = true;\n } // if recurring by interval and input is not a number\n\n\n if (metadata.trigger.trigger_type === 'Schedule' && metadata.trigger.trigger_params.schedule_type === 'Recurring') {\n let interval = parseInt(metadata.trigger.trigger_params.schedule.interval.period);\n\n if (isNaN(interval)) {\n setShowTriggerIntervalNaNError(true);\n error = true;\n }\n } // if time range is invalid\n\n\n const nowDate = new Date(moment.now());\n\n if (timeRange.timeFrom > timeRange.timeTo || timeRange.timeTo > nowDate) {\n setShowTimeRangeError(true);\n error = true;\n } // if cron based and cron input is invalid\n\n\n if (metadata.trigger.trigger_type === 'Schedule' && metadata.trigger.trigger_params.schedule_type === 'Cron based') {\n if (!isValidCron(metadata.trigger.trigger_params.schedule.cron.expression)) {\n setShowCronError(true);\n error = true;\n }\n } // if email delivery\n\n\n if (metadata.delivery.delivery_type === 'Channel') {\n // no recipients are listed\n if (metadata.delivery.delivery_params.recipients.length === 0) {\n setShowEmailRecipientsError(true);\n error = true;\n } // recipients have invalid email addresses: regexp checks format xxxxx@yyyy.zzz\n\n\n let emailRegExp = /\\S+@\\S+\\.\\S+/;\n let index;\n let recipients = metadata.delivery.delivery_params.recipients;\n\n for (index = 0; index < recipients.length; ++index) {\n if (recipients[0].search(emailRegExp) === -1) {\n setShowEmailRecipientsError(true);\n error = true;\n }\n }\n }\n\n return error;\n };\n\n const createNewReportDefinition = async (metadata, timeRange) => {\n const {\n httpClient\n } = props; //TODO: need better handle\n\n if (metadata.trigger.trigger_type === 'On demand' && metadata.trigger.trigger_params !== undefined) {\n delete metadata.trigger.trigger_params;\n }\n\n let error = false;\n await definitionInputValidation(metadata, error).then(response => {\n error = response;\n });\n\n if (error) {\n handleErrorToast();\n setPreErrorData(metadata);\n setComingFromError(true);\n } else {\n // convert header and footer to html\n if ('header' in metadata.report_params.core_params) {\n metadata.report_params.core_params.header = converter.makeHtml(metadata.report_params.core_params.header);\n }\n\n if ('footer' in metadata.report_params.core_params) {\n metadata.report_params.core_params.footer = converter.makeHtml(metadata.report_params.core_params.footer);\n }\n\n httpClient.post('../api/reporting/reportDefinition', {\n body: JSON.stringify(metadata),\n headers: {\n 'Content-Type': 'application/json'\n }\n }).then(async resp => {\n //TODO: consider handle the on demand report generation from server side instead\n if (metadata.trigger.trigger_type === 'On demand') {\n let onDemandDownloadMetadata = {\n query_url: `${metadata.report_params.core_params.base_url}?_g=(time:(from:'${timeRange.timeFrom.toISOString()}',to:'${timeRange.timeTo.toISOString()}'))`,\n time_from: timeRange.timeFrom.valueOf(),\n time_to: timeRange.timeTo.valueOf(),\n report_definition: metadata\n };\n generateReport(onDemandDownloadMetadata, httpClient);\n }\n\n window.location.assign(`opendistro_kibana_reports#/create=success`);\n }).catch(error => {\n console.log('error in creating report definition: ' + error);\n handleErrorToast();\n });\n }\n };\n\n useEffect(() => {\n window.scrollTo(0, 0);\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: 'Create report definition',\n href: '#/create'\n }]);\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h1\", null, \"Create report definition\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportSettings, {\n edit: false,\n reportDefinitionRequest: createReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange,\n showSettingsReportNameError: showSettingsReportNameError,\n showTimeRangeError: showTimeRangeError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportTrigger, {\n edit: false,\n reportDefinitionRequest: createReportDefinitionRequest,\n showTriggerIntervalNaNError: showTriggerIntervalNaNError,\n showCronError: showCronError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportDelivery, {\n edit: false,\n reportDefinitionRequest: createReportDefinitionRequest,\n showEmailRecipientsError: showEmailRecipientsError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"flexEnd\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButtonEmpty, {\n onClick: () => {\n window.location.assign(`opendistro_kibana_reports#/`);\n }\n }, \"Cancel\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => createNewReportDefinition(createReportDefinitionRequest, timeRange),\n id: 'createNewReportDefinition'\n }, \"Create\"))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiPageHeader, EuiTitle, EuiPageContent, EuiPageContentBody, EuiHorizontalRule, EuiSpacer, EuiCheckbox } from '@elastic/eui';\nimport { DELIVERY_TYPE_OPTIONS } from './delivery_constants';\nimport 'react-mde/lib/styles/css/react-mde-all.css';\nimport { EmailDelivery } from './email';\nexport function ReportDelivery(props) {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps\n } = props;\n const [emailCheckbox, setEmailCheckbox] = useState(false);\n\n const handleEmailCheckbox = e => {\n setEmailCheckbox(e.target.checked);\n\n if (e.target.checked) {\n // if checked, set delivery type to email\n reportDefinitionRequest.delivery.delivery_type = DELIVERY_TYPE_OPTIONS[1].id;\n } else {\n // uncheck email checkbox means to use default setting, which is kibana user\n defaultCreateDeliveryParams();\n }\n };\n\n const emailDelivery = emailCheckbox ? /*#__PURE__*/React.createElement(EmailDelivery, props) : null;\n\n const defaultCreateDeliveryParams = () => {\n reportDefinitionRequest.delivery = {\n delivery_type: DELIVERY_TYPE_OPTIONS[0].id,\n delivery_params: {\n kibana_recipients: []\n }\n };\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n const isEmailSelected = response.report_definition.delivery.delivery_type === DELIVERY_TYPE_OPTIONS[1].id;\n handleEmailCheckbox({\n target: {\n checked: isEmailSelected\n }\n });\n });\n } else {\n // By default it's set to deliver to kibana user\n defaultCreateDeliveryParams();\n }\n }, []);\n return /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Notification settings\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(EuiCheckbox, {\n id: \"emailCheckboxDelivery\",\n label: \"Add email recipients\",\n checked: emailCheckbox,\n onChange: handleEmailCheckbox\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), emailDelivery));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport const EMAIL_RECIPIENT_OPTIONS = [];\nexport const DELIVERY_TYPE_OPTIONS = [{\n id: 'Kibana user',\n label: 'Kibana user'\n}, {\n id: 'Channel',\n label: 'Email'\n}];","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport { EuiComboBox, EuiFieldText, EuiFormRow, EuiSpacer } from '@elastic/eui';\nimport React, { useEffect } from 'react';\nimport { useState } from 'react';\nimport ReactMDE from 'react-mde';\nimport { converter } from '../utils';\nimport { DELIVERY_TYPE_OPTIONS } from './delivery_constants';\nexport const EmailDelivery = props => {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps,\n showEmailRecipientsError\n } = props;\n const [emailRecipients, setEmailRecipients] = useState([]);\n const [selectedEmailRecipients, setSelectedEmailRecipients] = useState([]);\n const [emailSubject, setEmailSubject] = useState('');\n const [emailBody, setEmailBody] = useState('');\n const [selectedTab, setSelectedTab] = React.useState('write');\n\n const handleCreateEmailRecipient = (searchValue, flattenedOptions = []) => {\n const normalizedSearchValue = searchValue.trim().toLowerCase();\n\n if (!normalizedSearchValue) {\n return;\n }\n\n const newOption = {\n label: searchValue\n }; // Create the option if it doesn't exist.\n\n if (flattenedOptions.findIndex(option => option.label.trim().toLowerCase() === normalizedSearchValue) === -1) {\n setEmailRecipients([...emailRecipients, newOption]);\n }\n\n handleSelectEmailRecipients([...selectedEmailRecipients, newOption]);\n };\n\n const handleSelectEmailRecipients = e => {\n setSelectedEmailRecipients(e);\n reportDefinitionRequest.delivery.delivery_params.recipients = e.map(option => option.label);\n };\n\n const handleEmailSubject = e => {\n setEmailSubject(e.target.value);\n reportDefinitionRequest.delivery.delivery_params.title = e.target.value;\n };\n\n const handleEmailBody = e => {\n setEmailBody(e);\n reportDefinitionRequest.delivery.delivery_params.textDescription = e;\n reportDefinitionRequest.delivery.delivery_params.htmlDescription = converter.makeHtml(e);\n }; // TODO: need better handling when we add full support for kibana user report delivery\n\n\n const optionalMessageLabel = `Add optional message (${selectedTab} mode)`;\n\n const defaultEditDeliveryParams = delivery => {\n //TODO: need better handle?\n // if the original notification setting is kibana user\n if (delivery.delivery_type === DELIVERY_TYPE_OPTIONS[0].id) {\n defaultCreateDeliveryParams();\n delete reportDefinitionRequest.delivery.delivery_params.kibana_recipients;\n } else {\n //@ts-ignore\n const emailParams = delivery.delivery_params;\n const {\n recipients,\n title,\n textDescription\n } = emailParams;\n const recipientsOptions = recipients.map(email => ({\n label: email\n }));\n handleSelectEmailRecipients(recipientsOptions);\n setEmailRecipients(recipientsOptions);\n setEmailSubject(title);\n reportDefinitionRequest.delivery.delivery_params.title = title;\n handleEmailBody(textDescription);\n }\n };\n\n const defaultCreateDeliveryParams = () => {\n reportDefinitionRequest.delivery.delivery_params = {\n recipients: selectedEmailRecipients.map(option => option.label),\n title: emailSubject,\n textDescription: emailBody,\n htmlDescription: converter.makeHtml(emailBody)\n };\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n defaultEditDeliveryParams(response.report_definition.delivery);\n });\n } else {\n defaultCreateDeliveryParams();\n }\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Email recipients\",\n helpText: \"Select or add users\",\n isInvalid: showEmailRecipientsError\n }, /*#__PURE__*/React.createElement(EuiComboBox, {\n placeholder: 'Add users here',\n options: emailRecipients,\n selectedOptions: selectedEmailRecipients,\n onChange: handleSelectEmailRecipients,\n onCreateOption: handleCreateEmailRecipient,\n isClearable: true,\n \"data-test-subj\": \"demoComboBox\"\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Email subject\"\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: \"Subject line\",\n value: emailSubject,\n onChange: handleEmailSubject\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: optionalMessageLabel,\n fullWidth: true\n }, /*#__PURE__*/React.createElement(ReactMDE, {\n value: emailBody,\n onChange: handleEmailBody,\n selectedTab: selectedTab,\n onTabChange: setSelectedTab,\n toolbarCommands: [['header', 'bold', 'italic', 'strikethrough'], ['unordered-list', 'ordered-list', 'checked-list']],\n generateMarkdownPreview: markdown => Promise.resolve(converter.makeHtml(markdown))\n })), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"xs\"\n }));\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport { ReportDelivery } from './delivery';","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiButton, EuiPage, EuiTitle, EuiPageBody, EuiSpacer, EuiGlobalToastList } from '@elastic/eui';\nimport { ReportSettings } from '../report_settings';\nimport { ReportDelivery } from '../delivery';\nimport { ReportTrigger } from '../report_trigger';\nimport { converter } from '../utils';\nexport function EditReportDefinition(props) {\n const [toasts, setToasts] = useState([]);\n const [comingFromError, setComingFromError] = useState(false);\n const [preErrorData, setPreErrorData] = useState({});\n\n const addErrorUpdatingReportDefinitionToast = () => {\n const errorToast = {\n title: 'Error updating report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorUpdatingReportDefinitionToast = () => {\n addErrorUpdatingReportDefinitionToast();\n };\n\n const addErrorDeletingReportDefinitionToastHandler = () => {\n const errorToast = {\n title: 'Error deleting old scheduled report definition.',\n color: 'danger',\n iconType: 'alert',\n id: 'errorDeleteToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleErrorDeletingReportDefinitionToast = () => {\n addErrorDeletingReportDefinitionToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const reportDefinitionId = props['match']['params']['reportDefinitionId'];\n let reportDefinition;\n let editReportDefinitionRequest = {\n report_params: {\n report_name: '',\n report_source: '',\n description: '',\n core_params: {\n base_url: '',\n report_format: '',\n time_duration: ''\n }\n },\n delivery: {\n delivery_type: '',\n delivery_params: {}\n },\n trigger: {\n trigger_type: ''\n },\n time_created: 0,\n last_updated: 0,\n status: ''\n };\n reportDefinition = editReportDefinitionRequest; // initialize reportDefinition object\n\n let timeRange = {\n timeFrom: new Date(),\n timeTo: new Date()\n };\n\n if (comingFromError) {\n editReportDefinitionRequest = preErrorData;\n }\n\n const callUpdateAPI = async metadata => {\n const {\n httpClient\n } = props;\n httpClient.put(`../api/reporting/reportDefinitions/${reportDefinitionId}`, {\n body: JSON.stringify(metadata),\n params: reportDefinitionId.toString()\n }).then(async () => {\n window.location.assign(`opendistro_kibana_reports#/edit=success`);\n }).catch(error => {\n console.error('error in updating report definition:', error);\n handleErrorUpdatingReportDefinitionToast();\n setPreErrorData(metadata);\n setComingFromError(true);\n });\n };\n\n const editReportDefinition = async metadata => {\n console.log('metadata is', metadata);\n const {\n httpClient\n } = props;\n\n if ('header' in metadata.report_params.core_params) {\n metadata.report_params.core_params.header = converter.makeHtml(metadata.report_params.core_params.header);\n }\n\n if ('footer' in metadata.report_params.core_params) {\n metadata.report_params.core_params.footer = converter.makeHtml(metadata.report_params.core_params.footer);\n }\n /*\n we check if this editing updates the trigger type from Schedule to On demand. \n If so, need to first delete the reportDefinition along with the scheduled job first, by calling the delete\n report definition API\n */\n\n\n const {\n trigger: {\n trigger_type: triggerType\n }\n } = reportDefinition;\n\n if (triggerType !== 'On demand' && metadata.trigger.trigger_type === 'On demand') {\n httpClient.delete(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(async () => {\n await callUpdateAPI(metadata);\n }).catch(error => {\n console.log('error when deleting old scheduled report definition:', error);\n handleErrorDeletingReportDefinitionToast();\n });\n } else {\n await callUpdateAPI(metadata);\n }\n };\n\n useEffect(() => {\n window.scrollTo(0, 0);\n const {\n httpClient\n } = props;\n httpClient.get(`../api/reporting/reportDefinitions/${reportDefinitionId}`).then(response => {\n reportDefinition = response.report_definition;\n const {\n time_created: timeCreated,\n status,\n last_updated: lastUpdated,\n report_params: {\n report_name: reportName\n }\n } = reportDefinition; // configure non-editable fields\n\n editReportDefinitionRequest.time_created = timeCreated;\n editReportDefinitionRequest.last_updated = lastUpdated;\n editReportDefinitionRequest.status = status;\n props.setBreadcrumbs([{\n text: 'Reporting',\n href: '#'\n }, {\n text: `Report definition details: ${reportName}`,\n href: `#/report_definition_details/${reportDefinitionId}`\n }, {\n text: `Edit report definition: ${reportName}`\n }]);\n }).catch(error => {\n console.error('error when loading edit report definition page: ', error);\n });\n }, []);\n return /*#__PURE__*/React.createElement(EuiPage, null, /*#__PURE__*/React.createElement(EuiPageBody, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h1\", null, \"Edit report definition\")), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportSettings, {\n edit: true,\n editDefinitionId: reportDefinitionId,\n reportDefinitionRequest: editReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportTrigger, {\n edit: true,\n editDefinitionId: reportDefinitionId,\n reportDefinitionRequest: editReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(ReportDelivery, {\n edit: true,\n editDefinitionId: reportDefinitionId,\n reportDefinitionRequest: editReportDefinitionRequest,\n httpClientProps: props['httpClient'],\n timeRange: timeRange\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n justifyContent: \"flexEnd\"\n }, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButtonEmpty, {\n onClick: () => {\n window.location.assign('opendistro_kibana_reports#/');\n }\n }, \"Cancel\")), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiButton, {\n fill: true,\n onClick: () => editReportDefinition(editReportDefinitionRequest),\n id: 'editReportDefinitionButton'\n }, \"Save Changes\"))), /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport { ReportSettings } from './report_settings';","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiPageHeader, EuiTitle, EuiPageContent, EuiPageContentBody, EuiHorizontalRule, EuiText, EuiSpacer, EuiRadioGroup, EuiSelect, EuiTextArea, EuiCheckboxGroup } from '@elastic/eui';\nimport { REPORT_SOURCE_RADIOS, PDF_PNG_FILE_FORMAT_OPTIONS, HEADER_FOOTER_CHECKBOX, REPORT_SOURCE_TYPES } from './report_settings_constants';\nimport ReactMde from 'react-mde';\nimport 'react-mde/lib/styles/css/react-mde-all.css';\nimport { parseInContextUrl, getSavedSearchBaseUrlCreate, getVisualizationBaseUrlCreate, getSavedSearchOptions, getVisualizationOptions, getDashboardBaseUrlCreate, getDashboardOptions, handleDataToVisualReportSourceChange } from './report_settings_helpers';\nimport { TimeRangeSelect } from './time_range';\nimport { converter } from '../utils';\nexport function ReportSettings(props) {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps,\n timeRange,\n showSettingsReportNameError,\n showTimeRangeError\n } = props;\n const [reportName, setReportName] = useState('');\n const [reportDescription, setReportDescription] = useState('');\n const [reportSourceId, setReportSourceId] = useState('dashboardReportSource');\n const [dashboardSourceSelect, setDashboardSourceSelect] = useState('');\n const [dashboards, setDashboards] = useState([]);\n const [visualizationSourceSelect, setVisualizationSourceSelect] = useState('');\n const [visualizations, setVisualizations] = useState([]);\n const [savedSearchSourceSelect, setSavedSearchSourceSelect] = useState('');\n const [savedSearches, setSavedSearches] = useState([]);\n const [fileFormat, setFileFormat] = useState('pdf');\n\n const handleDashboards = e => {\n setDashboards(e);\n };\n\n const handleVisualizations = e => {\n setVisualizations(e);\n };\n\n const handleSavedSearches = e => {\n setSavedSearches(e);\n };\n\n const handleReportName = e => {\n setReportName(e.target.value);\n reportDefinitionRequest.report_params.report_name = e.target.value.toString();\n };\n\n const handleReportDescription = e => {\n setReportDescription(e.target.value);\n reportDefinitionRequest.report_params.description = e.target.value.toString();\n };\n\n const handleReportSource = e => {\n setReportSourceId(e);\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n if (e === 'dashboardReportSource') {\n reportDefinitionRequest.report_params.report_source = 'Dashboard';\n reportDefinitionRequest.report_params.core_params.base_url = getDashboardBaseUrlCreate(edit, editDefinitionId, fromInContext) + dashboards[0].value; // set params to visual report params after switch from saved search\n\n handleDataToVisualReportSourceChange(reportDefinitionRequest);\n setFileFormat('pdf');\n } else if (e === 'visualizationReportSource') {\n reportDefinitionRequest.report_params.report_source = 'Visualization';\n reportDefinitionRequest.report_params.core_params.base_url = getVisualizationBaseUrlCreate(edit, editDefinitionId, fromInContext) + visualizations[0].value; // set params to visual report params after switch from saved search\n\n handleDataToVisualReportSourceChange(reportDefinitionRequest);\n setFileFormat('pdf');\n } else if (e === 'savedSearchReportSource') {\n reportDefinitionRequest.report_params.report_source = 'Saved search';\n reportDefinitionRequest.report_params.core_params.base_url = getSavedSearchBaseUrlCreate(edit, editDefinitionId, fromInContext) + savedSearches[0].value;\n reportDefinitionRequest.report_params.core_params.saved_search_id = savedSearches[0].value;\n reportDefinitionRequest.report_params.core_params.report_format = 'csv';\n reportDefinitionRequest.report_params.core_params.limit = 10000;\n reportDefinitionRequest.report_params.core_params.excel = true;\n }\n };\n\n const handleDashboardSelect = e => {\n setDashboardSourceSelect(e.target.value);\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n reportDefinitionRequest.report_params.core_params.base_url = getDashboardBaseUrlCreate(edit, editDefinitionId, fromInContext) + e.target.value;\n };\n\n const handleVisualizationSelect = e => {\n setVisualizationSourceSelect(e.target.value);\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n reportDefinitionRequest.report_params.core_params.base_url = getVisualizationBaseUrlCreate(edit, editDefinitionId, fromInContext) + e.target.value;\n };\n\n const handleSavedSearchSelect = e => {\n setSavedSearchSourceSelect(e.target.value);\n reportDefinitionRequest.report_params.core_params.saved_search_id = e.target.value;\n let fromInContext = false;\n\n if (window.location.href.includes('?')) {\n fromInContext = true;\n }\n\n reportDefinitionRequest.report_params.core_params.base_url = getSavedSearchBaseUrlCreate(edit, editDefinitionId, fromInContext) + e.target.value;\n };\n\n const handleFileFormat = e => {\n setFileFormat(e);\n reportDefinitionRequest.report_params.core_params.report_format = e.toString();\n };\n\n const PDFandPNGFileFormats = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"File format\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: PDF_PNG_FILE_FORMAT_OPTIONS,\n idSelected: fileFormat,\n onChange: handleFileFormat\n })));\n };\n\n const SettingsMarkdown = () => {\n const [checkboxIdSelectHeaderFooter, setCheckboxIdSelectHeaderFooter] = useState({\n ['header']: false,\n ['footer']: false\n });\n const [footer, setFooter] = useState('');\n const [selectedTabFooter, setSelectedTabFooter] = React.useState('write');\n const [header, setHeader] = useState('');\n const [selectedTabHeader, setSelectedTabHeader] = React.useState('write');\n\n const handleHeader = e => {\n setHeader(e);\n reportDefinitionRequest.report_params.core_params.header = e;\n };\n\n const handleFooter = e => {\n setFooter(e);\n reportDefinitionRequest.report_params.core_params.footer = e;\n };\n\n const handleCheckboxHeaderFooter = optionId => {\n const newCheckboxIdToSelectedMap = { ...checkboxIdSelectHeaderFooter,\n ...{\n [optionId]: !checkboxIdSelectHeaderFooter[optionId]\n }\n };\n setCheckboxIdSelectHeaderFooter(newCheckboxIdToSelectedMap);\n };\n\n const showFooter = checkboxIdSelectHeaderFooter.footer ? /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Footer\",\n fullWidth: true\n }, /*#__PURE__*/React.createElement(ReactMde, {\n value: footer,\n onChange: handleFooter,\n selectedTab: selectedTabFooter,\n onTabChange: setSelectedTabFooter,\n toolbarCommands: [['header', 'bold', 'italic', 'strikethrough'], ['unordered-list', 'ordered-list', 'checked-list']],\n generateMarkdownPreview: markdown => Promise.resolve(converter.makeHtml(markdown))\n })) : null;\n const showHeader = checkboxIdSelectHeaderFooter.header ? /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Header\",\n fullWidth: true\n }, /*#__PURE__*/React.createElement(ReactMde, {\n value: header,\n onChange: handleHeader,\n selectedTab: selectedTabHeader,\n onTabChange: setSelectedTabHeader,\n toolbarCommands: [['header', 'bold', 'italic', 'strikethrough'], ['unordered-list', 'ordered-list', 'checked-list']],\n generateMarkdownPreview: markdown => Promise.resolve(converter.makeHtml(markdown))\n })) : null;\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n const reportDefinition = response.report_definition;\n const {\n report_params: {\n core_params: {\n header,\n footer\n }\n }\n } = reportDefinition; // set header/footer default\n\n if (header) {\n checkboxIdSelectHeaderFooter.header = true;\n\n if (!unmounted) {\n setHeader(converter.makeMarkdown(header));\n }\n }\n\n if (footer) {\n checkboxIdSelectHeaderFooter.footer = true;\n\n if (!unmounted) {\n setFooter(converter.makeMarkdown(footer));\n }\n }\n }).catch(error => {\n console.error('error in fetching report definition details:', error);\n });\n } else {\n // keeps header/footer from re-rendering empty when other fields in Report Settings are changed\n checkboxIdSelectHeaderFooter.header = 'header' in reportDefinitionRequest.report_params.core_params;\n checkboxIdSelectHeaderFooter.footer = 'footer' in reportDefinitionRequest.report_params.core_params;\n\n if (checkboxIdSelectHeaderFooter.header) {\n setHeader(reportDefinitionRequest.report_params.core_params.header);\n }\n\n if (checkboxIdSelectHeaderFooter.footer) {\n setFooter(reportDefinitionRequest.report_params.core_params.footer);\n }\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiCheckboxGroup, {\n options: HEADER_FOOTER_CHECKBOX,\n idToSelectedMap: checkboxIdSelectHeaderFooter,\n onChange: handleCheckboxHeaderFooter,\n legend: {\n children: 'Header and footer'\n }\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), showHeader, showFooter);\n };\n\n const ReportSourceDashboard = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Select dashboard\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"reportSourceDashboardSelect\",\n options: dashboards,\n value: dashboardSourceSelect,\n onChange: handleDashboardSelect\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const ReportSourceVisualization = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Select visualization\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"reportSourceVisualizationSelect\",\n options: visualizations,\n value: visualizationSourceSelect,\n onChange: handleVisualizationSelect\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const ReportSourceSavedSearch = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Select saved search\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"reportSourceSavedSearchSelect\",\n options: savedSearches,\n value: savedSearchSourceSelect,\n onChange: handleSavedSearchSelect\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const VisualReportFormatAndMarkdown = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(PDFandPNGFileFormats, null), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const setReportSourceDropdownOption = (options, reportSource, url) => {\n let index = 0;\n\n if (reportSource === REPORT_SOURCE_TYPES.dashboard) {\n for (index = 0; index < options.dashboard.length; ++index) {\n if (url.includes(options.dashboard[index].value)) {\n setDashboardSourceSelect(options.dashboard[index].value);\n }\n }\n } else if (reportSource === REPORT_SOURCE_TYPES.visualization) {\n for (index = 0; index < options.visualizations.length; ++index) {\n if (url.includes(options.visualizations[index].value)) {\n setVisualizationSourceSelect(options.visualizations[index].value);\n }\n }\n } else if (reportSource === REPORT_SOURCE_TYPES.savedSearch) {\n for (index = 0; index < options.savedSearch.length; ++index) {\n if (url.includes(options.savedSearch[index].value)) {\n setSavedSearchSourceSelect(options.savedSearch[index].value);\n }\n }\n }\n };\n\n const setDefaultFileFormat = fileFormat => {\n let index = 0;\n\n for (index = 0; index < PDF_PNG_FILE_FORMAT_OPTIONS.length; ++index) {\n if (fileFormat.toUpperCase() === PDF_PNG_FILE_FORMAT_OPTIONS[index].label) {\n setFileFormat(PDF_PNG_FILE_FORMAT_OPTIONS[index].id);\n }\n }\n };\n\n const setInContextDefaultConfiguration = () => {\n const url = window.location.href;\n const id = parseInContextUrl(url, 'id');\n\n if (url.includes('dashboard')) {\n setReportSourceId('dashboardReportSource');\n reportDefinitionRequest.report_params.report_source = REPORT_SOURCE_RADIOS[0].label;\n setDashboardSourceSelect(id);\n reportDefinitionRequest.report_params.core_params.base_url = getDashboardBaseUrlCreate(edit, id, true) + id;\n } else if (url.includes('visualize')) {\n setReportSourceId('visualizationReportSource');\n reportDefinitionRequest.report_params.report_source = REPORT_SOURCE_RADIOS[1].label;\n setVisualizationSourceSelect(id);\n reportDefinitionRequest.report_params.core_params.base_url = getVisualizationBaseUrlCreate(edit, editDefinitionId, true) + id;\n } else if (url.includes('discover')) {\n setReportSourceId('savedSearchReportSource');\n reportDefinitionRequest.report_params.core_params.report_format = 'csv';\n reportDefinitionRequest.report_params.core_params.saved_search_id = id;\n reportDefinitionRequest.report_params.report_source = REPORT_SOURCE_RADIOS[2].label;\n setSavedSearchSourceSelect(id);\n reportDefinitionRequest.report_params.core_params.base_url = getSavedSearchBaseUrlCreate(edit, editDefinitionId, true) + id;\n }\n };\n\n const setDefaultEditValues = async (response, reportSourceOptions) => {\n setReportName(response.report_definition.report_params.report_name);\n setReportDescription(response.report_definition.report_params.description);\n reportDefinitionRequest.report_params.report_name = response.report_definition.report_params.report_name;\n reportDefinitionRequest.report_params.description = response.report_definition.report_params.description;\n reportDefinitionRequest.report_params = response.report_definition.report_params;\n const reportSource = response.report_definition.report_params.report_source;\n REPORT_SOURCE_RADIOS.map(radio => {\n if (radio.label === reportSource) {\n setReportSourceId(radio.id);\n reportDefinitionRequest.report_params.report_source = reportSource;\n }\n });\n setDefaultFileFormat(response.report_definition.report_params.core_params.report_format);\n setReportSourceDropdownOption(reportSourceOptions, reportSource, response.report_definition.report_params.core_params.base_url);\n };\n\n const defaultConfigurationEdit = async httpClientProps => {\n let editData = {};\n await httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n editData = response;\n }).catch(error => {\n console.error('error in fetching report definition details:', error);\n });\n return editData;\n };\n\n const defaultConfigurationCreate = async httpClientProps => {\n let reportSourceOptions = {\n dashboard: [],\n visualizations: [],\n savedSearch: []\n };\n reportDefinitionRequest.report_params.core_params.report_format = fileFormat;\n await httpClientProps.get('../api/reporting/getReportSource/dashboard').then(async response => {\n let dashboardOptions = getDashboardOptions(response['hits']['hits']);\n reportSourceOptions.dashboard = dashboardOptions;\n handleDashboards(dashboardOptions);\n\n if (!edit) {\n setDashboardSourceSelect(dashboardOptions[0].value);\n reportDefinitionRequest.report_params.report_source = 'Dashboard';\n reportDefinitionRequest['report_params']['core_params']['base_url'] = getDashboardBaseUrlCreate(edit, editDefinitionId, false) + response['hits']['hits'][0]['_id'].substring(10);\n }\n }).catch(error => {\n console.log('error when fetching dashboards:', error);\n });\n await httpClientProps.get('../api/reporting/getReportSource/visualization').then(async response => {\n let visualizationOptions = getVisualizationOptions(response['hits']['hits']);\n reportSourceOptions.visualizations = visualizationOptions;\n await handleVisualizations(visualizationOptions);\n await setVisualizationSourceSelect(visualizationOptions[0].value);\n }).catch(error => {\n console.log('error when fetching visualizations:', error);\n });\n await httpClientProps.get('../api/reporting/getReportSource/search').then(async response => {\n let savedSearchOptions = getSavedSearchOptions(response['hits']['hits']);\n reportSourceOptions.savedSearch = savedSearchOptions;\n await handleSavedSearches(savedSearchOptions);\n await setSavedSearchSourceSelect(savedSearchOptions[0].value);\n }).catch(error => {\n console.log('error when fetching saved searches:', error);\n });\n return reportSourceOptions;\n };\n\n useEffect(() => {\n let reportSourceOptions = {};\n let editData = {};\n\n if (edit) {\n defaultConfigurationEdit(httpClientProps).then(async response => {\n editData = response;\n });\n }\n\n defaultConfigurationCreate(httpClientProps).then(async response => {\n reportSourceOptions = response; // if coming from in-context menu\n\n if (window.location.href.indexOf('?') > -1) {\n setInContextDefaultConfiguration();\n }\n\n if (edit) {\n setDefaultEditValues(editData, reportSourceOptions);\n }\n });\n }, []);\n const displayDashboardSelect = reportSourceId === 'dashboardReportSource' ? /*#__PURE__*/React.createElement(ReportSourceDashboard, null) : null;\n const displayVisualizationSelect = reportSourceId === 'visualizationReportSource' ? /*#__PURE__*/React.createElement(ReportSourceVisualization, null) : null;\n const displaySavedSearchSelect = reportSourceId === 'savedSearchReportSource' ? /*#__PURE__*/React.createElement(ReportSourceSavedSearch, null) : null;\n const displayVisualReportsFormatAndMarkdown = reportSourceId != 'savedSearchReportSource' ? /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(VisualReportFormatAndMarkdown, null), /*#__PURE__*/React.createElement(SettingsMarkdown, null)) : /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"File format\"\n }, /*#__PURE__*/React.createElement(EuiText, null, /*#__PURE__*/React.createElement(\"p\", null, \"CSV\"))));\n return /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Report Settings\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Name\",\n helpText: \"Valid characters are a-z, A-Z, 0-9, (), [], _ (underscore), - (hyphen) and (space).\",\n isInvalid: showSettingsReportNameError,\n id: 'reportSettingsName'\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: \"Report name (e.g Log Traffic Daily Report)\",\n value: reportName,\n onChange: handleReportName\n })))), /*#__PURE__*/React.createElement(EuiFlexGroup, {\n style: {\n maxWidth: 600\n }\n }, /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Description (optional)\",\n id: 'reportSettingsDescription'\n }, /*#__PURE__*/React.createElement(EuiTextArea, {\n placeholder: \"Describe this report (e.g Morning daily reports for log traffic)\",\n value: reportDescription,\n onChange: handleReportDescription\n })))), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Report source\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: REPORT_SOURCE_RADIOS,\n idSelected: reportSourceId,\n onChange: handleReportSource\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), displayDashboardSelect, displayVisualizationSelect, displaySavedSearchSelect, /*#__PURE__*/React.createElement(TimeRangeSelect, {\n timeRange: timeRange,\n reportDefinitionRequest: reportDefinitionRequest,\n edit: edit,\n id: editDefinitionId,\n httpClientProps: httpClientProps,\n showTimeRangeError: showTimeRangeError\n }), /*#__PURE__*/React.createElement(EuiSpacer, null), displayVisualReportsFormatAndMarkdown, /*#__PURE__*/React.createElement(EuiSpacer, null)));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport const REPORT_SOURCE_RADIOS = [{\n id: 'dashboardReportSource',\n label: 'Dashboard'\n}, {\n id: 'visualizationReportSource',\n label: 'Visualization'\n}, {\n id: 'savedSearchReportSource',\n label: 'Saved search'\n}];\nexport const PDF_PNG_FILE_FORMAT_OPTIONS = [{\n id: 'pdf',\n label: 'PDF'\n}, {\n id: 'png',\n label: 'PNG'\n}];\nexport const SAVED_SEARCH_FORMAT_OPTIONS = [{\n id: 'csvFormat',\n label: 'CSV'\n}, {\n id: 'xlsFormat',\n label: 'XLS'\n}];\nexport const HEADER_FOOTER_CHECKBOX = [{\n id: 'header',\n label: 'Add header'\n}, {\n id: 'footer',\n label: 'Add footer'\n}];\nexport const REPORT_SOURCE_TYPES = {\n dashboard: 'Dashboard',\n visualization: 'Visualization',\n savedSearch: 'Saved search'\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport const parseInContextUrl = (url, parameter) => {\n const info = url.split('?');\n\n if (parameter === 'id') {\n return info[1].substring(info[1].indexOf(':') + 1, info[1].length);\n } else if (parameter === 'timeFrom') {\n return info[2].substring(info[2].indexOf('=') + 1, info[2].length);\n } else if (parameter === 'timeTo') {\n return info[3].substring(info[3].indexOf('=') + 1, info[3].length);\n }\n\n return 'error: invalid parameter';\n};\nexport const getDashboardBaseUrlCreate = (edit, editDefinitionId, fromInContext) => {\n let baseUrl;\n\n if (!fromInContext) {\n baseUrl = location.pathname + location.hash;\n } else {\n baseUrl = '/app/dashboards#/view/';\n }\n\n if (edit) {\n return baseUrl.replace(`opendistro_kibana_reports#/edit/${editDefinitionId}`, 'dashboards#/view/');\n } else if (fromInContext) {\n return baseUrl;\n }\n\n return baseUrl.replace('opendistro_kibana_reports#/create', 'dashboards#/view/');\n};\nexport const getVisualizationBaseUrlCreate = (edit, editDefinitionId, fromInContext) => {\n let baseUrl;\n\n if (!fromInContext) {\n baseUrl = location.pathname + location.hash;\n } else {\n baseUrl = '/app/visualize#/edit/';\n }\n\n if (edit) {\n return baseUrl.replace(`opendistro_kibana_reports#/edit/${editDefinitionId}`, 'visualize#/edit/');\n } else if (fromInContext) {\n return baseUrl;\n }\n\n return baseUrl.replace('opendistro_kibana_reports#/create', 'visualize#/edit/');\n};\nexport const getSavedSearchBaseUrlCreate = (edit, editDefinitionId, fromInContext) => {\n let baseUrl;\n\n if (!fromInContext) {\n baseUrl = location.pathname + location.hash;\n } else {\n baseUrl = '/app/discover#/view/';\n }\n\n if (edit) {\n return baseUrl.replace(`opendistro_kibana_reports#/edit/${editDefinitionId}`, 'discover#/view/');\n } else if (fromInContext) {\n return baseUrl;\n }\n\n return baseUrl.replace('opendistro_kibana_reports#/create', 'discover#/view/');\n};\nexport const getDashboardOptions = data => {\n let index;\n let dashboard_options = [];\n\n for (index = 0; index < data.length; ++index) {\n let entry = {\n value: data[index]['_id'].substring(10),\n text: data[index]['_source']['dashboard']['title']\n };\n dashboard_options.push(entry);\n }\n\n return dashboard_options;\n};\nexport const getVisualizationOptions = data => {\n let index;\n let options = [];\n\n for (index = 0; index < data.length; ++index) {\n let entry = {\n value: data[index]['_id'].substring(14),\n text: data[index]['_source']['visualization']['title']\n };\n options.push(entry);\n }\n\n return options;\n};\nexport const getSavedSearchOptions = data => {\n let index;\n let options = [];\n\n for (index = 0; index < data.length; ++index) {\n let entry = {\n value: data[index]['_id'].substring(7),\n text: data[index]['_source']['search']['title']\n };\n options.push(entry);\n }\n\n return options;\n};\nexport const handleDataToVisualReportSourceChange = reportDefinitionRequest => {\n delete reportDefinitionRequest.report_params.core_params.saved_search_id;\n delete reportDefinitionRequest.report_params.core_params.limit;\n delete reportDefinitionRequest.report_params.core_params.excel;\n reportDefinitionRequest.report_params.core_params.report_format = 'pdf';\n};","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport moment from 'moment';\nimport React, { useState, useEffect } from 'react';\nimport { parseInContextUrl } from './report_settings_helpers';\nimport dateMath from '@elastic/datemath';\nimport { EuiFormRow, EuiGlobalToastList, EuiSuperDatePicker } from '@elastic/eui';\nexport function TimeRangeSelect(props) {\n const {\n reportDefinitionRequest,\n timeRange,\n edit,\n id,\n httpClientProps,\n showTimeRangeError\n } = props;\n const [recentlyUsedRanges, setRecentlyUsedRanges] = useState([]);\n const [isLoading, setIsLoading] = useState(false);\n const [start, setStart] = useState('now-30m');\n const [end, setEnd] = useState('now');\n const [toasts, setToasts] = useState([]);\n\n const addInvalidTimeRangeToastHandler = () => {\n const errorToast = {\n title: 'Invalid time range selected',\n color: 'danger',\n iconType: 'alert',\n id: 'timeRangeErrorToast'\n };\n setToasts(toasts.concat(errorToast));\n };\n\n const handleInvalidTimeRangeToast = () => {\n addInvalidTimeRangeToastHandler();\n };\n\n const removeToast = removedToast => {\n setToasts(toasts.filter(toast => toast.id !== removedToast.id));\n };\n\n const isValidTimeRange = (timeRangeMoment, limit, handleInvalidTimeRangeToast) => {\n if (limit === 'start') {\n if (!timeRangeMoment || !timeRangeMoment.isValid()) {\n handleInvalidTimeRangeToast();\n }\n } else if (limit === 'end') {\n if (!timeRangeMoment || !timeRangeMoment.isValid() || timeRangeMoment > moment()) {\n handleInvalidTimeRangeToast();\n }\n }\n };\n\n const setDefaultEditTimeRange = (duration, unmounted) => {\n let time_difference = moment.now() - duration;\n const fromDate = new Date(time_difference);\n parseTimeRange(fromDate, end, reportDefinitionRequest);\n\n if (!unmounted) {\n setStart(fromDate.toISOString());\n setEnd(end);\n }\n }; // valid time range check for absolute time end date\n\n\n const checkValidAbsoluteEndDate = end => {\n let endDate = new Date(end);\n let nowDate = new Date(moment.now());\n let valid = true;\n\n if (endDate.getTime() > nowDate.getTime()) {\n end = 'now';\n valid = false;\n }\n\n return valid;\n };\n\n useEffect(() => {\n let unmounted = false; // if we are coming from the in-context menu\n\n if (window.location.href.indexOf('?') > -1) {\n const url = window.location.href;\n const timeFrom = parseInContextUrl(url, 'timeFrom');\n const timeTo = parseInContextUrl(url, 'timeTo');\n parseTimeRange(timeFrom, timeTo, reportDefinitionRequest);\n\n if (!unmounted) {\n setStart(timeFrom);\n setEnd(timeTo);\n }\n } else {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${id}`).then(async response => {\n let duration = response.report_definition.report_params.core_params.time_duration;\n duration = moment.duration(duration);\n setDefaultEditTimeRange(duration, unmounted);\n }).catch(error => {\n console.error('error in fetching report definition details:', error);\n });\n } else {\n parseTimeRange(start, end, reportDefinitionRequest);\n }\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n\n const onTimeChange = ({\n start,\n end\n }) => {\n isValidTimeRange(dateMath.parse(start), 'start', handleInvalidTimeRangeToast);\n isValidTimeRange(dateMath.parse(end, {\n roundUp: true\n }), 'end', handleInvalidTimeRangeToast);\n const recentlyUsedRange = recentlyUsedRanges.filter(recentlyUsedRange => {\n const isDuplicate = recentlyUsedRange.start === start && recentlyUsedRange.end === end;\n return !isDuplicate;\n });\n const validEndDate = checkValidAbsoluteEndDate(end);\n\n if (!validEndDate) {\n handleInvalidTimeRangeToast();\n return;\n }\n\n recentlyUsedRange.unshift({\n start,\n end\n });\n setStart(start);\n setEnd(end);\n setRecentlyUsedRanges(recentlyUsedRange.length > 10 ? recentlyUsedRange.slice(0, 9) : recentlyUsedRange);\n setIsLoading(true);\n startLoading();\n parseTimeRange(start, end, reportDefinitionRequest);\n };\n\n const parseTimeRange = (start, end, reportDefinitionRequest) => {\n timeRange.timeFrom = dateMath.parse(start);\n timeRange.timeTo = dateMath.parse(end);\n const timeDuration = moment.duration(dateMath.parse(end).diff(dateMath.parse(start)));\n reportDefinitionRequest.report_params.core_params.time_duration = timeDuration.toISOString();\n };\n\n const startLoading = () => {\n setTimeout(stopLoading, 1000);\n };\n\n const stopLoading = () => {\n setIsLoading(false);\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Time range\",\n helpText: \"Time range is relative to the report creation date on the report trigger.\",\n isInvalid: showTimeRangeError\n }, /*#__PURE__*/React.createElement(EuiSuperDatePicker, {\n isDisabled: false,\n isLoading: isLoading,\n start: start,\n end: end,\n onTimeChange: onTimeChange,\n showUpdateButton: false\n }))), /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiGlobalToastList, {\n toasts: toasts,\n dismissToast: removeToast,\n toastLifeTimeMs: 6000\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nexport { ReportTrigger } from './report_trigger';","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport React, { useEffect, useState } from 'react';\nimport { EuiPageHeader, EuiTitle, EuiPageContent, EuiPageContentBody, EuiHorizontalRule, EuiFormRow, EuiRadioGroup, EuiDatePicker, EuiSelect, EuiSpacer, EuiFlexGroup, EuiFlexItem, EuiText, EuiFieldText, EuiCheckboxGroup, EuiLink, EuiFieldNumber } from '@elastic/eui';\nimport moment from 'moment';\nimport { SCHEDULE_RECURRING_OPTIONS, INTERVAL_TIME_PERIODS, WEEKLY_CHECKBOX_OPTIONS, MONTHLY_ON_THE_OPTIONS, TRIGGER_TYPE_OPTIONS, SCHEDULE_TYPE_OPTIONS, TIMEZONE_OPTIONS } from './report_trigger_constants';\nimport { TimezoneSelect } from './timezone';\nexport function ReportTrigger(props) {\n const {\n edit,\n editDefinitionId,\n reportDefinitionRequest,\n httpClientProps,\n showTriggerIntervalNaNError,\n showCronError\n } = props;\n const [reportTriggerType, setReportTriggerType] = useState(TRIGGER_TYPE_OPTIONS[0].id);\n const [scheduleType, setScheduleType] = useState(SCHEDULE_TYPE_OPTIONS[0].label); //TODO: should read local timezone and display\n\n const [scheduleRecurringFrequency, setScheduleRecurringFrequency] = useState('daily');\n const [recurring, setRecurringTime] = useState(moment());\n const [weeklyCheckbox, setWeeklyCheckbox] = useState({\n ['monCheckbox']: true\n });\n const [monthlySelect, setMonthlySelect] = useState(MONTHLY_ON_THE_OPTIONS[0].value);\n\n const handleReportTriggerType = e => {\n setReportTriggerType(e);\n reportDefinitionRequest.trigger.trigger_type = e;\n\n if (e === 'On demand') {\n delete reportDefinitionRequest.trigger.trigger_params;\n }\n };\n\n const handleScheduleType = e => {\n setScheduleType(e);\n\n if (e === SCHEDULE_TYPE_OPTIONS[1].label) {\n delete reportDefinitionRequest.trigger.trigger_params.schedule.interval;\n } else if (e === SCHEDULE_TYPE_OPTIONS[0].label) {\n delete reportDefinitionRequest.trigger.trigger_params.schedule.cron;\n }\n };\n\n const handleScheduleRecurringFrequency = e => {\n setScheduleRecurringFrequency(e.target.value);\n reportDefinitionRequest.trigger.trigger_params.schedule_type = e.target.value;\n };\n\n const handleRecurringTime = e => {\n setRecurringTime(e);\n };\n\n const handleWeeklyCheckbox = e => {\n const newCheckboxIdToSelectedMap = { ...weeklyCheckbox,\n ...{\n [e]: !weeklyCheckbox[e]\n }\n };\n setWeeklyCheckbox(newCheckboxIdToSelectedMap);\n };\n\n const handleMonthlySelect = e => {\n setMonthlySelect(e.target.value);\n };\n\n const RequestTime = () => {\n useEffect(() => {\n let recurringDaily = {\n interval: {\n period: 1,\n unit: 'DAYS',\n start_time: recurring.valueOf()\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: recurring.valueOf(),\n schedule: recurringDaily\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Request time\"\n }, /*#__PURE__*/React.createElement(EuiDatePicker, {\n showTimeSelect: true,\n showTimeSelectOnly: true,\n selected: recurring,\n onChange: handleRecurringTime,\n dateFormat: \"HH:mm\",\n timeFormat: \"HH:mm\"\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const RecurringDaily = () => {\n const [recurringDailyTime, setRecurringDailyTime] = useState(moment());\n\n const handleRecurringDailyTime = e => {\n setRecurringDailyTime(e);\n reportDefinitionRequest.trigger.trigger_params.schedule.interval.start_time = e.valueOf();\n };\n\n const setDailyParams = () => {\n let recurringDaily = {\n interval: {\n period: 1,\n unit: 'DAYS',\n start_time: recurringDailyTime.valueOf()\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: recurringDailyTime.valueOf(),\n schedule: recurringDaily\n };\n };\n\n const isDailySchedule = response => {\n return response.report_definition.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id && response.report_definition.trigger.trigger_params.schedule.interval.period === 1 && response.report_definition.trigger.trigger_params.schedule.interval === 'DAYS';\n };\n\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n // if switching from on demand to schedule\n if (response.report_definition.trigger.trigger_type === 'On demand') {\n setDailyParams();\n } else if (isDailySchedule(response)) {\n const date = moment(response.report_definition.trigger.trigger_params.schedule.interval.start_time);\n\n if (!unmounted) {\n setRecurringDailyTime(date);\n }\n } // if switching from on-demand to schedule\n else if (reportDefinitionRequest.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id) {\n setDailyParams();\n }\n });\n } else {\n setDailyParams();\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Request time\"\n }, /*#__PURE__*/React.createElement(EuiDatePicker, {\n showTimeSelect: true,\n showTimeSelectOnly: true,\n selected: recurringDailyTime,\n onChange: handleRecurringDailyTime,\n dateFormat: \"HH:mm\",\n timeFormat: \"HH:mm\"\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const RecurringInterval = () => {\n const [intervalText, setIntervalText] = useState('');\n const [intervalTimePeriod, setIntervalTimePeriod] = useState(INTERVAL_TIME_PERIODS[0].value);\n const [recurringIntervalTime, setRecurringIntervalTime] = useState(moment());\n\n const handleRecurringIntervalTime = e => {\n setRecurringIntervalTime(e);\n reportDefinitionRequest.trigger.trigger_params.schedule.interval.start_time = e.valueOf();\n };\n\n const handleIntervalText = e => {\n setIntervalText(e.target.value);\n };\n\n const handleIntervalTimePeriod = e => {\n setIntervalTimePeriod(e.target.value);\n };\n\n useEffect(() => {\n let interval = {\n interval: {\n period: parseInt(intervalText, 10),\n unit: intervalTimePeriod,\n start_time: recurringIntervalTime.valueOf()\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: recurringIntervalTime.valueOf(),\n schedule: interval\n };\n }, [intervalTimePeriod, intervalText]); // second useEffect() only to be triggered before render when on Edit\n\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n if (response.report_definition.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id) {\n const date = moment(response.report_definition.trigger.trigger_params.schedule.interval.start_time);\n\n if (!unmounted) {\n setRecurringIntervalTime(date);\n setIntervalText(response.report_definition.trigger.trigger_params.schedule.interval.period.toString());\n setIntervalTimePeriod(response.report_definition.trigger.trigger_params.schedule.interval.unit);\n }\n }\n });\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Every\",\n isInvalid: showTriggerIntervalNaNError\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: \"Must be a number\",\n value: intervalText,\n onChange: handleIntervalText\n })), /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiFormRow, null, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"intervalTimeUnit\",\n options: INTERVAL_TIME_PERIODS,\n value: intervalTimePeriod,\n onChange: handleIntervalTimePeriod\n }))))), /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Start time\"\n }, /*#__PURE__*/React.createElement(EuiDatePicker, {\n showTimeSelect: true,\n showTimeSelectOnly: true,\n selected: recurringIntervalTime,\n onChange: handleRecurringIntervalTime,\n dateFormat: \"HH:mm\",\n timeFormat: \"HH:mm\"\n })));\n };\n\n const RecurringWeekly = () => {\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Every\"\n }, /*#__PURE__*/React.createElement(EuiCheckboxGroup, {\n options: WEEKLY_CHECKBOX_OPTIONS,\n idToSelectedMap: weeklyCheckbox,\n onChange: handleWeeklyCheckbox\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), /*#__PURE__*/React.createElement(RequestTime, null));\n };\n\n const RecurringMonthly = () => {\n const [monthlyDayNumber, setMonthlyDayNumber] = useState('');\n\n const handleMonthlyDayNumber = e => {\n setMonthlyDayNumber(e.target.value);\n };\n\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"On the\"\n }, /*#__PURE__*/React.createElement(EuiFlexGroup, null, /*#__PURE__*/React.createElement(EuiFlexItem, {\n grow: false\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"monthlySelect\",\n options: MONTHLY_ON_THE_OPTIONS,\n value: monthlySelect,\n onChange: handleMonthlySelect\n })), /*#__PURE__*/React.createElement(EuiFlexItem, null, /*#__PURE__*/React.createElement(EuiFieldNumber, {\n placeholder: 'Day of month',\n value: monthlyDayNumber,\n onChange: handleMonthlyDayNumber\n })))), /*#__PURE__*/React.createElement(EuiSpacer, {\n size: \"s\"\n }), /*#__PURE__*/React.createElement(RequestTime, null));\n };\n\n const CronExpression = () => {\n const [cronExpression, setCronExpression] = useState('');\n\n const handleCronExpression = e => {\n setCronExpression(e.target.value);\n reportDefinitionRequest.trigger.trigger_params.schedule.cron.expression = e.target.value;\n };\n\n const setCronParams = () => {\n let cron = {\n cron: {\n expression: '',\n timezone: TIMEZONE_OPTIONS[0].value\n }\n };\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n enabled_time: Date.now().valueOf(),\n schedule: cron\n };\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n // if switching from on demand to schedule\n if (response.report_definition.trigger.trigger_type === 'On demand') {\n setCronParams();\n } else if (response.report_definition.trigger.trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[1].id) {\n setCronExpression(response.report_definition.trigger.trigger_params.schedule.cron.expression);\n } else {\n setCronParams();\n }\n });\n } else {\n setCronParams();\n }\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Custom cron expression\",\n isInvalid: showCronError,\n labelAppend: /*#__PURE__*/React.createElement(EuiText, {\n size: \"xs\"\n }, /*#__PURE__*/React.createElement(EuiLink, {\n href: \"https://opendistro.github.io/for-elasticsearch-docs/docs/alerting/cron/\"\n }, \"Cron help\"))\n }, /*#__PURE__*/React.createElement(EuiFieldText, {\n placeholder: 'Ex: 0 12 * * * (Fire at 12:00 PM (noon) every day)',\n value: cronExpression,\n onChange: handleCronExpression\n })), /*#__PURE__*/React.createElement(EuiSpacer, null));\n };\n\n const ScheduleTriggerRecurring = () => {\n const display_daily = scheduleRecurringFrequency === 'daily' ? /*#__PURE__*/React.createElement(RecurringDaily, null) : null;\n const display_interval = scheduleRecurringFrequency === 'byInterval' ? /*#__PURE__*/React.createElement(RecurringInterval, null) : null;\n const display_weekly = scheduleRecurringFrequency === 'weekly' ? /*#__PURE__*/React.createElement(RecurringWeekly, null) : null;\n const display_monthly = scheduleRecurringFrequency === 'monthly' ? /*#__PURE__*/React.createElement(RecurringMonthly, null) : null;\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Frequency\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"recurringFrequencySelect\",\n options: SCHEDULE_RECURRING_OPTIONS,\n value: scheduleRecurringFrequency,\n onChange: handleScheduleRecurringFrequency\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), display_daily, display_interval, display_weekly, display_monthly);\n };\n\n const ScheduleTrigger = () => {\n const display_recurring = scheduleType === SCHEDULE_TYPE_OPTIONS[0].id ? /*#__PURE__*/React.createElement(ScheduleTriggerRecurring, null) : null;\n const display_cron = scheduleType === SCHEDULE_TYPE_OPTIONS[1].id ? /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(CronExpression, null), /*#__PURE__*/React.createElement(TimezoneSelect, {\n reportDefinitionRequest: reportDefinitionRequest,\n httpClientProps: httpClientProps,\n edit: edit,\n editDefinitionId: editDefinitionId\n })) : null;\n useEffect(() => {\n // Set default trigger_type\n SCHEDULE_TYPE_OPTIONS.map(item => {\n if (item.id === scheduleType) {\n reportDefinitionRequest.trigger.trigger_params = { ...reportDefinitionRequest.trigger.trigger_params,\n schedule_type: item.id //TODO: need better handle\n\n };\n\n if (!edit) {\n reportDefinitionRequest.trigger.trigger_params.enabled = true;\n }\n\n if (!('enabled' in reportDefinitionRequest.trigger.trigger_params)) {\n reportDefinitionRequest.trigger.trigger_params.enabled = false;\n }\n }\n });\n }, [scheduleType]);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Request time\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: SCHEDULE_TYPE_OPTIONS,\n idSelected: scheduleType,\n onChange: handleScheduleType\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), display_recurring, display_cron);\n };\n\n const schedule = reportTriggerType === 'Schedule' ? /*#__PURE__*/React.createElement(ScheduleTrigger, null) : null;\n\n const defaultEditTriggerType = trigger_type => {\n let index = 0;\n\n for (index; index < TRIGGER_TYPE_OPTIONS.length; ++index) {\n if (TRIGGER_TYPE_OPTIONS[index].id === trigger_type) {\n setReportTriggerType(TRIGGER_TYPE_OPTIONS[index].id);\n }\n }\n };\n\n const defaultEditRequestType = trigger => {\n let index = 0;\n\n for (index; index < SCHEDULE_TYPE_OPTIONS.length; ++index) {\n if (SCHEDULE_TYPE_OPTIONS[index].id === trigger.trigger_params.schedule_type) {\n setScheduleType(SCHEDULE_TYPE_OPTIONS[index].id);\n }\n }\n };\n\n const defaultEditScheduleFrequency = trigger_params => {\n if (trigger_params.schedule_type === SCHEDULE_TYPE_OPTIONS[0].id) {\n if (trigger_params.schedule.interval.unit === 'DAYS') {\n setScheduleRecurringFrequency('daily');\n } else {\n setScheduleRecurringFrequency('byInterval');\n }\n }\n };\n\n const defaultConfigurationEdit = trigger => {\n defaultEditTriggerType(trigger.trigger_type);\n\n if (trigger.trigger_type === 'Schedule') {\n defaultEditScheduleFrequency(trigger.trigger_params);\n defaultEditRequestType(trigger);\n } else if (trigger.trigger_type == 'On demand') {\n setReportTriggerType('On demand');\n reportDefinitionRequest.trigger.trigger_type = 'On demand';\n }\n };\n\n useEffect(() => {\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n defaultConfigurationEdit(response.report_definition.trigger);\n reportDefinitionRequest.trigger = response.report_definition.trigger;\n });\n } // Set default trigger_type for create new report definition\n else {\n TRIGGER_TYPE_OPTIONS.map(item => {\n if (item.id === reportTriggerType) {\n reportDefinitionRequest.trigger.trigger_type = item.id;\n }\n });\n }\n }, []);\n return /*#__PURE__*/React.createElement(EuiPageContent, {\n panelPaddingSize: 'l'\n }, /*#__PURE__*/React.createElement(EuiPageHeader, null, /*#__PURE__*/React.createElement(EuiTitle, null, /*#__PURE__*/React.createElement(\"h2\", null, \"Report trigger\"))), /*#__PURE__*/React.createElement(EuiHorizontalRule, null), /*#__PURE__*/React.createElement(EuiPageContentBody, null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Trigger type\",\n id: \"reportDefinitionTriggerTypes\"\n }, /*#__PURE__*/React.createElement(EuiRadioGroup, {\n options: TRIGGER_TYPE_OPTIONS,\n idSelected: reportTriggerType,\n onChange: handleReportTriggerType\n })), /*#__PURE__*/React.createElement(EuiSpacer, null), schedule));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport moment from 'moment-timezone';\nexport const TRIGGER_TYPE_OPTIONS = [{\n id: 'On demand',\n label: 'On demand'\n}, {\n id: 'Schedule',\n label: 'Schedule'\n}];\nexport const SCHEDULE_TYPE_OPTIONS = [{\n id: 'Recurring',\n label: 'Recurring'\n}, {\n id: 'Cron based',\n label: 'Cron-based'\n}];\nexport const SCHEDULE_RECURRING_OPTIONS = [{\n value: 'daily',\n text: 'Daily'\n}, {\n value: 'byInterval',\n text: 'By interval'\n} // TODO: disable on UI. Add them back once we support\n// {\n// value: 'weekly',\n// text: 'Weekly',\n// },\n// {\n// value: 'monthly',\n// text: 'Monthly',\n// },\n];\nexport const INTERVAL_TIME_PERIODS = [{\n value: 'MINUTES',\n text: 'Minutes'\n}, {\n value: 'HOURS',\n text: 'Hours'\n}, {\n value: 'DAYS',\n text: 'Days'\n}];\nexport const WEEKLY_CHECKBOX_OPTIONS = [{\n id: 'monCheckbox',\n label: 'Mon'\n}, {\n id: 'tueCheckbox',\n label: 'Tue'\n}, {\n id: 'wedCheckbox',\n label: 'Wed'\n}, {\n id: 'thuCheckbox',\n label: 'Thu'\n}, {\n id: 'friCheckbox',\n label: 'Fri'\n}, {\n id: 'satCheckbox',\n label: 'Sat'\n}, {\n id: 'sunCheckbox',\n label: 'Sun'\n}];\nexport const MONTHLY_ON_THE_OPTIONS = [{\n value: 'day',\n text: 'Day'\n}];\nexport const TIMEZONE_OPTIONS = moment.tz.names().map(tz => ({\n value: tz,\n text: tz\n}));","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport { EuiFormRow, EuiSelect } from '@elastic/eui';\nimport React, { useState, useEffect } from 'react';\nimport { TIMEZONE_OPTIONS } from './report_trigger_constants';\nexport function TimezoneSelect(props) {\n const {\n reportDefinitionRequest,\n httpClientProps,\n edit,\n editDefinitionId\n } = props;\n const [timezone, setTimezone] = useState(TIMEZONE_OPTIONS[0].value);\n\n const handleTimezone = e => {\n setTimezone(e.target.value);\n\n if (reportDefinitionRequest.trigger.trigger_params.schedule_type === 'Cron based') {\n reportDefinitionRequest.trigger.trigger_params.schedule.cron.timezone = e.target.value;\n }\n };\n\n useEffect(() => {\n let unmounted = false;\n\n if (edit) {\n httpClientProps.get(`../api/reporting/reportDefinitions/${editDefinitionId}`).then(async response => {\n if (!unmounted && reportDefinitionRequest.trigger.trigger_params.schedule_type === 'Cron based') {\n setTimezone(response.report_definition.trigger.trigger_params.schedule.cron.timezone);\n }\n });\n }\n\n return () => {\n unmounted = true;\n };\n }, []);\n return /*#__PURE__*/React.createElement(\"div\", null, /*#__PURE__*/React.createElement(EuiFormRow, {\n label: \"Timezone\"\n }, /*#__PURE__*/React.createElement(EuiSelect, {\n id: \"setTimezone\",\n options: TIMEZONE_OPTIONS,\n value: timezone,\n onChange: handleTimezone\n })));\n}","/*\n * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\").\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * or in the \"license\" file accompanying this file. This file is distributed\n * on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\nimport Showdown from 'showdown';\nexport const converter = new Showdown.Converter({\n tables: true,\n simplifiedAutoLink: true,\n strikethrough: true,\n tasklists: true,\n noHeaderId: true\n});"],"mappings":";;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACnCA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACnFA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzNA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACxcA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACpHA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzPA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC7LA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC3PA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC1EA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACrBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACjJA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACbA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACxNA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACbA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACjeA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACjDA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC7HA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACvLA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACbA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC1cA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACpFA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzDA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""} \ No newline at end of file