diff --git a/forms-flow-api/src/formsflow_api/constants/__init__.py b/forms-flow-api/src/formsflow_api/constants/__init__.py index f3ff48689..7b74cd941 100644 --- a/forms-flow-api/src/formsflow_api/constants/__init__.py +++ b/forms-flow-api/src/formsflow_api/constants/__init__.py @@ -220,3 +220,9 @@ def default_flow_xml_data(name="Defaultflow"): """ + + +default_task_variables = [ + {"key": "applicationId", "label": "Submission Id", "type": "hidden"}, + {"key": "applicationStatus", "label": "Submission Status", "type": "hidden"}, +] diff --git a/forms-flow-api/src/formsflow_api/services/form_process_mapper.py b/forms-flow-api/src/formsflow_api/services/form_process_mapper.py index 458799693..aeb9b444d 100644 --- a/forms-flow-api/src/formsflow_api/services/form_process_mapper.py +++ b/forms-flow-api/src/formsflow_api/services/form_process_mapper.py @@ -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, @@ -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 diff --git a/forms-flow-api/src/formsflow_api/services/import_support.py b/forms-flow-api/src/formsflow_api/services/import_support.py index 7a5531c17..b4033879e 100644 --- a/forms-flow-api/src/formsflow_api/services/import_support.py +++ b/forms-flow-api/src/formsflow_api/services/import_support.py @@ -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, @@ -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", diff --git a/forms-flow-web/src/components/Form/EditForm/FlowEdit.js b/forms-flow-web/src/components/Form/EditForm/FlowEdit.js index 11323f597..97eb7034f 100644 --- a/forms-flow-web/src/components/Form/EditForm/FlowEdit.js +++ b/forms-flow-web/src/components/Form/EditForm/FlowEdit.js @@ -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); @@ -371,8 +370,7 @@ const FlowEdit = forwardRef(({ isPublished = false, CategoryType, disableAllRevertButton={processData.status === "Published"} /> {showTaskVarModal && ( - { const { t } = useTranslation(); return (
- {Object.entries(alternativeLabels).length > 0 ? ( - Object.entries(alternativeLabels).map( - ([key, { altVariable, labelOfComponent }]) => ( + {Object.values(alternativeLabels).length ? ( + Object.values(alternativeLabels).map( + ({key, altVariable, labelOfComponent }) => ( { + ({ 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] = { @@ -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, @@ -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;