"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ElasticsearchOverviewPage = void 0; var _react = _interopRequireWildcard(require("react")); var _i18n = require("@kbn/i18n"); var _lodash = require("lodash"); var _public = require("@kbn/kibana-react-plugin/public"); var _elasticsearch_template = require("./elasticsearch_template"); var _global_state_context = require("../../contexts/global_state_context"); var _elasticsearch = require("../../../components/elasticsearch"); var _use_charts = require("../../hooks/use_charts"); var _use_breadcrumbs = require("../../hooks/use_breadcrumbs"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ const ElasticsearchOverviewPage = ({ clusters }) => { var _services$data2; const globalState = (0, _react.useContext)(_global_state_context.GlobalStateContext); const { zoomInfo, onBrush } = (0, _use_charts.useCharts)(); const { services } = (0, _public.useKibana)(); const { generate: generateBreadcrumbs } = (0, _use_breadcrumbs.useBreadcrumbContainerContext)(); const clusterUuid = globalState.cluster_uuid; const ccs = globalState.ccs; const cluster = (0, _lodash.find)(clusters, { cluster_uuid: clusterUuid }); const [data, setData] = (0, _react.useState)(null); const [showShardActivityHistory, setShowShardActivityHistory] = (0, _react.useState)(false); const toggleShardActivityHistory = () => { setShowShardActivityHistory(!showShardActivityHistory); }; const filterShardActivityData = shardActivity => { return shardActivity.filter(row => { return showShardActivityHistory || row.stage !== 'DONE'; }); }; const title = _i18n.i18n.translate('xpack.monitoring.elasticsearch.overview.title', { defaultMessage: 'Elasticsearch' }); const pageTitle = _i18n.i18n.translate('xpack.monitoring.elasticsearch.overview.pageTitle', { defaultMessage: 'Elasticsearch overview' }); (0, _react.useEffect)(() => { if (cluster) { generateBreadcrumbs(cluster.cluster_name, { inElasticsearch: true }); } }, [cluster, generateBreadcrumbs]); const getPageData = (0, _react.useCallback)(async () => { var _services$data, _services$http; const bounds = (_services$data = services.data) === null || _services$data === void 0 ? void 0 : _services$data.query.timefilter.timefilter.getBounds(); const url = `../api/monitoring/v1/clusters/${clusterUuid}/elasticsearch`; const response = await ((_services$http = services.http) === null || _services$http === void 0 ? void 0 : _services$http.fetch(url, { method: 'POST', body: JSON.stringify({ ccs, timeRange: { min: bounds.min.toISOString(), max: bounds.max.toISOString() } }) })); setData(response); }, [ccs, clusterUuid, (_services$data2 = services.data) === null || _services$data2 === void 0 ? void 0 : _services$data2.query.timefilter.timefilter, services.http]); const renderOverview = overviewData => { if (overviewData === null) { return null; } const { clusterStatus, metrics, shardActivity, logs } = overviewData || {}; const shardActivityData = shardActivity && filterShardActivityData(shardActivity); // no filter on data = null return /*#__PURE__*/_react.default.createElement(_elasticsearch.ElasticsearchOverview, { clusterStatus: clusterStatus, metrics: metrics, logs: logs, cluster: cluster, shardActivity: shardActivityData, onBrush: onBrush, showShardActivityHistory: showShardActivityHistory, toggleShardActivityHistory: toggleShardActivityHistory, zoomInfo: zoomInfo, "data-test-subj": "elasticsearchOverviewPage" }); }; return /*#__PURE__*/_react.default.createElement(_elasticsearch_template.ElasticsearchTemplate, { title: title, pageTitle: pageTitle, getPageData: getPageData, "data-test-subj": "elasticsearchOverviewPage", cluster: cluster }, /*#__PURE__*/_react.default.createElement("div", { "data-test-subj": "elasticsearchOverviewPage" }, renderOverview(data))); }; exports.ElasticsearchOverviewPage = ElasticsearchOverviewPage;