index.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 {Repository} from 'sentry/types';
  6. import routeTitleGen from 'sentry/utils/routeTitle';
  7. import AsyncView from 'sentry/views/asyncView';
  8. import OrganizationRepositories from './organizationRepositories';
  9. type Props = RouteComponentProps<{orgId: string}, {}> & AsyncView['props'];
  10. type State = AsyncView['state'] & {
  11. itemList: Repository[] | null;
  12. };
  13. export default class OrganizationRepositoriesContainer extends AsyncView<Props, State> {
  14. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  15. const {orgId} = this.props.params;
  16. return [['itemList', `/organizations/${orgId}/repos/`, {query: {status: ''}}]];
  17. }
  18. // Callback used by child component to signal state change
  19. onRepositoryChange = (data: Pick<Repository, 'id' | 'status'>) => {
  20. const itemList = this.state.itemList;
  21. itemList?.forEach(item => {
  22. if (item.id === data.id) {
  23. item.status = data.status;
  24. }
  25. });
  26. this.setState({itemList});
  27. };
  28. getTitle() {
  29. const {orgId} = this.props.params;
  30. return routeTitleGen(t('Repositories'), orgId, false);
  31. }
  32. renderBody() {
  33. const {itemList, itemListPageLinks} = this.state;
  34. return (
  35. <Fragment>
  36. <OrganizationRepositories
  37. {...this.props}
  38. itemList={itemList!}
  39. onRepositoryChange={this.onRepositoryChange}
  40. />
  41. {itemListPageLinks && (
  42. <Pagination pageLinks={itemListPageLinks} {...this.props} />
  43. )}
  44. </Fragment>
  45. );
  46. }
  47. }