From 75ea9eaad44854b98f5a39cadf463f5f6d77edd6 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 12 May 2020 20:01:17 +0200 Subject: [PATCH] [Uptime] Fix document title according to page (#65665) --- x-pack/plugins/uptime/public/apps/plugin.ts | 11 +-- .../overview/overview_container.tsx | 7 +- .../__snapshots__/overview.test.tsx.snap | 10 +- .../public/pages/__tests__/overview.test.tsx | 13 +-- .../uptime/public/pages/certificates.tsx | 3 - .../plugins/uptime/public/pages/monitor.tsx | 4 +- .../plugins/uptime/public/pages/overview.tsx | 17 ++-- .../plugins/uptime/public/pages/settings.tsx | 5 +- x-pack/plugins/uptime/public/routes.tsx | 97 +++++++++++++------ x-pack/plugins/uptime/public/uptime_app.tsx | 2 +- 10 files changed, 86 insertions(+), 83 deletions(-) diff --git a/x-pack/plugins/uptime/public/apps/plugin.ts b/x-pack/plugins/uptime/public/apps/plugin.ts index c6a7eb261d8fd..b589bd64591fc 100644 --- a/x-pack/plugins/uptime/public/apps/plugin.ts +++ b/x-pack/plugins/uptime/public/apps/plugin.ts @@ -4,11 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public'; -import { - LegacyCoreStart, - AppMountParameters, - DEFAULT_APP_CATEGORIES, -} from '../../../../../src/core/public'; +import { AppMountParameters, DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public'; import { UMFrontendLibs } from '../lib/lib'; import { PLUGIN } from '../../common/constants'; import { FeatureCatalogueCategory } from '../../../../../src/plugins/home/public'; @@ -17,11 +13,6 @@ import { EmbeddableStart } from '../../../../../src/plugins/embeddable/public'; import { TriggersAndActionsUIPublicPluginSetup } from '../../../triggers_actions_ui/public'; import { DataPublicPluginSetup } from '../../../../../src/plugins/data/public'; -export interface StartObject { - core: LegacyCoreStart; - plugins: any; -} - export interface ClientPluginsSetup { data: DataPublicPluginSetup; home: HomePublicPluginSetup; diff --git a/x-pack/plugins/uptime/public/components/overview/overview_container.tsx b/x-pack/plugins/uptime/public/components/overview/overview_container.tsx index 320536bc63b3c..7fd71f3ac89be 100644 --- a/x-pack/plugins/uptime/public/components/overview/overview_container.tsx +++ b/x-pack/plugins/uptime/public/components/overview/overview_container.tsx @@ -6,16 +6,11 @@ import { useDispatch, useSelector } from 'react-redux'; import React, { useCallback } from 'react'; -import { DataPublicPluginSetup } from 'src/plugins/data/public'; import { OverviewPageComponent } from '../../pages/overview'; import { selectIndexPattern } from '../../state/selectors'; import { setEsKueryString } from '../../state/actions'; -export interface OverviewPageProps { - autocomplete: DataPublicPluginSetup['autocomplete']; -} - -export const OverviewPage: React.FC = props => { +export const OverviewPage: React.FC = props => { const dispatch = useDispatch(); const setEsKueryFilters = useCallback( (esFilters: string) => dispatch(setEsKueryString(esFilters)), diff --git a/x-pack/plugins/uptime/public/pages/__tests__/__snapshots__/overview.test.tsx.snap b/x-pack/plugins/uptime/public/pages/__tests__/__snapshots__/overview.test.tsx.snap index 71b3fb5c7146a..791bb4a57ae52 100644 --- a/x-pack/plugins/uptime/public/pages/__tests__/__snapshots__/overview.test.tsx.snap +++ b/x-pack/plugins/uptime/public/pages/__tests__/__snapshots__/overview.test.tsx.snap @@ -51,15 +51,7 @@ exports[`MonitorPage shallow renders expected elements for valid props 1`] = ` } } > - { title: 'heartbeat-8*', }; - const autocomplete = { - getQuerySuggestions: jest.fn(), - hasQuerySuggestions: () => true, - getValueSuggestions: jest.fn(), - addQuerySuggestionProvider: jest.fn(), - }; - it('shallow renders expected elements for valid props', () => { expect( shallowWithRouter( - + ) ).toMatchSnapshot(); }); diff --git a/x-pack/plugins/uptime/public/pages/certificates.tsx b/x-pack/plugins/uptime/public/pages/certificates.tsx index a2b37657cf3fe..517252dcd1969 100644 --- a/x-pack/plugins/uptime/public/pages/certificates.tsx +++ b/x-pack/plugins/uptime/public/pages/certificates.tsx @@ -23,7 +23,6 @@ import { OVERVIEW_ROUTE, SETTINGS_ROUTE, CLIENT_ALERT_TYPES } from '../../common import { getDynamicSettings } from '../state/actions/dynamic_settings'; import { UptimeRefreshContext } from '../contexts'; import * as labels from './translations'; -import { UptimePage, useUptimeTelemetry } from '../hooks'; import { certificatesSelector, getCertificatesAction } from '../state/certificates/certificates'; import { CertificateList, CertificateSearch, CertSort } from '../components/certificates'; import { ToggleAlertFlyoutButton } from '../components/overview/alerts/alerts_containers'; @@ -39,8 +38,6 @@ const getPageSizeValue = () => { }; export const CertificatesPage: React.FC = () => { - useUptimeTelemetry(UptimePage.Certificates); - useTrackPageview({ app: 'uptime', path: 'certificates' }); useTrackPageview({ app: 'uptime', path: 'certificates', delay: 15000 }); diff --git a/x-pack/plugins/uptime/public/pages/monitor.tsx b/x-pack/plugins/uptime/public/pages/monitor.tsx index fc796e679a2f6..129b673f9e102 100644 --- a/x-pack/plugins/uptime/public/pages/monitor.tsx +++ b/x-pack/plugins/uptime/public/pages/monitor.tsx @@ -11,7 +11,7 @@ import { monitorStatusSelector } from '../state/selectors'; import { PageHeader } from './page_header'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; import { useTrackPageview } from '../../../observability/public'; -import { useMonitorId, useUptimeTelemetry, UptimePage } from '../hooks'; +import { useMonitorId } from '../hooks'; import { MonitorCharts } from '../components/monitor'; import { MonitorStatusDetails, PingList } from '../components/monitor'; import { getDynamicSettings } from '../state/actions/dynamic_settings'; @@ -27,8 +27,6 @@ export const MonitorPage: React.FC = () => { const selectedMonitor = useSelector(monitorStatusSelector); - useUptimeTelemetry(UptimePage.Monitor); - useTrackPageview({ app: 'uptime', path: 'monitor' }); useTrackPageview({ app: 'uptime', path: 'monitor', delay: 15000 }); diff --git a/x-pack/plugins/uptime/public/pages/overview.tsx b/x-pack/plugins/uptime/public/pages/overview.tsx index 65f64aa7352a9..639f363e6f9b1 100644 --- a/x-pack/plugins/uptime/public/pages/overview.tsx +++ b/x-pack/plugins/uptime/public/pages/overview.tsx @@ -8,7 +8,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; import React, { useEffect } from 'react'; import styled from 'styled-components'; import { i18n } from '@kbn/i18n'; -import { useUptimeTelemetry, UptimePage, useGetUrlParams } from '../hooks'; +import { useGetUrlParams } from '../hooks'; import { stringifyUrlParams } from '../lib/helper/stringify_url_params'; import { PageHeader } from './page_header'; import { IIndexPattern } from '../../../../../src/plugins/data/public'; @@ -18,9 +18,9 @@ import { useTrackPageview } from '../../../observability/public'; import { MonitorList } from '../components/overview/monitor_list/monitor_list_container'; import { EmptyState, FilterGroup, KueryBar, ParsingErrorCallout } from '../components/overview'; import { StatusPanel } from '../components/overview/status_panel'; -import { OverviewPageProps } from '../components/overview/overview_container'; +import { useKibana } from '../../../../../src/plugins/kibana_react/public'; -interface Props extends OverviewPageProps { +interface Props { indexPattern: IIndexPattern | null; setEsKueryFilters: (esFilters: string) => void; } @@ -34,11 +34,15 @@ const EuiFlexItemStyled = styled(EuiFlexItem)` } `; -export const OverviewPageComponent = ({ autocomplete, indexPattern, setEsKueryFilters }: Props) => { +export const OverviewPageComponent = React.memo(({ indexPattern, setEsKueryFilters }: Props) => { const { absoluteDateRangeStart, absoluteDateRangeEnd, ...params } = useGetUrlParams(); const { search, filters: urlFilters } = params; - useUptimeTelemetry(UptimePage.Overview); + const { + services: { + data: { autocomplete }, + }, + } = useKibana(); useTrackPageview({ app: 'uptime', path: 'overview' }); useTrackPageview({ app: 'uptime', path: 'overview', delay: 15000 }); @@ -57,6 +61,7 @@ export const OverviewPageComponent = ({ autocomplete, indexPattern, setEsKueryFi }); useBreadcrumbs([]); // No extra breadcrumbs on overview + return ( <> @@ -83,4 +88,4 @@ export const OverviewPageComponent = ({ autocomplete, indexPattern, setEsKueryFi ); -}; +}); diff --git a/x-pack/plugins/uptime/public/pages/settings.tsx b/x-pack/plugins/uptime/public/pages/settings.tsx index d018567ae1104..b617e81bad88a 100644 --- a/x-pack/plugins/uptime/public/pages/settings.tsx +++ b/x-pack/plugins/uptime/public/pages/settings.tsx @@ -25,7 +25,6 @@ import { DynamicSettings } from '../../common/runtime_types'; import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; import { OVERVIEW_ROUTE } from '../../common/constants'; import { useKibana } from '../../../../../src/plugins/kibana_react/public'; -import { UptimePage, useUptimeTelemetry } from '../hooks'; import { IndicesForm } from '../components/settings/indices_form'; import { CertificateExpirationForm, @@ -75,13 +74,11 @@ const getFieldErrors = (formFields: DynamicSettings | null): SettingsPageFieldEr return null; }; -export const SettingsPage = () => { +export const SettingsPage: React.FC = () => { const dss = useSelector(selectDynamicSettings); useBreadcrumbs([{ text: Translations.settings.breadcrumbText }]); - useUptimeTelemetry(UptimePage.Settings); - const dispatch = useDispatch(); useEffect(() => { diff --git a/x-pack/plugins/uptime/public/routes.tsx b/x-pack/plugins/uptime/public/routes.tsx index ca97858998df7..455d5070128f5 100644 --- a/x-pack/plugins/uptime/public/routes.tsx +++ b/x-pack/plugins/uptime/public/routes.tsx @@ -4,9 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { FC } from 'react'; +import React, { FC, useEffect } from 'react'; import { Route, Switch } from 'react-router-dom'; -import { DataPublicPluginSetup } from '../../../../src/plugins/data/public'; import { OverviewPage } from './components/overview/overview_container'; import { CERTIFICATES_ROUTE, @@ -16,33 +15,73 @@ import { } from '../common/constants'; import { MonitorPage, NotFoundPage, SettingsPage } from './pages'; import { CertificatesPage } from './pages/certificates'; +import { UptimePage, useUptimeTelemetry } from './hooks'; -interface RouterProps { - autocomplete: DataPublicPluginSetup['autocomplete']; +interface RouteProps { + path: string; + component: React.FC; + dataTestSubj: string; + title: string; + telemetryId: UptimePage; } -export const PageRouter: FC = ({ autocomplete }) => ( - - -
- -
-
- -
- -
-
- -
- -
-
- -
- -
-
- -
-); +const baseTitle = 'Uptime - Kibana'; + +const Routes: RouteProps[] = [ + { + title: `Monitor | ${baseTitle}`, + path: MONITOR_ROUTE, + component: MonitorPage, + dataTestSubj: 'uptimeMonitorPage', + telemetryId: UptimePage.Monitor, + }, + { + title: `Settings | ${baseTitle}`, + path: SETTINGS_ROUTE, + component: SettingsPage, + dataTestSubj: 'uptimeSettingsPage', + telemetryId: UptimePage.Settings, + }, + { + title: `Certificates | ${baseTitle}`, + path: CERTIFICATES_ROUTE, + component: CertificatesPage, + dataTestSubj: 'uptimeCertificatesPage', + telemetryId: UptimePage.Certificates, + }, + { + title: baseTitle, + path: OVERVIEW_ROUTE, + component: OverviewPage, + dataTestSubj: 'uptimeOverviewPage', + telemetryId: UptimePage.Overview, + }, +]; + +const RouteInit: React.FC> = ({ + path, + title, + telemetryId, +}) => { + useUptimeTelemetry(telemetryId); + useEffect(() => { + document.title = title; + }, [path, title]); + return null; +}; + +export const PageRouter: FC = () => { + return ( + + {Routes.map(({ title, path, component: RouteComponent, dataTestSubj, telemetryId }) => ( + +
+ + +
+
+ ))} + +
+ ); +}; diff --git a/x-pack/plugins/uptime/public/uptime_app.tsx b/x-pack/plugins/uptime/public/uptime_app.tsx index 836d942d92165..2891a15510f31 100644 --- a/x-pack/plugins/uptime/public/uptime_app.tsx +++ b/x-pack/plugins/uptime/public/uptime_app.tsx @@ -106,7 +106,7 @@ const Application = (props: UptimeAppProps) => {
- +