123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- import {Fragment} from 'react';
- import {forceCheck} from 'react-lazyload';
- import type {RouteComponentProps} from 'react-router';
- import styled from '@emotion/styled';
- import pick from 'lodash/pick';
- import {fetchTagValues} from 'sentry/actionCreators/tags';
- import type {Client} from 'sentry/api';
- import {Alert} from 'sentry/components/alert';
- import GuideAnchor from 'sentry/components/assistant/guideAnchor';
- import EmptyMessage from 'sentry/components/emptyMessage';
- import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
- import * as Layout from 'sentry/components/layouts/thirds';
- import ExternalLink from 'sentry/components/links/externalLink';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import NoProjectMessage from 'sentry/components/noProjectMessage';
- import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
- import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
- import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
- import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
- import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
- import Pagination from 'sentry/components/pagination';
- import Panel from 'sentry/components/panels/panel';
- import SmartSearchBar from 'sentry/components/smartSearchBar';
- import {ItemType} from 'sentry/components/smartSearchBar/types';
- import {getRelativeSummary} from 'sentry/components/timeRangeSelector/utils';
- import {DEFAULT_STATS_PERIOD} from 'sentry/constants';
- import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
- import {releaseHealth} from 'sentry/data/platformCategories';
- import {IconSearch} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {space} from 'sentry/styles/space';
- import type {
- AvatarProject,
- Organization,
- PageFilters,
- Project,
- Release,
- Tag,
- } from 'sentry/types';
- import {ReleaseStatus} from 'sentry/types/release';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import {SEMVER_TAGS} from 'sentry/utils/discover/fields';
- import Projects from 'sentry/utils/projects';
- import routeTitleGen from 'sentry/utils/routeTitle';
- import withApi from 'sentry/utils/withApi';
- import withOrganization from 'sentry/utils/withOrganization';
- import withPageFilters from 'sentry/utils/withPageFilters';
- import withProjects from 'sentry/utils/withProjects';
- import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
- import Header from '../components/header';
- import ReleaseFeedbackBanner from '../components/releaseFeedbackBanner';
- import ReleaseArchivedNotice from '../detail/overview/releaseArchivedNotice';
- import {isMobileRelease} from '../utils';
- import ReleaseCard from './releaseCard';
- import ReleasesAdoptionChart from './releasesAdoptionChart';
- import ReleasesDisplayOptions, {ReleasesDisplayOption} from './releasesDisplayOptions';
- import ReleasesPromo from './releasesPromo';
- import ReleasesRequest from './releasesRequest';
- import ReleasesSortOptions, {ReleasesSortOption} from './releasesSortOptions';
- import ReleasesStatusOptions, {ReleasesStatusOption} from './releasesStatusOptions';
- type RouteParams = {
- orgId: string;
- };
- type Props = RouteComponentProps<RouteParams, {}> & {
- api: Client;
- organization: Organization;
- projects: Project[];
- selection: PageFilters;
- };
- type State = {
- releases: Release[];
- } & DeprecatedAsyncView['state'];
- class ReleasesList extends DeprecatedAsyncView<Props, State> {
- shouldReload = true;
- shouldRenderBadRequests = true;
- getTitle() {
- return routeTitleGen(t('Releases'), this.props.organization.slug, false);
- }
- getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
- const {organization, location} = this.props;
- const {statsPeriod} = location.query;
- const activeSort = this.getSort();
- const activeStatus = this.getStatus();
- const query = {
- ...pick(location.query, ['project', 'environment', 'cursor', 'query', 'sort']),
- summaryStatsPeriod: statsPeriod,
- per_page: 20,
- flatten: activeSort === ReleasesSortOption.DATE ? 0 : 1,
- adoptionStages: 1,
- status:
- activeStatus === ReleasesStatusOption.ARCHIVED
- ? ReleaseStatus.ARCHIVED
- : ReleaseStatus.ACTIVE,
- };
- const endpoints: ReturnType<DeprecatedAsyncView['getEndpoints']> = [
- [
- 'releases', // stateKey
- `/organizations/${organization.slug}/releases/`, // endpoint
- {query}, // params
- {disableEntireQuery: true}, // options - prevent cursor from being passed into query
- ],
- ];
- return endpoints;
- }
- componentDidUpdate(prevProps: Props, prevState: State) {
- super.componentDidUpdate(prevProps, prevState);
- if (prevState.releases !== this.state.releases) {
- /**
- * Manually trigger checking for elements in viewport.
- * Helpful when LazyLoad components enter the viewport without resize or scroll events,
- * https://github.com/twobin/react-lazyload#forcecheck
- *
- * HealthStatsCharts are being rendered only when they are scrolled into viewport.
- * This is how we re-check them without scrolling once releases change as this view
- * uses shouldReload=true and there is no reloading happening.
- */
- forceCheck();
- }
- }
- getQuery() {
- const {query} = this.props.location.query;
- return typeof query === 'string' ? query : undefined;
- }
- getSort(): ReleasesSortOption {
- const {environments} = this.props.selection;
- const {sort} = this.props.location.query;
- // Require 1 environment for date adopted
- if (sort === ReleasesSortOption.ADOPTION && environments.length !== 1) {
- return ReleasesSortOption.DATE;
- }
- const sortExists = Object.values(ReleasesSortOption).includes(sort);
- if (sortExists) {
- return sort;
- }
- return ReleasesSortOption.DATE;
- }
- getDisplay(): ReleasesDisplayOption {
- const {display} = this.props.location.query;
- switch (display) {
- case ReleasesDisplayOption.USERS:
- return ReleasesDisplayOption.USERS;
- default:
- return ReleasesDisplayOption.SESSIONS;
- }
- }
- getStatus(): ReleasesStatusOption {
- const {status} = this.props.location.query;
- switch (status) {
- case ReleasesStatusOption.ARCHIVED:
- return ReleasesStatusOption.ARCHIVED;
- default:
- return ReleasesStatusOption.ACTIVE;
- }
- }
- getSelectedProject(): Project | undefined {
- const {selection, projects} = this.props;
- const selectedProjectId =
- selection.projects && selection.projects.length === 1 && selection.projects[0];
- return projects?.find(p => p.id === `${selectedProjectId}`);
- }
- getSelectedProjectSlugs(): string[] {
- const {selection, projects} = this.props;
- const projIdSet = new Set(selection.projects);
- return projects.reduce((result: string[], proj) => {
- if (projIdSet.has(Number(proj.id))) {
- result.push(proj.slug);
- }
- return result;
- }, []);
- }
- get projectHasSessions() {
- return this.getSelectedProject()?.hasSessions ?? null;
- }
- handleSearch = (query: string) => {
- const {location, router} = this.props;
- router.push({
- ...location,
- query: {...location.query, cursor: undefined, query},
- });
- };
- handleSortBy = (sort: string) => {
- const {location, router} = this.props;
- router.push({
- ...location,
- query: {...location.query, cursor: undefined, sort},
- });
- };
- handleDisplay = (display: string) => {
- const {location, router} = this.props;
- let sort = location.query.sort;
- if (
- sort === ReleasesSortOption.USERS_24_HOURS &&
- display === ReleasesDisplayOption.SESSIONS
- ) {
- sort = ReleasesSortOption.SESSIONS_24_HOURS;
- } else if (
- sort === ReleasesSortOption.SESSIONS_24_HOURS &&
- display === ReleasesDisplayOption.USERS
- ) {
- sort = ReleasesSortOption.USERS_24_HOURS;
- } else if (
- sort === ReleasesSortOption.CRASH_FREE_USERS &&
- display === ReleasesDisplayOption.SESSIONS
- ) {
- sort = ReleasesSortOption.CRASH_FREE_SESSIONS;
- } else if (
- sort === ReleasesSortOption.CRASH_FREE_SESSIONS &&
- display === ReleasesDisplayOption.USERS
- ) {
- sort = ReleasesSortOption.CRASH_FREE_USERS;
- }
- router.push({
- ...location,
- query: {...location.query, cursor: undefined, display, sort},
- });
- };
- handleStatus = (status: string) => {
- const {location, router} = this.props;
- router.push({
- ...location,
- query: {...location.query, cursor: undefined, status},
- });
- };
- trackAddReleaseHealth = () => {
- const {organization, selection} = this.props;
- if (organization.id && selection.projects[0]) {
- trackAnalytics('releases_list.click_add_release_health', {
- organization,
- project_id: selection.projects[0],
- });
- }
- };
- tagValueLoader = (key: string, search: string) => {
- const {location, organization} = this.props;
- const {project: projectId} = location.query;
- return fetchTagValues({
- api: this.api,
- orgSlug: organization.slug,
- tagKey: key,
- search,
- projectIds: projectId ? [projectId] : undefined,
- endpointParams: location.query,
- });
- };
- getTagValues = async (tag: Tag, currentQuery: string): Promise<string[]> => {
- const values = await this.tagValueLoader(tag.key, currentQuery);
- return values.map(({value}) => value);
- };
- shouldShowLoadingIndicator() {
- const {loading, releases, reloading} = this.state;
- return (loading && !reloading) || (loading && !releases?.length);
- }
- renderLoading() {
- return this.renderBody();
- }
- renderError() {
- return this.renderBody();
- }
- get shouldShowQuickstart() {
- const {releases} = this.state;
- const selectedProject = this.getSelectedProject();
- const hasReleasesSetup = selectedProject?.features.includes('releases');
- return !releases?.length && !hasReleasesSetup && selectedProject;
- }
- renderEmptyMessage() {
- const {location} = this.props;
- const {statsPeriod, start, end} = location.query;
- const searchQuery = this.getQuery();
- const activeSort = this.getSort();
- const activeStatus = this.getStatus();
- const selectedPeriod =
- !!start && !!end
- ? t('time range')
- : getRelativeSummary(statsPeriod || DEFAULT_STATS_PERIOD).toLowerCase();
- if (searchQuery?.length) {
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">{`${t(
- 'There are no releases that match'
- )}: '${searchQuery}'.`}</EmptyMessage>
- </Panel>
- );
- }
- if (activeSort === ReleasesSortOption.USERS_24_HOURS) {
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">
- {t(
- 'There are no releases with active user data (users in the last 24 hours).'
- )}
- </EmptyMessage>
- </Panel>
- );
- }
- if (activeSort === ReleasesSortOption.SESSIONS_24_HOURS) {
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">
- {t(
- 'There are no releases with active session data (sessions in the last 24 hours).'
- )}
- </EmptyMessage>
- </Panel>
- );
- }
- if (
- activeSort === ReleasesSortOption.BUILD ||
- activeSort === ReleasesSortOption.SEMVER
- ) {
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">
- {t('There are no releases with semantic versioning.')}
- </EmptyMessage>
- </Panel>
- );
- }
- if (activeSort !== ReleasesSortOption.DATE) {
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">
- {`${t('There are no releases with data in the')} ${selectedPeriod}.`}
- </EmptyMessage>
- </Panel>
- );
- }
- if (activeStatus === ReleasesStatusOption.ARCHIVED) {
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">
- {t('There are no archived releases.')}
- </EmptyMessage>
- </Panel>
- );
- }
- return (
- <Panel>
- <EmptyMessage icon={<IconSearch size="xl" />} size="large">
- {`${t('There are no releases with data in the')} ${selectedPeriod}.`}
- </EmptyMessage>
- </Panel>
- );
- }
- renderHealthCta() {
- const {organization} = this.props;
- const {releases} = this.state;
- const selectedProject = this.getSelectedProject();
- if (!selectedProject || this.projectHasSessions !== false || !releases?.length) {
- return null;
- }
- return (
- <Projects orgId={organization.slug} slugs={[selectedProject.slug]}>
- {({projects, initiallyLoaded, fetchError}) => {
- const project: AvatarProject | undefined =
- projects?.length === 1 ? projects.at(0) : undefined;
- const projectCanHaveReleases =
- project?.platform && releaseHealth.includes(project.platform);
- if (!initiallyLoaded || fetchError || !projectCanHaveReleases) {
- return null;
- }
- return (
- <Alert type="info" showIcon>
- <AlertText>
- <div>
- {t(
- 'To track user adoption, crash rates, session data and more, add Release Health to your current setup.'
- )}
- </div>
- <ExternalLink
- href="https://docs.sentry.io/product/releases/setup/#release-health"
- onClick={this.trackAddReleaseHealth}
- >
- {t('Add Release Health')}
- </ExternalLink>
- </AlertText>
- </Alert>
- );
- }}
- </Projects>
- );
- }
- renderInnerBody(
- activeDisplay: ReleasesDisplayOption,
- showReleaseAdoptionStages: boolean
- ) {
- const {location, selection, organization, router} = this.props;
- const {releases, reloading, releasesPageLinks} = this.state;
- const selectedProject = this.getSelectedProject();
- const hasReleasesSetup = selectedProject?.features.includes('releases');
- if (this.shouldShowLoadingIndicator()) {
- return <LoadingIndicator />;
- }
- if (!releases?.length && hasReleasesSetup) {
- return this.renderEmptyMessage();
- }
- if (this.shouldShowQuickstart) {
- return <ReleasesPromo organization={organization} project={selectedProject!} />;
- }
- return (
- <ReleasesRequest
- releases={releases.map(({version}) => version)}
- organization={organization}
- selection={selection}
- location={location}
- display={[this.getDisplay()]}
- releasesReloading={reloading}
- healthStatsPeriod={location.query.healthStatsPeriod}
- >
- {({isHealthLoading, getHealthData}) => {
- const singleProjectSelected =
- selection.projects?.length === 1 &&
- selection.projects[0] !== ALL_ACCESS_PROJECTS;
- // TODO: project specific chart should live on the project details page.
- const isMobileProject =
- selectedProject?.platform && isMobileRelease(selectedProject.platform);
- return (
- <Fragment>
- {singleProjectSelected && this.projectHasSessions && isMobileProject && (
- <ReleasesAdoptionChart
- organization={organization}
- selection={selection}
- location={location}
- router={router}
- activeDisplay={activeDisplay}
- />
- )}
- {releases.map((release, index) => (
- <ReleaseCard
- key={`${release.projects[0].slug}-${release.version}`}
- activeDisplay={activeDisplay}
- release={release}
- organization={organization}
- location={location}
- selection={selection}
- reloading={reloading}
- showHealthPlaceholders={isHealthLoading}
- isTopRelease={index === 0}
- getHealthData={getHealthData}
- showReleaseAdoptionStages={showReleaseAdoptionStages}
- />
- ))}
- <Pagination pageLinks={releasesPageLinks} />
- </Fragment>
- );
- }}
- </ReleasesRequest>
- );
- }
- renderBody() {
- const {organization, selection} = this.props;
- const {releases, reloading, error} = this.state;
- const activeSort = this.getSort();
- const activeStatus = this.getStatus();
- const activeDisplay = this.getDisplay();
- const hasAnyMobileProject = selection.projects
- .map(id => `${id}`)
- .map(ProjectsStore.getById)
- .some(project => project?.platform && isMobileRelease(project.platform));
- const showReleaseAdoptionStages =
- hasAnyMobileProject && selection.environments.length === 1;
- return (
- <PageFiltersContainer showAbsolute={false}>
- <NoProjectMessage organization={organization}>
- <Header />
- <Layout.Body>
- <Layout.Main fullWidth>
- {organization.features.includes('releases-v2-banner') && (
- <ReleaseFeedbackBanner />
- )}
- {this.renderHealthCta()}
- <ReleasesPageFilterBar condensed>
- <GuideAnchor target="release_projects">
- <ProjectPageFilter />
- </GuideAnchor>
- <EnvironmentPageFilter />
- <DatePageFilter
- disallowArbitraryRelativeRanges
- menuFooterMessage={t(
- 'Changing this date range will recalculate the release metrics.'
- )}
- />
- </ReleasesPageFilterBar>
- {this.shouldShowQuickstart ? null : (
- <SortAndFilterWrapper>
- <StyledSmartSearchBar
- searchSource="releases"
- query={this.getQuery()}
- placeholder={t('Search by version, build, package, or stage')}
- hasRecentSearches={false}
- supportedTags={{
- ...SEMVER_TAGS,
- release: {
- key: 'release',
- name: 'release',
- },
- }}
- maxMenuHeight={500}
- supportedTagType={ItemType.PROPERTY}
- onSearch={this.handleSearch}
- onGetTagValues={this.getTagValues}
- />
- <ReleasesStatusOptions
- selected={activeStatus}
- onSelect={this.handleStatus}
- />
- <ReleasesSortOptions
- selected={activeSort}
- selectedDisplay={activeDisplay}
- onSelect={this.handleSortBy}
- environments={selection.environments}
- />
- <ReleasesDisplayOptions
- selected={activeDisplay}
- onSelect={this.handleDisplay}
- />
- </SortAndFilterWrapper>
- )}
- {!reloading &&
- activeStatus === ReleasesStatusOption.ARCHIVED &&
- !!releases?.length && <ReleaseArchivedNotice multi />}
- {error
- ? super.renderError()
- : this.renderInnerBody(activeDisplay, showReleaseAdoptionStages)}
- <FloatingFeedbackWidget />
- </Layout.Main>
- </Layout.Body>
- </NoProjectMessage>
- </PageFiltersContainer>
- );
- }
- }
- const AlertText = styled('div')`
- display: flex;
- align-items: flex-start;
- justify-content: flex-start;
- gap: ${space(2)};
- > *:nth-child(1) {
- flex: 1;
- }
- flex-direction: column;
- @media (min-width: ${p => p.theme.breakpoints.medium}) {
- flex-direction: row;
- }
- `;
- const ReleasesPageFilterBar = styled(PageFilterBar)`
- margin-bottom: ${space(2)};
- `;
- const SortAndFilterWrapper = styled('div')`
- display: grid;
- grid-template-columns: 1fr repeat(3, max-content);
- gap: ${space(2)};
- margin-bottom: ${space(2)};
- @media (max-width: ${p => p.theme.breakpoints.medium}) {
- grid-template-columns: repeat(3, 1fr);
- & > div {
- width: auto;
- }
- }
- @media (max-width: ${p => p.theme.breakpoints.small}) {
- grid-template-columns: minmax(0, 1fr);
- }
- `;
- const StyledSmartSearchBar = styled(SmartSearchBar)`
- @media (max-width: ${p => p.theme.breakpoints.medium}) {
- grid-column: 1 / -1;
- }
- `;
- export default withApi(withProjects(withOrganization(withPageFilters(ReleasesList))));
|