customIgnoreCountModal.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from 'react';
  2. import {ModalRenderProps} from 'app/actionCreators/modal';
  3. import Button from 'app/components/button';
  4. import ButtonBar from 'app/components/buttonBar';
  5. import {t} from 'app/locale';
  6. import {Choices, ResolutionStatusDetails} from 'app/types';
  7. import InputField from 'app/views/settings/components/forms/inputField';
  8. import SelectField from 'app/views/settings/components/forms/selectField';
  9. type CountNames = 'ignoreCount' | 'ignoreUserCount';
  10. type WindowNames = 'ignoreWindow' | 'ignoreUserWindow';
  11. type Props = ModalRenderProps & {
  12. onSelected: (statusDetails: ResolutionStatusDetails) => void;
  13. label: string;
  14. countLabel: string;
  15. countName: CountNames;
  16. windowName: WindowNames;
  17. windowChoices: Choices;
  18. };
  19. type State = {
  20. count: number;
  21. window: number | null;
  22. };
  23. class CustomIgnoreCountModal extends React.Component<Props, State> {
  24. state: State = {
  25. count: 100,
  26. window: null,
  27. };
  28. handleSubmit = () => {
  29. const {count, window} = this.state;
  30. const {countName, windowName} = this.props;
  31. const statusDetails: ResolutionStatusDetails = {[countName]: count};
  32. if (window) {
  33. statusDetails[windowName] = window;
  34. }
  35. this.props.onSelected(statusDetails);
  36. this.props.closeModal();
  37. };
  38. handleChange = (name: keyof State, value: number) => {
  39. this.setState({[name]: value} as State);
  40. };
  41. render() {
  42. const {
  43. Header,
  44. Footer,
  45. Body,
  46. countLabel,
  47. label,
  48. closeModal,
  49. windowChoices,
  50. } = this.props;
  51. const {count, window} = this.state;
  52. return (
  53. <React.Fragment>
  54. <Header>
  55. <h4>{label}</h4>
  56. </Header>
  57. <Body>
  58. <InputField
  59. inline={false}
  60. flexibleControlStateSize
  61. stacked
  62. label={countLabel}
  63. name="count"
  64. type="number"
  65. value={count}
  66. onChange={val => this.handleChange('count' as 'count', Number(val))}
  67. required
  68. placeholder={t('e.g. 100')}
  69. />
  70. <SelectField
  71. inline={false}
  72. flexibleControlStateSize
  73. stacked
  74. label={t('Time window')}
  75. value={window}
  76. name="window"
  77. onChange={val => this.handleChange('window' as const, val)}
  78. choices={windowChoices}
  79. placeholder={t('e.g. per hour')}
  80. allowClear
  81. help={t('(Optional) If supplied, this rule will apply as a rate of change.')}
  82. />
  83. </Body>
  84. <Footer>
  85. <ButtonBar gap={1}>
  86. <Button type="button" onClick={closeModal}>
  87. {t('Cancel')}
  88. </Button>
  89. <Button type="button" priority="primary" onClick={this.handleSubmit}>
  90. {t('Ignore')}
  91. </Button>
  92. </ButtonBar>
  93. </Footer>
  94. </React.Fragment>
  95. );
  96. }
  97. }
  98. export default CustomIgnoreCountModal;