Fixed and added conditions to flows without chat

This commit is contained in:
Lucas Oliveira 2023-07-10 16:42:41 -03:00
commit 7bfe0c88c1
2 changed files with 31 additions and 37 deletions

View file

@ -8,6 +8,7 @@ export default function ChatInput({
sendMessage, sendMessage,
setChatValue, setChatValue,
inputRef, inputRef,
noInput,
}) { }) {
useEffect(() => { useEffect(() => {
if (!lockChat && inputRef.current) { if (!lockChat && inputRef.current) {
@ -32,7 +33,7 @@ export default function ChatInput({
}} }}
rows={1} rows={1}
ref={inputRef} ref={inputRef}
disabled={lockChat} disabled={lockChat || noInput}
style={{ style={{
resize: "none", resize: "none",
bottom: `${inputRef?.current?.scrollHeight}px`, bottom: `${inputRef?.current?.scrollHeight}px`,
@ -48,7 +49,7 @@ export default function ChatInput({
setChatValue(e.target.value); setChatValue(e.target.value);
}} }}
className={classNames( className={classNames(
lockChat lockChat || noInput
? " form-modal-lock-true bg-input " ? " form-modal-lock-true bg-input "
: " form-modal-lock-false", : " form-modal-lock-false",
"form-modal-lockchat" "form-modal-lockchat"

View file

@ -333,41 +333,35 @@ export default function FormModal({
}, [open]); }, [open]);
function sendMessage() { function sendMessage() {
if (chatValue !== "") { let nodeValidationErrors = validateNodes(reactFlowInstance);
let nodeValidationErrors = validateNodes(reactFlowInstance); if (nodeValidationErrors.length === 0) {
if (nodeValidationErrors.length === 0) { setLockChat(true);
setLockChat(true); let inputs = tabsState[id.current].formKeysData.input_keys;
let inputs = tabsState[id.current].formKeysData.input_keys; setChatValue("");
setChatValue(""); const message = inputs;
const message = inputs; addChatHistory(
addChatHistory( message,
message, true,
true, chatKey,
chatKey, tabsState[flow.id].formKeysData.template
tabsState[flow.id].formKeysData.template );
); sendAll({
sendAll({ ...reactFlowInstance.toObject(),
...reactFlowInstance.toObject(), inputs: inputs,
inputs: inputs, chatHistory,
chatHistory, name: flow.name,
name: flow.name, description: flow.description,
description: flow.description, });
}); setTabsState((old) => {
setTabsState((old) => { if (!chatKey) return old;
let newTabsState = _.cloneDeep(old); let newTabsState = _.cloneDeep(old);
newTabsState[id.current].formKeysData.input_keys[chatKey] = ""; newTabsState[id.current].formKeysData.input_keys[chatKey] = "";
return newTabsState; return newTabsState;
}); });
} else {
setErrorData({
title: "Oops! Looks like you missed some required information:",
list: nodeValidationErrors,
});
}
} else { } else {
setErrorData({ setErrorData({
title: "Error sending message", title: "Oops! Looks like you missed some required information:",
list: ["The message cannot be empty."], list: nodeValidationErrors,
}); });
} }
} }
@ -549,13 +543,12 @@ export default function FormModal({
<div className="langflow-chat-input"> <div className="langflow-chat-input">
<ChatInput <ChatInput
chatValue={chatValue} chatValue={chatValue}
noInput={!chatKey}
lockChat={lockChat} lockChat={lockChat}
sendMessage={sendMessage} sendMessage={sendMessage}
setChatValue={(value) => { setChatValue={(value) => {
setChatValue(value); setChatValue(value);
setTabsState((old) => { setTabsState((old) => {
// chatKey is undefined when there are no chat input keys
if (!chatKey) return old;
let newTabsState = _.cloneDeep(old); let newTabsState = _.cloneDeep(old);
newTabsState[id.current].formKeysData.input_keys[ newTabsState[id.current].formKeysData.input_keys[
chatKey chatKey