index.tsx 20 KB

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