customResolutionModal.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Component} from 'react';
  2. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  3. import Button from 'sentry/components/button';
  4. import {SelectAsyncField} from 'sentry/components/deprecatedforms';
  5. import TimeSince from 'sentry/components/timeSince';
  6. import Version from 'sentry/components/version';
  7. import {t} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {Release} from 'sentry/types';
  10. type Props = ModalRenderProps & {
  11. onSelected: ({inRelease: string}) => void;
  12. orgSlug: string;
  13. projectSlug?: string;
  14. };
  15. type State = {
  16. version: string;
  17. };
  18. class CustomResolutionModal extends Component<Props, State> {
  19. state: State = {
  20. version: '',
  21. };
  22. onChange = (value: string | number | boolean) => {
  23. this.setState({version: value as string}); // TODO(ts): Add select value type as generic to select controls
  24. };
  25. onAsyncFieldResults = (results: Release[]) =>
  26. results.map(release => ({
  27. value: release.version,
  28. label: <Version version={release.version} anchor={false} />,
  29. details: (
  30. <span>
  31. {t('Created')} <TimeSince date={release.dateCreated} />
  32. </span>
  33. ),
  34. release,
  35. }));
  36. render() {
  37. const {orgSlug, projectSlug, closeModal, onSelected, Header, Body, Footer} =
  38. this.props;
  39. const url = projectSlug
  40. ? `/projects/${orgSlug}/${projectSlug}/releases/`
  41. : `/organizations/${orgSlug}/releases/`;
  42. const onSubmit = (e: React.FormEvent) => {
  43. e.preventDefault();
  44. onSelected({inRelease: this.state.version});
  45. closeModal();
  46. };
  47. return (
  48. <form onSubmit={onSubmit}>
  49. <Header>{t('Resolved In')}</Header>
  50. <Body>
  51. <SelectAsyncField
  52. label={t('Version')}
  53. id="version"
  54. name="version"
  55. onChange={this.onChange}
  56. placeholder={t('e.g. 1.0.4')}
  57. url={url}
  58. onResults={this.onAsyncFieldResults}
  59. onQuery={query => ({query})}
  60. />
  61. </Body>
  62. <Footer>
  63. <Button type="button" css={{marginRight: space(1.5)}} onClick={closeModal}>
  64. {t('Cancel')}
  65. </Button>
  66. <Button type="submit" priority="primary">
  67. {t('Save Changes')}
  68. </Button>
  69. </Footer>
  70. </form>
  71. );
  72. }
  73. }
  74. export default CustomResolutionModal;