Skip to content

Commit b78f785

Browse files
shahzad31awahab07
andauthored
[Synthetics] User experience and monitor details, load when in view (#144385)
Co-authored-by: Abdul Zahid <awahab07@yahoo.com>
1 parent d4064c8 commit b78f785

File tree

10 files changed

+92
-10
lines changed

10 files changed

+92
-10
lines changed

x-pack/plugins/observability/public/components/shared/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import React, { lazy, Suspense } from 'react';
99
import { EuiLoadingSpinner } from '@elastic/eui';
10+
import { LoadWhenInViewProps } from './load_when_in_view/load_when_in_view';
1011
import type { CoreVitalProps, HeaderMenuPortalProps } from './types';
1112
import type {
1213
FieldValueSuggestionsProps,
@@ -102,3 +103,13 @@ export function DatePicker(props: DatePickerProps) {
102103
</Suspense>
103104
);
104105
}
106+
107+
const LoadWhenInViewLazy = lazy(() => import('./load_when_in_view/load_when_in_view'));
108+
109+
export function LoadWhenInView(props: LoadWhenInViewProps) {
110+
return (
111+
<Suspense fallback={<EuiLoadingSpinner />}>
112+
<LoadWhenInViewLazy {...props} />
113+
</Suspense>
114+
);
115+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import React, { useEffect, useState } from 'react';
9+
import { EuiLoadingContent } from '@elastic/eui';
10+
import useIntersection from 'react-use/lib/useIntersection';
11+
12+
export interface LoadWhenInViewProps {
13+
children: JSX.Element;
14+
initialHeight?: string | number;
15+
placeholderTitle: string;
16+
}
17+
18+
// eslint-disable-next-line import/no-default-export
19+
export default function LoadWhenInView({
20+
children,
21+
placeholderTitle,
22+
initialHeight = 100,
23+
}: LoadWhenInViewProps) {
24+
const intersectionRef = React.useRef(null);
25+
const intersection = useIntersection(intersectionRef, {
26+
root: null,
27+
rootMargin: '0px',
28+
threshold: 0.25,
29+
});
30+
31+
const [isVisible, setIsVisible] = useState(false);
32+
33+
useEffect(() => {
34+
if (intersection && intersection.intersectionRatio > 0.25) {
35+
setIsVisible(true);
36+
}
37+
}, [intersection, intersection?.intersectionRatio]);
38+
39+
return isVisible ? (
40+
children
41+
) : (
42+
<div
43+
data-test-subj="renderOnlyInViewPlaceholderContainer"
44+
ref={intersectionRef}
45+
role="region"
46+
aria-label={placeholderTitle}
47+
style={{ height: initialHeight }}
48+
>
49+
<EuiLoadingContent />
50+
</div>
51+
);
52+
}

x-pack/plugins/observability/public/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export {
5555
SelectableUrlList,
5656
ExploratoryView,
5757
DatePicker,
58+
LoadWhenInView,
5859
} from './components/shared';
5960

6061
export type { LazyObservabilityPageTemplateProps } from './components/shared';

x-pack/plugins/synthetics/e2e/page_objects/monitor_management.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77
import { expect, Page } from '@elastic/synthetics';
8-
import { getQuerystring } from '@kbn/observability-plugin/e2e/utils';
8+
import { getQuerystring, TIMEOUT_60_SEC } from '@kbn/observability-plugin/e2e/utils';
99
import { DataStream } from '../../common/runtime_types/monitor_management';
1010
import { loginPageProvider } from './login';
1111
import { utilsPageProvider } from './utils';
@@ -162,7 +162,7 @@ export function monitorManagementPageProvider({
162162

163163
async selectLocations({ locations }: { locations: string[] }) {
164164
for (let i = 0; i < locations.length; i++) {
165-
await page.check(`text=${locations[i]}`);
165+
await page.check(`text=${locations[i]}`, TIMEOUT_60_SEC);
166166
}
167167
},
168168

x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_summary.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
EuiLoadingSpinner,
1717
} from '@elastic/eui';
1818
import { i18n } from '@kbn/i18n';
19+
import { LoadWhenInView } from '@kbn/observability-plugin/public';
1920

2021
import { useEarliestStartDate } from '../hooks/use_earliest_start_data';
2122
import { MonitorErrorSparklines } from './monitor_error_sparklines';
@@ -27,7 +28,7 @@ import { DurationPanel } from './duration_panel';
2728
import { MonitorDetailsPanel } from './monitor_details_panel';
2829
import { AvailabilitySparklines } from './availability_sparklines';
2930
import { LastTestRun } from './last_test_run';
30-
import { TestRunsTable } from './test_runs_table';
31+
import { LAST_10_TEST_RUNS, TestRunsTable } from './test_runs_table';
3132
import { MonitorErrorsCount } from './monitor_errors_count';
3233

3334
export const MonitorSummary = () => {
@@ -121,7 +122,9 @@ export const MonitorSummary = () => {
121122
</EuiFlexItem>
122123
</EuiFlexGroup>
123124
<EuiSpacer size="m" />
124-
<TestRunsTable paginable={false} from={from} to={to} />
125+
<LoadWhenInView placeholderTitle={LAST_10_TEST_RUNS}>
126+
<TestRunsTable paginable={false} from={from} to={to} />
127+
</LoadWhenInView>
125128
</>
126129
);
127130
};

x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/test_runs_table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const TEST_RUNS = i18n.translate('xpack.synthetics.monitorDetails.summary.testRu
230230
defaultMessage: 'Test Runs',
231231
});
232232

233-
const LAST_10_TEST_RUNS = i18n.translate(
233+
export const LAST_10_TEST_RUNS = i18n.translate(
234234
'xpack.synthetics.monitorDetails.summary.lastTenTestRuns',
235235
{
236236
defaultMessage: 'Last 10 Test Runs',

x-pack/plugins/ux/e2e/journeys/ux_js_errors.journey.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ journey('UX JsErrors', async ({ page, params }) => {
4545

4646
step('Confirm error count', async () => {
4747
// Wait until chart data is loaded
48-
page.waitForLoadState('networkidle');
48+
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
49+
await page.waitForLoadState('networkidle');
4950
await page.waitForSelector(`text=${jsErrorCount}`);
5051

5152
const jsErrors = await (

x-pack/plugins/ux/e2e/journeys/ux_long_task_metric_journey.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ journey('UX LongTaskMetrics', async ({ page, params }) => {
5454

5555
step('Confirm metrics values', async () => {
5656
// Wait until chart data is loaded
57-
page.waitForLoadState('networkidle');
57+
await page.waitForLoadState('networkidle');
5858
// wait for first metric to be shown
59-
page.waitForSelector(`text="237 ms"`);
59+
await page.waitForSelector(`text="237 ms"`);
6060

6161
let metric = await (
6262
await page.waitForSelector(byTestId(longestMetric))

x-pack/plugins/ux/e2e/journeys/ux_visitor_breakdown.journey.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ journey('UX Visitor Breakdown', async ({ page, params }) => {
4545

4646
step('Confirm charts are visible', async () => {
4747
// Wait until chart data is loaded
48+
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
4849
await page.waitForLoadState('networkidle');
50+
await waitForLoadingToFinish({ page });
4951

5052
await Promise.all(
5153
chartIds.map(

x-pack/plugins/ux/public/components/app/rum_dashboard/rum_dashboard.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
99
import React from 'react';
10+
import { LoadWhenInView } from '@kbn/observability-plugin/public';
11+
import { I18LABELS } from './translations';
1012
import { UXMetrics } from './ux_metrics';
1113
import { ImpactfulMetrics } from './impactful_metrics';
1214
import { PageLoadAndViews } from './panels/page_load_and_views';
@@ -29,10 +31,20 @@ export function RumDashboard() {
2931
<PageLoadAndViews />
3032
</EuiFlexItem>
3133
<EuiFlexItem>
32-
<VisitorBreakdownsPanel />
34+
<LoadWhenInView
35+
initialHeight={300}
36+
placeholderTitle={I18LABELS.pageLoadDurationByRegion}
37+
>
38+
<VisitorBreakdownsPanel />
39+
</LoadWhenInView>
3340
</EuiFlexItem>
3441
<EuiFlexItem>
35-
<ImpactfulMetrics />
42+
<LoadWhenInView
43+
initialHeight={300}
44+
placeholderTitle={I18LABELS.jsErrors}
45+
>
46+
<ImpactfulMetrics />
47+
</LoadWhenInView>
3648
</EuiFlexItem>
3749
</EuiFlexGroup>
3850
);

0 commit comments

Comments
 (0)