From a7f65b58877e50c1398a2cc950ea8f322baa633f Mon Sep 17 00:00:00 2001 From: aliang <1098486429@qq.com> Date: Sat, 9 Nov 2024 05:18:41 +0700 Subject: [PATCH] fix(ui): fix the error handling for thread editing (#3391) * fix(webserver): forbid empty content message update * fix(ui): fix the error handling for thread editing --------- Co-authored-by: Wei Zhang --- .../components/assistant-message-section.tsx | 28 +++++++++++-------- ee/tabby-ui/app/search/components/search.tsx | 16 +++++++---- ee/tabby-ui/components/chat/chat.tsx | 3 +- ee/tabby-ui/lib/hooks/use-thread-run.ts | 8 +----- ee/tabby-ui/lib/tabby/gql.ts | 7 +++-- ee/tabby-ui/lib/types/common.ts | 8 ++++++ 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/ee/tabby-ui/app/search/components/assistant-message-section.tsx b/ee/tabby-ui/app/search/components/assistant-message-section.tsx index a3b71adeb27c..44f5734ea53e 100644 --- a/ee/tabby-ui/app/search/components/assistant-message-section.tsx +++ b/ee/tabby-ui/app/search/components/assistant-message-section.tsx @@ -13,7 +13,12 @@ import * as z from 'zod' import { MARKDOWN_CITATION_REGEX } from '@/lib/constants/regex' import { MessageAttachmentCode } from '@/lib/gql/generates/graphql' -import { AttachmentDocItem, RelevantCodeContext } from '@/lib/types' +import { makeFormErrorHandler } from '@/lib/tabby/gql' +import { + AttachmentDocItem, + ExtendedCombinedError, + RelevantCodeContext +} from '@/lib/types' import { cn, formatLineHashForCodeBrowser, @@ -207,9 +212,9 @@ export function AssistantMessageSection({ } const handleUpdateAssistantMessage = async (message: ConversationMessage) => { - const errorMessage = await onUpdateMessage(message) - if (errorMessage) { - return errorMessage + const error = await onUpdateMessage(message) + if (error) { + return error } else { setIsEditing(false) } @@ -518,7 +523,9 @@ function MessageContentForm({ }: { message: ConversationMessage onCancel: () => void - onSubmit: (newMessage: ConversationMessage) => Promise + onSubmit: ( + newMessage: ConversationMessage + ) => Promise }) { const formSchema = z.object({ content: z.string().trim() @@ -528,17 +535,16 @@ function MessageContentForm({ defaultValues: { content: message.content } }) const { isSubmitting } = form.formState - const { content } = form.watch() - const isEmptyContent = !content || isEmpty(content.trim()) const [draftMessage] = useState(message) const handleSubmit = async (values: z.infer) => { - const errorMessage = await onSubmit({ + const error = await onSubmit({ ...draftMessage, content: values.content }) - if (errorMessage) { - form.setError('root', { message: errorMessage }) + + if (error) { + makeFormErrorHandler(form)(error) } } @@ -576,7 +582,7 @@ function MessageContentForm({ > Cancel -