teamCrumb.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import debounce from 'lodash/debounce';
  3. import IdBadge from 'sentry/components/idBadge';
  4. import {DEFAULT_DEBOUNCE_DURATION} from 'sentry/constants';
  5. import recreateRoute from 'sentry/utils/recreateRoute';
  6. import {useParams} from 'sentry/utils/useParams';
  7. import {useTeams} from 'sentry/utils/useTeams';
  8. import BreadcrumbDropdown from 'sentry/views/settings/components/settingsBreadcrumb/breadcrumbDropdown';
  9. import MenuItem from 'sentry/views/settings/components/settingsBreadcrumb/menuItem';
  10. import {CrumbLink} from '.';
  11. type Props = RouteComponentProps<{teamId: string}, {}>;
  12. function TeamCrumb({routes, route, ...props}: Props) {
  13. const {teams, onSearch, fetching} = useTeams();
  14. const params = useParams();
  15. const team = teams.find(({slug}) => slug === params.teamId);
  16. const hasMenu = teams.length > 1;
  17. const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
  18. onSearch(e.target.value);
  19. };
  20. const debouncedHandleSearch = debounce(handleSearchChange, DEFAULT_DEBOUNCE_DURATION);
  21. if (!team) {
  22. return null;
  23. }
  24. const teamUrl = `/settings/${params.orgId}/teams/${team.slug}/`;
  25. return (
  26. <BreadcrumbDropdown
  27. name={
  28. <CrumbLink to={teamUrl}>
  29. <IdBadge avatarSize={18} team={team} />
  30. </CrumbLink>
  31. }
  32. onSelect={item => {
  33. browserHistory.push(
  34. recreateRoute('', {
  35. routes,
  36. params: {...params, teamId: item.value},
  37. })
  38. );
  39. }}
  40. hasMenu={hasMenu}
  41. route={route}
  42. items={teams.map((teamItem, index) => ({
  43. index,
  44. value: teamItem.slug,
  45. label: (
  46. <MenuItem>
  47. <IdBadge team={teamItem} />
  48. </MenuItem>
  49. ),
  50. }))}
  51. onChange={debouncedHandleSearch}
  52. busyItemsStillVisible={fetching}
  53. {...props}
  54. />
  55. );
  56. }
  57. export default TeamCrumb;