index.tsx 21 KB

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