ruleNameOwnerForm.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 {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) =>
  45. team.isMember || team.id === ownerId || team.access.includes('team:admin')
  46. }
  47. useId
  48. includeUnassigned
  49. disabled={disabled}
  50. />
  51. );
  52. }}
  53. </StyledFormField>
  54. );
  55. return (
  56. <Fragment>
  57. <StyledListItem>{t('Establish ownership')}</StyledListItem>
  58. {renderRuleName()}
  59. {renderTeamSelect()}
  60. </Fragment>
  61. );
  62. }
  63. const StyledListItem = styled(ListItem)`
  64. margin: ${space(2)} 0 ${space(1)} 0;
  65. font-size: ${p => p.theme.fontSizeExtraLarge};
  66. `;
  67. const StyledTextField = styled(TextField)`
  68. border-bottom: none;
  69. padding: 0;
  70. & > div {
  71. padding: 0;
  72. width: 100%;
  73. }
  74. margin-bottom: ${space(1)};
  75. `;
  76. const StyledFormField = styled(FormField)<{extraMargin?: boolean}>`
  77. padding: 0;
  78. & > div {
  79. padding: 0;
  80. width: 100%;
  81. }
  82. margin-bottom: ${p => `${p.extraMargin ? '60px' : space(1)}`};
  83. `;