index.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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';
  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 {trackAnalyticsEvent} 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 AsyncView from 'sentry/views/asyncView';
  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. } & AsyncView['state'];
  68. class ReleasesList extends AsyncView<Props, State> {
  69. shouldReload = true;
  70. shouldRenderBadRequests = true;
  71. getTitle() {
  72. return routeTitleGen(t('Releases'), this.props.organization.slug, false);
  73. }
  74. getEndpoints(): ReturnType<AsyncView['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<AsyncView['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. trackAnalyticsEvent({
  213. eventKey: `releases_list.click_add_release_health`,
  214. eventName: `Releases List: Click Add Release Health`,
  215. organization_id: parseInt(organization.id, 10),
  216. project_id: selection.projects[0],
  217. });
  218. }
  219. };
  220. tagValueLoader = (key: string, search: string) => {
  221. const {location, organization} = this.props;
  222. const {project: projectId} = location.query;
  223. return fetchTagValues({
  224. api: this.api,
  225. orgSlug: organization.slug,
  226. tagKey: key,
  227. search,
  228. projectIds: projectId ? [projectId] : undefined,
  229. endpointParams: location.query,
  230. });
  231. };
  232. getTagValues = async (tag: Tag, currentQuery: string): Promise<string[]> => {
  233. const values = await this.tagValueLoader(tag.key, currentQuery);
  234. return values.map(({value}) => value);
  235. };
  236. shouldShowLoadingIndicator() {
  237. const {loading, releases, reloading} = this.state;
  238. return (loading && !reloading) || (loading && !releases?.length);
  239. }
  240. renderLoading() {
  241. return this.renderBody();
  242. }
  243. renderError() {
  244. return this.renderBody();
  245. }
  246. get shouldShowQuickstart() {
  247. const {releases} = this.state;
  248. const selectedProject = this.getSelectedProject();
  249. const hasReleasesSetup = selectedProject?.features.includes('releases');
  250. return !releases?.length && !hasReleasesSetup && selectedProject;
  251. }
  252. renderEmptyMessage() {
  253. const {location} = this.props;
  254. const {statsPeriod, start, end} = location.query;
  255. const searchQuery = this.getQuery();
  256. const activeSort = this.getSort();
  257. const activeStatus = this.getStatus();
  258. const selectedPeriod =
  259. !!start && !!end
  260. ? t('time range')
  261. : getRelativeSummary(statsPeriod || DEFAULT_STATS_PERIOD).toLowerCase();
  262. if (searchQuery && searchQuery.length) {
  263. return (
  264. <Panel>
  265. <EmptyMessage icon={<IconSearch size="xl" />} size="large">{`${t(
  266. 'There are no releases that match'
  267. )}: '${searchQuery}'.`}</EmptyMessage>
  268. </Panel>
  269. );
  270. }
  271. if (activeSort === ReleasesSortOption.USERS_24_HOURS) {
  272. return (
  273. <Panel>
  274. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  275. {t(
  276. 'There are no releases with active user data (users in the last 24 hours).'
  277. )}
  278. </EmptyMessage>
  279. </Panel>
  280. );
  281. }
  282. if (activeSort === ReleasesSortOption.SESSIONS_24_HOURS) {
  283. return (
  284. <Panel>
  285. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  286. {t(
  287. 'There are no releases with active session data (sessions in the last 24 hours).'
  288. )}
  289. </EmptyMessage>
  290. </Panel>
  291. );
  292. }
  293. if (
  294. activeSort === ReleasesSortOption.BUILD ||
  295. activeSort === ReleasesSortOption.SEMVER
  296. ) {
  297. return (
  298. <Panel>
  299. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  300. {t('There are no releases with semantic versioning.')}
  301. </EmptyMessage>
  302. </Panel>
  303. );
  304. }
  305. if (activeSort !== ReleasesSortOption.DATE) {
  306. return (
  307. <Panel>
  308. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  309. {`${t('There are no releases with data in the')} ${selectedPeriod}.`}
  310. </EmptyMessage>
  311. </Panel>
  312. );
  313. }
  314. if (activeStatus === ReleasesStatusOption.ARCHIVED) {
  315. return (
  316. <Panel>
  317. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  318. {t('There are no archived releases.')}
  319. </EmptyMessage>
  320. </Panel>
  321. );
  322. }
  323. return (
  324. <Panel>
  325. <EmptyMessage icon={<IconSearch size="xl" />} size="large">
  326. {`${t('There are no releases with data in the')} ${selectedPeriod}.`}
  327. </EmptyMessage>
  328. </Panel>
  329. );
  330. }
  331. renderHealthCta() {
  332. const {organization} = this.props;
  333. const {releases} = this.state;
  334. const selectedProject = this.getSelectedProject();
  335. if (!selectedProject || this.projectHasSessions !== false || !releases?.length) {
  336. return null;
  337. }
  338. return (
  339. <Projects orgId={organization.slug} slugs={[selectedProject.slug]}>
  340. {({projects, initiallyLoaded, fetchError}) => {
  341. const project = projects && projects.length === 1 && projects[0];
  342. const projectCanHaveReleases =
  343. project && project.platform && releaseHealth.includes(project.platform);
  344. if (!initiallyLoaded || fetchError || !projectCanHaveReleases) {
  345. return null;
  346. }
  347. return (
  348. <Alert type="info" showIcon>
  349. <AlertText>
  350. <div>
  351. {t(
  352. 'To track user adoption, crash rates, session data and more, add Release Health to your current setup.'
  353. )}
  354. </div>
  355. <ExternalLink
  356. href="https://docs.sentry.io/product/releases/setup/#release-health"
  357. onClick={this.trackAddReleaseHealth}
  358. >
  359. {t('Add Release Health')}
  360. </ExternalLink>
  361. </AlertText>
  362. </Alert>
  363. );
  364. }}
  365. </Projects>
  366. );
  367. }
  368. renderInnerBody(
  369. activeDisplay: ReleasesDisplayOption,
  370. showReleaseAdoptionStages: boolean
  371. ) {
  372. const {location, selection, organization, router} = this.props;
  373. const {releases, reloading, releasesPageLinks} = this.state;
  374. const selectedProject = this.getSelectedProject();
  375. const hasReleasesSetup = selectedProject?.features.includes('releases');
  376. if (this.shouldShowLoadingIndicator()) {
  377. return <LoadingIndicator />;
  378. }
  379. if (!releases?.length && hasReleasesSetup) {
  380. return this.renderEmptyMessage();
  381. }
  382. if (this.shouldShowQuickstart) {
  383. return <ReleasesPromo organization={organization} project={selectedProject!} />;
  384. }
  385. return (
  386. <ReleasesRequest
  387. releases={releases.map(({version}) => version)}
  388. organization={organization}
  389. selection={selection}
  390. location={location}
  391. display={[this.getDisplay()]}
  392. releasesReloading={reloading}
  393. healthStatsPeriod={location.query.healthStatsPeriod}
  394. >
  395. {({isHealthLoading, getHealthData}) => {
  396. const singleProjectSelected =
  397. selection.projects?.length === 1 &&
  398. selection.projects[0] !== ALL_ACCESS_PROJECTS;
  399. const isMobileProject =
  400. selectedProject?.platform && isMobileRelease(selectedProject.platform);
  401. return (
  402. <Fragment>
  403. {singleProjectSelected && this.projectHasSessions && isMobileProject && (
  404. <ReleasesAdoptionChart
  405. organization={organization}
  406. selection={selection}
  407. location={location}
  408. router={router}
  409. activeDisplay={activeDisplay}
  410. />
  411. )}
  412. {releases.map((release, index) => (
  413. <ReleaseCard
  414. key={`${release.version}-${release.projects[0].slug}`}
  415. activeDisplay={activeDisplay}
  416. release={release}
  417. organization={organization}
  418. location={location}
  419. selection={selection}
  420. reloading={reloading}
  421. showHealthPlaceholders={isHealthLoading}
  422. isTopRelease={index === 0}
  423. getHealthData={getHealthData}
  424. showReleaseAdoptionStages={showReleaseAdoptionStages}
  425. />
  426. ))}
  427. <Pagination pageLinks={releasesPageLinks} />
  428. </Fragment>
  429. );
  430. }}
  431. </ReleasesRequest>
  432. );
  433. }
  434. renderBody() {
  435. const {organization, selection} = this.props;
  436. const {releases, reloading, error} = this.state;
  437. const activeSort = this.getSort();
  438. const activeStatus = this.getStatus();
  439. const activeDisplay = this.getDisplay();
  440. const hasAnyMobileProject = selection.projects
  441. .map(id => `${id}`)
  442. .map(ProjectsStore.getById)
  443. .some(project => project?.platform && isMobileRelease(project.platform));
  444. const showReleaseAdoptionStages =
  445. hasAnyMobileProject && selection.environments.length === 1;
  446. const hasReleasesSetup = releases && releases.length > 0;
  447. return (
  448. <PageFiltersContainer showAbsolute={false}>
  449. <NoProjectMessage organization={organization}>
  450. <Layout.Header>
  451. <Layout.HeaderContent>
  452. <Layout.Title>
  453. {t('Releases')}
  454. <PageHeadingQuestionTooltip
  455. docsUrl="https://docs.sentry.io/product/releases/"
  456. title={t(
  457. '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.'
  458. )}
  459. />
  460. </Layout.Title>
  461. </Layout.HeaderContent>
  462. </Layout.Header>
  463. <Layout.Body>
  464. <Layout.Main fullWidth>
  465. {this.renderHealthCta()}
  466. <ReleasesPageFilterBar condensed>
  467. <GuideAnchor target="release_projects">
  468. <ProjectPageFilter />
  469. </GuideAnchor>
  470. <EnvironmentPageFilter />
  471. <DatePageFilter
  472. alignDropdown="left"
  473. disallowArbitraryRelativeRanges
  474. hint={t(
  475. 'Changing this date range will recalculate the release metrics.'
  476. )}
  477. />
  478. </ReleasesPageFilterBar>
  479. {this.shouldShowQuickstart ? null : (
  480. <SortAndFilterWrapper>
  481. <GuideAnchor
  482. target="releases_search"
  483. position="bottom"
  484. disabled={!hasReleasesSetup}
  485. >
  486. <StyledSmartSearchBar
  487. searchSource="releases"
  488. query={this.getQuery()}
  489. placeholder={t('Search by version, build, package, or stage')}
  490. hasRecentSearches={false}
  491. supportedTags={{
  492. ...SEMVER_TAGS,
  493. release: {
  494. key: 'release',
  495. name: 'release',
  496. },
  497. }}
  498. maxMenuHeight={500}
  499. supportedTagType={ItemType.PROPERTY}
  500. onSearch={this.handleSearch}
  501. onGetTagValues={this.getTagValues}
  502. />
  503. </GuideAnchor>
  504. <ReleasesStatusOptions
  505. selected={activeStatus}
  506. onSelect={this.handleStatus}
  507. />
  508. <ReleasesSortOptions
  509. selected={activeSort}
  510. selectedDisplay={activeDisplay}
  511. onSelect={this.handleSortBy}
  512. environments={selection.environments}
  513. />
  514. <ReleasesDisplayOptions
  515. selected={activeDisplay}
  516. onSelect={this.handleDisplay}
  517. />
  518. </SortAndFilterWrapper>
  519. )}
  520. {!reloading &&
  521. activeStatus === ReleasesStatusOption.ARCHIVED &&
  522. !!releases?.length && <ReleaseArchivedNotice multi />}
  523. {error
  524. ? super.renderError(new Error('Unable to load all required endpoints'))
  525. : this.renderInnerBody(activeDisplay, showReleaseAdoptionStages)}
  526. </Layout.Main>
  527. </Layout.Body>
  528. </NoProjectMessage>
  529. </PageFiltersContainer>
  530. );
  531. }
  532. }
  533. const AlertText = styled('div')`
  534. display: flex;
  535. align-items: flex-start;
  536. justify-content: flex-start;
  537. gap: ${space(2)};
  538. > *:nth-child(1) {
  539. flex: 1;
  540. }
  541. flex-direction: column;
  542. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  543. flex-direction: row;
  544. }
  545. `;
  546. const ReleasesPageFilterBar = styled(PageFilterBar)`
  547. margin-bottom: ${space(2)};
  548. `;
  549. const SortAndFilterWrapper = styled('div')`
  550. display: grid;
  551. grid-template-columns: 1fr repeat(3, max-content);
  552. gap: ${space(2)};
  553. margin-bottom: ${space(2)};
  554. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  555. grid-template-columns: repeat(3, 1fr);
  556. & > div {
  557. width: auto;
  558. }
  559. }
  560. @media (max-width: ${p => p.theme.breakpoints.small}) {
  561. grid-template-columns: minmax(0, 1fr);
  562. }
  563. `;
  564. const StyledSmartSearchBar = styled(SmartSearchBar)`
  565. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  566. grid-column: 1 / -1;
  567. }
  568. `;
  569. export default withProjects(withOrganization(withPageFilters(ReleasesList)));