index.tsx 20 KB

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