index.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import Pagination from 'sentry/components/pagination';
  4. import {t} from 'sentry/locale';
  5. import {Organization, Repository} from 'sentry/types';
  6. import routeTitleGen from 'sentry/utils/routeTitle';
  7. import withOrganization from 'sentry/utils/withOrganization';
  8. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  9. import OrganizationRepositories from './organizationRepositories';
  10. type Props = RouteComponentProps<{}, {}> & {
  11. organization: Organization;
  12. } & DeprecatedAsyncView['props'];
  13. type State = DeprecatedAsyncView['state'] & {
  14. itemList: Repository[] | null;
  15. };
  16. class OrganizationRepositoriesContainer extends DeprecatedAsyncView<Props, State> {
  17. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  18. const {organization} = this.props;
  19. return [
  20. ['itemList', `/organizations/${organization.slug}/repos/`, {query: {status: ''}}],
  21. ];
  22. }
  23. // Callback used by child component to signal state change
  24. onRepositoryChange = (data: Pick<Repository, 'id' | 'status'>) => {
  25. const itemList = this.state.itemList;
  26. itemList?.forEach(item => {
  27. if (item.id === data.id) {
  28. item.status = data.status;
  29. }
  30. });
  31. this.setState({itemList});
  32. };
  33. getTitle() {
  34. const {organization} = this.props;
  35. return routeTitleGen(t('Repositories'), organization.slug, false);
  36. }
  37. renderBody() {
  38. const {itemList, itemListPageLinks} = this.state;
  39. return (
  40. <Fragment>
  41. <OrganizationRepositories
  42. {...this.props}
  43. itemList={itemList!}
  44. onRepositoryChange={this.onRepositoryChange}
  45. />
  46. {itemListPageLinks && (
  47. <Pagination pageLinks={itemListPageLinks} {...this.props} />
  48. )}
  49. </Fragment>
  50. );
  51. }
  52. }
  53. export default withOrganization(OrganizationRepositoriesContainer);