teamDropdown.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import Input from 'app/components/forms/input';
  4. import {t} from 'app/locale';
  5. import {Team} from 'app/types';
  6. import Filter from './filter';
  7. const ALERT_LIST_QUERY_DEFAULT_TEAMS = ['myteams', 'unassigned'];
  8. type Props = {
  9. teams: Team[];
  10. selectedTeam: string;
  11. handleChangeTeam: (teamId: string) => void;
  12. };
  13. export function getTeamParams(team?: string | string[]): string[] {
  14. if (team === undefined) {
  15. return ALERT_LIST_QUERY_DEFAULT_TEAMS;
  16. }
  17. if (team === '') {
  18. return [];
  19. }
  20. if (Array.isArray(team)) {
  21. return team;
  22. }
  23. return [team];
  24. }
  25. function TeamDropdown({teams, selectedTeam, handleChangeTeam}: Props) {
  26. const [teamFilterSearch, setTeamFilterSearch] = useState<string | undefined>();
  27. const teamItems = teams.map(({id, name}) => ({
  28. label: name,
  29. value: id,
  30. filtered: teamFilterSearch
  31. ? !name.toLowerCase().includes(teamFilterSearch.toLowerCase())
  32. : false,
  33. checked: selectedTeam === id,
  34. }));
  35. return (
  36. <Filter
  37. header={
  38. <StyledInput
  39. autoFocus
  40. placeholder={t('Filter by team name')}
  41. onClick={event => {
  42. event.stopPropagation();
  43. }}
  44. onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
  45. setTeamFilterSearch(event.target.value);
  46. }}
  47. value={teamFilterSearch || ''}
  48. />
  49. }
  50. onFilterChange={handleChangeTeam}
  51. dropdownSection={{
  52. id: 'teams',
  53. label: t('Teams'),
  54. items: teamItems,
  55. }}
  56. />
  57. );
  58. }
  59. export default TeamDropdown;
  60. const StyledInput = styled(Input)`
  61. border: none;
  62. border-bottom: 1px solid ${p => p.theme.gray200};
  63. border-radius: 0;
  64. `;