Skip to content

Commit

Permalink
Extract and refactor clean queue dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Sep 26, 2024
1 parent 827baa6 commit 74a7634
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 74 deletions.
20 changes: 11 additions & 9 deletions ui/src/components/DraggableModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ import React from 'react';
import { Modal } from 'react-bootstrap';
import Draggable from 'react-draggable';

class DraggableModalDialog extends React.Component {
render() {
return (
<Draggable handle=".modal-header" defaultPosition={this.props.defaultpos}>
<Modal.Dialog {...this.props} />
</Draggable>
);
}
function DraggableModalDialog(props) {
const { defaultpos } = props;

return (
<Draggable handle=".modal-header" defaultPosition={defaultpos}>
<Modal.Dialog {...props} />
</Draggable>
);
}

export function DraggableModal(props) {
const { children } = props;

return (
<Modal
dialogAs={DraggableModalDialog}
enforceFocus={false}
backdrop="static"
{...props}
>
{props.children}
{children}
</Modal>
);
}
90 changes: 40 additions & 50 deletions ui/src/components/GenericDialog/ConfirmActionDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,46 @@
/* eslint-disable react/jsx-handler-names */
import React from 'react';
import { Modal, Button } from 'react-bootstrap';

export default class ConfirmActionDialog extends React.Component {
constructor(props) {
super(props);
this.onOkClick = this.onOkClick.bind(this);
this.onCancelClick = this.onCancelClick.bind(this);
}
function ConfirmActionDialog(props) {
const {
title,
okBtnLabel = 'OK',
cancelBtnLabel = 'Cancel',
show = false,
children,
onHide,
onOk,
onCancel,
} = props;

onOkClick() {
if (this.props.onOk) {
this.props.onOk();
}

this.props.hide();
}

onCancelClick() {
if (this.props.onCancel) {
this.props.onCancel();
}

this.props.hide();
}

render() {
return (
<Modal show={this.props.show}>
<Modal.Header>
<Modal.Title>{this.props.title}</Modal.Title>
</Modal.Header>
<Modal.Body>{this.props.message}</Modal.Body>
<Modal.Footer>
<Button variant="outline-secondary" onClick={this.onCancelClick}>
{this.props.cancelButtonText}
</Button>
<Button variant="outline-secondary" onClick={this.onOkClick}>
{this.props.okButtonText}
</Button>
</Modal.Footer>
</Modal>
);
}
return (
<Modal show={show} data-default-styles onHide={onHide}>
<Modal.Header>
<Modal.Title>{title}</Modal.Title>
</Modal.Header>
<Modal.Body>{children}</Modal.Body>
<Modal.Footer>
<Button
variant="warning"
onClick={() => {
onOk?.();
onHide();
}}
>
{okBtnLabel}
</Button>
<Button
variant="outline-secondary"
onClick={() => {
onCancel?.();
onHide();
}}
>
{cancelBtnLabel}
</Button>
</Modal.Footer>
</Modal>
);
}

ConfirmActionDialog.defaultProps = {
show: false,
title: '',
message: '',
okButtonText: 'Ok',
cancelButtonText: 'Cancel',
onOk: false,
onCancel: false,
};
export default ConfirmActionDialog;
2 changes: 2 additions & 0 deletions ui/src/components/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import './rachat.css';
import { getInitialState } from '../actions/login';
import MXNavbar from './MXNavbar/MXNavbar';
import ChatWidget from './ChatWidget';
import ClearQueueDialog from './SampleGrid/ClearQueueDialog';

function Main() {
const dispatch = useDispatch();
Expand Down Expand Up @@ -54,6 +55,7 @@ function Main() {
)}

<SelectProposalContainer />
<ClearQueueDialog />
<TaskContainer />
<PleaseWaitDialog />
<ErrorNotificationPanel />
Expand Down
26 changes: 26 additions & 0 deletions ui/src/components/SampleGrid/ClearQueueDialog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import ConfirmActionDialog from '../GenericDialog/ConfirmActionDialog';
import { useDispatch, useSelector } from 'react-redux';
import { clearQueue } from '../../actions/queue';
import { showConfirmClearQueueDialog } from '../../actions/general';

function ClearQueueDialog() {
const dispatch = useDispatch();
const show = useSelector(
(state) => state.general.showConfirmClearQueueDialog,
);

return (
<ConfirmActionDialog
title="Clear sample grid?"
okBtnLabel="Clear"
show={show}
onOk={() => dispatch(clearQueue())}
onHide={() => dispatch(showConfirmClearQueueDialog(false))}
>
This will remove all samples and collections from the grid.
</ConfirmActionDialog>
);
}

export default ClearQueueDialog;
15 changes: 0 additions & 15 deletions ui/src/containers/SampleListViewContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
} from '../actions/sampleGrid';

import {
clearQueue,
deleteSamplesFromQueue,
setEnabledSample,
addSamplesToQueue,
Expand All @@ -54,7 +53,6 @@ import { showTaskForm } from '../actions/taskForm';

import SampleGridTableContainer from './SampleGridTableContainer';

import ConfirmActionDialog from '../components/GenericDialog/ConfirmActionDialog';
import QueueSettings from './QueueSettings.jsx';

import '../components/SampleGrid/SampleGridTable.css';
Expand Down Expand Up @@ -789,14 +787,6 @@ class SampleListViewContainer extends React.Component {
id="sampleGridContainer"
className="samples-grid-table-container mt-4"
>
<ConfirmActionDialog
title="Clear sample grid ?"
message="This will remove all samples (and collections) from the grid,
are you sure you would like to continue ?"
onOk={this.props.clearQueue}
show={this.props.general.showConfirmClearQueueDialog}
hide={this.props.confirmClearQueueHide}
/>
{this.props.loading ? (
<div
className="center-in-box"
Expand Down Expand Up @@ -1016,17 +1006,12 @@ function mapDispatchToProps(dispatch) {
dispatch(setEnabledSample(qidList, value)),
deleteTask: (qid, taskIndex) => dispatch(deleteTask(qid, taskIndex)),
deleteTaskList: (sampleIDList) => dispatch(deleteTaskList(sampleIDList)),
clearQueue: () => dispatch(clearQueue()),
addSamplesToQueue: (sampleData) => dispatch(addSamplesToQueue(sampleData)),
stopQueue: () => dispatch(stopQueue()),
confirmClearQueueShow: bindActionCreators(
showConfirmClearQueueDialog,
dispatch,
),
confirmClearQueueHide: bindActionCreators(
showConfirmClearQueueDialog.bind(null, false),
dispatch,
),
showConfirmCollectDialog: bindActionCreators(
showConfirmCollectDialog,
dispatch,
Expand Down

0 comments on commit 74a7634

Please sign in to comment.