import {Fragment, useEffect, useState} from 'react';
import styled from '@emotion/styled';
import * as Sentry from '@sentry/react';
import emptyStateImg from 'sentry-images/spot/performance-empty-state.svg';
import emptyTraceImg from 'sentry-images/spot/performance-empty-trace.svg';
import tourAlert from 'sentry-images/spot/performance-tour-alert.svg';
import tourCorrelate from 'sentry-images/spot/performance-tour-correlate.svg';
import tourMetrics from 'sentry-images/spot/performance-tour-metrics.svg';
import tourTrace from 'sentry-images/spot/performance-tour-trace.svg';
import {
addErrorMessage,
addLoadingMessage,
clearIndicators,
} from 'sentry/actionCreators/indicator';
import type {Client} from 'sentry/api';
import UnsupportedAlert from 'sentry/components/alerts/unsupportedAlert';
import {Button, LinkButton} from 'sentry/components/button';
import ButtonBar from 'sentry/components/buttonBar';
import {GuidedSteps} from 'sentry/components/guidedSteps/guidedSteps';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import type {TourStep} from 'sentry/components/modals/featureTourModal';
import FeatureTourModal, {
TourImage,
TourText,
} from 'sentry/components/modals/featureTourModal';
import {AuthTokenGeneratorProvider} from 'sentry/components/onboarding/gettingStartedDoc/authTokenGenerator';
import {OnboardingCodeSnippet} from 'sentry/components/onboarding/gettingStartedDoc/onboardingCodeSnippet';
import {
type Configuration,
TabbedCodeSnippet,
} from 'sentry/components/onboarding/gettingStartedDoc/step';
import {
type DocsParams,
ProductSolution,
} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {useLoadGettingStarted} from 'sentry/components/onboarding/gettingStartedDoc/utils/useLoadGettingStarted';
import LegacyOnboardingPanel from 'sentry/components/onboardingPanel';
import Panel from 'sentry/components/panels/panel';
import PanelBody from 'sentry/components/panels/panelBody';
import {filterProjects} from 'sentry/components/performanceOnboarding/utils';
import {SidebarPanelKey} from 'sentry/components/sidebar/types';
import {
withoutPerformanceSupport,
withPerformanceOnboarding,
} from 'sentry/data/platformCategories';
import platforms, {otherPlatform} from 'sentry/data/platforms';
import {t, tct} from 'sentry/locale';
import ConfigStore from 'sentry/stores/configStore';
import SidebarPanelStore from 'sentry/stores/sidebarPanelStore';
import {useLegacyStore} from 'sentry/stores/useLegacyStore';
import pulsingIndicatorStyles from 'sentry/styles/pulsingIndicator';
import {space} from 'sentry/styles/space';
import type {Organization} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import {trackAnalytics} from 'sentry/utils/analytics';
import {browserHistory} from 'sentry/utils/browserHistory';
import {generateLinkToEventInTraceView} from 'sentry/utils/discover/urls';
import EventWaiter from 'sentry/utils/eventWaiter';
import useApi from 'sentry/utils/useApi';
import {useLocation} from 'sentry/utils/useLocation';
import useProjects from 'sentry/utils/useProjects';
import {traceAnalytics} from './newTraceDetails/traceAnalytics';
const performanceSetupUrl =
'https://docs.sentry.io/performance-monitoring/getting-started/';
const docsLink = (
{t('Setup')}
);
export const PERFORMANCE_TOUR_STEPS: TourStep[] = [
{
title: t('Track Application Metrics'),
image: ,
body: (
{t(
'Monitor your slowest pageloads and APIs to see which users are having the worst time.'
)}
),
actions: docsLink,
},
{
title: t('Correlate Errors and Traces'),
image: ,
body: (
{t(
'See what errors occurred within a transaction and the impact of those errors.'
)}
),
actions: docsLink,
},
{
title: t('Watch and Alert'),
image: ,
body: (
{t(
'Highlight mission-critical pages and APIs and set latency alerts to notify you before things go wrong.'
)}
),
actions: docsLink,
},
{
title: t('Trace Across Systems'),
image: ,
body: (
{t(
"Follow a trace from a user's session and drill down to identify any bottlenecks that occur."
)}
),
},
];
type SampleButtonProps = {
api: Client;
errorMessage: React.ReactNode;
loadingMessage: React.ReactNode;
organization: Organization;
project: Project;
triggerText: React.ReactNode;
};
function SampleButton({
triggerText,
loadingMessage,
errorMessage,
project,
organization,
api,
}: SampleButtonProps) {
const location = useLocation();
return (
);
}
type OnboardingProps = {
organization: Organization;
project: Project;
};
export function LegacyOnboarding({organization, project}: OnboardingProps) {
const api = useApi();
const {projects} = useProjects();
const location = useLocation();
const {projectsForOnboarding} = filterProjects(projects);
const showOnboardingChecklist = organization.features.includes(
'performance-onboarding-checklist'
);
useEffect(() => {
if (
showOnboardingChecklist &&
location.hash === '#performance-sidequest' &&
projectsForOnboarding.some(p => p.id === project.id)
) {
SidebarPanelStore.activatePanel(SidebarPanelKey.PERFORMANCE_ONBOARDING);
}
}, [location.hash, projectsForOnboarding, project.id, showOnboardingChecklist]);
function handleAdvance(step: number, duration: number) {
trackAnalytics('performance_views.tour.advance', {
step,
duration,
organization,
});
}
function handleClose(step: number, duration: number) {
trackAnalytics('performance_views.tour.close', {
step,
duration,
organization,
});
}
const currentPlatform = project.platform;
const hasPerformanceOnboarding = currentPlatform
? withPerformanceOnboarding.has(currentPlatform)
: false;
const noPerformanceSupport =
currentPlatform && withoutPerformanceSupport.has(currentPlatform);
let setupButton = (
{t('Start Setup')}
);
if (hasPerformanceOnboarding && showOnboardingChecklist) {
setupButton = (
);
}
return (
{noPerformanceSupport && (
)}
}>
{t('Pinpoint problems')}
{t(
'Something seem slow? Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
)}
{t('Query for Traces, Get Answers')}
{t(
'You can query and aggregate spans to create metrics that help you debug busted API calls, slow image loads, or any other metrics you’d like to track.'
)}
{t(
'Find traces tied to a user complaint and pinpoint exactly what broke'
)}
{t(
'Debug persistent issues by investigating API payloads, cache sizes, user tokens, and more'
)}
{t(
'Track any span attribute as a metric to catch slowdowns before they escalate'
)}
{tct(
'Fiddlesticks. Performance isn’t available for your [platform] project yet but we’re definitely still working on it. Stay tuned.',
{platform: currentPlatform?.name || project.slug}
)}
{tct(
'Fiddlesticks. The tracing onboarding checklist isn’t available for your [project] project yet, but for now, go to Sentry docs for installation details.',
{project: project.slug}
)}