nameAndDescFields.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import TextArea from 'sentry/components/forms/controls/textarea';
  5. import Input from 'sentry/components/input';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import {SectionHeader} from 'sentry/views/dashboards/widgetBuilder/components/common/sectionHeader';
  9. import {useWidgetBuilderContext} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
  10. import {BuilderStateAction} from 'sentry/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState';
  11. function WidgetBuilderNameAndDescription() {
  12. const {state, dispatch} = useWidgetBuilderContext();
  13. const [isDescSelected, setIsDescSelected] = useState(state.description ? true : false);
  14. return (
  15. <Fragment>
  16. <SectionHeader title={t('Widget Name & Description')} />
  17. <StyledInput
  18. size="md"
  19. placeholder={t('Name')}
  20. title={t('Widget Name')}
  21. type="text"
  22. aria-label={t('Widget Name')}
  23. value={state.title}
  24. onChange={e => {
  25. dispatch({type: BuilderStateAction.SET_TITLE, payload: e.target.value});
  26. }}
  27. />
  28. {!isDescSelected && (
  29. <AddDescriptionButton
  30. priority="link"
  31. aria-label={t('Add Widget Description')}
  32. onClick={() => {
  33. setIsDescSelected(true);
  34. }}
  35. data-test-id={'add-description'}
  36. >
  37. {t('+ Add Widget Description')}
  38. </AddDescriptionButton>
  39. )}
  40. {isDescSelected && (
  41. <DescriptionTextArea
  42. placeholder={t('Description')}
  43. aria-label={t('Widget Description')}
  44. autosize
  45. rows={4}
  46. value={state.description}
  47. onChange={e => {
  48. dispatch({type: BuilderStateAction.SET_DESCRIPTION, payload: e.target.value});
  49. }}
  50. />
  51. )}
  52. </Fragment>
  53. );
  54. }
  55. export default WidgetBuilderNameAndDescription;
  56. const StyledInput = styled(Input)`
  57. margin-bottom: ${space(1)};
  58. `;
  59. const AddDescriptionButton = styled(Button)`
  60. margin-bottom: ${space(1)};
  61. `;
  62. const DescriptionTextArea = styled(TextArea)`
  63. margin: ${space(2)} 0;
  64. `;