diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/helpers/get-class-file-preview.ts b/src/frontend/src/modals/IOModal/components/chatView/chatInput/helpers/get-class-file-preview.ts index 3f3cf2762..1990f5518 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/helpers/get-class-file-preview.ts +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/helpers/get-class-file-preview.ts @@ -1,5 +1,5 @@ export const getClassNamesFilePreview = (inputFocus) => { - return `flex w-full items-center gap-4 rounded-t-lg bg-background px-14 py-5 overflow-auto custom-scroll ${ + return `transition-all duration-300 flex w-full items-center gap-4 rounded-t-lg bg-background px-14 py-5 overflow-auto custom-scroll ${ inputFocus ? "border-2 border-b-0 border-ring" : "border border-b-0 border-border" diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx index 3f516945c..bda6e64d5 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx @@ -7,7 +7,9 @@ import remarkMath from "remark-math"; import MaleTechnology from "../../../../../assets/male-technologist.png"; import Robot from "../../../../../assets/robot.png"; import CodeTabsComponent from "../../../../../components/codeTabsComponent"; -import IconComponent from "../../../../../components/genericIconComponent"; +import IconComponent, { + ForwardedIconComponent, +} from "../../../../../components/genericIconComponent"; import SanitizedHTMLWrapper from "../../../../../components/sanitizedHTMLWrapper"; import useAlertStore from "../../../../../stores/alertStore"; import useFlowStore from "../../../../../stores/flowStore"; @@ -22,6 +24,7 @@ export default function ChatMessage({ updateChat, setLockChat, }: chatMessagePropsType): JSX.Element { + const [showFile, setShowFile] = useState(true); const convert = new Convert({ newline: true }); const [hidden, setHidden] = useState(true); const template = chat.template; @@ -235,7 +238,7 @@ dark:prose-invert" }, ]} activeTab={"0"} - setActiveTab={() => { }} + setActiveTab={() => {}} /> ) : ( @@ -277,65 +280,77 @@ dark:prose-invert" {promptOpen ? template?.split("\n")?.map((line, index) => { - const regex = /{([^}]+)}/g; - let match; - let parts: Array = []; - let lastIndex = 0; - while ((match = regex.exec(line)) !== null) { - // Push text up to the match - if (match.index !== lastIndex) { - parts.push(line.substring(lastIndex, match.index)); - } - // Push div with matched text - if (chat.message[match[1]]) { - parts.push( - - {chat.message[match[1]]} - - ); - } + const regex = /{([^}]+)}/g; + let match; + let parts: Array = []; + let lastIndex = 0; + while ((match = regex.exec(line)) !== null) { + // Push text up to the match + if (match.index !== lastIndex) { + parts.push(line.substring(lastIndex, match.index)); + } + // Push div with matched text + if (chat.message[match[1]]) { + parts.push( + + {chat.message[match[1]]} + , + ); + } - // Update last index - lastIndex = regex.lastIndex; - } - // Push text after the last match - if (lastIndex !== line.length) { - parts.push(line.substring(lastIndex)); - } - return

{parts}

; - }) + // Update last index + lastIndex = regex.lastIndex; + } + // Push text after the last match + if (lastIndex !== line.length) { + parts.push(line.substring(lastIndex)); + } + return

{parts}

; + }) : chatMessage}
) : ( - - {chatMessage} - +
+ + {chatMessage} + + {chat.files && ( +
+ {chat.files.map((file, index) => { + return ( +
+ setShowFile(!showFile)} + className="flex cursor-pointer gap-2 text-sm text-muted-foreground" + > + {file.name} + + + +
+ ); + })} +
+ )} +
)} )}
- {chat.files && ( -
- {chat.files.map((file, index) => { - return ( -
- -
- ); - })} -
- )} ); } diff --git a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx index 2489824f8..c21688247 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/fileComponent/index.tsx @@ -1,9 +1,12 @@ import * as base64js from "base64-js"; import { useState } from "react"; -import IconComponent from "../../../../../components/genericIconComponent"; +import IconComponent, { + ForwardedIconComponent, +} from "../../../../../components/genericIconComponent"; import { fileCardPropsType } from "../../../../../types/components"; import useFlowsManagerStore from "../../../../../stores/flowsManagerStore"; import { BACKEND_URL, BASE_URL_API } from "../../../../../constants/constants"; +import formatFileName from "../filePreviewChat/utils/format-file-name"; const imgTypes = new Set(["png", "jpg"]); @@ -11,10 +14,9 @@ export default function FileCard({ fileName, content, fileType, -}: fileCardPropsType): JSX.Element { - const handleDownload = (): void => { - //TODO: update download function - }; + showFile = true, +}: fileCardPropsType): JSX.Element | undefined { + const handleDownload = (): void => {}; const [isHovered, setIsHovered] = useState(false); const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId); function handleMouseEnter(): void { @@ -24,58 +26,63 @@ export default function FileCard({ setIsHovered(false); } - if (imgTypes.has(fileType)) { + const imgSrc = `${BACKEND_URL.slice(0, BACKEND_URL.length - 1)}${BASE_URL_API}files/images/${content}`; + + if (showFile) { + if (imgTypes.has(fileType)) { + return ( +
+
+ generated image + {isHovered && ( +
+ +
+ )} +
+
+ ); + } + return (
- generated image - {isHovered && ( -
- +
+ +
+ {formatFileName(fileName, 20)} + File
- )} -
- ); - } - - return ( - - ); + ); + } + return undefined; } diff --git a/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx b/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx index 0e8a23921..fada2ef59 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/filePreviewChat/utils/format-file-name.tsx @@ -1,8 +1,11 @@ -export default function formatFileName(name: string): string { +export default function formatFileName( + name: string, + numberToTruncate: number = 29, +): string { const fileExtension = name.split(".").pop(); // Get the file extension const baseName = name.slice(0, name.lastIndexOf(".")); // Get the base name without the extension if (baseName.length > 6) { - return `${baseName.slice(0, 29)}...${fileExtension}`; + return `${baseName.slice(0, numberToTruncate)}...${fileExtension}`; } return name; } diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 9d3d0f259..c09feb13b 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -523,6 +523,7 @@ export type fileCardPropsType = { fileName: string; content: string; fileType: string; + showFile?: boolean; }; export type nodeToolbarPropsType = {