nameAndDescFields.tsx 2.2 KB

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