Skip to content

Commit

Permalink
FWF-4075 [bugfix] added default task variable on form creation (AOT-T…
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaib-aot authored Dec 13, 2024
1 parent b6104b2 commit 340d0b3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
6 changes: 6 additions & 0 deletions forms-flow-api/src/formsflow_api/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,9 @@ def default_flow_xml_data(name="Defaultflow"):
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>"""


default_task_variables = [
{"key": "applicationId", "label": "Submission Id", "type": "hidden"},
{"key": "applicationStatus", "label": "Submission Status", "type": "hidden"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from formsflow_api_utils.utils.enums import FormProcessMapperStatus
from formsflow_api_utils.utils.user_context import UserContext, user_context

from formsflow_api.constants import BusinessErrorCode, default_flow_xml_data
from formsflow_api.constants import (
BusinessErrorCode,
default_flow_xml_data,
default_task_variables,
)
from formsflow_api.models import (
Application,
Authorization,
Expand Down Expand Up @@ -377,7 +381,7 @@ def create_form(data, is_designer, **kwargs): # pylint:disable=too-many-locals
process_key = None
anonymous = False
description = data.get("description", "")
task_variable = []
task_variable = [*default_task_variables]
is_migrated = True
current_app.logger.info(f"Creating new form {is_new_form}")
# If creating new version for a existing form, fetch process key, name from mapper
Expand Down
4 changes: 2 additions & 2 deletions forms-flow-api/src/formsflow_api/services/import_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from jsonschema import ValidationError, validate
from lxml import etree

from formsflow_api.constants import BusinessErrorCode
from formsflow_api.constants import BusinessErrorCode, default_task_variables
from formsflow_api.models import AuthType, FormHistory, Process, ProcessType
from formsflow_api.schemas import (
FormProcessMapperSchema,
Expand Down Expand Up @@ -414,7 +414,7 @@ def import_new_form_workflow(
"form_type": form_response.get("type"),
"parent_form_id": form_id,
"is_anonymous": file_data.get("forms")[0].get("anonymous") or False,
"task_variable": "[]",
"task_variable": json.dumps(default_task_variables),
"process_key": process_name,
"process_name": process_name,
"status": "inactive",
Expand Down
4 changes: 1 addition & 3 deletions forms-flow-web/src/components/Form/EditForm/FlowEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const FlowEdit = forwardRef(({ isPublished = false, CategoryType,
const { createDesigns } = userRoles();
const [showTaskVarModal, setShowTaskVarModal] = useState(false);
const [isWorkflowChanged, setIsWorkflowChanged] = useState(false);
const formData = useSelector((state) => state.form?.form || {});
const [isMigrationChecked, setIsMigrationChecked] = useState(false);
const [showMigrationModal, setShowMigrationModal] = useState(false);
const [isMigraionLoading, setIsMigraionLoading] = useState(false);
Expand Down Expand Up @@ -371,8 +370,7 @@ const FlowEdit = forwardRef(({ isPublished = false, CategoryType,
disableAllRevertButton={processData.status === "Published"}
/>
{showTaskVarModal && (
<TaskVariableModal
form={formData}
<TaskVariableModal
showTaskVarModal={showTaskVarModal}
onClose={CloseTaskVarModal}
isPublished={isPublished}
Expand Down
32 changes: 10 additions & 22 deletions forms-flow-web/src/components/Modals/TaskVariableModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ import {
import { Form } from "@aot-technologies/formio-react";
import PropTypes from "prop-types";
import { useDispatch ,useSelector } from "react-redux";
import utils from "@aot-technologies/formiojs/lib/utils";
import {
saveFormProcessMapperPut,
} from "../../apiManager/services/processServices";


//TBD in case of Bundle form display
const PillList = React.memo(({ alternativeLabels, onRemove }) => {
const { t } = useTranslation();
return (
<div className="pill-container">
{Object.entries(alternativeLabels).length > 0 ? (
Object.entries(alternativeLabels).map(
([key, { altVariable, labelOfComponent }]) => (
{Object.values(alternativeLabels).length ? (
Object.values(alternativeLabels).map(
({key, altVariable, labelOfComponent }) => (
<CustomPill
key={key}
label={altVariable || labelOfComponent}
Expand All @@ -46,6 +45,7 @@ PillList.propTypes = {
alternativeLabels: PropTypes.object.isRequired,
onRemove: PropTypes.func.isRequired,
};

const FormComponent = React.memo(
({ form,
alternativeLabels,
Expand Down Expand Up @@ -270,32 +270,19 @@ FormComponent.propTypes = {
setSelectedComponent: PropTypes.func.isRequired,
};
const TaskVariableModal = React.memo(
({ showTaskVarModal, isPublished = false ,onClose, form }) => {
({ showTaskVarModal, isPublished = false ,onClose }) => {
const { t } = useTranslation();
const dispatch = useDispatch();
const formProcessList = useSelector(
(state) => state.process.formProcessList
);

const form = useSelector((state) => state.form?.form || {});
const [alternativeLabels, setAlternativeLabels] = useState({});

useEffect(() => {
//filtering applicationId and applicationStatus components from form
const filteredComponents = Object.values(utils.flattenComponents(form.components)).filter(
({ key }) => key === "applicationStatus" || key === "applicationId"
);

const updatedLabels = {};
// Add filtered components to updatedLabels
filteredComponents.forEach(({ key, label, type }) => {
updatedLabels[key] = {
key,
altVariable: label,
labelOfComponent: label,
type: type,
};
});

const updatedLabels = {};
// Add taskVariables to updatedLabels
formProcessList?.taskVariables?.forEach(({ key, label, type }) => {
updatedLabels[key] = {
Expand All @@ -307,12 +294,14 @@ const TaskVariableModal = React.memo(
});
setAlternativeLabels(updatedLabels);
}, [formProcessList]);

const [selectedComponent, setSelectedComponent] = useState({
key: null,
type: "",
label: "",
altVariable: "",
});

const removeSelectedVariable = useCallback((key) => {
setSelectedComponent((prev) => ({
...prev,
Expand Down Expand Up @@ -418,7 +407,6 @@ const TaskVariableModal = React.memo(
TaskVariableModal.propTypes = {
showTaskVarModal: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
form: PropTypes.object.isRequired,
isPublished: PropTypes.bool.isRequired,
};
export default TaskVariableModal;

0 comments on commit 340d0b3

Please sign in to comment.