Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
LaviniaStiliadou committed Sep 17, 2023
1 parent f24afa8 commit 6654e12
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 76 deletions.
56 changes: 34 additions & 22 deletions components/bpmn-q/modeler-component/editor/ui/ConfirmationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import Modal from '../ui/modal/Modal';
import React from "react";
import Modal from "../ui/modal/Modal";

// polyfill upcoming structural components
const Title = Modal.Title || (({children}) => <h2>{children}</h2>);
const Body = Modal.Body || (({children}) => <div>{children}</div>);
const Footer = Modal.Footer || (({children}) => <div>{children}</div>);
const Title = Modal.Title || (({ children }) => <h2>{children}</h2>);
const Body = Modal.Body || (({ children }) => <div>{children}</div>);
const Footer = Modal.Footer || (({ children }) => <div>{children}</div>);

/**
* Modal component for confirming the discard of changes in the editor.
Expand All @@ -24,20 +24,32 @@ const Footer = Modal.Footer || (({children}) => <div>{children}</div>);
* @returns {JSX.Element} The modal as a React component.
* @constructor
*/
export default function ConfirmationModal({onClose, onConfirm}) {

return <Modal onClose={onClose}>
<Title>
Confirm Discard Changes
</Title>
<Body>
There are unsaved changes. Are you sure you want to discard all changes and generate a new diagram?
</Body>
<Footer>
<div id="configFormButtons">
<button type="submit" className="qwm-btn qwm-btn-primary" onClick={() => onConfirm()}>Yes</button>
<button type="button" className="qwm-btn qwm-btn-secondary" onClick={() => onClose()}>No</button>
</div>
</Footer>
</Modal>;
}
export default function ConfirmationModal({ onClose, onConfirm }) {
return (
<Modal onClose={onClose}>
<Title>Confirm Discard Changes</Title>
<Body>
There are unsaved changes. Are you sure you want to discard all changes
and generate a new diagram?
</Body>
<Footer>
<div id="configFormButtons">
<button
type="submit"
className="qwm-btn qwm-btn-primary"
onClick={() => onConfirm()}
>
Yes
</button>
<button
type="button"
className="qwm-btn qwm-btn-secondary"
onClick={() => onClose()}
>
No
</button>
</div>
</Footer>
</Modal>
);
}
110 changes: 57 additions & 53 deletions components/bpmn-q/modeler-component/editor/ui/NewDiagramButton.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,67 @@
import React, { useState, useEffect } from 'react';
import { createNewDiagram } from '../util/IoUtilities';
import { getModeler } from '../ModelerHandler';
import ConfirmationModal from './ConfirmationModal';
import React, { useState, useEffect } from "react";
import { createNewDiagram } from "../util/IoUtilities";
import { getModeler } from "../ModelerHandler";
import ConfirmationModal from "./ConfirmationModal";

export default function NewDiagramButton(props) {
const { modeler } = props;
const [unsavedChanges, setUnsavedChanges] = useState(false);
const [showConfirmationModal, setShowConfirmationModal] = useState(false);
const { modeler } = props;
const [unsavedChanges, setUnsavedChanges] = useState(false);
const [showConfirmationModal, setShowConfirmationModal] = useState(false);

useEffect(() => {
if (unsavedChanges) {
setShowConfirmationModal(true);
useEffect(() => {
if (unsavedChanges) {
setShowConfirmationModal(true);
} else {
createNewDiagram(modeler);
}
}, [unsavedChanges, modeler]);

const checkUnsavedChanges = () => {
getModeler().saveXML({ format: true }, function (err, xml) {
if (!err) {
let oldXml = getModeler().oldXml;
if (oldXml !== undefined) {
oldXml = oldXml.trim();
}
if (oldXml !== xml.trim() && oldXml !== undefined) {
setUnsavedChanges(true);
setShowConfirmationModal(true);
} else {
createNewDiagram(modeler);
setShowConfirmationModal(false);
createNewDiagram(modeler);
}
}, [unsavedChanges, modeler]);

const checkUnsavedChanges = () => {
getModeler().saveXML({ format: true }, function (err, xml) {
if (!err) {
let oldXml = getModeler().oldXml;
if (oldXml !== undefined) {
oldXml = oldXml.trim();
}
if (oldXml !== xml.trim() && oldXml !== undefined) {
setUnsavedChanges(true);
setShowConfirmationModal(true);
} else {
setShowConfirmationModal(false);
createNewDiagram(modeler);
}
}
});
};
}
});
};

const handleConfirmDiscard = () => {
createNewDiagram(modeler);
setUnsavedChanges(false);
setShowConfirmationModal(false);
};
const handleConfirmDiscard = () => {
createNewDiagram(modeler);
setUnsavedChanges(false);
setShowConfirmationModal(false);
};

const handleCancelDiscard = () => {
setShowConfirmationModal(false);
};
const handleCancelDiscard = () => {
setShowConfirmationModal(false);
};

return (
<div>
<button className="qwm-toolbar-btn" title="Create a new workflow diagram" onClick={checkUnsavedChanges}>
<span className="qwm-icon-new-file">
<span className="qwm-indent">New Diagram</span>
</span>
</button>
return (
<div>
<button
className="qwm-toolbar-btn"
title="Create a new workflow diagram"
onClick={checkUnsavedChanges}
>
<span className="qwm-icon-new-file">
<span className="qwm-indent">New Diagram</span>
</span>
</button>

{showConfirmationModal && (
<ConfirmationModal
onClose={handleCancelDiscard}
onConfirm={handleConfirmDiscard}
/>
)}
</div>
);
{showConfirmationModal && (
<ConfirmationModal
onClose={handleCancelDiscard}
onConfirm={handleConfirmDiscard}
/>
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ async function openFileDialog(modeler, content, fileName, fileFormat) {
],
});
writeFile(fileHandle, content);
if (fileFormat === saveFileFormats.BPMN || fileFormat === saveFileFormats.ALL) {
if (
fileFormat === saveFileFormats.BPMN ||
fileFormat === saveFileFormats.ALL
) {
modeler.oldXml = content;
}
}
Expand Down

0 comments on commit 6654e12

Please sign in to comment.