ruleNameOwnerForm.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import FormField from 'sentry/components/forms/formField';
  4. import TeamSelector from 'sentry/components/forms/teamSelector';
  5. import TextField from 'sentry/components/forms/textField';
  6. import ListItem from 'sentry/components/list/listItem';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {Project, Team} from 'sentry/types';
  10. type Props = {
  11. disabled: boolean;
  12. project: Project;
  13. };
  14. export default function RuleNameOwnerForm({disabled, project}: Props) {
  15. const renderRuleName = () => (
  16. <StyledTextField
  17. data-test-id="alert-name"
  18. disabled={disabled}
  19. name="name"
  20. label={null}
  21. help={null}
  22. placeholder={t('Enter Alert Name')}
  23. required
  24. flexibleControlStateSize
  25. />
  26. );
  27. const renderTeamSelect = () => (
  28. <StyledFormField
  29. extraMargin
  30. name="owner"
  31. label={null}
  32. help={null}
  33. disabled={disabled}
  34. flexibleControlStateSize
  35. >
  36. {({model}) => {
  37. const owner = model.getValue('owner');
  38. const ownerId = owner && owner.split(':')[1];
  39. return (
  40. <TeamSelector
  41. value={ownerId}
  42. project={project}
  43. onChange={({value}) => model.setValue('owner', value && `team:${value}`)}
  44. teamFilter={(team: Team) => team.isMember || team.id === ownerId}
  45. useId
  46. includeUnassigned
  47. disabled={disabled}
  48. />
  49. );
  50. }}
  51. </StyledFormField>
  52. );
  53. return (
  54. <Fragment>
  55. <StyledListItem>{t('Establish ownership')}</StyledListItem>
  56. {renderRuleName()}
  57. {renderTeamSelect()}
  58. </Fragment>
  59. );
  60. }
  61. const StyledListItem = styled(ListItem)`
  62. margin: ${space(2)} 0 ${space(1)} 0;
  63. font-size: ${p => p.theme.fontSizeExtraLarge};
  64. `;
  65. const StyledTextField = styled(TextField)`
  66. border-bottom: none;
  67. padding: 0;
  68. & > div {
  69. padding: 0;
  70. width: 100%;
  71. }
  72. margin-bottom: ${space(1)};
  73. `;
  74. const StyledFormField = styled(FormField)<{extraMargin?: boolean}>`
  75. padding: 0;
  76. & > div {
  77. padding: 0;
  78. width: 100%;
  79. }
  80. margin-bottom: ${p => `${p.extraMargin ? '60px' : space(1)}`};
  81. `;