ruleNameOwnerForm.tsx 2.3 KB

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