index.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. import {Fragment} from 'react';
  2. import {forceCheck} from 'react-lazyload';
  3. import {RouteComponentProps} from 'react-router';
  4. import styled from '@emotion/styled';
  5. import pick from 'lodash/pick';
  6. import {fetchTagValues} from 'sentry/actionCreators/tags';
  7. import {Alert} from 'sentry/components/alert';
  8. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  9. import DatePageFilter from 'sentry/components/datePageFilter';
  10. import EmptyMessage from 'sentry/components/emptyMessage';
  11. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  12. import * as Layout from 'sentry/components/layouts/thirds';
  13. import ExternalLink from 'sentry/components/links/externalLink';
  14. import LoadingIndicator from 'sentry/components/loadingIndicator';
  15. import NoProjectMessage from 'sentry/components/noProjectMessage';
  16. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  17. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  18. import {getRelativeSummary} from 'sentry/components/organizations/timeRangeSelector/utils';
  19. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  20. import Pagination from 'sentry/components/pagination';
  21. import Panel from 'sentry/components/panels/panel';
  22. import ProjectPageFilter from 'sentry/components/projectPageFilter';
  23. import SmartSearchBar from 'sentry/components/smartSearchBar';
  24. import {ItemType} from 'sentry/components/smartSearchBar/types';
  25. import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
  26. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  27. import {releaseHealth} from 'sentry/data/platformCategories';
  28. import {IconSearch} from 'sentry/icons';
  29. import {t} from 'sentry/locale';
  30. import ProjectsStore from 'sentry/stores/projectsStore';
  31. import {space} from 'sentry/styles/space';
  32. import {
  33. Organization,
  34. PageFilters,
  35. Project,
  36. Release,
  37. ReleaseStatus,
  38. Tag,
  39. } from 'sentry/types';
  40. import {trackAnalytics} from 'sentry/utils/analytics';
  41. import {SEMVER_TAGS} from 'sentry/utils/discover/fields';
  42. import Projects from 'sentry/utils/projects';
  43. import routeTitleGen from 'sentry/utils/routeTitle';
  44. import withOrganization from 'sentry/utils/withOrganization';
  45. import withPageFilters from 'sentry/utils/withPageFilters';
  46. import withProjects from 'sentry/utils/withProjects';
  47. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  48. import ReleaseArchivedNotice from '../detail/overview/releaseArchivedNotice';
  49. import {isMobileRelease} from '../utils';
  50. import ReleaseCard from './releaseCard';
  51. import ReleasesAdoptionChart from './releasesAdoptionChart';
  52. import ReleasesDisplayOptions, {ReleasesDisplayOption} from './releasesDisplayOptions';
  53. import ReleasesPromo from './releasesPromo';
  54. import ReleasesRequest from './releasesRequest';
  55. import ReleasesSortOptions, {ReleasesSortOption} from './releasesSortOptions';
  56. import ReleasesStatusOptions, {ReleasesStatusOption} from './releasesStatusOptions';
  57. type RouteParams = {
  58. orgId: string;
  59. };
  60. type Props = RouteComponentProps<RouteParams, {}> & {
  61. organization: Organization;
  62. projects: Project[];
  63. selection: PageFilters;
  64. };
  65. type State = {
  66. releases: Release[];
  67. } & DeprecatedAsyncView['state'];
  68. class ReleasesList extends DeprecatedAsyncView<Props, State> {
  69. shouldReload = true;
  70. shouldRenderBadRequests = true;
  71. getTitle() {
  72. return routeTitleGen(t('Releases'), this.props.organization.slug, false);
  73. }
  74. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  75. const {organization, location} = this.props;
  76. const {statsPeriod} = location.query;
  77. const activeSort = this.getSort();
  78. const activeStatus = this.getStatus();
  79. const query = {
  80. ...pick(location.query, ['project', 'environment', 'cursor', 'query', 'sort']),
  81. summaryStatsPeriod: statsPeriod,
  82. per_page: 20,
  83. flatten: activeSort === ReleasesSortOption.DATE ? 0 : 1,
  84. adoptionStages: 1,
  85. status:
  86. activeStatus === ReleasesStatusOption.ARCHIVED
  87. ? ReleaseStatus.ARCHIVED
  88. : ReleaseStatus.ACTIVE,
  89. };
  90. const endpoints: ReturnType<DeprecatedAsyncView['getEndpoints']> = [
  91. [
  92. 'releases',
  93. `/organizations/${organization.slug}/releases/`,
  94. {query},
  95. {disableEntireQuery: true},
  96. ],
  97. ];
  98. return endpoints;
  99. }
  100. componentDidUpdate(prevProps: Props, prevState: State) {
  101. super.componentDidUpdate(prevProps, prevState);
  102. if (prevState.releases !== this.state.releases) {
  103. /**
  104. * Manually trigger checking for elements in viewport.
  105. * Helpful when LazyLoad components enter the viewport without resize or scroll events,
  106. * https://github.com/twobin/react-lazyload#forcecheck
  107. *
  108. * HealthStatsCharts are being rendered only when they are scrolled into viewport.
  109. * This is how we re-check them without scrolling once releases change as this view
  110. * uses shouldReload=true and there is no reloading happening.
  111. */
  112. forceCheck();
  113. }
  114. }
  115. getQuery() {
  116. const {query} = this.props.location.query;
  117. return typeof query === 'string' ? query : undefined;
  118. }
  119. getSort(): ReleasesSortOption {
  120. const {environments} = this.props.selection;
  121. const {sort} = this.props.location.query;
  122. // Require 1 environment for date adopted
  123. if (sort === ReleasesSortOption.ADOPTION && environments.length !== 1) {
  124. return ReleasesSortOption.DATE;
  125. }
  126. const sortExists = Object.values(ReleasesSortOption).includes(sort);
  127. if (sortExists) {
  128. return sort;
  129. }
  130. return ReleasesSortOption.DATE;
  131. }
  132. getDisplay(): ReleasesDisplayOption {
  133. const {display} = this.props.location.query;
  134. switch (display) {
  135. case ReleasesDisplayOption.USERS:
  136. return ReleasesDisplayOption.USERS;
  137. default:
  138. return ReleasesDisplayOption.SESSIONS;
  139. }
  140. }
  141. getStatus(): ReleasesStatusOption {
  142. const {status} = this.props.location.query;
  143. switch (status) {
  144. case ReleasesStatusOption.ARCHIVED:
  145. return ReleasesStatusOption.ARCHIVED;
  146. default:
  147. return ReleasesStatusOption.ACTIVE;
  148. }
  149. }
  150. getSelectedProject(): Project | undefined {
  151. const {selection, projects} = this.props;
  152. const selectedProjectId =
  153. selection.projects && selection.projects.length === 1 && selection.projects[0];
  154. return projects?.find(p => p.id === `${selectedProjectId}`);
  155. }
  156. get projectHasSessions() {
  157. return this.getSelectedProject()?.hasSessions ?? null;
  158. }
  159. handleSearch = (query: string) => {
  160. const {location, router} = this.props;
  161. router.push({
  162. ...location,
  163. query: {...location.query, cursor: undefined, query},
  164. });
  165. };
  166. handleSortBy = (sort: string) => {
  167. const {location, router} = this.props;
  168. router.push({
  169. ...location,
  170. query: {...location.query, cursor: undefined, sort},
  171. });
  172. };
  173. handleDisplay = (display: string) => {
  174. const {location, router} = this.props;
  175. let sort = location.query.sort;
  176. if (
  177. sort === ReleasesSortOption.USERS_24_HOURS &&
  178. display === ReleasesDisplayOption.SESSIONS
  179. ) {
  180. sort = ReleasesSortOption.SESSIONS_24_HOURS;
  181. } else if (
  182. sort === ReleasesSortOption.SESSIONS_24_HOURS &&
  183. display === ReleasesDisplayOption.USERS
  184. ) {
  185. sort = ReleasesSortOption.USERS_24_HOURS;
  186. } else if (
  187. sort === ReleasesSortOption.CRASH_FREE_USERS &&
  188. display === ReleasesDisplayOption.SESSIONS
  189. ) {
  190. sort = ReleasesSortOption.CRASH_FREE_SESSIONS;
  191. } else if (
  192. sort === ReleasesSortOption.CRASH_FREE_SESSIONS &&
  193. display === ReleasesDisplayOption.USERS
  194. ) {
  195. sort = ReleasesSortOption.CRASH_FREE_USERS;
  196. }
  197. router.push({
  198. ...location,
  199. query: {...location.query, cursor: undefined, display, sort},
  200. });
  201. };
  202. handleStatus = (status: string) => {
  203. const {location, router} = this.props;
  204. router.push({
  205. ...location,
  206. query: {...location.query, cursor: undefined, status},
  207. });
  208. };
  209. trackAddReleaseHealth = () => {
  210. const {organization, selection} = this.props;
  211. if (organization.id && selection.projects[0]) {
  212. trackAnalytics('releases_list.click_add_release_health', {
  213. organization,
  214. project_id: selection.projects[0],
  215. });
  216. }
  217. };
  218. tagValueLoader = (key: string, search: string) => {
  219. const {location, organization} = this.props;
  220. const {project: projectId} = location.query;
  221. return fetchTagValues({
  222. api: this.api,
  223. orgSlug: organization.slug,
  224. tagKey: key,
  225. search,
  226. projectIds: projectId ? [projectId] : undefined,
  227. endpointParams: location.query,
  228. });
  229. };
  230. getTagValues = async (tag: Tag, currentQuery: string): Promise<string[]> => {
  231. const values = await this.tagValueLoader(tag.key, currentQuery);
  232. return values.map(({value}) => value);
  233. };
  234. shouldShowLoadingIndicator() {
  235. const {loading, releases, reloading} = this.state;
  236. return (loading && !reloading) || (loading && !releases?.length);
  237. }
  238. renderLoading() {
  239. return this.renderBody();
  240. }
  241. renderError() {
  242. return this.renderBody();
  243. }
  244. get shouldShowQuickstart() {
  245. const {releases} = this.state;
  246. const selectedProject = this.getSelectedProject();
  247. const hasReleasesSetup = selectedProject?.features.includes('releases');
  248. return !releases?.length && !hasReleasesSetup && selectedProject;
  249. }
  250. renderEmptyMessage() {
  251. const {location} = this.props;
  252. const {statsPeriod, start, end} = location.query;
  253. const searchQuery = this.getQuery();
  254. const activeSort = this.getSort();
  255. const activeStatus = this.getStatus();
  256. const selectedPeriod =
  257. !!start && !!end
  258. ? t('time range')
  259. : getRelativeSummary(statsPeriod || DEFAULT_STATS_PERIOD).toLowerCase();
  260. if (searchQuery && searchQuery.length) {
  261. return (
  262. <Panel>
  263. <EmptyMessage icon={<IconSearch size="xl" />} size="large">{`${t(
  264. 'There are no releases that match'
  265. )}: '${searchQuery}'.`}</EmptyMessage>
  266. </Panel>
  267. );
  268. }
  269. if (activeSort === ReleasesSortOption.USERS_24_HOURS) {
  270. return (
  271. <Panel>
  272. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  273. {t(
  274. 'There are no releases with active user data (users in the last 24 hours).'
  275. )}
  276. </EmptyMessage>
  277. </Panel>
  278. );
  279. }
  280. if (activeSort === ReleasesSortOption.SESSIONS_24_HOURS) {
  281. return (
  282. <Panel>
  283. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  284. {t(
  285. 'There are no releases with active session data (sessions in the last 24 hours).'
  286. )}
  287. </EmptyMessage>
  288. </Panel>
  289. );
  290. }
  291. if (
  292. activeSort === ReleasesSortOption.BUILD ||
  293. activeSort === ReleasesSortOption.SEMVER
  294. ) {
  295. return (
  296. <Panel>
  297. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  298. {t('There are no releases with semantic versioning.')}
  299. </EmptyMessage>
  300. </Panel>
  301. );
  302. }
  303. if (activeSort !== ReleasesSortOption.DATE) {
  304. return (
  305. <Panel>
  306. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  307. {`${t('There are no releases with data in the')} ${selectedPeriod}.`}
  308. </EmptyMessage>
  309. </Panel>
  310. );
  311. }
  312. if (activeStatus === ReleasesStatusOption.ARCHIVED) {
  313. return (
  314. <Panel>
  315. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  316. {t('There are no archived releases.')}
  317. </EmptyMessage>
  318. </Panel>
  319. );
  320. }
  321. return (
  322. <Panel>
  323. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  324. {`${t('There are no releases with data in the')} ${selectedPeriod}.`}
  325. </EmptyMessage>
  326. </Panel>
  327. );
  328. }
  329. renderHealthCta() {
  330. const {organization} = this.props;
  331. const {releases} = this.state;
  332. const selectedProject = this.getSelectedProject();
  333. if (!selectedProject || this.projectHasSessions !== false || !releases?.length) {
  334. return null;
  335. }
  336. return (
  337. <Projects orgId={organization.slug} slugs={[selectedProject.slug]}>
  338. {({projects, initiallyLoaded, fetchError}) => {
  339. const project = projects && projects.length === 1 && projects[0];
  340. const projectCanHaveReleases =
  341. project && project.platform && releaseHealth.includes(project.platform);
  342. if (!initiallyLoaded || fetchError || !projectCanHaveReleases) {
  343. return null;
  344. }
  345. return (
  346. <Alert type="info" showIcon>
  347. <AlertText>
  348. <div>
  349. {t(
  350. 'To track user adoption, crash rates, session data and more, add Release Health to your current setup.'
  351. )}
  352. </div>
  353. <ExternalLink
  354. href="https://docs.sentry.io/product/releases/setup/#release-health"
  355. onClick={this.trackAddReleaseHealth}
  356. >
  357. {t('Add Release Health')}
  358. </ExternalLink>
  359. </AlertText>
  360. </Alert>
  361. );
  362. }}
  363. </Projects>
  364. );
  365. }
  366. renderInnerBody(
  367. activeDisplay: ReleasesDisplayOption,
  368. showReleaseAdoptionStages: boolean
  369. ) {
  370. const {location, selection, organization, router} = this.props;
  371. const {releases, reloading, releasesPageLinks} = this.state;
  372. const selectedProject = this.getSelectedProject();
  373. const hasReleasesSetup = selectedProject?.features.includes('releases');
  374. if (this.shouldShowLoadingIndicator()) {
  375. return <LoadingIndicator />;
  376. }
  377. if (!releases?.length && hasReleasesSetup) {
  378. return this.renderEmptyMessage();
  379. }
  380. if (this.shouldShowQuickstart) {
  381. return <ReleasesPromo organization={organization} project={selectedProject!} />;
  382. }
  383. return (
  384. <ReleasesRequest
  385. releases={releases.map(({version}) => version)}
  386. organization={organization}
  387. selection={selection}
  388. location={location}
  389. display={[this.getDisplay()]}
  390. releasesReloading={reloading}
  391. healthStatsPeriod={location.query.healthStatsPeriod}
  392. >
  393. {({isHealthLoading, getHealthData}) => {
  394. const singleProjectSelected =
  395. selection.projects?.length === 1 &&
  396. selection.projects[0] !== ALL_ACCESS_PROJECTS;
  397. const isMobileProject =
  398. selectedProject?.platform && isMobileRelease(selectedProject.platform);
  399. return (
  400. <Fragment>
  401. {singleProjectSelected && this.projectHasSessions && isMobileProject && (
  402. <ReleasesAdoptionChart
  403. organization={organization}
  404. selection={selection}
  405. location={location}
  406. router={router}
  407. activeDisplay={activeDisplay}
  408. />
  409. )}
  410. {releases.map((release, index) => (
  411. <ReleaseCard
  412. key={`${release.version}-${release.projects[0].slug}`}
  413. activeDisplay={activeDisplay}
  414. release={release}
  415. organization={organization}
  416. location={location}
  417. selection={selection}
  418. reloading={reloading}
  419. showHealthPlaceholders={isHealthLoading}
  420. isTopRelease={index === 0}
  421. getHealthData={getHealthData}
  422. showReleaseAdoptionStages={showReleaseAdoptionStages}
  423. />
  424. ))}
  425. <Pagination pageLinks={releasesPageLinks} />
  426. </Fragment>
  427. );
  428. }}
  429. </ReleasesRequest>
  430. );
  431. }
  432. renderBody() {
  433. const {organization, selection} = this.props;
  434. const {releases, reloading, error} = this.state;
  435. const activeSort = this.getSort();
  436. const activeStatus = this.getStatus();
  437. const activeDisplay = this.getDisplay();
  438. const hasAnyMobileProject = selection.projects
  439. .map(id => `${id}`)
  440. .map(ProjectsStore.getById)
  441. .some(project => project?.platform && isMobileRelease(project.platform));
  442. const showReleaseAdoptionStages =
  443. hasAnyMobileProject && selection.environments.length === 1;
  444. const hasReleasesSetup = releases && releases.length > 0;
  445. return (
  446. <PageFiltersContainer showAbsolute={false}>
  447. <NoProjectMessage organization={organization}>
  448. <Layout.Header>
  449. <Layout.HeaderContent>
  450. <Layout.Title>
  451. {t('Releases')}
  452. <PageHeadingQuestionTooltip
  453. docsUrl="https://docs.sentry.io/product/releases/"
  454. title={t(
  455. 'A visualization of your release adoption from the past 24 hours, providing a high-level view of the adoption stage, percentage of crash-free users and sessions, and more.'
  456. )}
  457. />
  458. </Layout.Title>
  459. </Layout.HeaderContent>
  460. </Layout.Header>
  461. <Layout.Body>
  462. <Layout.Main fullWidth>
  463. {this.renderHealthCta()}
  464. <ReleasesPageFilterBar condensed>
  465. <GuideAnchor target="release_projects">
  466. <ProjectPageFilter />
  467. </GuideAnchor>
  468. <EnvironmentPageFilter />
  469. <DatePageFilter
  470. alignDropdown="left"
  471. disallowArbitraryRelativeRanges
  472. hint={t(
  473. 'Changing this date range will recalculate the release metrics.'
  474. )}
  475. />
  476. </ReleasesPageFilterBar>
  477. {this.shouldShowQuickstart ? null : (
  478. <SortAndFilterWrapper>
  479. <GuideAnchor
  480. target="releases_search"
  481. position="bottom"
  482. disabled={!hasReleasesSetup}
  483. >
  484. <StyledSmartSearchBar
  485. searchSource="releases"
  486. query={this.getQuery()}
  487. placeholder={t('Search by version, build, package, or stage')}
  488. hasRecentSearches={false}
  489. supportedTags={{
  490. ...SEMVER_TAGS,
  491. release: {
  492. key: 'release',
  493. name: 'release',
  494. },
  495. }}
  496. maxMenuHeight={500}
  497. supportedTagType={ItemType.PROPERTY}
  498. onSearch={this.handleSearch}
  499. onGetTagValues={this.getTagValues}
  500. />
  501. </GuideAnchor>
  502. <ReleasesStatusOptions
  503. selected={activeStatus}
  504. onSelect={this.handleStatus}
  505. />
  506. <ReleasesSortOptions
  507. selected={activeSort}
  508. selectedDisplay={activeDisplay}
  509. onSelect={this.handleSortBy}
  510. environments={selection.environments}
  511. />
  512. <ReleasesDisplayOptions
  513. selected={activeDisplay}
  514. onSelect={this.handleDisplay}
  515. />
  516. </SortAndFilterWrapper>
  517. )}
  518. {!reloading &&
  519. activeStatus === ReleasesStatusOption.ARCHIVED &&
  520. !!releases?.length && <ReleaseArchivedNotice multi />}
  521. {error
  522. ? super.renderError()
  523. : this.renderInnerBody(activeDisplay, showReleaseAdoptionStages)}
  524. </Layout.Main>
  525. </Layout.Body>
  526. </NoProjectMessage>
  527. </PageFiltersContainer>
  528. );
  529. }
  530. }
  531. const AlertText = styled('div')`
  532. display: flex;
  533. align-items: flex-start;
  534. justify-content: flex-start;
  535. gap: ${space(2)};
  536. > *:nth-child(1) {
  537. flex: 1;
  538. }
  539. flex-direction: column;
  540. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  541. flex-direction: row;
  542. }
  543. `;
  544. const ReleasesPageFilterBar = styled(PageFilterBar)`
  545. margin-bottom: ${space(2)};
  546. `;
  547. const SortAndFilterWrapper = styled('div')`
  548. display: grid;
  549. grid-template-columns: 1fr repeat(3, max-content);
  550. gap: ${space(2)};
  551. margin-bottom: ${space(2)};
  552. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  553. grid-template-columns: repeat(3, 1fr);
  554. & > div {
  555. width: auto;
  556. }
  557. }
  558. @media (max-width: ${p => p.theme.breakpoints.small}) {
  559. grid-template-columns: minmax(0, 1fr);
  560. }
  561. `;
  562. const StyledSmartSearchBar = styled(SmartSearchBar)`
  563. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  564. grid-column: 1 / -1;
  565. }
  566. `;
  567. export default withProjects(withOrganization(withPageFilters(ReleasesList)));