123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- import * as React from 'react';
- import styled from '@emotion/styled';
- import {Location} from 'history';
- import Feature from 'app/components/acl/feature';
- import {GuideAnchor} from 'app/components/assistant/guideAnchor';
- import Button from 'app/components/button';
- import ButtonBar from 'app/components/buttonBar';
- import {CreateAlertFromViewButton} from 'app/components/createAlertButton';
- import FeatureBadge from 'app/components/featureBadge';
- import * as Layout from 'app/components/layouts/thirds';
- import ListLink from 'app/components/links/listLink';
- import NavTabs from 'app/components/navTabs';
- import {IconSettings} from 'app/icons';
- import {t} from 'app/locale';
- import {Organization, Project} from 'app/types';
- import {trackAnalyticsEvent} from 'app/utils/analytics';
- import EventView from 'app/utils/discover/eventView';
- import {decodeScalar} from 'app/utils/queryString';
- import Breadcrumb from 'app/views/performance/breadcrumb';
- import {eventsRouteWithQuery} from './transactionEvents/utils';
- import {tagsRouteWithQuery} from './transactionTags/utils';
- import {vitalsRouteWithQuery} from './transactionVitals/utils';
- import TeamKeyTransactionButton from './teamKeyTransactionButton';
- import TransactionThresholdButton from './transactionThresholdButton';
- import {TransactionThresholdMetric} from './transactionThresholdModal';
- import {transactionSummaryRouteWithQuery} from './utils';
- export enum Tab {
- TransactionSummary,
- RealUserMonitoring,
- Tags,
- Events,
- }
- type Props = {
- eventView: EventView;
- location: Location;
- organization: Organization;
- projects: Project[];
- transactionName: string;
- currentTab: Tab;
- hasWebVitals: boolean;
- onChangeThreshold?: (threshold: number, metric: TransactionThresholdMetric) => void;
- handleIncompatibleQuery: React.ComponentProps<
- typeof CreateAlertFromViewButton
- >['onIncompatibleQuery'];
- };
- class TransactionHeader extends React.Component<Props> {
- trackAlertClick(errors?: Record<string, boolean>) {
- const {organization} = this.props;
- trackAnalyticsEvent({
- eventKey: 'performance_views.summary.create_alert_clicked',
- eventName: 'Performance Views: Create alert clicked',
- organization_id: organization.id,
- status: errors ? 'error' : 'success',
- errors,
- url: window.location.href,
- });
- }
- trackVitalsTabClick = () => {
- const {organization} = this.props;
- trackAnalyticsEvent({
- eventKey: 'performance_views.vitals.vitals_tab_clicked',
- eventName: 'Performance Views: Vitals tab clicked',
- organization_id: organization.id,
- });
- };
- trackTagsTabClick = () => {
- const {organization} = this.props;
- trackAnalyticsEvent({
- eventKey: 'performance_views.tags.tags_tab_clicked',
- eventName: 'Performance Views: Tags tab clicked',
- organization_id: organization.id,
- });
- };
- trackEventsTabClick = () => {
- const {organization} = this.props;
- trackAnalyticsEvent({
- eventKey: 'performance_views.events.events_tab_clicked',
- eventName: 'Performance Views: Events tab clicked',
- organization_id: organization.id,
- });
- };
- handleIncompatibleQuery: React.ComponentProps<
- typeof CreateAlertFromViewButton
- >['onIncompatibleQuery'] = (incompatibleAlertNoticeFn, errors) => {
- this.trackAlertClick(errors);
- this.props.handleIncompatibleQuery?.(incompatibleAlertNoticeFn, errors);
- };
- handleCreateAlertSuccess = () => {
- this.trackAlertClick();
- };
- renderCreateAlertButton() {
- const {eventView, organization, projects} = this.props;
- return (
- <CreateAlertFromViewButton
- eventView={eventView}
- organization={organization}
- projects={projects}
- onIncompatibleQuery={this.handleIncompatibleQuery}
- onSuccess={this.handleCreateAlertSuccess}
- referrer="performance"
- />
- );
- }
- renderKeyTransactionButton() {
- const {eventView, organization, transactionName} = this.props;
- return (
- <TeamKeyTransactionButton
- transactionName={transactionName}
- eventView={eventView}
- organization={organization}
- />
- );
- }
- renderSettingsButton() {
- const {organization, transactionName, eventView, onChangeThreshold} = this.props;
- return (
- <Feature
- organization={organization}
- features={['project-transaction-threshold-override']}
- >
- {({hasFeature}) =>
- hasFeature ? (
- <GuideAnchor
- target="project_transaction_threshold_override"
- position="bottom"
- >
- <TransactionThresholdButton
- organization={organization}
- transactionName={transactionName}
- eventView={eventView}
- onChangeThreshold={onChangeThreshold}
- />
- </GuideAnchor>
- ) : (
- <Button
- href={`/settings/${organization.slug}/performance/`}
- icon={<IconSettings />}
- aria-label={t('Settings')}
- />
- )
- }
- </Feature>
- );
- }
- render() {
- const {organization, location, transactionName, currentTab, hasWebVitals} =
- this.props;
- const summaryTarget = transactionSummaryRouteWithQuery({
- orgSlug: organization.slug,
- transaction: transactionName,
- projectID: decodeScalar(location.query.project),
- query: location.query,
- });
- const vitalsTarget = vitalsRouteWithQuery({
- orgSlug: organization.slug,
- transaction: transactionName,
- projectID: decodeScalar(location.query.project),
- query: location.query,
- });
- const tagsTarget = tagsRouteWithQuery({
- orgSlug: organization.slug,
- transaction: transactionName,
- projectID: decodeScalar(location.query.project),
- query: location.query,
- });
- const eventsTarget = eventsRouteWithQuery({
- orgSlug: organization.slug,
- transaction: transactionName,
- projectID: decodeScalar(location.query.project),
- query: location.query,
- });
- return (
- <Layout.Header>
- <Layout.HeaderContent>
- <Breadcrumb
- organization={organization}
- location={location}
- transactionName={transactionName}
- realUserMonitoring={currentTab === Tab.RealUserMonitoring}
- />
- <Layout.Title>{transactionName}</Layout.Title>
- </Layout.HeaderContent>
- <Layout.HeaderActions>
- <ButtonBar gap={1}>
- <Feature organization={organization} features={['incidents']}>
- {({hasFeature}) => hasFeature && this.renderCreateAlertButton()}
- </Feature>
- {this.renderKeyTransactionButton()}
- {this.renderSettingsButton()}
- </ButtonBar>
- </Layout.HeaderActions>
- <React.Fragment>
- <StyledNavTabs>
- <ListLink
- to={summaryTarget}
- isActive={() => currentTab === Tab.TransactionSummary}
- >
- {t('Overview')}
- </ListLink>
- {hasWebVitals && (
- <ListLink
- to={vitalsTarget}
- isActive={() => currentTab === Tab.RealUserMonitoring}
- onClick={this.trackVitalsTabClick}
- >
- {t('Web Vitals')}
- </ListLink>
- )}
- <Feature features={['organizations:performance-tag-page']}>
- <ListLink
- to={tagsTarget}
- isActive={() => currentTab === Tab.Tags}
- onClick={this.trackTagsTabClick}
- >
- {t('Tags')}
- <FeatureBadge type="beta" noTooltip />
- </ListLink>
- </Feature>
- <Feature features={['organizations:performance-events-page']}>
- <ListLink
- to={eventsTarget}
- isActive={() => currentTab === Tab.Events}
- onClick={this.trackEventsTabClick}
- >
- {t('All Events')}
- <FeatureBadge type="new" noTooltip />
- </ListLink>
- </Feature>
- </StyledNavTabs>
- </React.Fragment>
- </Layout.Header>
- );
- }
- }
- const StyledNavTabs = styled(NavTabs)`
- margin-bottom: 0;
- /* Makes sure the tabs are pushed into another row */
- width: 100%;
- `;
- export default TransactionHeader;
|