index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 [['itemList', `/organizations/${organization.slug}/repos/`]];
  20. }
  21. // Callback used by child component to signal state change
  22. onRepositoryChange = (data: Pick<Repository, 'id' | 'status'>) => {
  23. const itemList = this.state.itemList;
  24. itemList?.forEach(item => {
  25. if (item.id === data.id) {
  26. item.status = data.status;
  27. }
  28. });
  29. this.setState({itemList});
  30. };
  31. getTitle() {
  32. const {organization} = this.props;
  33. return routeTitleGen(t('Repositories'), organization.slug, false);
  34. }
  35. renderBody() {
  36. const {itemList, itemListPageLinks} = this.state;
  37. return (
  38. <Fragment>
  39. <OrganizationRepositories
  40. {...this.props}
  41. itemList={itemList!}
  42. onRepositoryChange={this.onRepositoryChange}
  43. />
  44. {itemListPageLinks && (
  45. <Pagination pageLinks={itemListPageLinks} {...this.props} />
  46. )}
  47. </Fragment>
  48. );
  49. }
  50. }
  51. export default withOrganization(OrganizationRepositoriesContainer);