customResolutionModal.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Fragment, useState} from 'react';
  2. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  3. import Button from 'sentry/components/button';
  4. import SelectAsyncField from 'sentry/components/deprecatedforms/selectAsyncField';
  5. import TimeSince from 'sentry/components/timeSince';
  6. import Version from 'sentry/components/version';
  7. import {t} from 'sentry/locale';
  8. import configStore from 'sentry/stores/configStore';
  9. import space from 'sentry/styles/space';
  10. import type {Release} from 'sentry/types';
  11. interface CustomResolutionModalProps extends ModalRenderProps {
  12. onSelected: (change: {inRelease: string}) => void;
  13. orgSlug: string;
  14. projectSlug?: string;
  15. }
  16. function CustomResolutionModal(props: CustomResolutionModalProps) {
  17. const [version, setVersion] = useState('');
  18. const currentUser = configStore.get('user');
  19. const onChange = (value: any) => {
  20. setVersion(value.item);
  21. };
  22. const onAsyncFieldResults = (results: Release[]) => {
  23. return results.map(release => {
  24. const isAuthor = release.authors.some(
  25. author => author.email && author.email === currentUser?.email
  26. );
  27. return {
  28. item: release.version,
  29. label: <Version version={release.version} anchor={false} />,
  30. details: (
  31. <span>
  32. {t('Created')} <TimeSince date={release.dateCreated} />
  33. {isAuthor ? <Fragment> — {t('You committed')}</Fragment> : null}
  34. </span>
  35. ),
  36. release,
  37. };
  38. });
  39. };
  40. const url = props.projectSlug
  41. ? `/projects/${props.orgSlug}/${props.projectSlug}/releases/`
  42. : `/organizations/${props.orgSlug}/releases/`;
  43. const onSubmit = (e: React.FormEvent) => {
  44. e.preventDefault();
  45. props.onSelected({inRelease: version});
  46. props.closeModal();
  47. };
  48. const {Header, Body, Footer} = props;
  49. return (
  50. <form onSubmit={onSubmit}>
  51. <Header>
  52. <h4>{t('Resolved In')}</h4>
  53. </Header>
  54. <Body>
  55. <SelectAsyncField
  56. label={t('Version')}
  57. id="version"
  58. name="version"
  59. onChange={onChange}
  60. placeholder={t('e.g. 1.0.4')}
  61. url={url}
  62. onResults={onAsyncFieldResults}
  63. onQuery={query => ({query})}
  64. />
  65. </Body>
  66. <Footer>
  67. <Button type="button" css={{marginRight: space(1.5)}} onClick={props.closeModal}>
  68. {t('Cancel')}
  69. </Button>
  70. <Button type="submit" priority="primary">
  71. {t('Save Changes')}
  72. </Button>
  73. </Footer>
  74. </form>
  75. );
  76. }
  77. export default CustomResolutionModal;