repositorySwitcher.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import styled from '@emotion/styled';
  2. import {CompactSelect} from 'sentry/components/compactSelect';
  3. import {t} from 'sentry/locale';
  4. import type {Repository} from 'sentry/types/integrations';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import useRouter from 'sentry/utils/useRouter';
  7. interface RepositorySwitcherProps {
  8. repositories: Repository[];
  9. activeRepository?: Repository;
  10. }
  11. function RepositorySwitcher({repositories, activeRepository}: RepositorySwitcherProps) {
  12. const router = useRouter();
  13. const location = useLocation();
  14. const handleRepoFilterChange = (activeRepo: string) => {
  15. router.push({
  16. ...location,
  17. query: {...location.query, cursor: undefined, activeRepo},
  18. });
  19. };
  20. const activeRepo = activeRepository?.name;
  21. return (
  22. <CompactSelect
  23. triggerLabel={activeRepo}
  24. triggerProps={{prefix: t('Filter')}}
  25. value={activeRepo}
  26. options={repositories.map(repo => ({
  27. value: repo.name,
  28. textValue: repo.name,
  29. label: <RepoLabel>{repo.name}</RepoLabel>,
  30. }))}
  31. onChange={opt => handleRepoFilterChange(String(opt?.value))}
  32. />
  33. );
  34. }
  35. export default RepositorySwitcher;
  36. const RepoLabel = styled('div')`
  37. ${p => p.theme.overflowEllipsis}
  38. `;