task locking

main
alex 2023-05-27 22:36:00 +02:00
parent 4211a1a1ac
commit 837e7ee23d
2 changed files with 60 additions and 21 deletions

View File

@ -1,5 +1,6 @@
import { import {
Alert, Alert,
Avatar,
Button, Button,
Form, Form,
Input, Input,
@ -9,6 +10,7 @@ import {
Result, Result,
Steps, Steps,
Tag, Tag,
Tooltip,
notification, notification,
} from "antd"; } from "antd";
import { useContext } from "react"; import { useContext } from "react";
@ -22,7 +24,11 @@ import {
MyAvatar, MyAvatar,
getUserId, getUserId,
} from "../../utils"; } from "../../utils";
import { InfoCircleOutlined } from "@ant-design/icons"; import {
AntDesignOutlined,
InfoCircleOutlined,
LockOutlined,
} from "@ant-design/icons";
export default function GroupTasksViewModal({ isOpen }) { export default function GroupTasksViewModal({ isOpen }) {
const webSocketContext = useContext(WebSocketContext); const webSocketContext = useContext(WebSocketContext);
@ -167,13 +173,14 @@ export default function GroupTasksViewModal({ isOpen }) {
); );
}; };
const alertActionHandler = (status, taskStepId, index) => { const alertActionHandler = (status, taskStepId, index, taskLocked) => {
switch (status) { switch (status) {
case Constants.GROUP_TASKS_STATUS.FAILED: case Constants.GROUP_TASKS_STATUS.FAILED:
return ( return (
<Button <Button
size="small" size="small"
danger danger
disabled={taskLocked}
onClick={() => onClick={() =>
handleTaskFailedTryAgainRunTaskStep(taskStepId, index + 1) handleTaskFailedTryAgainRunTaskStep(taskStepId, index + 1)
} }
@ -185,6 +192,7 @@ export default function GroupTasksViewModal({ isOpen }) {
return ( return (
<Button <Button
size="small" size="small"
disabled={taskLocked}
onClick={() => handleTaskContinueTaskStep(taskStepId, index + 1)} onClick={() => handleTaskContinueTaskStep(taskStepId, index + 1)}
> >
Continue Continue
@ -327,10 +335,23 @@ export default function GroupTasksViewModal({ isOpen }) {
)} )}
</p> </p>
{console.log("stepLocked", groupTaskSteps[index].Locked)}
<Alert <Alert
message={<b>{getAlertMessage(groupTaskSteps[index].Status)}</b>} message={
<b>
{getAlertMessage(groupTaskSteps[index].Status)}{" "}
{groupTaskSteps[index].LockedByUserId !== "" && (
<>
<LockOutlined />{" "}
<MyAvatar
tooltip
allUsers={webSocketContext.AllUsers}
userId={groupTaskSteps[index].LockedByUserId}
avatarWidth={24}
/>
</>
)}
</b>
}
description={ description={
groupTaskSteps[index].Status === groupTaskSteps[index].Status ===
Constants.GROUP_TASKS_STATUS.INPUT_REQUIRED ? ( Constants.GROUP_TASKS_STATUS.INPUT_REQUIRED ? (
@ -339,7 +360,8 @@ export default function GroupTasksViewModal({ isOpen }) {
currentGroupTask={currentGroupTask} currentGroupTask={currentGroupTask}
groupTaskParameters={groupTask.parameters} groupTaskParameters={groupTask.parameters}
notificationApi={notificationApi} notificationApi={notificationApi}
step={index} step={index + 1}
taskLockedByUserId={groupTaskSteps[index].LockedByUserId}
/> />
) : ( ) : (
getGroupTaskStepLog(groupTaskSteps[index].Log) getGroupTaskStepLog(groupTaskSteps[index].Log)
@ -350,7 +372,8 @@ export default function GroupTasksViewModal({ isOpen }) {
action={alertActionHandler( action={alertActionHandler(
groupTaskSteps[index].Status, groupTaskSteps[index].Status,
groupTaskSteps[index].Id, groupTaskSteps[index].Id,
index index,
groupTaskSteps[index].LockedByUserId
)} )}
/> />
</> </>
@ -503,6 +526,7 @@ function InputRequiredHandler({
groupTaskParameters, groupTaskParameters,
notificationApi, notificationApi,
step, step,
taskLockedByUserId,
}) { }) {
const globalInputs = JSON.parse(currentGroupTask.GlobalInputs); const globalInputs = JSON.parse(currentGroupTask.GlobalInputs);
@ -530,17 +554,10 @@ function InputRequiredHandler({
let lastChanges = []; let lastChanges = [];
const onInputChange = (currentGroupTaskId, parameterName) => { const onInputChange = (currentGroupTaskId) => {
console.log(
"change",
currentGroupTaskId,
parameterName,
step
);
lastChanges = lastChanges.filter( lastChanges = lastChanges.filter(
(lc) => Date.now() - new Date(lc.changeTime) < 3000 (lc) =>
Date.now() - new Date(lc.changeTime) < Constants.GROUP_TASK_LOCKED_TIME
); );
const lastChange = lastChanges.find((lC) => lC.step === step); const lastChange = lastChanges.find((lC) => lC.step === step);
@ -551,8 +568,6 @@ function InputRequiredHandler({
changeTime: Date.now(), changeTime: Date.now(),
}); });
console.warn("lock");
webSocketContext.SendSocketMessage(SentMessagesCommands.TaskLocking, { webSocketContext.SendSocketMessage(SentMessagesCommands.TaskLocking, {
lockedByUserId: getUserId(), lockedByUserId: getUserId(),
groupTaskId: currentGroupTaskId, groupTaskId: currentGroupTaskId,
@ -579,6 +594,7 @@ function InputRequiredHandler({
key={"input-" + groupTaskParameter.parameterName} key={"input-" + groupTaskParameter.parameterName}
id={groupTaskParameter.parameterName} id={groupTaskParameter.parameterName}
defaultValue={getDefaultValue(groupTaskParameter)} defaultValue={getDefaultValue(groupTaskParameter)}
disabled={taskLockedByUserId !== ""}
onChange={() => onChange={() =>
onInputChange( onInputChange(
currentGroupTask.Id, currentGroupTask.Id,
@ -603,6 +619,7 @@ function InputRequiredHandler({
id={groupTaskParameter.parameterName} id={groupTaskParameter.parameterName}
style={{ width: "100%" }} style={{ width: "100%" }}
defaultValue={getDefaultValue(groupTaskParameter)} defaultValue={getDefaultValue(groupTaskParameter)}
disabled={taskLockedByUserId !== ""}
onChange={() => onChange={() =>
onInputChange( onInputChange(
currentGroupTask.Id, currentGroupTask.Id,

View File

@ -36,6 +36,7 @@ export const Constants = {
}, },
MAX_AVATAR_SIZE: 5 * 1024 * 1024, MAX_AVATAR_SIZE: 5 * 1024 * 1024,
ACCEPTED_FILE_TYPES: ["image/png", "image/jpeg", "image/jpg"], ACCEPTED_FILE_TYPES: ["image/png", "image/jpeg", "image/jpg"],
GROUP_TASK_LOCKED_TIME: 3 * 1000,
}; };
/** /**
@ -109,6 +110,7 @@ const ReceivedMessagesCommands = {
ScanResult: 14, ScanResult: 14,
UpdateScannerLastUsed: 15, UpdateScannerLastUsed: 15,
TaskLocked: 16, TaskLocked: 16,
TaskUnlocked: 17,
}; };
// commands sent to the backend server // commands sent to the backend server
@ -311,12 +313,32 @@ export function WebSocketProvider({
}); });
break; break;
case ReceivedMessagesCommands.TaskLocked: case ReceivedMessagesCommands.TaskLocked:
console.log("taskLocked", body);
setGroupTasksSteps((arr) => { setGroupTasksSteps((arr) => {
const newArr = [...arr]; const newArr = [...arr];
newArr[ newArr[
arr.findIndex((arr1) => arr1.GroupTasksId === body.groupTaskId) arr.findIndex(
].Locked = true; (arr1) =>
arr1.GroupTasksId === body.groupTaskId &&
arr1.Step === body.step
)
].LockedByUserId = body.lockedByUserId;
return newArr;
});
break;
case ReceivedMessagesCommands.TaskUnlocked:
setGroupTasksSteps((arr) => {
const newArr = [...arr];
newArr[
arr.findIndex(
(arr1) =>
arr1.GroupTasksId === body.GroupTaskId &&
arr1.Step === body.Step
)
].LockedByUserId = "";
return newArr; return newArr;
}); });