index.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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 EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  11. import ExternalLink from 'sentry/components/links/externalLink';
  12. import LoadingIndicator from 'sentry/components/loadingIndicator';
  13. import NoProjectMessage from 'sentry/components/noProjectMessage';
  14. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  15. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  16. import {getRelativeSummary} from 'sentry/components/organizations/timeRangeSelector/utils';
  17. import PageHeading from 'sentry/components/pageHeading';
  18. import Pagination from 'sentry/components/pagination';
  19. import {Panel} from 'sentry/components/panels';
  20. import ProjectPageFilter from 'sentry/components/projectPageFilter';
  21. import SmartSearchBar from 'sentry/components/smartSearchBar';
  22. import {ItemType} from 'sentry/components/smartSearchBar/types';
  23. import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
  24. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  25. import {releaseHealth} from 'sentry/data/platformCategories';
  26. import {IconSearch} from 'sentry/icons';
  27. import {t} from 'sentry/locale';
  28. import ProjectsStore from 'sentry/stores/projectsStore';
  29. import {PageContent, PageHeader} from 'sentry/styles/organization';
  30. import space from 'sentry/styles/space';
  31. import {
  32. Organization,
  33. PageFilters,
  34. Project,
  35. Release,
  36. ReleaseStatus,
  37. Tag,
  38. } from 'sentry/types';
  39. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  40. import {SEMVER_TAGS} from 'sentry/utils/discover/fields';
  41. import Projects from 'sentry/utils/projects';
  42. import routeTitleGen from 'sentry/utils/routeTitle';
  43. import withOrganization from 'sentry/utils/withOrganization';
  44. import withPageFilters from 'sentry/utils/withPageFilters';
  45. import withProjects from 'sentry/utils/withProjects';
  46. import AsyncView from 'sentry/views/asyncView';
  47. import EmptyMessage from 'sentry/views/settings/components/emptyMessage';
  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. this.api,
  225. organization.slug,
  226. key,
  227. search,
  228. projectId ? [projectId] : null,
  229. 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. <PageContent>
  450. <NoProjectMessage organization={organization}>
  451. <PageHeader>
  452. <PageHeading>{t('Releases')}</PageHeading>
  453. </PageHeader>
  454. {this.renderHealthCta()}
  455. <ReleasesPageFilterBar condensed>
  456. <ProjectPageFilter />
  457. <EnvironmentPageFilter />
  458. <DatePageFilter
  459. alignDropdown="left"
  460. disallowArbitraryRelativeRanges
  461. hint={t('Changing this date range will recalculate the release metrics.')}
  462. />
  463. </ReleasesPageFilterBar>
  464. {this.shouldShowQuickstart ? null : (
  465. <SortAndFilterWrapper>
  466. <GuideAnchor
  467. target="releases_search"
  468. position="bottom"
  469. disabled={!hasReleasesSetup}
  470. >
  471. <StyledSmartSearchBar
  472. searchSource="releases"
  473. query={this.getQuery()}
  474. placeholder={t('Search by version, build, package, or stage')}
  475. hasRecentSearches={false}
  476. supportedTags={{
  477. ...SEMVER_TAGS,
  478. release: {
  479. key: 'release',
  480. name: 'release',
  481. },
  482. }}
  483. maxMenuHeight={500}
  484. supportedTagType={ItemType.PROPERTY}
  485. onSearch={this.handleSearch}
  486. onGetTagValues={this.getTagValues}
  487. />
  488. </GuideAnchor>
  489. <ReleasesStatusOptions
  490. selected={activeStatus}
  491. onSelect={this.handleStatus}
  492. />
  493. <ReleasesSortOptions
  494. selected={activeSort}
  495. selectedDisplay={activeDisplay}
  496. onSelect={this.handleSortBy}
  497. environments={selection.environments}
  498. />
  499. <ReleasesDisplayOptions
  500. selected={activeDisplay}
  501. onSelect={this.handleDisplay}
  502. />
  503. </SortAndFilterWrapper>
  504. )}
  505. {!reloading &&
  506. activeStatus === ReleasesStatusOption.ARCHIVED &&
  507. !!releases?.length && <ReleaseArchivedNotice multi />}
  508. {error
  509. ? super.renderError(new Error('Unable to load all required endpoints'))
  510. : this.renderInnerBody(activeDisplay, showReleaseAdoptionStages)}
  511. </NoProjectMessage>
  512. </PageContent>
  513. </PageFiltersContainer>
  514. );
  515. }
  516. }
  517. const AlertText = styled('div')`
  518. display: flex;
  519. align-items: flex-start;
  520. justify-content: flex-start;
  521. gap: ${space(2)};
  522. > *:nth-child(1) {
  523. flex: 1;
  524. }
  525. flex-direction: column;
  526. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  527. flex-direction: row;
  528. }
  529. `;
  530. const ReleasesPageFilterBar = styled(PageFilterBar)`
  531. margin-bottom: ${space(2)};
  532. `;
  533. const SortAndFilterWrapper = styled('div')`
  534. display: grid;
  535. grid-template-columns: 1fr repeat(3, max-content);
  536. gap: ${space(2)};
  537. margin-bottom: ${space(2)};
  538. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  539. grid-template-columns: repeat(3, 1fr);
  540. }
  541. @media (max-width: ${p => p.theme.breakpoints.small}) {
  542. grid-template-columns: minmax(0, 1fr);
  543. }
  544. `;
  545. const StyledSmartSearchBar = styled(SmartSearchBar)`
  546. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  547. grid-column: 1 / -1;
  548. }
  549. `;
  550. export default withProjects(withOrganization(withPageFilters(ReleasesList)));