diff --git a/forms-flow-web/src/components/Dashboard/StatusChart.js b/forms-flow-web/src/components/Dashboard/StatusChart.js index f3011213c0..e3a2f66304 100644 --- a/forms-flow-web/src/components/Dashboard/StatusChart.js +++ b/forms-flow-web/src/components/Dashboard/StatusChart.js @@ -71,7 +71,7 @@ const ChartForm = React.memo((props) => { spinner text={t("Loading...")} > -
+
state.bpmTasks.filterList); const [variables, setVariables] = useState([]); - const [forms, setForms] = useState({ data: [], isLoading: true }); + const [forms, setForms] = useState({ data: [], isLoading: true }); const [selectedForm, setSelectedForm] = useState(null); const [taskVariablesKeys, setTaskVariablesKeys] = useState({}); + const [processLoading, setProcessLoading] = useState(false); const [overlayGroupShow, setOverlayGroupShow] = useState(false); const [overlayUserShow, setOverlayUserShow] = useState(false); @@ -98,19 +114,7 @@ export default function CreateNewFilterDrawer({ const { t } = useTranslation(); const [modalShow, setModalShow] = useState(false); - const [checkboxes, setCheckboxes] = useState({ - applicationId: true, - assignee: true, - taskTitle: true, - createdDate: true, - dueDate: true, - followUp: true, - priority: true, - groups: true, - }); - const taskAttributesCount = Object.values(checkboxes).filter( - (value) => value === true - ).length; + const [checkboxes, setCheckboxes] = useState(initialValueOfTaskAttribute); const fetchTasks = (resData) => { const reqParamData = { @@ -143,6 +147,17 @@ export default function CreateNewFilterDrawer({ return inputString; }; + const setTaskVariablesAndItsKeys = (variables = []) => { + setVariables(variables); + // taking variable names to check it is already exist or not + setTaskVariablesKeys( + variables.reduce((i, variable) => { + i[variable.name] = variable.name; + return i; + }, {}) + ); + }; + useEffect(() => { if (selectedFilterData) { setFilterName(selectedFilterData?.name); @@ -165,17 +180,17 @@ export default function CreateNewFilterDrawer({ setShowUndefinedVariable( selectedFilterData?.properties?.showUndefinedVariable ); - - setSelectedForm(selectedFilterData?.properties?.formId || null); - setVariables(selectedFilterData.variables || []); - if(selectedFilterData.variables){ - // taking variable names to check it is already exist or not - setTaskVariablesKeys(selectedFilterData.variables.reduce((i,variable)=>{ - i[variable.name] = variable.name; - return i; - },{})); + + if (selectedFilterData?.properties?.formId) { + setSelectedForm(selectedFilterData?.properties?.formId || null); + setProcessLoading(true); + dispatch(getFormProcesses(selectedFilterData?.properties?.formId,()=>{ + setProcessLoading(false); + })); } + setTaskVariablesAndItsKeys(selectedFilterData.variables); + if ( !selectedFilterData?.users?.length && !selectedFilterData?.roles?.length @@ -204,9 +219,10 @@ export default function CreateNewFilterDrawer({ } // if the user has this role then we will check the condition else it will always true - if(userRoles.includes(FORMSFLOW_ADMIN)){ - setIsTasksForCurrentUserGroupsEnabled(selectedFilterData?.criteria?. - candidateGroupsExpression ? true : false); + if (userRoles.includes(FORMSFLOW_ADMIN)) { + setIsTasksForCurrentUserGroupsEnabled( + selectedFilterData?.criteria?.candidateGroupsExpression ? true : false + ); } setCheckboxes({ @@ -249,43 +265,32 @@ export default function CreateNewFilterDrawer({ } }, [openFilterDrawer]); - //if a form selected then need fetch it's task variable - useEffect(() => { - if (selectedForm) { - dispatch(getFormProcesses(selectedForm)); - }else{ - dispatch(resetFormProcessData()); - } - }, [selectedForm]); - - - - /** - * Handles changing the selected task variables. - * - * When a variable is checked, adds it to the variables array. - * When a variable is unchecked, removes it from the variables array. - * Also updates the taskVariablesKeys object with the checked state. - */ - const handleChangeTaskVariables = (e, variable) => { - const { checked } = e.target; - if (checked) { - setVariables((prev) => [ - ...prev, - { name: variable.key, label: variable.label }, - ]); + const resetVariables = () => { + setVariables([]); + setTaskVariablesKeys({ + applicationId: "applicationId", + formName: "formName", + }); + }; + + const onChangeSelectForm = (e) => { + if (e?.value) { + setProcessLoading(true); + dispatch(getFormProcesses(e.value,()=>{ + setProcessLoading(false); + })); + if (e?.value === selectedFilterData?.properties?.formId) { + setTaskVariablesAndItsKeys(selectedFilterData?.variables); + } else { + resetVariables(); + } } else { - setVariables((prev) => prev.filter((i) => i.name !== variable.key)); + resetVariables(); + dispatch(resetFormProcessData()); } - setTaskVariablesKeys((prev) => ({ - ...prev, - [variable.key]: checked ? variable.key : null, - })); + setSelectedForm(e?.value); }; - - - const successCallBack = (resData) => { dispatch( fetchFilterList((err, data) => { @@ -339,7 +344,8 @@ export default function CreateNewFilterDrawer({ setIsMyTasksEnabled(false); setSelectedForm(null); dispatch(resetFormProcessData()); - setForms({data:[], isLoading:true}); + setCheckboxes(initialValueOfTaskAttribute); + setForms({ data: [], isLoading: true }); }; const handleSubmit = () => { @@ -374,7 +380,7 @@ export default function CreateNewFilterDrawer({ const data = { name: filterName, - criteria: { + criteria: { processDefinitionNameLike: definitionKeyId && `%${definitionKeyId}%`, candidateGroup: MULTITENANCY_ENABLED && candidateGroup @@ -523,39 +529,45 @@ export default function CreateNewFilterDrawer({ setCandidateGroup(data); }; - + const onSaveTaskAttribute = ( + taskVariablesKeys, + variables, + checkboxes, + showUndefinedVariable + ) => { + setVariables(variables); + setTaskVariablesKeys(taskVariablesKeys); + setCheckboxes(checkboxes); + setShowUndefinedVariable(showUndefinedVariable); + }; const list = () => ( -
+
{(t) => t("Create new filter")}
- { - toggleDrawer(); - }} - > +
-
- {(t) => t("Filter Name")} -
- setFilterName(e.target.value)} - title={t("Add fliter name")} - /> +
+ + setFilterName(e.target.value)} + title={t("Add fliter name")} + /> +
- +
{(t) => t("Criteria")}{" "} @@ -609,8 +621,6 @@ export default function CreateNewFilterDrawer({ )} - -
{(t) => t("Definition Key")}
@@ -725,8 +735,22 @@ export default function CreateNewFilterDrawer({
) : null} - +
+ +
+
+ {(t) => t("Select Form")} +
+ {setSelectedForm(e?.value);}} - value={ - forms?.data.find( - (form) => form.value === selectedForm - ) - } - isClearable - placeholder={t("select a form")} - options={forms?.data} - isLoading={forms.isLoading} - /> -
- - + +
@@ -913,8 +924,7 @@ export default function CreateNewFilterDrawer({
) : null}
- - + @@ -976,14 +986,14 @@ export default function CreateNewFilterDrawer({
)} @@ -1007,7 +1017,7 @@ export default function CreateNewFilterDrawer({ width: 100, }} > - {list("le ft")} + {list()}
diff --git a/forms-flow-web/src/components/ServiceFlow/list/sort/TaskAttributeComponent.js b/forms-flow-web/src/components/ServiceFlow/list/sort/TaskAttributeComponent.js index 17c1874418..b3b679366f 100644 --- a/forms-flow-web/src/components/ServiceFlow/list/sort/TaskAttributeComponent.js +++ b/forms-flow-web/src/components/ServiceFlow/list/sort/TaskAttributeComponent.js @@ -1,50 +1,114 @@ -import React from "react"; +import React, { useState } from "react"; import { Row, Col } from "react-bootstrap"; import Modal from "react-bootstrap/Modal"; import ModalTitle from "react-bootstrap/ModalTitle"; import Form from "react-bootstrap/Form"; -import {Translation, useTranslation } from "react-i18next"; +import { Translation, useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; function TaskAttributeComponent({ show, + selectedForm, onHide, - setCheckboxes, - checkboxes, - showUndefinedVariable, - setShowUndefinedVariable, - handleChangeTaskVariables, + selectedTaskAttrbutes, + selectedTaskVariablesKeys, selectedTaskVariables, - selectedForm + onSaveTaskAttribute, + processLoading, + // showUndefinedVariable, }) { - - const taskVariables = useSelector(state => state.process?.formProcessList?.taskVariable || []); + const taskVariables = useSelector( + (state) => state.process?.formProcessList?.taskVariable || [] + ); const { t } = useTranslation(); + + const [variables, setVariables] = useState(selectedTaskVariables); + const [taskVariablesKeys, setTaskVariablesKeys] = useState( + selectedTaskVariablesKeys + ); + const [checkboxes, setCheckboxes] = useState(selectedTaskAttrbutes); + // const [selectUndefinedVariable, setSelectUndefinedVariable] = useState( + // showUndefinedVariable + // ); + + // const UndefinedVaribaleCheckboxChange = (e) => { + // setSelectUndefinedVariable(e.target.checked); + // }; + const handleCheckboxChange = (event) => { const { name, checked } = event.target; setCheckboxes({ ...checkboxes, [name]: checked }); }; - - - const UndefinedVaribaleCheckboxChange = (e) => { - setShowUndefinedVariable(e.target.checked); + + /** + * Handles changing the selected task variables. + * + * When a variable is checked, adds it to the variables array. + * When a variable is unchecked, removes it from the variables array. + * Also updates the taskVariablesKeys object with the checked state. + */ + const handleChangeTaskVariables = (e, variable) => { + const { checked } = e.target; + if (checked) { + setVariables((prev) => [ + ...prev, + { name: variable.key, label: variable.label }, + ]); + } else { + setVariables((prev) => prev.filter((i) => i.name !== variable.key)); + } + /** + * Updates the taskVariablesKeys object with the checked state + * of the variable. If checked is true, adds the variable key. + * If checked is false, removes the variable key. + */ + setTaskVariablesKeys((prev) => ({ + ...prev, + [variable.key]: checked ? variable.key : null, + })); + }; + + const handleSave = () => { + onSaveTaskAttribute( + taskVariablesKeys, + variables, + checkboxes, + // selectUndefinedVariable + ); + onHide(); }; + return ( - {(t) => t("Task Attribute")} - + + {(t) => t("Task Attribute")} + + -

{(t) => t("Only selected task attributes will be available on task list view")}

+

+ + {(t) => + t( + "Select the predefined attributes and custom task variables created as part of form submission you wish to display in the task list" + ) + } + {" "} +

@@ -120,42 +184,67 @@ function TaskAttributeComponent({
-
+
{(t) => t("Task variables")} - +
- - - {selectedForm ? - taskVariables.map(variable=>( - variable.key !== 'applicationId' ? - - {handleChangeTaskVariables(e,variable);}} - /> - : null - )) :
- {t("To display task variables, select a form as part of the filter")} + {/* */} +
+ {selectedForm ? ( + taskVariables?.length > 0 ? ( + taskVariables.map((variable) => + variable.key !== "applicationId" ? ( + + { + handleChangeTaskVariables(e, variable); + }} + /> + + ) : null + ) + ) : ( + !processLoading && ( +
+ {t("No task variables found")} +
+ ) + ) + ) : ( +
+ {t( + "To display task variables, select a form as part of the filter" + )} +
+ )}
- } - - -