"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ApmMainTemplate = ApmMainTemplate; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _public = require("@kbn/kibana-react-plugin/public"); var _react = _interopRequireDefault(require("react")); var _reactRouterDom = require("react-router-dom"); var _environments_context = require("../../../context/environments_context/environments_context"); var _use_fetcher = require("../../../hooks/use_fetcher"); var _service_groups = require("../../app/service_groups"); var _service_groups_button_group = require("../../app/service_groups/service_groups_button_group"); var _environment_filter = require("../../shared/environment_filter"); var _no_data_config = require("./no_data_config"); var _use_apm_plugin_context = require("../../../context/apm_plugin/use_apm_plugin_context"); /* * 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. */ // Paths that must skip the no data screen const bypassNoDataScreenPaths = ['/settings', '/diagnostics']; /* * This template contains: * - The Shared Observability Nav (https://github.com/elastic/kibana/blob/f7698bd8aa8787d683c728300ba4ca52b202369c/x-pack/plugins/observability/public/components/shared/page_template/README.md) * - The APM Header Action Menu * - Page title * * Optionally: * - EnvironmentFilter * - ServiceGroupSaveButton */ function ApmMainTemplate({ pageTitle, pageHeader, children, environmentFilter = true, showServiceGroupSaveButton = false, showServiceGroupsNav = false, selectedNavButton, ...pageTemplateProps }) { const location = (0, _reactRouterDom.useLocation)(); const { services } = (0, _public.useKibana)(); const { http, docLinks, observabilityShared, application } = services; const basePath = http === null || http === void 0 ? void 0 : http.basePath.get(); const { config } = (0, _use_apm_plugin_context.useApmPluginContext)(); const ObservabilityPageTemplate = observabilityShared.navigation.PageTemplate; const { data, status } = (0, _use_fetcher.useFetcher)(callApmApi => { return callApmApi('GET /internal/apm/has_data'); }, []); // create static data view on inital load (0, _use_fetcher.useFetcher)(callApmApi => { const canCreateDataView = application === null || application === void 0 ? void 0 : application.capabilities.savedObjectsManagement.edit; if (canCreateDataView) { return callApmApi('POST /internal/apm/data_view/static'); } }, [application === null || application === void 0 ? void 0 : application.capabilities.savedObjectsManagement.edit]); const shouldBypassNoDataScreen = bypassNoDataScreenPaths.some(path => location.pathname.includes(path)); const { data: fleetApmPoliciesData, status: fleetApmPoliciesStatus } = (0, _use_fetcher.useFetcher)(callApmApi => { if (!(data !== null && data !== void 0 && data.hasData) && !shouldBypassNoDataScreen) { return callApmApi('GET /internal/apm/fleet/has_apm_policies'); } }, [shouldBypassNoDataScreen, data === null || data === void 0 ? void 0 : data.hasData]); const isLoading = status === _use_fetcher.FETCH_STATUS.LOADING || fleetApmPoliciesStatus === _use_fetcher.FETCH_STATUS.LOADING; const noDataConfig = (0, _no_data_config.getNoDataConfig)({ basePath, docsLink: docLinks.links.observability.guide, hasApmData: data === null || data === void 0 ? void 0 : data.hasData, hasApmIntegrations: fleetApmPoliciesData === null || fleetApmPoliciesData === void 0 ? void 0 : fleetApmPoliciesData.hasApmPolicies, shouldBypassNoDataScreen, loading: isLoading, isServerless: config === null || config === void 0 ? void 0 : config.serverlessOnboarding }); const rightSideItems = [...(showServiceGroupSaveButton ? [/*#__PURE__*/_react.default.createElement(_service_groups.ServiceGroupSaveButton, null)] : []), ...(environmentFilter ? [/*#__PURE__*/_react.default.createElement(_environment_filter.ApmEnvironmentFilter, null)] : [])]; const pageTemplate = /*#__PURE__*/_react.default.createElement(ObservabilityPageTemplate, (0, _extends2.default)({ noDataConfig: shouldBypassNoDataScreen ? undefined : noDataConfig, isPageDataLoaded: isLoading === false, pageHeader: { pageTitle, rightSideItems, ...pageHeader, children: showServiceGroupsNav && selectedNavButton ? /*#__PURE__*/_react.default.createElement(_service_groups_button_group.ServiceGroupsButtonGroup, { selectedNavButton: selectedNavButton }) : null } }, pageTemplateProps), children); if (environmentFilter) { return /*#__PURE__*/_react.default.createElement(_environments_context.EnvironmentsContextProvider, null, pageTemplate); } return pageTemplate; }