index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {Fragment} from 'react';
  2. import LoadingError from 'sentry/components/loadingError';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import Pagination from 'sentry/components/pagination';
  5. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  6. import {t} from 'sentry/locale';
  7. import type {Repository} from 'sentry/types';
  8. import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
  9. import routeTitleGen from 'sentry/utils/routeTitle';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import OrganizationRepositories from './organizationRepositories';
  13. function OrganizationRepositoriesContainer() {
  14. const organization = useOrganization();
  15. const location = useLocation();
  16. const queryClient = useQueryClient();
  17. const {
  18. data: itemList,
  19. isLoading,
  20. isError,
  21. getResponseHeader,
  22. } = useApiQuery<Repository[]>(
  23. [`/organizations/${organization.slug}/repos/`, {query: location.query}],
  24. {staleTime: 0}
  25. );
  26. const itemListPageLinks = getResponseHeader?.('Link');
  27. if (isLoading) {
  28. return <LoadingIndicator />;
  29. }
  30. if (isError) {
  31. return <LoadingError />;
  32. }
  33. // Callback used by child component to signal state change
  34. function onRepositoryChange(data: Pick<Repository, 'id' | 'status'>) {
  35. setApiQueryData<Repository[]>(
  36. queryClient,
  37. [`/organizations/${organization.slug}/repos/`, {query: location.query}],
  38. oldItemList =>
  39. oldItemList.map(item =>
  40. item.id === data.id ? {...item, status: data.status} : item
  41. )
  42. );
  43. }
  44. return (
  45. <Fragment>
  46. <SentryDocumentTitle
  47. title={routeTitleGen(t('Repositories'), organization.slug, false)}
  48. />
  49. <OrganizationRepositories
  50. organization={organization}
  51. itemList={itemList!}
  52. onRepositoryChange={onRepositoryChange}
  53. />
  54. {itemListPageLinks && <Pagination pageLinks={itemListPageLinks} />}
  55. </Fragment>
  56. );
  57. }
  58. export default OrganizationRepositoriesContainer;