From b6333d0e4963e8ca625f67edc855abc7d6154e65 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Date: Fri, 14 Mar 2025 16:49:06 -0300 Subject: [PATCH] feat: add detailed view for prompt component (#7036) * Changed prompt component to show the prompt with more details * Fix classes for edit node * Fixed test --------- Co-authored-by: Rodrigo Nader --- .../components/promptComponent/index.tsx | 115 ++++++------------ .../regression/generalBugs-shard-10.spec.ts | 2 +- 2 files changed, 36 insertions(+), 81 deletions(-) diff --git a/src/frontend/src/components/core/parameterRenderComponent/components/promptComponent/index.tsx b/src/frontend/src/components/core/parameterRenderComponent/components/promptComponent/index.tsx index e8da54b77..04778fcd9 100644 --- a/src/frontend/src/components/core/parameterRenderComponent/components/promptComponent/index.tsx +++ b/src/frontend/src/components/core/parameterRenderComponent/components/promptComponent/index.tsx @@ -1,48 +1,18 @@ -import { GRADIENT_CLASS } from "@/constants/constants"; +import SanitizedHTMLWrapper from "@/components/common/sanitizedHTMLWrapper"; +import { regexHighlight } from "@/constants/constants"; import PromptModal from "@/modals/promptModal"; import { cn } from "../../../../../utils/utils"; -import IconComponent from "../../../../common/genericIconComponent"; import { Button } from "../../../../ui/button"; import { getPlaceholder } from "../../helpers/get-placeholder-disabled"; import { InputProps, PromptAreaComponentType } from "../../types"; const promptContentClasses = { - base: "overflow-hidden text-clip whitespace-nowrap bg-background", - editNode: "input-edit-node input-dialog", - normal: "primary-input text-muted-foreground", + base: "overflow-hidden text-clip whitespace-nowrap bg-background h-fit max-h-28", + editNode: "input-edit-node input-dialog py-2", + normal: "primary-input text-primary", disabled: "disabled-state", }; -const externalLinkIconClasses = { - gradient: ({ - disabled, - editNode, - }: { - disabled: boolean; - editNode: boolean; - }) => - disabled - ? "" - : editNode - ? "gradient-fade-input-edit-node " - : "gradient-fade-input ", - background: ({ - disabled, - editNode, - }: { - disabled: boolean; - editNode: boolean; - }) => - disabled - ? "" - : editNode - ? "background-fade-input-edit-node " - : "background-fade-input", - icon: "icons-parameters-comp absolute right-3 h-4 w-4 shrink-0", - editNodeTop: "top-[0.375rem]", - normalTop: "top-2.5", -}; - export default function PromptAreaComponent({ field_name, nodeClass, @@ -54,6 +24,24 @@ export default function PromptAreaComponent({ id = "", readonly = false, }: InputProps): JSX.Element { + const coloredContent = (typeof value === "string" ? value : "") + .replace(//g, ">") + .replace(regexHighlight, (match, p1, p2) => { + // Decide which group was matched. If p1 is not undefined, do nothing + // we don't want to change the text. If p2 is not undefined, then we + // have a variable, so we should highlight it. + // ! This will not work with multiline or indented json yet + if (p1 !== undefined) { + return match; + } else if (p2 !== undefined) { + return `{${p2}}`; + } + + return match; + }) + .replace(/\n/g, "
"); + const renderPromptText = () => ( - {value !== "" - ? value - : getPlaceholder(disabled, "Type your prompt here...")} + {value !== "" ? ( + + ) : ( + + {getPlaceholder(disabled, "Type your prompt here...")} + + )} ); - const renderExternalLinkIcon = () => ( - <> -