123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import {useCallback, useEffect} from 'react';
- import {browserHistory} from 'react-router';
- import styled from '@emotion/styled';
- import {Location} from 'history';
- import Alert from 'sentry/components/alert';
- import Button from 'sentry/components/button';
- import DatePageFilter from 'sentry/components/datePageFilter';
- import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
- import * as Layout from 'sentry/components/layouts/thirds';
- import NoProjectMessage from 'sentry/components/noProjectMessage';
- import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
- import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
- import PageHeading from 'sentry/components/pageHeading';
- import Pagination from 'sentry/components/pagination';
- import {ProfileTransactionsTable} from 'sentry/components/profiling/profileTransactionsTable';
- import ProjectPageFilter from 'sentry/components/projectPageFilter';
- import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
- import SmartSearchBar, {SmartSearchBarProps} from 'sentry/components/smartSearchBar';
- import {MAX_QUERY_LENGTH} from 'sentry/constants';
- import {t} from 'sentry/locale';
- import {PageContent} from 'sentry/styles/organization';
- import space from 'sentry/styles/space';
- import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
- import {useProfileFilters} from 'sentry/utils/profiling/hooks/useProfileFilters';
- import {useProfiles} from 'sentry/utils/profiling/hooks/useProfiles';
- import {useProfileTransactions} from 'sentry/utils/profiling/hooks/useProfileTransactions';
- import {generateProfilingOnboardingRoute} from 'sentry/utils/profiling/routes';
- import {decodeScalar} from 'sentry/utils/queryString';
- import useOrganization from 'sentry/utils/useOrganization';
- import usePageFilters from 'sentry/utils/usePageFilters';
- import {ProfilingScatterChart} from './landing/profilingScatterChart';
- interface ProfilingContentProps {
- location: Location;
- }
- function ProfilingContent({location}: ProfilingContentProps) {
- const organization = useOrganization();
- const {selection} = usePageFilters();
- const cursor = decodeScalar(location.query.cursor);
- const query = decodeScalar(location.query.query, '');
- const profileFilters = useProfileFilters({query: '', selection});
- const profiles = useProfiles({cursor, query, selection});
- const transactions = useProfileTransactions({cursor, query, selection});
- useEffect(() => {
- trackAdvancedAnalyticsEvent('profiling_views.landing', {
- organization,
- });
- }, [organization]);
- const handleSearch: SmartSearchBarProps['onSearch'] = useCallback(
- (searchQuery: string) => {
- browserHistory.push({
- ...location,
- query: {
- ...location.query,
- cursor: undefined,
- query: searchQuery || undefined,
- },
- });
- },
- [location]
- );
- const onSetupProfilingClick = useCallback(() => {
- browserHistory.push(generateProfilingOnboardingRoute({orgSlug: organization.slug}));
- }, [organization.slug]);
- return (
- <SentryDocumentTitle title={t('Profiling')} orgSlug={organization.slug}>
- <PageFiltersContainer>
- <NoProjectMessage organization={organization}>
- <StyledPageContent>
- <Layout.Header>
- <StyledLayoutHeaderContent>
- <StyledHeading>{t('Profiling')}</StyledHeading>
- <Button onClick={onSetupProfilingClick}>Setup Profiling</Button>
- </StyledLayoutHeaderContent>
- </Layout.Header>
- <Layout.Body>
- <Layout.Main fullWidth>
- <ActionBar>
- <PageFilterBar condensed>
- <ProjectPageFilter />
- <EnvironmentPageFilter />
- <DatePageFilter alignDropdown="left" />
- </PageFilterBar>
- <SmartSearchBar
- organization={organization}
- hasRecentSearches
- searchSource="profile_landing"
- supportedTags={profileFilters}
- query={query}
- onSearch={handleSearch}
- maxQueryLength={MAX_QUERY_LENGTH}
- />
- </ActionBar>
- {profiles.type === 'errored' && (
- <Alert type="error" showIcon>
- {t('Unable to load profiles')}
- </Alert>
- )}
- <ProfilingScatterChart
- datetime={
- selection?.datetime ?? {
- start: null,
- end: null,
- period: null,
- utc: null,
- }
- }
- traces={profiles.type === 'resolved' ? profiles.data.traces : []}
- isLoading={profiles.type === 'loading'}
- />
- <ProfileTransactionsTable
- error={
- transactions.type === 'errored' ? t('Unable to load profiles') : null
- }
- isLoading={transactions.type === 'loading'}
- transactions={
- transactions.type === 'resolved' ? transactions.data.transactions : []
- }
- />
- <Pagination
- pageLinks={
- transactions.type === 'resolved' ? transactions.data.pageLinks : null
- }
- />
- </Layout.Main>
- </Layout.Body>
- </StyledPageContent>
- </NoProjectMessage>
- </PageFiltersContainer>
- </SentryDocumentTitle>
- );
- }
- const StyledPageContent = styled(PageContent)`
- padding: 0;
- `;
- const StyledLayoutHeaderContent = styled(Layout.HeaderContent)`
- display: flex;
- justify-content: space-between;
- flex-direction: row;
- `;
- const StyledHeading = styled(PageHeading)`
- line-height: 40px;
- `;
- const ActionBar = styled('div')`
- display: grid;
- gap: ${space(2)};
- grid-template-columns: min-content auto;
- margin-bottom: ${space(2)};
- `;
- export default ProfilingContent;
|