Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirmation modal #211

Merged
merged 17 commits into from Jul 18, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to鈥
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

add confirmation modal

  • Loading branch information...
bpostlethwaite committed Jun 14, 2018
commit 425c811feb67576392693dbb61a71c981aaa23c2
@@ -0,0 +1,68 @@
import PropTypes from 'prop-types';
import {Component} from 'react';

/**
* Confirm wraps window.confirm
*/
export default class Confirm extends Component {

constructor(props) {
super(props);
}

componentDidUpdate(prevProps) {
const previouslyAsked = prevProps.init && prevProps.init.ask;
const currentlyAsking = this.props.init && this.props.init.ask;

if (!previouslyAsked && currentlyAsking) {
const accepted = window.confirm(this.props.message);
if (!this.props.setProps) {
return;
}
if (!accepted && !this.props.call_on_cancel) {
this.props.setProps({init: {ask: false}});
} else {
this.props.setProps({
result: {
timestamp: Date.now(),
value: this.props.init.value,
accepted: accepted
},
init: {
ask: false
}
})
}
}
}

render() {
return null;
}
}

Confirm.defaultProps = {
result: {
timestamp: -1
},
call_on_cancel: false
}

Confirm.propTypes = {
id: PropTypes.string,
message: PropTypes.string,
init: PropTypes.shape({
value: PropTypes.any,
ask: PropTypes.bool
}),
call_on_cancel: PropTypes.bool,
result: PropTypes.shape({
timestamp: PropTypes.integer,
value: PropTypes.any
}),

/**
* Dash-assigned callback that gets fired when the value changes.
*/
setProps: PropTypes.func
};
@@ -15,9 +15,11 @@ import Textarea from './components/Textarea.react';
import DatePickerSingle from './components/DatePickerSingle.react';
import DatePickerRange from './components/DatePickerRange.react';
import Upload from './components/Upload.react';
import Confirm from './components/Confirm.react';

export {
Checklist,
Confirm,
Dropdown,
Graph,
Input,
ProTip! Use n and p to navigate between commits in a pull request.
You can鈥檛 perform that action at this time.