autofixInstructionsModal.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import TextareaAutosize from 'react-autosize-textarea';
  2. import styled from '@emotion/styled';
  3. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  4. import {Button} from 'sentry/components/button';
  5. import Form from 'sentry/components/forms/form';
  6. import FormField from 'sentry/components/forms/formField';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. interface AutofixContextModalProps extends ModalRenderProps {
  10. groupId: string;
  11. triggerAutofix: (value: string) => void;
  12. }
  13. export function AutofixInstructionsModal({
  14. Header,
  15. Footer,
  16. closeModal,
  17. triggerAutofix,
  18. groupId,
  19. }: AutofixContextModalProps) {
  20. return (
  21. <Form
  22. hideFooter
  23. onSubmit={data => {
  24. triggerAutofix(data.instruction ?? '');
  25. closeModal();
  26. }}
  27. >
  28. <Header>
  29. <h4>{t('Provide context to Autofix')}</h4>
  30. </Header>
  31. <div>
  32. <FullSizeFieldGroup name="instruction" inline={false} flexibleControlStateSize>
  33. {({id, name, onChange, onBlur, disabled, value}) => (
  34. <FullSizeTextAreaField
  35. id={id}
  36. name={name}
  37. aria-label={t('Provide context')}
  38. placeholder={t(
  39. 'This error seems to be caused by ... go look at path/file to make sure it does …'
  40. )}
  41. onChange={e => onChange((e.target as HTMLTextAreaElement).value, e)}
  42. disabled={disabled}
  43. value={value}
  44. onBlur={onBlur}
  45. maxRows={20}
  46. autoFocus
  47. style={{resize: 'none'}}
  48. />
  49. )}
  50. </FullSizeFieldGroup>
  51. </div>
  52. <Footer>
  53. <FooterButtons>
  54. <Button onClick={closeModal}>{t('Cancel')}</Button>
  55. <Button
  56. priority="primary"
  57. type="submit"
  58. analyticsEventKey="autofix.start_fix_with_instructions_clicked"
  59. analyticsEventName="Autofix: Start Fix With Instructions Clicked"
  60. analyticsParams={{group_id: groupId}}
  61. >
  62. {t("Let's go!")}
  63. </Button>
  64. </FooterButtons>
  65. </Footer>
  66. </Form>
  67. );
  68. }
  69. const FullSizeTextAreaField = styled(TextareaAutosize)`
  70. padding: 0;
  71. width: 100%;
  72. border: none;
  73. resize: none;
  74. min-height: 100px;
  75. &:focus {
  76. outline: none;
  77. }
  78. &::placeholder {
  79. color: ${p => p.theme.subText};
  80. }
  81. `;
  82. const FullSizeFieldGroup = styled(FormField)`
  83. padding: 0;
  84. `;
  85. const FooterButtons = styled('div')`
  86. display: grid;
  87. gap: ${space(1)};
  88. grid-auto-flow: column;
  89. justify-content: flex-end;
  90. flex: 1;
  91. `;