forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UX App] Improve page and filters responsiveness (elastic#91536)
- Loading branch information
Showing
9 changed files
with
205 additions
and
172 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
x-pack/plugins/apm/public/components/app/RumDashboard/ClientMetrics/Metrics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import numeral from '@elastic/numeral'; | ||
import styled from 'styled-components'; | ||
import { useContext, useEffect } from 'react'; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiStat, | ||
EuiToolTip, | ||
EuiIconTip, | ||
} from '@elastic/eui'; | ||
import { useFetcher } from '../../../../hooks/use_fetcher'; | ||
import { I18LABELS } from '../translations'; | ||
import { useUxQuery } from '../hooks/useUxQuery'; | ||
import { formatToSec } from '../UXMetrics/KeyUXMetrics'; | ||
import { CsmSharedContext } from '../CsmSharedContext'; | ||
|
||
const ClFlexGroup = styled(EuiFlexGroup)` | ||
flex-direction: row; | ||
@media only screen and (max-width: 768px) { | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
`; | ||
|
||
function formatTitle(unit: string, value?: number) { | ||
if (typeof value === 'undefined') return I18LABELS.dataMissing; | ||
return formatToSec(value, unit); | ||
} | ||
|
||
function PageViewsTotalTitle({ pageViews }: { pageViews?: number }) { | ||
if (typeof pageViews === 'undefined') { | ||
return <>{I18LABELS.dataMissing}</>; | ||
} | ||
return pageViews < 10000 ? ( | ||
<>{numeral(pageViews).format('0,0')}</> | ||
) : ( | ||
<EuiToolTip content={numeral(pageViews).format('0,0')}> | ||
<>{numeral(pageViews).format('0 a')}</> | ||
</EuiToolTip> | ||
); | ||
} | ||
|
||
export function Metrics() { | ||
const uxQuery = useUxQuery(); | ||
|
||
const { data, status } = useFetcher( | ||
(callApmApi) => { | ||
if (uxQuery) { | ||
return callApmApi({ | ||
endpoint: 'GET /api/apm/rum/client-metrics', | ||
params: { | ||
query: { | ||
...uxQuery, | ||
}, | ||
}, | ||
}); | ||
} | ||
return Promise.resolve(null); | ||
}, | ||
[uxQuery] | ||
); | ||
|
||
const { setSharedData } = useContext(CsmSharedContext); | ||
|
||
useEffect(() => { | ||
setSharedData({ totalPageViews: data?.pageViews?.value ?? 0 }); | ||
}, [data, setSharedData]); | ||
|
||
const STAT_STYLE = { minWidth: '150px', maxWidth: '250px' }; | ||
|
||
return ( | ||
<ClFlexGroup wrap responsive={false}> | ||
<EuiFlexItem style={STAT_STYLE}> | ||
<EuiStat | ||
titleSize="l" | ||
title={formatTitle('ms', data?.totalPageLoadDuration?.value)} | ||
description={ | ||
<> | ||
{I18LABELS.totalPageLoad} | ||
<EuiIconTip | ||
content={I18LABELS.totalPageLoadTooltip} | ||
type="questionInCircle" | ||
/> | ||
</> | ||
} | ||
isLoading={status !== 'success'} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem style={STAT_STYLE}> | ||
<EuiStat | ||
titleSize="l" | ||
title={formatTitle('ms', data?.backEnd?.value)} | ||
description={ | ||
<> | ||
{I18LABELS.backEnd} | ||
<EuiIconTip | ||
content={I18LABELS.backEndTooltip} | ||
type="questionInCircle" | ||
/> | ||
</> | ||
} | ||
isLoading={status !== 'success'} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem style={STAT_STYLE}> | ||
<EuiStat | ||
titleSize="l" | ||
title={formatTitle('ms', data?.frontEnd?.value)} | ||
description={ | ||
<> | ||
{I18LABELS.frontEnd} | ||
<EuiIconTip | ||
content={I18LABELS.frontEndTooltip} | ||
type="questionInCircle" | ||
/> | ||
</> | ||
} | ||
isLoading={status !== 'success'} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem style={STAT_STYLE}> | ||
<EuiStat | ||
titleSize="l" | ||
title={<PageViewsTotalTitle pageViews={data?.pageViews?.value} />} | ||
description={I18LABELS.pageViews} | ||
isLoading={status !== 'success'} | ||
/> | ||
</EuiFlexItem> | ||
</ClFlexGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.