123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- import {Fragment, useEffect} from 'react';
- import {RouteComponentProps} from 'react-router';
- import {css} from '@emotion/react';
- import styled from '@emotion/styled';
- import {Location} from 'history';
- import {addSuccessMessage} from 'sentry/actionCreators/indicator';
- import {openModal} from 'sentry/actionCreators/modal';
- import {Button} from 'sentry/components/button';
- import ButtonBar from 'sentry/components/buttonBar';
- import IdBadge from 'sentry/components/idBadge';
- import Placeholder from 'sentry/components/placeholder';
- import {usingCustomerDomain} from 'sentry/constants';
- import {IconCheckmark} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import PreferencesStore from 'sentry/stores/preferencesStore';
- import {useLegacyStore} from 'sentry/stores/useLegacyStore';
- import pulsingIndicatorStyles from 'sentry/styles/pulsingIndicator';
- import {space} from 'sentry/styles/space';
- import {Project} from 'sentry/types';
- import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
- import useOrganization from 'sentry/utils/useOrganization';
- import useProjects from 'sentry/utils/useProjects';
- import GenericFooter from '../genericFooter';
- import {useHeartbeat} from './useHeartbeat';
- enum BeatStatus {
- AWAITING = 'awaiting',
- PENDING = 'pending',
- COMPLETE = 'complete',
- }
- async function openChangeRouteModal(
- router: RouteComponentProps<{}, {}>['router'],
- nextLocation: Location
- ) {
- const mod = await import(
- 'sentry/views/onboarding/components/heartbeatFooter/changeRouteModal'
- );
- const {ChangeRouteModal} = mod;
- openModal(deps => (
- <ChangeRouteModal {...deps} router={router} nextLocation={nextLocation} />
- ));
- }
- type Props = Pick<RouteComponentProps<{}, {}>, 'router' | 'route' | 'location'> & {
- projectSlug: Project['slug'];
- newOrg?: boolean;
- };
- export function HeartbeatFooter({projectSlug, router, route, location, newOrg}: Props) {
- const organization = useOrganization();
- const preferences = useLegacyStore(PreferencesStore);
- const {initiallyLoaded, fetchError, fetching, projects} = useProjects({
- orgId: organization.id,
- slugs: [projectSlug],
- });
- const projectsLoading = !initiallyLoaded && fetching;
- const project =
- !projectsLoading && !fetchError && projects.length
- ? projects.find(proj => proj.slug === projectSlug)
- : undefined;
- const {
- loading,
- firstErrorReceived,
- firstTransactionReceived,
- sessionReceived,
- serverConnected,
- } = useHeartbeat(project?.slug, project?.id);
- useEffect(() => {
- const onUnload = (nextLocation?: Location) => {
- const {orgId, platform, projectId} = router.params;
- let isSetupDocsForNewOrg =
- location.pathname === `/onboarding/setup-docs/` &&
- nextLocation?.pathname !== `/onboarding/setup-docs/`;
- let isGettingStartedForExistingOrg =
- location.pathname === `/projects/${projectId}/getting-started/${platform}/` ||
- location.pathname === `/getting-started/${projectId}/${platform}/`;
- let isSetupDocsForNewOrgBackButton = `/onboarding/select-platform/`;
- let isWelcomeForNewOrgBackButton = `/onboarding/welcome/`;
- if (!usingCustomerDomain) {
- isSetupDocsForNewOrg =
- location.pathname === `/onboarding/${organization.slug}/setup-docs/` &&
- nextLocation?.pathname !== `/onboarding/${organization.slug}/setup-docs/`;
- isGettingStartedForExistingOrg =
- location.pathname === `/${orgId}/${projectId}/getting-started/${platform}/` ||
- location.pathname === `/organizations/${orgId}/${projectId}/getting-started/`;
- isSetupDocsForNewOrgBackButton = `/onboarding/${organization.slug}/select-platform/`;
- isWelcomeForNewOrgBackButton = `/onboarding/${organization.slug}/welcome/`;
- }
- if (isSetupDocsForNewOrg || isGettingStartedForExistingOrg) {
- // TODO(Priscila): I have to adjust this to check for all selected projects in the onboarding of new orgs
- if (serverConnected && firstErrorReceived) {
- return true;
- }
- // Next Location is always available when user clicks on a item with a new route
- if (nextLocation) {
- // Back button in the onboarding of new orgs
- if (
- nextLocation.pathname === isSetupDocsForNewOrgBackButton ||
- nextLocation.pathname === isWelcomeForNewOrgBackButton
- ) {
- return true;
- }
- if (nextLocation.query.setUpRemainingOnboardingTasksLater) {
- return true;
- }
- openChangeRouteModal(router, nextLocation);
- return false;
- }
- return true;
- }
- return true;
- };
- router.setRouteLeaveHook(route, onUnload);
- }, [serverConnected, firstErrorReceived, route, router, organization.slug, location]);
- useEffect(() => {
- if (loading || !serverConnected) {
- return;
- }
- addSuccessMessage(t('SDK Connected'));
- }, [serverConnected, loading]);
- useEffect(() => {
- if (loading || !sessionReceived) {
- return;
- }
- trackAdvancedAnalyticsEvent('heartbeat.onboarding_session_received', {
- organization,
- new_organization: !!newOrg,
- });
- }, [sessionReceived, loading, newOrg, organization]);
- useEffect(() => {
- if (loading || !firstTransactionReceived) {
- return;
- }
- trackAdvancedAnalyticsEvent('heartbeat.onboarding_first_transaction_received', {
- organization,
- new_organization: !!newOrg,
- });
- }, [firstTransactionReceived, loading, newOrg, organization]);
- useEffect(() => {
- if (loading || !firstErrorReceived) {
- return;
- }
- trackAdvancedAnalyticsEvent('heartbeat.onboarding_first_error_received', {
- organization,
- new_organization: !!newOrg,
- });
- addSuccessMessage(t('First error received'));
- }, [firstErrorReceived, loading, newOrg, organization]);
- return (
- <Wrapper newOrg={!!newOrg} sidebarCollapsed={!!preferences.collapsed}>
- <PlatformIconAndName>
- {projectsLoading ? (
- <LoadingPlaceholder height="28px" width="276px" />
- ) : (
- <IdBadge
- project={project}
- displayPlatformName
- avatarSize={28}
- hideOverflow
- disableLink
- />
- )}
- </PlatformIconAndName>
- <Beats>
- {loading ? (
- <Fragment>
- <LoadingPlaceholder height="28px" width="160px" />
- <LoadingPlaceholder height="28px" width="160px" />
- </Fragment>
- ) : firstErrorReceived ? (
- <Fragment>
- <Beat status={BeatStatus.COMPLETE}>
- <IconCheckmark size="sm" isCircled />
- {t('DSN response received')}
- </Beat>
- <Beat status={BeatStatus.COMPLETE}>
- <IconCheckmark size="sm" isCircled />
- {t('First error received')}
- </Beat>
- </Fragment>
- ) : serverConnected ? (
- <Fragment>
- <Beat status={BeatStatus.COMPLETE}>
- <IconCheckmark size="sm" isCircled />
- {t('DSN response received')}
- </Beat>
- <Beat status={BeatStatus.AWAITING}>
- <PulsingIndicator>2</PulsingIndicator>
- {t('Awaiting first error')}
- </Beat>
- </Fragment>
- ) : (
- <Fragment>
- <Beat status={BeatStatus.AWAITING}>
- <PulsingIndicator>1</PulsingIndicator>
- {t('Awaiting DSN response')}
- </Beat>
- <Beat status={BeatStatus.PENDING}>
- <PulsingIndicator>2</PulsingIndicator>
- {t('Awaiting first error')}
- </Beat>
- </Fragment>
- )}
- </Beats>
- <Actions>
- <ButtonBar gap={1}>
- {newOrg ? (
- <Fragment>
- {loading ? (
- <LoadingPlaceholderButton width="135px" />
- ) : firstErrorReceived ? (
- <Button
- priority="primary"
- busy={projectsLoading}
- to={`/organizations/${organization.slug}/issues/${
- firstErrorReceived &&
- firstErrorReceived !== true &&
- 'id' in firstErrorReceived
- ? `${firstErrorReceived.id}/`
- : ''
- }?referrer=onboarding-first-event-footer`}
- onClick={() => {
- trackAdvancedAnalyticsEvent(
- 'heartbeat.onboarding_go_to_my_error_button_clicked',
- {
- organization,
- new_organization: !!newOrg,
- }
- );
- }}
- >
- {t('Go to my error')}
- </Button>
- ) : (
- <Button
- priority="primary"
- busy={projectsLoading}
- to={`/organizations/${organization.slug}/issues/`} // TODO(Priscila): See what Jesse meant with 'explore sentry'. What should be the expected action?
- onClick={() => {
- trackAdvancedAnalyticsEvent(
- 'heartbeat.onboarding_explore_sentry_button_clicked',
- {organization}
- );
- }}
- >
- {t('Explore Sentry')}
- </Button>
- )}
- </Fragment>
- ) : (
- <Fragment>
- <Button
- busy={projectsLoading}
- to={{
- pathname: `/organizations/${organization.slug}/performance/`,
- query: {project: project?.id},
- }}
- onClick={() => {
- trackAdvancedAnalyticsEvent(
- 'heartbeat.onboarding_go_to_performance_button_clicked',
- {organization}
- );
- }}
- >
- {t('Go to Performance')}
- </Button>
- {firstErrorReceived ? (
- <Button
- priority="primary"
- busy={projectsLoading}
- to={`/organizations/${organization.slug}/issues/${
- firstErrorReceived &&
- firstErrorReceived !== true &&
- 'id' in firstErrorReceived
- ? `${firstErrorReceived.id}/`
- : ''
- }`}
- onClick={() => {
- trackAdvancedAnalyticsEvent(
- 'heartbeat.onboarding_go_to_my_error_button_clicked',
- {
- organization,
- new_organization: !!newOrg,
- }
- );
- }}
- >
- {t('Go to my error')}
- </Button>
- ) : (
- <Button
- priority="primary"
- busy={projectsLoading}
- to={{
- pathname: `/organizations/${organization.slug}/issues/`,
- query: {project: project?.id},
- hash: '#welcome',
- }}
- onClick={() => {
- trackAdvancedAnalyticsEvent(
- 'heartbeat.onboarding_go_to_issues_button_clicked',
- {organization}
- );
- }}
- >
- {t('Go to Issues')}
- </Button>
- )}
- </Fragment>
- )}
- </ButtonBar>
- </Actions>
- </Wrapper>
- );
- }
- const Wrapper = styled(GenericFooter)<{newOrg: boolean; sidebarCollapsed: boolean}>`
- display: none;
- display: flex;
- flex-direction: row;
- justify-content: flex-end;
- padding: ${space(2)} ${space(4)};
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- align-items: center;
- gap: ${space(3)};
- }
- ${p =>
- !p.newOrg &&
- css`
- @media (min-width: ${p.theme.breakpoints.medium}) {
- width: calc(
- 100% -
- ${p.theme.sidebar[p.sidebarCollapsed ? 'collapsedWidth' : 'expandedWidth']}
- );
- right: 0;
- left: auto;
- }
- `}
- `;
- const PlatformIconAndName = styled('div')`
- display: none;
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- max-width: 100%;
- overflow: hidden;
- width: 100%;
- display: block;
- }
- `;
- const Beats = styled('div')`
- display: none;
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- gap: ${space(2)};
- display: grid;
- grid-template-columns: repeat(2, max-content);
- justify-content: center;
- align-items: center;
- }
- `;
- const LoadingPlaceholder = styled(Placeholder)`
- width: ${p => p.width ?? '100%'};
- `;
- const LoadingPlaceholderButton = styled(LoadingPlaceholder)`
- height: ${p => p.theme.form.md.height}px;
- `;
- const PulsingIndicator = styled('div')`
- ${pulsingIndicatorStyles};
- font-size: ${p => p.theme.fontSizeExtraSmall};
- color: ${p => p.theme.white};
- height: 16px;
- width: 16px;
- display: flex;
- align-items: center;
- justify-content: center;
- :before {
- top: auto;
- left: auto;
- }
- `;
- const Beat = styled('div')<{status: BeatStatus}>`
- width: 160px;
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: ${space(0.5)};
- font-size: ${p => p.theme.fontSizeSmall};
- color: ${p => p.theme.pink300};
- ${p =>
- p.status === BeatStatus.PENDING &&
- css`
- color: ${p.theme.disabled};
- ${PulsingIndicator} {
- background: ${p.theme.disabled};
- :before {
- content: none;
- }
- }
- `}
- ${p =>
- p.status === BeatStatus.COMPLETE &&
- css`
- color: ${p.theme.successText};
- ${PulsingIndicator} {
- background: ${p.theme.success};
- :before {
- content: none;
- }
- }
- `}
- `;
- const Actions = styled('div')`
- display: flex;
- justify-content: flex-end;
- `;
|