-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f24afa8
commit 6654e12
Showing
3 changed files
with
95 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 57 additions & 53 deletions
110
components/bpmn-q/modeler-component/editor/ui/NewDiagramButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters