123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- import {Fragment} from 'react';
- import {RouteComponentProps} from 'react-router';
- import {Location} from 'history';
- import {CommitRow} from 'sentry/components/commitRow';
- import {Body, Main} from 'sentry/components/layouts/thirds';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import Pagination from 'sentry/components/pagination';
- import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels';
- import {t} from 'sentry/locale';
- import {Commit, Organization, Project, Repository} from 'sentry/types';
- import {formatVersion} from 'sentry/utils/formatters';
- import routeTitleGen from 'sentry/utils/routeTitle';
- import AsyncView from 'sentry/views/asyncView';
- import {getCommitsByRepository, getQuery, getReposToRender} from '../utils';
- import EmptyState from './emptyState';
- import RepositorySwitcher from './repositorySwitcher';
- import withReleaseRepos from './withReleaseRepos';
- type Props = RouteComponentProps<{orgId: string; release: string}, {}> & {
- location: Location;
- orgSlug: Organization['slug'];
- projectSlug: Project['slug'];
- release: string;
- releaseRepos: Repository[];
- activeReleaseRepo?: Repository;
- } & AsyncView['props'];
- type State = {
- commits: Commit[];
- } & AsyncView['state'];
- class Commits extends AsyncView<Props, State> {
- getTitle() {
- const {params, projectSlug} = this.props;
- const {orgId} = params;
- return routeTitleGen(
- t('Commits - Release %s', formatVersion(params.release)),
- orgId,
- false,
- projectSlug
- );
- }
- getDefaultState(): State {
- return {
- ...super.getDefaultState(),
- commits: [],
- };
- }
- componentDidUpdate(prevProps: Props, prevState: State) {
- if (prevProps.activeReleaseRepo?.name !== this.props.activeReleaseRepo?.name) {
- this.remountComponent();
- return;
- }
- super.componentDidUpdate(prevProps, prevState);
- }
- getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
- const {
- projectSlug,
- activeReleaseRepo: activeRepository,
- location,
- orgSlug,
- release,
- } = this.props;
- const query = getQuery({location, activeRepository});
- return [
- [
- 'commits',
- `/projects/${orgSlug}/${projectSlug}/releases/${encodeURIComponent(
- release
- )}/commits/`,
- {query},
- ],
- ];
- }
- renderLoading() {
- return this.renderBody();
- }
- renderContent() {
- const {commits, commitsPageLinks, loading} = this.state;
- const {activeReleaseRepo} = this.props;
- if (loading) {
- return <LoadingIndicator />;
- }
- if (!commits.length) {
- return (
- <EmptyState>
- {!activeReleaseRepo
- ? t('There are no commits associated with this release.')
- : t(
- 'There are no commits associated with this release in the %s repository.',
- activeReleaseRepo.name
- )}
- </EmptyState>
- );
- }
- const commitsByRepository = getCommitsByRepository(commits);
- const reposToRender = getReposToRender(Object.keys(commitsByRepository));
- return (
- <Fragment>
- {reposToRender.map(repoName => (
- <Panel key={repoName}>
- <PanelHeader>{repoName}</PanelHeader>
- <PanelBody>
- {commitsByRepository[repoName]?.map(commit => (
- <CommitRow key={commit.id} commit={commit} />
- ))}
- </PanelBody>
- </Panel>
- ))}
- <Pagination pageLinks={commitsPageLinks} />
- </Fragment>
- );
- }
- renderBody() {
- const {location, router, activeReleaseRepo, releaseRepos} = this.props;
- return (
- <Fragment>
- {releaseRepos.length > 1 && (
- <RepositorySwitcher
- repositories={releaseRepos}
- activeRepository={activeReleaseRepo}
- location={location}
- router={router}
- />
- )}
- {this.renderContent()}
- </Fragment>
- );
- }
- renderComponent() {
- return (
- <Body>
- <Main fullWidth>{super.renderComponent()}</Main>
- </Body>
- );
- }
- }
- export default withReleaseRepos(Commits);
|