From 7d086e32e60a7a0d56b8b88477ebeb739802405a Mon Sep 17 00:00:00 2001 From: Lokesh Goel Date: Tue, 23 Jan 2024 17:31:45 +0530 Subject: [PATCH] single line code is now shown in better colors and font --- src/commands/iq/iqLoginhandler.ts | 2 +- src/reactViews/iq/bootstrap.tsx | 4 +-- .../iq/pages/chatscreen/IqChat.scss | 28 +++++++++++++------ src/reactViews/iq/pages/chatscreen/IqChat.tsx | 19 ++++++++----- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/commands/iq/iqLoginhandler.ts b/src/commands/iq/iqLoginhandler.ts index ae943a04..d5b25c2a 100644 --- a/src/commands/iq/iqLoginhandler.ts +++ b/src/commands/iq/iqLoginhandler.ts @@ -75,7 +75,7 @@ export const verifyOrganization = async (orgId: string): Promise => { }; } const orgDetails = await iqRestApiService.getOrganizationDetails(jwtToken,orgId); - if(orgDetails.iq.enabled === false) { + if(!orgDetails.iq || orgDetails.iq.enabled === false) { return { isOrgVerified: false, errorMessage: `Couchbase iQ is not enabled for this organization, Please enable it on cloud.couchbase.com ` diff --git a/src/reactViews/iq/bootstrap.tsx b/src/reactViews/iq/bootstrap.tsx index bf29e9fd..b603e64d 100644 --- a/src/reactViews/iq/bootstrap.tsx +++ b/src/reactViews/iq/bootstrap.tsx @@ -17,7 +17,7 @@ export const App: React.FC = () => { const showPageRef = React.useRef(<>); showPageRef.current = showPage; const [showErrorModal, setShowErrorModal] = React.useState(false); - const [errorMessage, setErrorMessage] = React.useState(""); + const [errorMessage, setErrorMessage] = React.useState(<>); React.useEffect(()=>{ showPageRef.current = showPage; @@ -108,7 +108,7 @@ export const App: React.FC = () => { {isLoading && } } onClose={() => { setShowErrorModal(false); setShowPage(); diff --git a/src/reactViews/iq/pages/chatscreen/IqChat.scss b/src/reactViews/iq/pages/chatscreen/IqChat.scss index 53a15db7..e32f4e26 100644 --- a/src/reactViews/iq/pages/chatscreen/IqChat.scss +++ b/src/reactViews/iq/pages/chatscreen/IqChat.scss @@ -45,11 +45,22 @@ border-top: solid 1px var(--vscode-settings-sashBorder) !important; } +.single-line-code { + display: inline; + white-space: pre-wrap; + opacity: 0.7; + background-color: #e5ffff80; + color: rgb(172, 53, 33); + font-family: "Mono Sans", "Consolas", "Monaco", "Lucida Console", + "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", + "Courier New"; +} + .multiline-code-container { - .multiline-code{ + .multiline-code { margin-top: 0 !important; } - + .multiline-code-header { display: flex; justify-content: space-between; @@ -78,7 +89,7 @@ justify-content: flex-end; align-items: center; padding: 5px 10px; - background-color: rgba(198,227,250,0.8); + background-color: rgba(198, 227, 250, 0.8); border-bottom-right-radius: 0.7em; margin: 0; } @@ -90,13 +101,13 @@ .iconButton { cursor: pointer; margin: 0 5px 3px 5px; - font-size: 1.5rem; + font-size: 1.5rem; background: transparent !important; padding: 2px 0 0 0; height: 25px; width: 25px; - :hover{ + :hover { background-color: transparent !important; opacity: 0.7; } @@ -127,9 +138,8 @@ .chat-over-message { text-align: center; } - .chat-over-newchat-button{ + .chat-over-newchat-button { display: flex; - margin: 15px auto 5px auto - + margin: 15px auto 5px auto; } -} \ No newline at end of file +} diff --git a/src/reactViews/iq/pages/chatscreen/IqChat.tsx b/src/reactViews/iq/pages/chatscreen/IqChat.tsx index 1169666c..45fe7126 100644 --- a/src/reactViews/iq/pages/chatscreen/IqChat.tsx +++ b/src/reactViews/iq/pages/chatscreen/IqChat.tsx @@ -216,7 +216,7 @@ const IqChat = ({ org, setIsLoading }) => { return (
-
{language.toUpperCase()}
+
{language === "n1ql" ? "SQL++" : language.toUpperCase()}
{language === "n1ql" && ( @@ -454,16 +454,21 @@ const IqChat = ({ org, setIsLoading }) => { const match = /language-(\w+)/.exec( className || "" ); - return match ? ( + const code = String(children).replace(/\n$/, ""); + const isMultiline = code.includes('\n'); + const language = match ? match[1] : isMultiline ? "n1ql" : "plaintextCode"; + return language === "plaintextCode" ? + ( + + {children} + + ) + : ( - ) : ( - - {children} - ); }, }}