Skip to content

Commit

Permalink
Optimized performance and fixed bpmn xml compare issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaib-aot committed Nov 29, 2024
1 parent 6a38cbd commit 4610fc9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions forms-flow-web/src/components/Form/EditForm/FlowEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ const FlowEdit = forwardRef(({ isPublished = false, CategoryType, setWorkflowIsC
}
//if xml is same as existing process data, no need to update
const isEqual = await compareXML(processData?.processData, xml);

if (isEqual && !isReverted) {
showToast && toast.success(t("Process updated successfully"));
disableWorkflowChange();
return;
}

Expand Down
4 changes: 3 additions & 1 deletion forms-flow-web/src/components/Modeler/ProcessCreateEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ const ProcessCreateEdit = ({ type }) => {
if (!isValid) return;

const isEqual = await checkIfEqual(isCreate, xml);
if (!isReverted && !isCreateMode && isEqual)
if (!isReverted && !isCreateMode && isEqual){
disableWorkflowChange();
return handleAlreadyUpToDate(isPublishing);
}

setSavingFlow(true);

Expand Down
23 changes: 13 additions & 10 deletions forms-flow-web/src/helper/processHelper.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { extractDataFromDiagram } from "../components/Modeler/helpers/helper";
import BpmnModdle from "bpmn-moddle";
import DmnModdle from "dmn-moddle";
import isEqual from "lodash/isEqual";
import { toast } from "react-toastify";
import {
ERROR_LINTING_CLASSNAME,
WARNING_LINTING_CLASSNAME,
} from "../components/Modeler/constants/bpmnModelerConstants";
const bpmnModdle = new BpmnModdle();
const dmnModdle = new DmnModdle();

export const parseBpmn = async (xmlString) => {
const { rootElement: definitionsA } = await bpmnModdle.fromXML(xmlString);
return definitionsA;


const normalizeXML = (xmlString) => {
const parser = new DOMParser();
const serializer = new XMLSerializer();
// Parse the XML string to a DOM object
const xmlDoc = parser.parseFromString(xmlString, "application/xml");
// Serialize the DOM back to a string (minimized formatting differences)
return serializer.serializeToString(xmlDoc);
};

export const compareXML = async (xmlString1, xmlString2) => {
try {
// Parse both BPMN XMLs to their JSON structure
const bpmn1 = await parseBpmn(xmlString1);
const bpmn2 = await parseBpmn(xmlString2);
const bpmn1 = normalizeXML(xmlString1);
const bpmn2 = normalizeXML(xmlString2);
// Compare the JSON structures
return isEqual(bpmn1, bpmn2);
return bpmn1 == bpmn2;
} catch (error) {
console.error("Error while comparing BPMN:", error);
}
Expand Down Expand Up @@ -63,7 +66,7 @@ export const validateProcess = (xml, lintErrors, translation = (i) => i) => {
export const createXMLFromModeler = async (modeler) => {
try {
// Convert diagram to xml
let { xml } = await modeler.saveXML();
let { xml } = await modeler.saveXML({ format: true });
// Set isExecutable to true
xml = xml.replaceAll('isExecutable="false"', 'isExecutable="true"');
return xml;
Expand Down

0 comments on commit 4610fc9

Please sign in to comment.