123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import type {Location} from 'history';
- import {t} from 'sentry/locale';
- import type {Organization} from 'sentry/types/organization';
- import type {Project} from 'sentry/types/project';
- import EventView from 'sentry/utils/discover/eventView';
- import {isAggregateField} from 'sentry/utils/discover/fields';
- import type {WebVital} from 'sentry/utils/fields';
- import {WEB_VITAL_DETAILS} from 'sentry/utils/performance/vitals/constants';
- import {decodeScalar} from 'sentry/utils/queryString';
- import {MutableSearch} from 'sentry/utils/tokenizeSearch';
- import withOrganization from 'sentry/utils/withOrganization';
- import withProjects from 'sentry/utils/withProjects';
- import PageLayout from '../pageLayout';
- import Tab from '../tabs';
- import {PERCENTILE, VITAL_GROUPS} from './constants';
- import VitalsContent from './content';
- type Props = {
- location: Location;
- organization: Organization;
- projects: Project[];
- };
- function TransactionVitals(props: Props) {
- const {location, organization, projects} = props;
- return (
- <PageLayout
- location={location}
- organization={organization}
- projects={projects}
- tab={Tab.WEB_VITALS}
- getDocumentTitle={getDocumentTitle}
- generateEventView={generateEventView}
- childComponent={VitalsContent}
- />
- );
- }
- function getDocumentTitle(transactionName: string): string {
- const hasTransactionName =
- typeof transactionName === 'string' && String(transactionName).trim().length > 0;
- if (hasTransactionName) {
- return [String(transactionName).trim(), t('Vitals')].join(' \u2014 ');
- }
- return [t('Summary'), t('Vitals')].join(' \u2014 ');
- }
- function generateEventView({
- location,
- transactionName,
- }: {
- location: Location;
- transactionName: string;
- }): EventView {
- const query = decodeScalar(location.query.query, '');
- const conditions = new MutableSearch(query);
- conditions.setFilterValues('event.type', ['transaction']);
- conditions.setFilterValues('transaction', [transactionName]);
- Object.keys(conditions.filters).forEach(field => {
- if (isAggregateField(field)) {
- conditions.removeFilter(field);
- }
- });
- const vitals = VITAL_GROUPS.reduce((allVitals: WebVital[], group) => {
- return allVitals.concat(group.vitals);
- }, []);
- return EventView.fromNewQueryWithLocation(
- {
- id: undefined,
- version: 2,
- name: transactionName,
- fields: [
- ...vitals.map(vital => `percentile(${vital}, ${PERCENTILE})`),
- ...vitals.map(vital => `count_at_least(${vital}, 0)`),
- ...vitals.map(
- vital => `count_at_least(${vital}, ${WEB_VITAL_DETAILS[vital].poorThreshold})`
- ),
- ],
- query: conditions.formatString(),
- projects: [],
- },
- location
- );
- }
- export default withProjects(withOrganization(TransactionVitals));
|