save dynamic inputs to task steps as its not working perfectly with getElementById if user has other task open
parent
0d9e79f6e6
commit
8d93066e5f
|
@ -236,7 +236,9 @@ export default function GroupTasksViewModal({ isOpen }) {
|
|||
key: index,
|
||||
title:
|
||||
groupTaskSteps[index] !== undefined &&
|
||||
groupTaskSteps[index].Inputs !== "" ? (
|
||||
groupTaskSteps[index].Inputs !== "" &&
|
||||
groupTaskSteps[index].Status !==
|
||||
Constants.GROUP_TASKS_STATUS.INPUT_REQUIRED ? (
|
||||
<>
|
||||
{groupTask.name}{" "}
|
||||
<Popover
|
||||
|
@ -265,9 +267,9 @@ export default function GroupTasksViewModal({ isOpen }) {
|
|||
<span>
|
||||
{
|
||||
JSON.parse(groupTaskSteps[index].Inputs).find(
|
||||
(step) =>
|
||||
step.parameterName === task.parameterName
|
||||
).value
|
||||
(input) =>
|
||||
input.parameterName === task.parameterName
|
||||
)?.value
|
||||
}
|
||||
</span>
|
||||
<br />
|
||||
|
@ -331,8 +333,6 @@ export default function GroupTasksViewModal({ isOpen }) {
|
|||
)}
|
||||
</p>
|
||||
|
||||
{console.log(groupTaskSteps[index])}
|
||||
|
||||
<Alert
|
||||
message={
|
||||
<b>
|
||||
|
@ -357,6 +357,11 @@ export default function GroupTasksViewModal({ isOpen }) {
|
|||
webSocketContext={webSocketContext}
|
||||
currentGroupTask={currentGroupTask}
|
||||
groupTaskParameters={groupTask.parameters}
|
||||
groupTaskStepInputs={
|
||||
groupTaskSteps[index] !== undefined &&
|
||||
groupTaskSteps[index].Inputs !== "" &&
|
||||
groupTaskSteps[index].Inputs
|
||||
}
|
||||
notificationApi={notificationApi}
|
||||
step={index + 1}
|
||||
taskLockedByUserId={groupTaskSteps[index].LockedByUserId}
|
||||
|
@ -522,6 +527,7 @@ function InputRequiredHandler({
|
|||
webSocketContext,
|
||||
currentGroupTask,
|
||||
groupTaskParameters,
|
||||
groupTaskStepInputs,
|
||||
notificationApi,
|
||||
step,
|
||||
taskLockedByUserId,
|
||||
|
@ -529,8 +535,20 @@ function InputRequiredHandler({
|
|||
const [inputFields, setInputFields] = useState({});
|
||||
|
||||
const globalInputs = JSON.parse(currentGroupTask.GlobalInputs);
|
||||
const stepInputs = JSON.parse(groupTaskStepInputs);
|
||||
|
||||
const getDefaultValue = (groupTaskParameter) => {
|
||||
if (stepInputs !== false) {
|
||||
const stepInput = stepInputs.find(
|
||||
(stepInput) =>
|
||||
stepInput.parameterName === groupTaskParameter.parameterName
|
||||
)?.value;
|
||||
|
||||
if (stepInput) {
|
||||
return stepInput;
|
||||
}
|
||||
}
|
||||
|
||||
if (globalInputs === undefined || !groupTaskParameter.global) return null;
|
||||
|
||||
return globalInputs.find(
|
||||
|
|
45
src/utils.js
45
src/utils.js
|
@ -1,6 +1,6 @@
|
|||
import { UserOutlined } from "@ant-design/icons";
|
||||
import { Avatar, Badge, Tooltip } from "antd";
|
||||
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
||||
import { createContext, useEffect, useRef, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Buffer } from "buffer";
|
||||
|
||||
|
@ -342,11 +342,54 @@ export function WebSocketProvider({
|
|||
});
|
||||
break;
|
||||
case ReceivedMessagesCommands.UpdateGroupTaskStepUserInputValue:
|
||||
// html based DOM manipulation
|
||||
const foundInput = document.getElementById(body.element);
|
||||
|
||||
if (foundInput) {
|
||||
setNativeValue(foundInput, body.value);
|
||||
}
|
||||
|
||||
// update group task step as html based DOM manipulation only works if user has no other modal open
|
||||
setGroupTasksSteps((arr) => {
|
||||
const newArr = [...arr];
|
||||
|
||||
const stepIndex = arr.findIndex(
|
||||
(arr1) =>
|
||||
arr1.GroupTasksId === body.groupTaskId &&
|
||||
arr1.Step === body.step
|
||||
);
|
||||
|
||||
if (stepIndex === -1) return newArr;
|
||||
|
||||
let inputs = [];
|
||||
|
||||
if (newArr[stepIndex].Inputs !== "") {
|
||||
inputs = JSON.parse(newArr[stepIndex].Inputs);
|
||||
}
|
||||
|
||||
let parameterFound = false;
|
||||
|
||||
for (let i = 0; i < inputs.length; i++) {
|
||||
if (inputs[i].parameterName === body.parameterName) {
|
||||
inputs[i].value = body.value;
|
||||
parameterFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parameterFound) {
|
||||
let obj = {};
|
||||
|
||||
obj["parameterName"] = body.parameterName;
|
||||
obj["value"] = body.value;
|
||||
|
||||
inputs.push(obj);
|
||||
}
|
||||
|
||||
newArr[stepIndex].Inputs = JSON.stringify(inputs);
|
||||
|
||||
return newArr;
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue