From 6654e12e582861b7ea9bc5a03db9504809f7bcda Mon Sep 17 00:00:00 2001 From: LaviniaStiliadou Date: Sun, 17 Sep 2023 23:04:47 +0200 Subject: [PATCH] fix lint --- .../editor/ui/ConfirmationModal.js | 56 +++++---- .../editor/ui/NewDiagramButton.js | 110 +++++++++--------- .../editor/util/IoUtilities.js | 5 +- 3 files changed, 95 insertions(+), 76 deletions(-) diff --git a/components/bpmn-q/modeler-component/editor/ui/ConfirmationModal.js b/components/bpmn-q/modeler-component/editor/ui/ConfirmationModal.js index b0cf5651..bcf8642b 100644 --- a/components/bpmn-q/modeler-component/editor/ui/ConfirmationModal.js +++ b/components/bpmn-q/modeler-component/editor/ui/ConfirmationModal.js @@ -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}) =>

{children}

); -const Body = Modal.Body || (({children}) =>
{children}
); -const Footer = Modal.Footer || (({children}) =>
{children}
); +const Title = Modal.Title || (({ children }) =>

{children}

); +const Body = Modal.Body || (({ children }) =>
{children}
); +const Footer = Modal.Footer || (({ children }) =>
{children}
); /** * Modal component for confirming the discard of changes in the editor. @@ -24,20 +24,32 @@ const Footer = Modal.Footer || (({children}) =>
{children}
); * @returns {JSX.Element} The modal as a React component. * @constructor */ -export default function ConfirmationModal({onClose, onConfirm}) { - - return - - Confirm Discard Changes - - - There are unsaved changes. Are you sure you want to discard all changes and generate a new diagram? - -
-
- - -
-
-
; -} \ No newline at end of file +export default function ConfirmationModal({ onClose, onConfirm }) { + return ( + + Confirm Discard Changes + + There are unsaved changes. Are you sure you want to discard all changes + and generate a new diagram? + +
+
+ + +
+
+
+ ); +} diff --git a/components/bpmn-q/modeler-component/editor/ui/NewDiagramButton.js b/components/bpmn-q/modeler-component/editor/ui/NewDiagramButton.js index 528a5467..776d992d 100644 --- a/components/bpmn-q/modeler-component/editor/ui/NewDiagramButton.js +++ b/components/bpmn-q/modeler-component/editor/ui/NewDiagramButton.js @@ -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 ( -
- + return ( +
+ - {showConfirmationModal && ( - - )} -
- ); + {showConfirmationModal && ( + + )} +
+ ); } diff --git a/components/bpmn-q/modeler-component/editor/util/IoUtilities.js b/components/bpmn-q/modeler-component/editor/util/IoUtilities.js index a15039ae..fa6ca2d6 100644 --- a/components/bpmn-q/modeler-component/editor/util/IoUtilities.js +++ b/components/bpmn-q/modeler-component/editor/util/IoUtilities.js @@ -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; } }