|
| 1 | +import React from 'react'; |
1 | 2 | import {browserHistory} from 'react-router'; |
2 | 3 | import styled from '@emotion/styled'; |
3 | 4 | import {Location} from 'history'; |
4 | 5 |
|
| 6 | +import Alert from 'sentry/components/alert'; |
5 | 7 | import Button from 'sentry/components/button'; |
6 | 8 | import DropdownControl, {DropdownItem} from 'sentry/components/dropdownControl'; |
7 | 9 | import SearchBar from 'sentry/components/events/searchBar'; |
8 | 10 | import * as Layout from 'sentry/components/layouts/thirds'; |
| 11 | +import ExternalLink from 'sentry/components/links/externalLink'; |
9 | 12 | import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse'; |
10 | | -import {t} from 'sentry/locale'; |
| 13 | +import {IconInfo} from 'sentry/icons'; |
| 14 | +import {t, tct} from 'sentry/locale'; |
11 | 15 | import space from 'sentry/styles/space'; |
12 | 16 | import {Organization} from 'sentry/types'; |
13 | 17 | import {trackAnalyticsEvent} from 'sentry/utils/analytics'; |
14 | 18 | import EventView from 'sentry/utils/discover/eventView'; |
| 19 | +import {WebVital} from 'sentry/utils/discover/fields'; |
15 | 20 | import Histogram from 'sentry/utils/performance/histogram'; |
16 | 21 | import {FILTER_OPTIONS} from 'sentry/utils/performance/histogram/constants'; |
| 22 | +import VitalsCardsDiscoverQuery from 'sentry/utils/performance/vitals/vitalsCardsDiscoverQuery'; |
17 | 23 | import {decodeScalar} from 'sentry/utils/queryString'; |
18 | 24 |
|
19 | | -import {ZOOM_KEYS} from './constants'; |
| 25 | +import {VITAL_GROUPS, ZOOM_KEYS} from './constants'; |
20 | 26 | import VitalsPanel from './vitalsPanel'; |
21 | 27 |
|
22 | 28 | type Props = { |
@@ -44,63 +50,100 @@ function VitalsContent(props: Props) { |
44 | 50 | }); |
45 | 51 | }; |
46 | 52 |
|
| 53 | + const allVitals = VITAL_GROUPS.reduce((keys: WebVital[], {vitals}) => { |
| 54 | + return keys.concat(vitals); |
| 55 | + }, []); |
| 56 | + |
47 | 57 | return ( |
48 | 58 | <Histogram location={location} zoomKeys={ZOOM_KEYS}> |
49 | 59 | {({activeFilter, handleFilterChange, handleResetView, isZoomed}) => ( |
50 | 60 | <Layout.Main fullWidth> |
51 | | - <StyledActions> |
52 | | - <StyledSearchBar |
53 | | - organization={organization} |
54 | | - projectIds={eventView.project} |
55 | | - query={query} |
56 | | - fields={eventView.fields} |
57 | | - onSearch={handleSearch} |
58 | | - /> |
59 | | - <DropdownControl |
60 | | - buttonProps={{prefix: t('Outliers')}} |
61 | | - label={activeFilter.label} |
62 | | - > |
63 | | - {FILTER_OPTIONS.map(({label, value}) => ( |
64 | | - <DropdownItem |
65 | | - key={value} |
66 | | - onSelect={(filterOption: string) => { |
67 | | - trackAnalyticsEvent({ |
68 | | - eventKey: 'performance_views.vitals.filter_changed', |
69 | | - eventName: 'Performance Views: Change vitals filter', |
70 | | - organization_id: organization.id, |
71 | | - value: filterOption, |
72 | | - }); |
73 | | - handleFilterChange(filterOption); |
74 | | - }} |
75 | | - eventKey={value} |
76 | | - isActive={value === activeFilter.value} |
77 | | - > |
78 | | - {label} |
79 | | - </DropdownItem> |
80 | | - ))} |
81 | | - </DropdownControl> |
82 | | - <Button |
83 | | - onClick={() => { |
84 | | - trackAnalyticsEvent({ |
85 | | - eventKey: 'performance_views.vitals.reset_view', |
86 | | - eventName: 'Performance Views: Reset vitals view', |
87 | | - organization_id: organization.id, |
88 | | - }); |
89 | | - |
90 | | - handleResetView(); |
91 | | - }} |
92 | | - disabled={!isZoomed} |
93 | | - data-test-id="reset-view" |
94 | | - > |
95 | | - {t('Reset View')} |
96 | | - </Button> |
97 | | - </StyledActions> |
98 | | - <VitalsPanel |
99 | | - organization={organization} |
100 | | - location={location} |
| 61 | + <VitalsCardsDiscoverQuery |
101 | 62 | eventView={eventView} |
102 | | - dataFilter={activeFilter.value} |
103 | | - /> |
| 63 | + orgSlug={organization.slug} |
| 64 | + location={location} |
| 65 | + vitals={allVitals} |
| 66 | + > |
| 67 | + {results => { |
| 68 | + const isMissingVitalsData = |
| 69 | + !results.isLoading && |
| 70 | + allVitals.some(vital => !results.vitalsData?.[vital]); |
| 71 | + |
| 72 | + return ( |
| 73 | + <React.Fragment> |
| 74 | + {isMissingVitalsData && ( |
| 75 | + <Alert type="info" icon={<IconInfo size="md" />}> |
| 76 | + {tct( |
| 77 | + 'If this page is looking a little bare, keep in mind not all browsers support these vitals. [link]', |
| 78 | + { |
| 79 | + link: ( |
| 80 | + <ExternalLink href="https://docs.sentry.io/product/performance/web-vitals/#browser-support"> |
| 81 | + {t('Read more about browser support.')} |
| 82 | + </ExternalLink> |
| 83 | + ), |
| 84 | + } |
| 85 | + )} |
| 86 | + </Alert> |
| 87 | + )} |
| 88 | + |
| 89 | + <StyledActions> |
| 90 | + <StyledSearchBar |
| 91 | + organization={organization} |
| 92 | + projectIds={eventView.project} |
| 93 | + query={query} |
| 94 | + fields={eventView.fields} |
| 95 | + onSearch={handleSearch} |
| 96 | + /> |
| 97 | + <DropdownControl |
| 98 | + buttonProps={{prefix: t('Outliers')}} |
| 99 | + label={activeFilter.label} |
| 100 | + > |
| 101 | + {FILTER_OPTIONS.map(({label, value}) => ( |
| 102 | + <DropdownItem |
| 103 | + key={value} |
| 104 | + onSelect={(filterOption: string) => { |
| 105 | + trackAnalyticsEvent({ |
| 106 | + eventKey: 'performance_views.vitals.filter_changed', |
| 107 | + eventName: 'Performance Views: Change vitals filter', |
| 108 | + organization_id: organization.id, |
| 109 | + value: filterOption, |
| 110 | + }); |
| 111 | + handleFilterChange(filterOption); |
| 112 | + }} |
| 113 | + eventKey={value} |
| 114 | + isActive={value === activeFilter.value} |
| 115 | + > |
| 116 | + {label} |
| 117 | + </DropdownItem> |
| 118 | + ))} |
| 119 | + </DropdownControl> |
| 120 | + <Button |
| 121 | + onClick={() => { |
| 122 | + trackAnalyticsEvent({ |
| 123 | + eventKey: 'performance_views.vitals.reset_view', |
| 124 | + eventName: 'Performance Views: Reset vitals view', |
| 125 | + organization_id: organization.id, |
| 126 | + }); |
| 127 | + |
| 128 | + handleResetView(); |
| 129 | + }} |
| 130 | + disabled={!isZoomed} |
| 131 | + data-test-id="reset-view" |
| 132 | + > |
| 133 | + {t('Reset View')} |
| 134 | + </Button> |
| 135 | + </StyledActions> |
| 136 | + <VitalsPanel |
| 137 | + organization={organization} |
| 138 | + location={location} |
| 139 | + eventView={eventView} |
| 140 | + dataFilter={activeFilter.value} |
| 141 | + results={results} |
| 142 | + /> |
| 143 | + </React.Fragment> |
| 144 | + ); |
| 145 | + }} |
| 146 | + </VitalsCardsDiscoverQuery> |
104 | 147 | </Layout.Main> |
105 | 148 | )} |
106 | 149 | </Histogram> |
|
0 commit comments