123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- import {Component, Fragment} from 'react';
- import {browserHistory, InjectedRouter} from 'react-router';
- import styled from '@emotion/styled';
- import {Location} from 'history';
- import omit from 'lodash/omit';
- import {Client} from 'sentry/api';
- import Feature from 'sentry/components/acl/feature';
- import Alert from 'sentry/components/alert';
- import Button from 'sentry/components/button';
- import ButtonBar from 'sentry/components/buttonBar';
- import {getInterval} from 'sentry/components/charts/utils';
- import {CreateAlertFromViewButton} from 'sentry/components/createAlertButton';
- import SearchBar from 'sentry/components/events/searchBar';
- import * as Layout from 'sentry/components/layouts/thirds';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
- import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
- import {IconCheckmark, IconChevron, IconClose} from 'sentry/icons';
- import {IconFlag} from 'sentry/icons/iconFlag';
- import {t} from 'sentry/locale';
- import space from 'sentry/styles/space';
- import {Organization, Project} from 'sentry/types';
- import {generateQueryWithTag} from 'sentry/utils';
- import {getUtcToLocalDateObject} from 'sentry/utils/dates';
- import EventView from 'sentry/utils/discover/eventView';
- import {WebVital} from 'sentry/utils/discover/fields';
- import MetricsRequest from 'sentry/utils/metrics/metricsRequest';
- import {Browser} from 'sentry/utils/performance/vitals/constants';
- import {decodeScalar} from 'sentry/utils/queryString';
- import Teams from 'sentry/utils/teams';
- import {MutableSearch} from 'sentry/utils/tokenizeSearch';
- import withProjects from 'sentry/utils/withProjects';
- import {transformMetricsToArea} from 'sentry/views/performance/landing/widgets/transforms/transformMetricsToArea';
- import Breadcrumb from '../breadcrumb';
- import MetricsSearchBar from '../metricsSearchBar';
- import {MetricsSwitch} from '../metricsSwitch';
- import {getTransactionSearchQuery} from '../utils';
- import Table from './table';
- import {
- vitalDescription,
- vitalMap,
- vitalSupportedBrowsers,
- vitalToMetricsField,
- } from './utils';
- import VitalChart from './vitalChart';
- import VitalChartMetrics from './vitalChartMetrics';
- import VitalInfo from './vitalInfo';
- const FRONTEND_VITALS = [WebVital.FCP, WebVital.LCP, WebVital.FID, WebVital.CLS];
- type Props = {
- api: Client;
- eventView: EventView;
- isMetricsData: boolean;
- location: Location;
- organization: Organization;
- projects: Project[];
- router: InjectedRouter;
- vitalName: WebVital;
- };
- type State = {
- error: string | undefined;
- incompatibleAlertNotice: React.ReactNode;
- };
- function getSummaryConditions(query: string) {
- const parsed = new MutableSearch(query);
- parsed.freeText = [];
- return parsed.formatString();
- }
- class VitalDetailContent extends Component<Props, State> {
- state: State = {
- incompatibleAlertNotice: null,
- error: undefined,
- };
- handleSearch = (query: string) => {
- const {location} = this.props;
- const queryParams = normalizeDateTimeParams({
- ...(location.query || {}),
- query,
- });
- // do not propagate pagination when making a new search
- const searchQueryParams = omit(queryParams, 'cursor');
- browserHistory.push({
- pathname: location.pathname,
- query: searchQueryParams,
- });
- };
- generateTagUrl = (key: string, value: string) => {
- const {location} = this.props;
- const query = generateQueryWithTag(location.query, {key, value});
- return {
- ...location,
- query,
- };
- };
- handleIncompatibleQuery: React.ComponentProps<
- typeof CreateAlertFromViewButton
- >['onIncompatibleQuery'] = (incompatibleAlertNoticeFn, _errors) => {
- const incompatibleAlertNotice = incompatibleAlertNoticeFn(() =>
- this.setState({incompatibleAlertNotice: null})
- );
- this.setState({incompatibleAlertNotice});
- };
- renderCreateAlertButton() {
- const {eventView, organization, projects} = this.props;
- return (
- <CreateAlertFromViewButton
- eventView={eventView}
- organization={organization}
- projects={projects}
- onIncompatibleQuery={this.handleIncompatibleQuery}
- onSuccess={() => {}}
- referrer="performance"
- />
- );
- }
- renderVitalSwitcher() {
- const {vitalName, location} = this.props;
- const position = FRONTEND_VITALS.indexOf(vitalName);
- if (position < 0) {
- return null;
- }
- const previousDisabled = position === 0;
- const nextDisabled = position === FRONTEND_VITALS.length - 1;
- const switchVital = newVitalName => {
- return () => {
- browserHistory.push({
- pathname: location.pathname,
- query: {
- ...location.query,
- vitalName: newVitalName,
- },
- });
- };
- };
- return (
- <ButtonBar merged>
- <Button
- icon={<IconChevron direction="left" size="sm" />}
- aria-label={t('Previous')}
- disabled={previousDisabled}
- onClick={switchVital(FRONTEND_VITALS[position - 1])}
- />
- <Button
- icon={<IconChevron direction="right" size="sm" />}
- aria-label={t('Next')}
- disabled={nextDisabled}
- onClick={switchVital(FRONTEND_VITALS[position + 1])}
- />
- </ButtonBar>
- );
- }
- setError = (error: string | undefined) => {
- this.setState({error});
- };
- renderError() {
- const {error} = this.state;
- if (!error) {
- return null;
- }
- return (
- <Alert type="error" icon={<IconFlag size="md" />}>
- {error}
- </Alert>
- );
- }
- renderContent(vital: WebVital) {
- const {isMetricsData, location, organization, eventView, api, projects} = this.props;
- const {fields, start, end, statsPeriod, environment, project} = eventView;
- const query = decodeScalar(location.query.query, '');
- const orgSlug = organization.slug;
- const localDateStart = start ? getUtcToLocalDateObject(start) : null;
- const localDateEnd = end ? getUtcToLocalDateObject(end) : null;
- const interval = getInterval(
- {start: localDateStart, end: localDateEnd, period: statsPeriod},
- 'high'
- );
- if (isMetricsData) {
- const field = `p75(${vitalToMetricsField[vital]})`;
- return (
- <Fragment>
- <StyledMetricsSearchBar
- searchSource="performance_vitals_metrics"
- orgSlug={orgSlug}
- projectIds={project}
- query={query}
- onSearch={this.handleSearch}
- />
- <MetricsRequest
- api={api}
- orgSlug={orgSlug}
- start={start}
- end={end}
- statsPeriod={statsPeriod}
- project={project}
- environment={environment}
- field={[field]}
- query={new MutableSearch(query).formatString()} // TODO(metrics): not all tags will be compatible with metrics
- interval={interval}
- >
- {p75RequestProps => {
- const {loading, errored, response, reloading} = p75RequestProps;
- const p75Data = transformMetricsToArea(
- {
- location,
- fields: [field],
- },
- p75RequestProps
- );
- return (
- <Fragment>
- <VitalChartMetrics
- start={localDateStart}
- end={localDateEnd}
- statsPeriod={statsPeriod}
- project={project}
- environment={environment}
- loading={loading}
- response={response}
- errored={errored}
- reloading={reloading}
- field={field}
- vital={vital}
- />
- <StyledVitalInfo>
- <VitalInfo
- orgSlug={orgSlug}
- location={location}
- vital={vital}
- project={project}
- environment={environment}
- start={start}
- end={end}
- statsPeriod={statsPeriod}
- isMetricsData={isMetricsData}
- isLoading={loading}
- p75AllTransactions={p75Data.dataMean?.[0].mean}
- />
- </StyledVitalInfo>
- <div>TODO</div>
- </Fragment>
- );
- }}
- </MetricsRequest>
- </Fragment>
- );
- }
- const filterString = getTransactionSearchQuery(location);
- const summaryConditions = getSummaryConditions(filterString);
- return (
- <Fragment>
- <StyledSearchBar
- searchSource="performance_vitals"
- organization={organization}
- projectIds={project}
- query={query}
- fields={fields}
- onSearch={this.handleSearch}
- />
- <VitalChart
- organization={organization}
- query={query}
- project={project}
- environment={environment}
- start={localDateStart}
- end={localDateEnd}
- statsPeriod={statsPeriod}
- interval={interval}
- />
- <StyledVitalInfo>
- <VitalInfo
- orgSlug={orgSlug}
- location={location}
- vital={vital}
- project={project}
- environment={environment}
- start={start}
- end={end}
- statsPeriod={statsPeriod}
- />
- </StyledVitalInfo>
- <Teams provideUserTeams>
- {({teams, initiallyLoaded}) =>
- initiallyLoaded ? (
- <TeamKeyTransactionManager.Provider
- organization={organization}
- teams={teams}
- selectedTeams={['myteams']}
- selectedProjects={project.map(String)}
- >
- <Table
- eventView={eventView}
- projects={projects}
- organization={organization}
- location={location}
- setError={this.setError}
- summaryConditions={summaryConditions}
- />
- </TeamKeyTransactionManager.Provider>
- ) : (
- <LoadingIndicator />
- )
- }
- </Teams>
- </Fragment>
- );
- }
- render() {
- const {location, organization, vitalName} = this.props;
- const {incompatibleAlertNotice} = this.state;
- const vital = vitalName || WebVital.LCP;
- return (
- <Fragment>
- <Layout.Header>
- <Layout.HeaderContent>
- <Breadcrumb
- organization={organization}
- location={location}
- vitalName={vital}
- />
- <Layout.Title>{vitalMap[vital]}</Layout.Title>
- </Layout.HeaderContent>
- <Layout.HeaderActions>
- <ButtonBar gap={1}>
- <MetricsSwitch onSwitch={() => this.handleSearch('')} />
- <Feature organization={organization} features={['incidents']}>
- {({hasFeature}) => hasFeature && this.renderCreateAlertButton()}
- </Feature>
- {this.renderVitalSwitcher()}
- </ButtonBar>
- </Layout.HeaderActions>
- </Layout.Header>
- <Layout.Body>
- {this.renderError()}
- {incompatibleAlertNotice && (
- <Layout.Main fullWidth>{incompatibleAlertNotice}</Layout.Main>
- )}
- <Layout.Main fullWidth>
- <StyledDescription>{vitalDescription[vitalName]}</StyledDescription>
- <SupportedBrowsers>
- {Object.values(Browser).map(browser => (
- <BrowserItem key={browser}>
- {vitalSupportedBrowsers[vitalName]?.includes(browser) ? (
- <IconCheckmark color="green200" size="sm" />
- ) : (
- <IconClose color="red300" size="sm" />
- )}
- {browser}
- </BrowserItem>
- ))}
- </SupportedBrowsers>
- {this.renderContent(vital)}
- </Layout.Main>
- </Layout.Body>
- </Fragment>
- );
- }
- }
- export default withProjects(VitalDetailContent);
- const StyledDescription = styled('div')`
- font-size: ${p => p.theme.fontSizeMedium};
- margin-bottom: ${space(3)};
- `;
- const StyledSearchBar = styled(SearchBar)`
- margin-bottom: ${space(2)};
- `;
- const StyledVitalInfo = styled('div')`
- margin-bottom: ${space(3)};
- `;
- const StyledMetricsSearchBar = styled(MetricsSearchBar)`
- margin-bottom: ${space(2)};
- `;
- const SupportedBrowsers = styled('div')`
- display: inline-flex;
- gap: ${space(2)};
- margin-bottom: ${space(3)};
- `;
- const BrowserItem = styled('div')`
- display: flex;
- align-items: center;
- gap: ${space(1)};
- `;
|