refactor: Improve async handling and file clearing logic (#8835)
* fix chat image sent * 🐛 (chat-input.tsx): fix issue where files were not being cleared immediately after sending a message 📝 (chat-input.tsx): refactor code to improve readability and maintainability by extracting filesToSend logic into a separate variable * Delete diff_output_ts.txt * ♻️ (chat-input.tsx): refactor code to store and restore files when sending a message to prevent losing files if an error occurs during sending. * ✅ (fileUploadComponent.spec.ts): update timeout values for better test reliability and performance * ✅ (fileUploadComponent.spec.ts): update test assertion to check for the correct attribute value to ensure accurate testing --------- Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
98c4e6ecb0
commit
db48cd38cd
4 changed files with 13 additions and 22 deletions
|
|
@ -166,18 +166,20 @@ export default function ChatInput({
|
||||||
|
|
||||||
const send = async () => {
|
const send = async () => {
|
||||||
const storedChatValue = chatValue;
|
const storedChatValue = chatValue;
|
||||||
|
const filesToSend = files
|
||||||
|
.map((file) => file.path ?? "")
|
||||||
|
.filter((file) => file !== "");
|
||||||
|
const storedFiles = [...files];
|
||||||
|
setFiles([]);
|
||||||
try {
|
try {
|
||||||
await sendMessage({
|
await sendMessage({
|
||||||
repeat: 1,
|
repeat: 1,
|
||||||
files: files
|
files: filesToSend,
|
||||||
.map((file) => file.path ?? "")
|
|
||||||
.filter((file) => file !== ""),
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setChatValueStore(storedChatValue);
|
setChatValueStore(storedChatValue);
|
||||||
|
setFiles(storedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
setFiles([]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkSendingOk = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
const checkSendingOk = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { cn } from "../../../../../../utils/utils";
|
||||||
|
|
||||||
interface NoInputViewProps {
|
interface NoInputViewProps {
|
||||||
isBuilding: boolean;
|
isBuilding: boolean;
|
||||||
sendMessage: (args: { repeat: number }) => void;
|
sendMessage: (args: { repeat: number }) => Promise<void>;
|
||||||
stopBuilding: () => void;
|
stopBuilding: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,8 +23,8 @@ const NoInputView: React.FC<NoInputViewProps> = ({
|
||||||
<Button
|
<Button
|
||||||
data-testid="button-send"
|
data-testid="button-send"
|
||||||
className="font-semibold"
|
className="font-semibold"
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
sendMessage({
|
await sendMessage({
|
||||||
repeat: 1,
|
repeat: 1,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ export default function IOModal({
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
disable={disable}
|
disable={disable}
|
||||||
type={isPlayground ? "full-screen" : undefined}
|
type={isPlayground ? "full-screen" : undefined}
|
||||||
onSubmit={() => sendMessage({ repeat: 1 })}
|
onSubmit={async () => await sendMessage({ repeat: 1 })}
|
||||||
size="x-large"
|
size="x-large"
|
||||||
className="!rounded-[12px] p-0"
|
className="!rounded-[12px] p-0"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -304,19 +304,18 @@ test(
|
||||||
await page.dispatchEvent('[data-testid="drag-files-component"]', "drop", {
|
await page.dispatchEvent('[data-testid="drag-files-component"]', "drop", {
|
||||||
dataTransfer,
|
dataTransfer,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(page.getByText(`${newTxtFile}.txt`).last()).toBeVisible({
|
await expect(page.getByText(`${newTxtFile}.txt`).last()).toBeVisible({
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByTestId(`checkbox-${newTxtFile}`).last(),
|
page.getByTestId(`checkbox-${newTxtFile}`).last(),
|
||||||
).toHaveAttribute("data-state", "checked", { timeout: 1000 });
|
).toHaveAttribute("data-state", "checked", { timeout: 3000 });
|
||||||
|
|
||||||
await page.getByTestId("select-files-modal-button").click();
|
await page.getByTestId("select-files-modal-button").click();
|
||||||
await expect(page.getByText(`${renamedJsonFile}.txt`).first()).toBeHidden(
|
await expect(page.getByText(`${renamedJsonFile}.txt`).first()).toBeHidden(
|
||||||
{
|
{
|
||||||
timeout: 1000,
|
timeout: 3000,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await expect(page.getByText(`${newTxtFile}.txt`).first()).toBeVisible({
|
await expect(page.getByText(`${newTxtFile}.txt`).first()).toBeVisible({
|
||||||
|
|
@ -324,16 +323,6 @@ test(
|
||||||
});
|
});
|
||||||
await page.getByTestId(`remove-file-button-${renamedTxtFile}`).click();
|
await page.getByTestId(`remove-file-button-${renamedTxtFile}`).click();
|
||||||
|
|
||||||
await page
|
|
||||||
.getByTestId("handle-file-shownode-raw content-right")
|
|
||||||
.first()
|
|
||||||
.click();
|
|
||||||
|
|
||||||
await page
|
|
||||||
.getByTestId("handle-chatoutput-noshownode-inputs-target")
|
|
||||||
.first()
|
|
||||||
.click();
|
|
||||||
|
|
||||||
await page
|
await page
|
||||||
.getByRole("button", { name: "Playground", exact: true })
|
.getByRole("button", { name: "Playground", exact: true })
|
||||||
.click();
|
.click();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue