Improve wait time input (#1681)
This commit is contained in:
@@ -10,8 +10,8 @@ import { EditableNodeTitle } from "../components/EditableNodeTitle";
|
|||||||
import { NodeActionMenu } from "../NodeActionMenu";
|
import { NodeActionMenu } from "../NodeActionMenu";
|
||||||
import { WorkflowBlockIcon } from "../WorkflowBlockIcon";
|
import { WorkflowBlockIcon } from "../WorkflowBlockIcon";
|
||||||
import type { WaitNode } from "./types";
|
import type { WaitNode } from "./types";
|
||||||
import { WorkflowBlockInput } from "@/components/WorkflowBlockInput";
|
|
||||||
import { useIsFirstBlockInWorkflow } from "../../hooks/useIsFirstNodeInWorkflow";
|
import { useIsFirstBlockInWorkflow } from "../../hooks/useIsFirstNodeInWorkflow";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
|
||||||
function WaitNode({ id, data }: NodeProps<WaitNode>) {
|
function WaitNode({ id, data }: NodeProps<WaitNode>) {
|
||||||
const { updateNodeData } = useReactFlow();
|
const { updateNodeData } = useReactFlow();
|
||||||
@@ -89,18 +89,10 @@ function WaitNode({ id, data }: NodeProps<WaitNode>) {
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
<Input
|
||||||
<WorkflowBlockInput
|
|
||||||
nodeId={id}
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
max="300"
|
|
||||||
value={inputs.waitInSeconds}
|
value={inputs.waitInSeconds}
|
||||||
onChange={(value) => {
|
onChange={(event) => {
|
||||||
if (!editable) {
|
handleChange("waitInSeconds", event.target.value);
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleChange("waitInSeconds", Number(value));
|
|
||||||
}}
|
}}
|
||||||
className="nopan text-xs"
|
className="nopan text-xs"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { Node } from "@xyflow/react";
|
|||||||
import { NodeBaseData } from "../types";
|
import { NodeBaseData } from "../types";
|
||||||
|
|
||||||
export type WaitNodeData = NodeBaseData & {
|
export type WaitNodeData = NodeBaseData & {
|
||||||
waitInSeconds: number;
|
waitInSeconds: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WaitNode = Node<WaitNodeData, "wait">;
|
export type WaitNode = Node<WaitNodeData, "wait">;
|
||||||
@@ -11,7 +11,7 @@ export const waitNodeDefaultData: WaitNodeData = {
|
|||||||
label: "",
|
label: "",
|
||||||
continueOnFailure: false,
|
continueOnFailure: false,
|
||||||
editable: true,
|
editable: true,
|
||||||
waitInSeconds: 1,
|
waitInSeconds: "1",
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isWaitNode(node: Node): node is WaitNode {
|
export function isWaitNode(node: Node): node is WaitNode {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ import {
|
|||||||
isExtractionNode,
|
isExtractionNode,
|
||||||
} from "./nodes/ExtractionNode/types";
|
} from "./nodes/ExtractionNode/types";
|
||||||
import { loginNodeDefaultData } from "./nodes/LoginNode/types";
|
import { loginNodeDefaultData } from "./nodes/LoginNode/types";
|
||||||
import { waitNodeDefaultData } from "./nodes/WaitNode/types";
|
import { isWaitNode, waitNodeDefaultData } from "./nodes/WaitNode/types";
|
||||||
import { fileDownloadNodeDefaultData } from "./nodes/FileDownloadNode/types";
|
import { fileDownloadNodeDefaultData } from "./nodes/FileDownloadNode/types";
|
||||||
import { ProxyLocation } from "@/api/types";
|
import { ProxyLocation } from "@/api/types";
|
||||||
import { pdfParserNodeDefaultData } from "./nodes/PDFParserNode/types";
|
import { pdfParserNodeDefaultData } from "./nodes/PDFParserNode/types";
|
||||||
@@ -301,7 +301,7 @@ function convertToNode(
|
|||||||
type: "wait",
|
type: "wait",
|
||||||
data: {
|
data: {
|
||||||
...commonData,
|
...commonData,
|
||||||
waitInSeconds: block.wait_sec ?? 1,
|
waitInSeconds: String(block.wait_sec ?? 1),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -962,7 +962,7 @@ function getWorkflowBlock(node: WorkflowBlockNode): BlockYAML {
|
|||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
block_type: "wait",
|
block_type: "wait",
|
||||||
wait_sec: node.data.waitInSeconds,
|
wait_sec: Number(node.data.waitInSeconds),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case "fileDownload": {
|
case "fileDownload": {
|
||||||
@@ -1809,6 +1809,18 @@ function getWorkflowErrors(nodes: Array<AppNode>): Array<string> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const waitNodes = nodes.filter(isWaitNode);
|
||||||
|
waitNodes.forEach((node) => {
|
||||||
|
const waitTimeString = node.data.waitInSeconds.trim();
|
||||||
|
|
||||||
|
const decimalRegex = new RegExp("^\\d+$");
|
||||||
|
const isNumber = decimalRegex.test(waitTimeString);
|
||||||
|
|
||||||
|
if (!isNumber) {
|
||||||
|
errors.push(`${node.data.label}: Invalid input for wait time.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user