Skip to content

Commit

Permalink
Merge pull request #2282 from abilpraju-aot/feature/FWF-3677-process-…
Browse files Browse the repository at this point in the history
…diagram

updated with modal on downloading  bpmn
  • Loading branch information
arun-s-aot authored Oct 24, 2024
2 parents 8f6979b + 31c1575 commit 35494c7
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 100 deletions.
3 changes: 2 additions & 1 deletion forms-flow-web/src/apiManager/endpoints/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ const API = {
GET_BPM_TASK_FILTERS : `${BPM_BASE_URL_EXT}/v1/task-filters`,
VALIDATE_TENANT: `${MT_ADMIN_BASE_URL}/${MT_ADMIN_BASE_URL_VERSION}/tenants/<tenant_id>/validate`,
VALIDATE_FORM_NAME: `${WEB_BASE_URL}/form/validate`,
EXPORT_FORM: `${WEB_BASE_URL}/form/<form_id>/export`
EXPORT_FORM: `${WEB_BASE_URL}/form/<form_id>/export`,
GET_PROCESS_XML: `${WEB_BASE_URL}/process/<process_key>`
};

export default API;
13 changes: 6 additions & 7 deletions forms-flow-web/src/apiManager/services/processServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
setAllDmnProcessList,
setBpmnModel,
setApplicationCount,
setSubflowCount
setSubflowCount,
setProcessData
} from "../../actions/processActions";
import { replaceUrl } from "../../helper/helper";
import { StorageService } from "@formsflow/service";
Expand Down Expand Up @@ -470,11 +471,9 @@ export const getProcessActivities = (process_instance_id, ...rest) => {
export const fetchDiagram = (
process_key,
tenant_key = null,
isDmn = false,
...rest
) => {
const api = isDmn ? API.DMN_XML : API.PROCESSES_XML;

const api = API.GET_PROCESS_XML;
let url = replaceUrl(api, "<process_key>", process_key);

if (tenant_key) {
Expand All @@ -490,10 +489,10 @@ export const fetchDiagram = (
true
)
.then((res) => {
if (res.data && (isDmn ? res.data.dmnXml : res.data.bpmn20Xml)) {
if (res.data) {
dispatch(
setProcessDiagramXML(isDmn ? res.data.dmnXml : res.data.bpmn20Xml)
);
setProcessDiagramXML(res.data.processData));
dispatch(setProcessData(res.data));

// console.log('res.data.bpmn20Xml>>',res.data.bpmn20Xml);
} else {
Expand Down
28 changes: 20 additions & 8 deletions forms-flow-web/src/components/Modals/ActionModal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import Modal from "react-bootstrap/Modal";
import { CustomButton } from "@formsflow/components";
import { DuplicateIcon, ImportIcon, PencilIcon, SaveTemplateIcon, CloseIcon } from "@formsflow/components";
import { DuplicateIcon, ImportIcon, PencilIcon, SaveTemplateIcon, CloseIcon, TrashIcon } from "@formsflow/components";

const ActionModal = React.memo(({ newActionModal, onClose, CategoryType, onAction }) => {
const handleAction = (actionType)=>{
Expand Down Expand Up @@ -49,7 +49,7 @@ const ActionModal = React.memo(({ newActionModal, onClose, CategoryType, onActio
variant="secondary"
size="sm"
label="Import"
icon={<ImportIcon color="#253DF4" />}
icon={<ImportIcon />}
className=""
dataTestid="import-form-button"
ariaLabel="Import Form"
Expand All @@ -60,7 +60,7 @@ const ActionModal = React.memo(({ newActionModal, onClose, CategoryType, onActio
variant="secondary"
size="sm"
label="Export"
icon={<PencilIcon color="#253DF4" />}
icon={<PencilIcon />}
className=""
dataTestid="export-form-button"
ariaLabel="Export Form"
Expand All @@ -71,7 +71,7 @@ const ActionModal = React.memo(({ newActionModal, onClose, CategoryType, onActio
variant="secondary"
size="sm"
label="Delete"
icon={<CloseIcon color="#253DF4" />}
icon={<TrashIcon />}
className=""
dataTestid="delete-form-button"
ariaLabel="Delete Form"
Expand All @@ -89,34 +89,46 @@ const ActionModal = React.memo(({ newActionModal, onClose, CategoryType, onActio
variant="secondary"
size="sm"
label="Duplicate"
icon={<DuplicateIcon color="#253DF4" />}
icon={<DuplicateIcon />}
className=""
dataTestid="duplicate-workflow-button"
ariaLabel="Duplicate Workflow"
onClick={() => handleAction("DUPLICATE")}
/>


<CustomButton
variant="secondary"
size="sm"
label="Import"
icon={<ImportIcon color="#253DF4" />}
icon={<ImportIcon />}
className=""
dataTestid="import-workflow-button"
ariaLabel="Import Workflow"
onClick={() => handleAction("IMPORT")}
/>


<CustomButton
variant="secondary"
size="sm"
label="Export"
icon={<PencilIcon color="#253DF4" />}
icon={<PencilIcon />}
className=""
dataTestid="export-workflow-button"
ariaLabel="Export Workflow"
onClick={() => handleAction("EXPORT")}
/>
<CustomButton
variant="secondary"
size="sm"
label="Delete"
icon={<TrashIcon />}
className=""
dataTestid="delete-workflow-button"
ariaLabel="Delete Workflow"
onClick={() => handleAction("DELETE")}
/>

</div>
)}
</Modal.Body>
Expand Down
164 changes: 164 additions & 0 deletions forms-flow-web/src/components/Modals/ExportDiagrams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import React, { useState, useEffect } from "react";
import Modal from "react-bootstrap/Modal";
import ProgressBar from "react-bootstrap/ProgressBar";
import { CloseIcon, CustomButton, FailedIcon } from "@formsflow/components"; // Icons for success/failure
import { Translation } from "react-i18next";

const ExportDiagram = React.memo(
({
showExportModal,
onClose,
onExport,
fileName,
modalTitle = "Export BPMN",
successMessage = "Export Successful",
errorMessage = null,
retryButtonText = "Try Again",
cancelButtonText = "Cancel",
}) => {
const [state, setState] = useState({
progress: 0,
exportStatus: "Export in Progress",
isExportComplete: false,
isError: false,
});

const { progress, exportStatus, isExportComplete, isError } = state;

// Helper function to reset state for retry or new export
const resetState = (hasError = false) => {
setState({
progress: hasError ? 100 : 0, // Set progress to 100 in case of error
exportStatus: hasError ? "Export failed" : "Export in Progress",
isExportComplete: hasError, // Set complete only in case of error
isError: hasError,
});
};

const exportData = () => {
resetState(); // Reset to initial state for new export
onExport({
onProgress: (percentCompleted) => {
setState((prevState) => ({
...prevState,
progress: percentCompleted,
}));
},
})
.then(() => {
setState((prevState) => ({
...prevState,
progress: 100,
isExportComplete: true,
isError: !!errorMessage, // If errorMessage exists, it's an error case
exportStatus: errorMessage ? "Export failed" : successMessage,
}));
})
.catch(() => {
setState({
progress: 100, // Ensure progress reaches 100 in error case
exportStatus: "Export failed",
isExportComplete: true,
isError: true,
});
});
};

useEffect(() => {
if (showExportModal) {
if (!errorMessage) {
exportData(); // Start export if there's no error
} else {
resetState(true); // If errorMessage exists, set error state
}
} else {
resetState(); // Reset modal state when closed
}
}, [showExportModal, errorMessage]);

return (
<Modal
show={showExportModal}
onHide={onClose}
centered
aria-labelledby="contained-modal-title-vcenter"
scrollable
size="sm"
>
<Modal.Header>
<Modal.Title>
<b>
<Translation>{(t) => t(modalTitle)}</Translation>
</b>
</Modal.Title>
<div className="d-flex align-items-center">
<CloseIcon width="16.5" height="16.5" onClick={onClose} />
</div>
</Modal.Header>
<Modal.Body className="build-modal-body">
<ProgressBar
now={progress}
animated={!isExportComplete && !isError}
variant="primary"
/>
<div className="mt-2 text-wrap d-flex align-items-center">
<span className="text-dark">{fileName}&nbsp;</span>
<span className={isError ? "text-danger" : "text-primary"}>
{isError ? (
<>
<Translation>
{(t) => (
<>
{t(exportStatus)} <FailedIcon color="ff-danger" />
</>
)}
</Translation>
</>
) : (
<Translation>{(t) => t(successMessage)}</Translation>
)}
</span>
</div>
{isError && (
<div className="text-danger mt-2">
<p>
<Translation>
{(t) =>
t(
"A system error occurred during export. Please try again."
)
}
</Translation>
</p>
</div>
)}
</Modal.Body>
{isError && <Modal.Footer className="d-flex justify-content-start flex-wrap">
<>
<CustomButton
variant="primary"
size="md"
label={<Translation>{(t) => t(retryButtonText)}</Translation>}
onClick={exportData}
className="mb-2"
dataTestid="try-again"
ariaLabel="Try Again"
/>
<CustomButton
variant="secondary"
size="md"
label={<Translation>{(t) => t(cancelButtonText)}</Translation>}
onClick={onClose}
className="mb-2"
dataTestid="cancel"
ariaLabel="Cancel"
/>
</>
</Modal.Footer>
}
</Modal>
);
}
);

export default ExportDiagram;
Loading

0 comments on commit 35494c7

Please sign in to comment.