2020-08-27 15:39:16 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { AppState } from "reducers";
|
2021-12-15 11:51:57 +00:00
|
|
|
import { Keys } from "@blueprintjs/core";
|
2020-08-27 15:39:16 +00:00
|
|
|
import {
|
|
|
|
|
showRunActionConfirmModal,
|
|
|
|
|
cancelRunActionConfirmModal,
|
|
|
|
|
acceptRunActionConfirmModal,
|
2021-08-27 09:25:28 +00:00
|
|
|
} from "actions/pluginActionActions";
|
2021-11-01 04:54:06 +00:00
|
|
|
import DialogComponent from "components/ads/DialogComponent";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import Button, { Category, Size } from "components/ads/Button";
|
|
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
QUERY_CONFIRMATION_MODAL_MESSAGE,
|
|
|
|
|
} from "constants/messages";
|
2020-08-27 15:39:16 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
isModalOpen: boolean;
|
|
|
|
|
dispatch: any;
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-01 04:54:06 +00:00
|
|
|
const ModalBody = styled.div`
|
|
|
|
|
padding-bottom: 20px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ModalFooter = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
|
|
|
|
button {
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-08-27 15:39:16 +00:00
|
|
|
class ConfirmRunModal extends React.Component<Props> {
|
2021-12-15 11:51:57 +00:00
|
|
|
addEventListener = () => {
|
|
|
|
|
document.addEventListener("keydown", this.onKeyUp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
removeEventListener = () => {
|
|
|
|
|
document.removeEventListener("keydown", this.onKeyUp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onKeyUp = (event: KeyboardEvent) => {
|
|
|
|
|
if (event.keyCode === Keys.ENTER) {
|
|
|
|
|
this.onConfirm();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onConfirm = () => {
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
dispatch(acceptRunActionConfirmModal());
|
|
|
|
|
this.handleClose();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleClose = () => {
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
dispatch(showRunActionConfirmModal(false));
|
|
|
|
|
dispatch(cancelRunActionConfirmModal());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
|
const { isModalOpen } = this.props;
|
|
|
|
|
if (isModalOpen) {
|
|
|
|
|
this.addEventListener();
|
|
|
|
|
} else {
|
|
|
|
|
this.removeEventListener();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 15:39:16 +00:00
|
|
|
render() {
|
|
|
|
|
const { dispatch, isModalOpen } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
2021-11-01 04:54:06 +00:00
|
|
|
<DialogComponent
|
2021-12-15 11:51:57 +00:00
|
|
|
canEscapeKeyClose
|
2021-11-01 04:54:06 +00:00
|
|
|
isOpen={isModalOpen}
|
|
|
|
|
maxHeight={"80vh"}
|
2021-12-15 11:51:57 +00:00
|
|
|
onClose={this.handleClose}
|
2021-11-01 04:54:06 +00:00
|
|
|
title="Confirm Action"
|
|
|
|
|
width={"580px"}
|
|
|
|
|
>
|
|
|
|
|
<ModalBody>{createMessage(QUERY_CONFIRMATION_MODAL_MESSAGE)}</ModalBody>
|
|
|
|
|
<ModalFooter>
|
|
|
|
|
<Button
|
|
|
|
|
category={Category.tertiary}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
dispatch(cancelRunActionConfirmModal());
|
2021-12-15 11:51:57 +00:00
|
|
|
this.handleClose();
|
2021-11-01 04:54:06 +00:00
|
|
|
}}
|
|
|
|
|
size={Size.medium}
|
|
|
|
|
tag="button"
|
|
|
|
|
text="Cancel"
|
|
|
|
|
type="button"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
category={Category.primary}
|
2021-12-15 11:51:57 +00:00
|
|
|
onClick={this.onConfirm}
|
2021-11-01 04:54:06 +00:00
|
|
|
size={Size.medium}
|
|
|
|
|
tag="button"
|
|
|
|
|
text="Confirm"
|
|
|
|
|
type="button"
|
|
|
|
|
/>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</DialogComponent>
|
2020-08-27 15:39:16 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
|
|
|
isModalOpen: state.ui.confirmRunAction.modalOpen,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ConfirmRunModal);
|