From a5db14cadb75a4fc97568bd06cb0ecae18856038 Mon Sep 17 00:00:00 2001 From: Juan Valacco <97040903+jvalacco-dataherald@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:40:05 -0300 Subject: [PATCH] DH-4799 [ai][admin-console] use natural language response from the engine when hitting Run on the query editor page --- .../query/custom-response-dialog.tsx | 7 +++++- .../src/components/query/workspace.tsx | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/apps/ai/clients/admin-console/src/components/query/custom-response-dialog.tsx b/apps/ai/clients/admin-console/src/components/query/custom-response-dialog.tsx index 831f9382..a40ffc78 100644 --- a/apps/ai/clients/admin-console/src/components/query/custom-response-dialog.tsx +++ b/apps/ai/clients/admin-console/src/components/query/custom-response-dialog.tsx @@ -18,7 +18,7 @@ import { Textarea } from '@/components/ui/textarea' import { yupResolver } from '@hookform/resolvers/yup' import { DialogDescription } from '@radix-ui/react-dialog' import { Info } from 'lucide-react' -import { FC } from 'react' +import { FC, useEffect } from 'react' import { useForm } from 'react-hook-form' import * as Yup from 'yup' @@ -60,6 +60,11 @@ const CustomResponseDialog: FC = ({ onClose(formValues.customResponse) } + useEffect( + () => form.reset({ customResponse: initialValue }), + [form, initialValue], + ) + return ( e.preventDefault()}> diff --git a/apps/ai/clients/admin-console/src/components/query/workspace.tsx b/apps/ai/clients/admin-console/src/components/query/workspace.tsx index 37705ed8..5f03e914 100644 --- a/apps/ai/clients/admin-console/src/components/query/workspace.tsx +++ b/apps/ai/clients/admin-console/src/components/query/workspace.tsx @@ -74,8 +74,9 @@ const QueryWorkspace: FC = ({ const lastUpdatedDate: Date = new Date(last_updated) const [currentSqlQuery, setCurrentSqlQuery] = useState(sql_query) const [verificationStatus, setVerifiedStatus] = useState(status) - const [textResponse, setCustomResponse] = useState(response) - const [textResponseHasChanges, setTextResponseHasChanges] = useState(false) + const [customResponse, setCustomResponse] = useState(response) + const [customResponseHasChanges, setcustomResponseHasChanges] = + useState(false) const [openEditResponseDialog, setOpenEditResponseDialog] = useState(false) const [savingQuery, setSavingQuery] = useState(false) const [loadingSqlQueryResults, setLoadingQueryResults] = useState(false) @@ -113,7 +114,7 @@ const QueryWorkspace: FC = ({ setSavingQuery(true) await onPatchQuery({ query_status: verificationStatus, - custom_response: textResponse, + custom_response: customResponse, sql_query: currentSqlQuery, }) if (isVerified(verificationStatus)) { @@ -159,19 +160,23 @@ const QueryWorkspace: FC = ({ const handleVerifyChange = (verificationStatus: QueryWorkspaceStatus) => { setVerifiedStatus(verificationStatus) - if (isRejected(verificationStatus) && !textResponseHasChanges) { + if (isRejected(verificationStatus) && !customResponseHasChanges) { setOpenEditResponseDialog(true) } } - const handleCloseEditDialog = (newCustomResponse = textResponse) => { + const handleCloseEditDialog = (newCustomResponse = customResponse) => { setCustomResponse(newCustomResponse) setOpenEditResponseDialog(false) } useEffect(() => { - setTextResponseHasChanges(textResponse !== response) - }, [response, textResponse]) + setcustomResponseHasChanges(customResponse !== query.response) + }, [query.response, customResponse]) + + useEffect(() => { + setCustomResponse(query.response) + }, [query]) const rejectedBanner = (
@@ -235,7 +240,7 @@ const QueryWorkspace: FC = ({
) : ( - textResponse && ( + customResponse && (
@@ -256,7 +261,7 @@ const QueryWorkspace: FC = ({ Edit
-
{textResponse}
+
{customResponse}
{(isVerified(verificationStatus) || isRejected(verificationStatus)) && ( = ({ } description="Compose the question's response message that will be sent to the Slack thread" isOpen={openEditResponseDialog} - initialValue={textResponse} + initialValue={customResponse} onClose={handleCloseEditDialog} >