<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import Router from 'next/router';
import { withStyles, Button } from '@material-ui/core';

const styles = theme => ({
  actionBox: {
    display: 'flex',
    flex: '0 0 auto',
    flexWrap: 'wrap',
    justifyContent: 'flex-end',
    marginTop: theme.spacing.unit,
  },
  saveButton: {
    width: '33%',
  },
  cancelButton: {
    width: '25%',
    marginRight: theme.spacing.unit,
  },
  [theme.breakpoints.down('xs')]: {
    saveButton: {
      width: '100%',
    },
    cancelButton: {
      marginRight: 0,
      marginTop: theme.spacing.unit,
      width: '100%',
      order: 1,
    },
  },
});

const QuestionFormActionBox = ({ classes, formikProps }) => (
  <div className={classes.actionBox}>
    <Button
      disabled={formikProps.isSubmitting}
      onClick={() => {
        // We should check if form is dirty before leaving page.
        // And show a dialog for confirmation.
        Router.push(`/admin/questao?id=${formikProps.values.id}`);
      }}
      className={classes.cancelButton}
      size="large"
      variant="outlined"
    >
      Cancelar
    </Button>
    <Button
      disabled={formikProps.isSubmitting}
      type="submit"
      className={classes.saveButton}
      color="secondary"
      size="large"
      variant="contained"
    >
      Salvar
    </Button>
  </div>
);

QuestionFormActionBox.propTypes = {
  classes: PropTypes.object.isRequired,
  formikProps: PropTypes.object.isRequired,
};

export default withStyles(styles)(QuestionFormActionBox);
<commit_msg>Add warning dialog before canceling question update<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import Router from 'next/router';
import { withStyles, Button } from '@material-ui/core';
import { compose } from 'react-apollo';
import { withState } from 'recompose';
import CancelDialog from '../CancelDialog';

const styles = theme => ({
  actionBox: {
    display: 'flex',
    flex: '0 0 auto',
    flexWrap: 'wrap',
    justifyContent: 'flex-end',
    marginTop: theme.spacing.unit,
  },
  saveButton: {
    width: '33%',
  },
  cancelButton: {
    width: '25%',
    marginRight: theme.spacing.unit,
  },
  [theme.breakpoints.down('xs')]: {
    saveButton: {
      width: '100%',
    },
    cancelButton: {
      marginRight: 0,
      marginTop: theme.spacing.unit,
      width: '100%',
      order: 1,
    },
  },
});

const createCancelEditingHandler = (formikProps, showWarning) => () => {
  if (formikProps.dirty) {
    showWarning(true);
    return;
  }
  Router.push(`/admin/questao?id=${formikProps.values.id}`);
};

const QuestionFormActionBox = ({
  classes,
  formikProps,
  setWarningDialogOpen,
  warningDialogOpen,
}) => (
  <div className={classes.actionBox}>
    <Button
      disabled={formikProps.isSubmitting}
      onClick={createCancelEditingHandler(formikProps, setWarningDialogOpen)}
      className={classes.cancelButton}
      size="large"
      variant="outlined"
    >
      Cancelar
    </Button>
    <CancelDialog
      onCancel={() => setWarningDialogOpen(false)}
      onContinue={() => {
        Router.push(`/admin/questao?id=${formikProps.values.id}`);
      }}
      open={warningDialogOpen}
    />
    <Button
      disabled={formikProps.isSubmitting}
      type="submit"
      className={classes.saveButton}
      color="secondary"
      size="large"
      variant="contained"
    >
      Salvar
    </Button>
  </div>
);

QuestionFormActionBox.propTypes = {
  classes: PropTypes.object.isRequired,
  formikProps: PropTypes.object.isRequired,
  setWarningDialogOpen: PropTypes.func.isRequired,
  warningDialogOpen: PropTypes.bool.isRequired,
};

export default compose(
  withState('warningDialogOpen', 'setWarningDialogOpen', false),
  withStyles(styles),
)(QuestionFormActionBox);

{'fraction_non_alphanumeric': 0.14289439374185137, 'fraction_numerical': 0.007301173402868318, 'mean_word_length': 3.1923497267759564, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3948805', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1202, 'n_words': 234}