123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import {Component, createRef, Fragment} from 'react';
- import moment from 'moment';
- import {sprintf} from 'sprintf-js';
- import {ModalRenderProps} from 'sentry/actionCreators/modal';
- import Alert from 'sentry/components/alert';
- import Button from 'sentry/components/button';
- import ButtonBar from 'sentry/components/buttonBar';
- import {t} from 'sentry/locale';
- import {ResolutionStatusDetails} from 'sentry/types';
- const defaultProps = {
- label: t('Ignore this issue until \u2026'),
- };
- type Props = ModalRenderProps & {
- onSelected: (details: ResolutionStatusDetails) => void;
- } & typeof defaultProps;
- type State = {
- dateWarning: boolean;
- };
- export default class CustomIgnoreDurationModal extends Component<Props, State> {
- static defaultProps = defaultProps;
- state: State = {
- dateWarning: false,
- };
- snoozeDateInputRef = createRef<HTMLInputElement>();
- snoozeTimeInputRef = createRef<HTMLInputElement>();
- selectedIgnoreMinutes = () => {
- const dateStr = this.snoozeDateInputRef.current?.value; // YYYY-MM-DD
- const timeStr = this.snoozeTimeInputRef.current?.value; // HH:MM
- if (dateStr && timeStr) {
- const selectedDate = moment.utc(dateStr + ' ' + timeStr);
- if (selectedDate.isValid()) {
- const now = moment.utc();
- return selectedDate.diff(now, 'minutes');
- }
- }
- return 0;
- };
- snoozeClicked = () => {
- const minutes = this.selectedIgnoreMinutes();
- if (minutes <= 0) {
- this.setState({
- dateWarning: minutes <= 0,
- });
- return;
- }
- this.props.onSelected({ignoreDuration: minutes});
- this.props.closeModal();
- };
- render() {
- // Give the user a sane starting point to select a date
- // (prettier than the empty date/time inputs):
- const defaultDate = new Date();
- defaultDate.setDate(defaultDate.getDate() + 14);
- defaultDate.setSeconds(0);
- defaultDate.setMilliseconds(0);
- const defaultDateVal = sprintf(
- '%d-%02d-%02d',
- defaultDate.getUTCFullYear(),
- defaultDate.getUTCMonth() + 1,
- defaultDate.getUTCDate()
- );
- const defaultTimeVal = sprintf('%02d:00', defaultDate.getUTCHours());
- const {Header, Body, Footer, label} = this.props;
- return (
- <Fragment>
- <Header>{label}</Header>
- <Body>
- <form className="form-horizontal">
- <div className="control-group">
- <h6 className="nav-header">{t('Date')}</h6>
- <input
- className="form-control"
- type="date"
- id="snooze-until-date"
- defaultValue={defaultDateVal}
- ref={this.snoozeDateInputRef}
- required
- style={{padding: '0 10px'}}
- />
- </div>
- <div className="control-group m-b-1">
- <h6 className="nav-header">{t('Time (UTC)')}</h6>
- <input
- className="form-control"
- type="time"
- id="snooze-until-time"
- defaultValue={defaultTimeVal}
- ref={this.snoozeTimeInputRef}
- style={{padding: '0 10px'}}
- required
- />
- </div>
- </form>
- </Body>
- {this.state.dateWarning && (
- <Alert type="error" showIcon>
- {t('Please enter a valid date in the future')}
- </Alert>
- )}
- <Footer>
- <ButtonBar gap={1}>
- <Button type="button" priority="default" onClick={this.props.closeModal}>
- {t('Cancel')}
- </Button>
- <Button type="button" priority="primary" onClick={this.snoozeClicked}>
- {t('Ignore')}
- </Button>
- </ButtonBar>
- </Footer>
- </Fragment>
- );
- }
- }
|