123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- import {FC, Fragment, useEffect, useRef} from 'react';
- import {browserHistory} from 'react-router';
- import styled from '@emotion/styled';
- import {Location} from 'history';
- import {openModal} from 'sentry/actionCreators/modal';
- import Feature from 'sentry/components/acl/feature';
- import Button from 'sentry/components/button';
- import ButtonBar from 'sentry/components/buttonBar';
- import DatePageFilter from 'sentry/components/datePageFilter';
- import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
- import SearchBar from 'sentry/components/events/searchBar';
- import {GlobalSdkUpdateAlert} from 'sentry/components/globalSdkUpdateAlert';
- import * as Layout from 'sentry/components/layouts/thirds';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
- import PageHeading from 'sentry/components/pageHeading';
- import TransactionNameSearchBar from 'sentry/components/performance/searchBar';
- import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
- import ProjectPageFilter from 'sentry/components/projectPageFilter';
- import {MAX_QUERY_LENGTH} from 'sentry/constants';
- import {IconSettings} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import {PageContent} from 'sentry/styles/organization';
- import space from 'sentry/styles/space';
- import {Organization, PageFilters, Project} from 'sentry/types';
- import EventView from 'sentry/utils/discover/eventView';
- import {generateAggregateFields} from 'sentry/utils/discover/fields';
- import {GenericQueryBatcher} from 'sentry/utils/performance/contexts/genericQueryBatcher';
- import {
- PageErrorAlert,
- PageErrorProvider,
- } from 'sentry/utils/performance/contexts/pageError';
- import useTeams from 'sentry/utils/useTeams';
- import Onboarding from '../onboarding';
- import {MetricsEventsDropdown} from '../transactionSummary/transactionOverview/metricEvents/metricsEventsDropdown';
- import {getTransactionSearchQuery} from '../utils';
- import {AllTransactionsView} from './views/allTransactionsView';
- import {BackendView} from './views/backendView';
- import {FrontendOtherView} from './views/frontendOtherView';
- import {FrontendPageloadView} from './views/frontendPageloadView';
- import {MobileView} from './views/mobileView';
- import SamplingModal, {modalCss} from './samplingModal';
- import {
- getDefaultDisplayForPlatform,
- getLandingDisplayFromParam,
- handleLandingDisplayChange,
- LANDING_DISPLAYS,
- LandingDisplayField,
- } from './utils';
- type Props = {
- eventView: EventView;
- handleSearch: (searchQuery: string) => void;
- handleTrendsClick: () => void;
- location: Location;
- onboardingProject: Project | undefined;
- organization: Organization;
- projects: Project[];
- selection: PageFilters;
- setError: (msg: string | undefined) => void;
- withStaticFilters: boolean;
- };
- const fieldToViewMap: Record<LandingDisplayField, FC<Props>> = {
- [LandingDisplayField.ALL]: AllTransactionsView,
- [LandingDisplayField.BACKEND]: BackendView,
- [LandingDisplayField.FRONTEND_OTHER]: FrontendOtherView,
- [LandingDisplayField.FRONTEND_PAGELOAD]: FrontendPageloadView,
- [LandingDisplayField.MOBILE]: MobileView,
- };
- export function PerformanceLanding(props: Props) {
- const {
- organization,
- location,
- eventView,
- projects,
- handleSearch,
- handleTrendsClick,
- onboardingProject,
- withStaticFilters,
- } = props;
- const {teams, initiallyLoaded} = useTeams({provideUserTeams: true});
- const hasMounted = useRef(false);
- const paramLandingDisplay = getLandingDisplayFromParam(location);
- const defaultLandingDisplayForProjects = getDefaultDisplayForPlatform(
- projects,
- eventView
- );
- const landingDisplay = paramLandingDisplay ?? defaultLandingDisplayForProjects;
- const showOnboarding = onboardingProject !== undefined;
- useEffect(() => {
- if (hasMounted.current) {
- browserHistory.replace({
- pathname: location.pathname,
- query: {
- ...location.query,
- landingDisplay: undefined,
- },
- });
- }
- }, [eventView.project.join('.')]);
- useEffect(() => {
- hasMounted.current = true;
- }, []);
- const filterString = withStaticFilters
- ? 'transaction.duration:<15m'
- : getTransactionSearchQuery(location, eventView.query);
- const ViewComponent = fieldToViewMap[landingDisplay.field];
- const fnOpenModal = () => {
- openModal(
- modalProps => (
- <SamplingModal
- {...modalProps}
- organization={organization}
- eventView={eventView}
- projects={projects}
- onApply={() => {}}
- isMEPEnabled
- />
- ),
- {modalCss, backdrop: 'static'}
- );
- };
- let pageFilters: React.ReactNode = (
- <PageFilterBar condensed>
- <ProjectPageFilter />
- <EnvironmentPageFilter />
- <DatePageFilter alignDropdown="left" />
- </PageFilterBar>
- );
- if (showOnboarding) {
- pageFilters = <SearchContainerWithFilter>{pageFilters}</SearchContainerWithFilter>;
- }
- const SearchFilterContainer =
- organization.features.includes('performance-use-metrics') &&
- !organization.features.includes('performance-transaction-name-only-search')
- ? SearchContainerWithFilterAndMetrics
- : SearchContainerWithFilter;
- return (
- <StyledPageContent data-test-id="performance-landing-v3">
- <PageErrorProvider>
- <Layout.Header>
- <Layout.HeaderContent>
- <StyledHeading>{t('Performance')}</StyledHeading>
- </Layout.HeaderContent>
- <Layout.HeaderActions>
- {!showOnboarding && (
- <ButtonBar gap={3}>
- <Button
- priority="primary"
- data-test-id="landing-header-trends"
- onClick={() => handleTrendsClick()}
- >
- {t('View Trends')}
- </Button>
- <Feature features={['organizations:performance-use-metrics']}>
- <Button
- onClick={() => fnOpenModal()}
- icon={<IconSettings />}
- aria-label={t('Settings')}
- data-test-id="open-meps-settings"
- />
- </Feature>
- </ButtonBar>
- )}
- </Layout.HeaderActions>
- <Layout.HeaderNavTabs>
- {LANDING_DISPLAYS.map(({label, field}) => (
- <li key={label} className={landingDisplay.field === field ? 'active' : ''}>
- <a
- href="#"
- data-test-id={`landing-tab-${field}`}
- onClick={() =>
- handleLandingDisplayChange(
- field,
- location,
- projects,
- organization,
- eventView
- )
- }
- >
- {t(label)}
- </a>
- </li>
- ))}
- </Layout.HeaderNavTabs>
- </Layout.Header>
- <Layout.Body>
- <Layout.Main fullWidth>
- <GlobalSdkUpdateAlert />
- <PageErrorAlert />
- {showOnboarding ? (
- <Fragment>
- {pageFilters}
- <Onboarding organization={organization} project={onboardingProject} />
- </Fragment>
- ) : (
- <Fragment>
- <SearchFilterContainer>
- {pageFilters}
- <Feature
- features={['organizations:performance-transaction-name-only-search']}
- >
- {({hasFeature}) =>
- hasFeature ? (
- // TODO replace `handleSearch prop` with transaction name search once
- // transaction name search becomes the default search bar
- <TransactionNameSearchBar
- organization={organization}
- location={location}
- eventView={eventView}
- />
- ) : (
- <SearchBar
- searchSource="performance_landing"
- organization={organization}
- projectIds={eventView.project}
- query={filterString}
- fields={generateAggregateFields(
- organization,
- [...eventView.fields, {field: 'tps()'}],
- ['epm()', 'eps()']
- )}
- onSearch={handleSearch}
- maxQueryLength={MAX_QUERY_LENGTH}
- />
- )
- }
- </Feature>
- <Feature
- features={['organizations:performance-transaction-name-only-search']}
- >
- {({hasFeature}) => !hasFeature && <MetricsEventsDropdown />}
- </Feature>
- </SearchFilterContainer>
- {initiallyLoaded ? (
- <TeamKeyTransactionManager.Provider
- organization={organization}
- teams={teams}
- selectedTeams={['myteams']}
- selectedProjects={eventView.project.map(String)}
- >
- <GenericQueryBatcher>
- <ViewComponent {...props} />
- </GenericQueryBatcher>
- </TeamKeyTransactionManager.Provider>
- ) : (
- <LoadingIndicator />
- )}
- </Fragment>
- )}
- </Layout.Main>
- </Layout.Body>
- </PageErrorProvider>
- </StyledPageContent>
- );
- }
- const StyledPageContent = styled(PageContent)`
- padding: 0;
- `;
- const StyledHeading = styled(PageHeading)`
- line-height: 40px;
- `;
- const SearchContainerWithFilter = styled('div')`
- display: grid;
- grid-template-rows: auto auto;
- gap: ${space(2)};
- margin-bottom: ${space(2)};
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- grid-template-rows: auto;
- grid-template-columns: auto 1fr;
- }
- `;
- const SearchContainerWithFilterAndMetrics = styled('div')`
- display: grid;
- grid-template-rows: auto auto auto;
- gap: ${space(2)};
- margin-bottom: ${space(2)};
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- grid-template-rows: auto;
- grid-template-columns: auto 1fr auto;
- }
- `;
|