From a3410b7f69389398e9a684c2c9b742d039f032de Mon Sep 17 00:00:00 2001 From: Yash-1511 Date: Thu, 5 Jun 2025 13:51:03 +0530 Subject: [PATCH] feat(conversation): hide SQL blocks by default based on user preference --- .../src/components/Conversation/CodeBlock.tsx | 23 +++++++++++-------- .../src/components/Conversation/Message.tsx | 5 +++- .../Conversation/MessageResultRenderer.tsx | 4 ++++ frontend/src/hooks/settings.ts | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/Conversation/CodeBlock.tsx b/frontend/src/components/Conversation/CodeBlock.tsx index abad168c..4ef9730d 100644 --- a/frontend/src/components/Conversation/CodeBlock.tsx +++ b/frontend/src/components/Conversation/CodeBlock.tsx @@ -10,11 +10,7 @@ import { CustomTooltip } from "../Library/Tooltip"; import { monokai } from "react-syntax-highlighter/dist/esm/styles/hljs"; import { format } from "prettier-sql"; import { useEffect, useRef, useState } from "react"; -import { - useRunSqlInConversation, - useUpdateSqlQuery, - useGetUserProfile, -} from "@/hooks"; +import { useRunSqlInConversation, useUpdateSqlQuery } from "@/hooks"; import { Alert, AlertActions, @@ -99,6 +95,8 @@ export const CodeBlock = ({ onSaveSQLStringResult, forChart = false, minimize, + hideSqlByDefault, + resultType, }: { code: string; resultId: string; @@ -109,8 +107,9 @@ export const CodeBlock = ({ ) => void; forChart: boolean; minimize?: boolean; + hideSqlByDefault?: boolean; + resultType?: string; }) => { - const { data: profile } = useGetUserProfile(); const [savedCode, setSavedCode] = useState(() => formattedCodeOrInitial(code, dialect as SupportedFormatters) ); @@ -118,9 +117,11 @@ export const CodeBlock = ({ formattedCodeOrInitial(code, dialect as SupportedFormatters) ); // Determine if SQL should be minimized by default based on user preference - const shouldHideSql = profile?.hide_sql_preference; + const effectiveDialectIsSql = + dialect?.toLowerCase() === "sql" || + (resultType === "SQL_QUERY_STRING_RESULT" && dialect === undefined); const [minimized, setMinimized] = useState( - minimize || shouldHideSql || false + minimize || (hideSqlByDefault && effectiveDialectIsSql) || false ); const textareaRef = useRef(null); const syntaxHighlighterId = `syntax-highlighter-${resultId}`; @@ -269,7 +270,11 @@ export const CodeBlock = ({