From f3c043cf06a63ff469ad57e04b4aa71f2e1c35a3 Mon Sep 17 00:00:00 2001 From: "Ankush Pala ankush@lastmileai.dev" <> Date: Thu, 18 Jan 2024 19:51:57 -0500 Subject: [PATCH] 8/n Read-only mode: Input rendering Attempted to add read-only functionality wherever applicable to input renderings. ## Testplan | ![image1](https://github.com/lastmile-ai/aiconfig/assets/141073967/31405238-bbd1-42c0-a5fc-58102fe05021) | ![image2](https://github.com/lastmile-ai/aiconfig/assets/141073967/bb8d6543-25d0-4b61-826b-ded9ddab4295) | | --- | --- | | ![image1](https://github.com/lastmile-ai/aiconfig/assets/141073967/dcec6c8b-fbe8-4aea-b2f1-f55153866385) | ![image2](https://github.com/lastmile-ai/aiconfig/assets/141073967/8e90c287-3304-484e-8831-496b0f5cd2a8) | | ![image1](https://github.com/lastmile-ai/aiconfig/assets/141073967/38e2fc27-bb39-4143-8dc1-67876110f1c6) | ![image2](https://github.com/lastmile-ai/aiconfig/assets/141073967/34d4db13-74b5-4617-bb5c-5c851e41afb8) | | ![image1](https://github.com/lastmile-ai/aiconfig/assets/141073967/80953234-3a0c-4aa5-bfc5-7d7c9176be58) | ![image2](https://github.com/lastmile-ai/aiconfig/assets/141073967/4d66ec78-04f8-45ae-b396-a91e8f3355d3) | ## dependencies built ontop of #961 --- .../src/components/JSONEditorToggleButton.tsx | 7 ++++- .../client/src/components/JSONRenderer.tsx | 7 +++-- .../PromptInputConfigRenderer.tsx | 22 +++++++++++-- .../attachments/AttachmentContainer.tsx | 8 +++-- .../attachments/AttachmentUploader.tsx | 5 ++- .../PromptInputAttachmentsSchemaRenderer.tsx | 6 ++-- .../PromptInputDataSchemaRenderer.tsx | 31 ++++++++++++------- .../PromptInputSchemaRenderer.tsx | 22 +++++++++++-- 8 files changed, 82 insertions(+), 26 deletions(-) diff --git a/python/src/aiconfig/editor/client/src/components/JSONEditorToggleButton.tsx b/python/src/aiconfig/editor/client/src/components/JSONEditorToggleButton.tsx index 4da61d451..1b3d41956 100644 --- a/python/src/aiconfig/editor/client/src/components/JSONEditorToggleButton.tsx +++ b/python/src/aiconfig/editor/client/src/components/JSONEditorToggleButton.tsx @@ -1,5 +1,7 @@ import { ActionIcon, Tooltip } from "@mantine/core"; import { IconBraces, IconBracesOff } from "@tabler/icons-react"; +import AIConfigContext from "../contexts/AIConfigContext"; +import { useContext } from "react"; type Props = { isRawJSON: boolean; @@ -10,8 +12,11 @@ export default function JSONEditorToggleButton({ isRawJSON, setIsRawJSON, }: Props) { + const { readOnly } = useContext(AIConfigContext); + + const toggleJSONButtonLabel = readOnly ? "View JSON" : "Toggle JSON Editor"; return ( - + setIsRawJSON(!isRawJSON)}> {isRawJSON ? : } diff --git a/python/src/aiconfig/editor/client/src/components/JSONRenderer.tsx b/python/src/aiconfig/editor/client/src/components/JSONRenderer.tsx index 37ba6fe5f..00dc723c8 100644 --- a/python/src/aiconfig/editor/client/src/components/JSONRenderer.tsx +++ b/python/src/aiconfig/editor/client/src/components/JSONRenderer.tsx @@ -1,7 +1,8 @@ import { Prism } from "@mantine/prism"; import { JSONObject, JSONValue } from "aiconfig"; -import { memo } from "react"; +import { memo, useContext } from "react"; import JSONEditor from "./JSONEditor"; +import AIConfigContext from "../contexts/AIConfigContext"; type Props = { content: JSONValue; @@ -14,7 +15,9 @@ export default memo(function JSONRenderer({ onChange, schema, }: Props) { - return !onChange ? ( + const { readOnly } = useContext(AIConfigContext); + // Prism is a read only renderer. + return !onChange || readOnly ? ( {JSON.stringify(content, null, 2)} diff --git a/python/src/aiconfig/editor/client/src/components/prompt/prompt_input/PromptInputConfigRenderer.tsx b/python/src/aiconfig/editor/client/src/components/prompt/prompt_input/PromptInputConfigRenderer.tsx index a37010a3d..d9e864e8e 100644 --- a/python/src/aiconfig/editor/client/src/components/prompt/prompt_input/PromptInputConfigRenderer.tsx +++ b/python/src/aiconfig/editor/client/src/components/prompt/prompt_input/PromptInputConfigRenderer.tsx @@ -1,6 +1,8 @@ -import { Textarea } from "@mantine/core"; +import { Spoiler, Textarea } from "@mantine/core"; import { PromptInput } from "aiconfig"; -import { memo } from "react"; +import { memo, useContext } from "react"; +import AIConfigContext from "../../../contexts/AIConfigContext"; +import { TextRenderer } from "../TextRenderer"; type Props = { input: PromptInput; @@ -11,10 +13,24 @@ export default memo(function PromptInputConfigRenderer({ input, onChangeInput, }: Props) { - return ( + const {readOnly} = useContext(AIConfigContext); + return readOnly ? ( +
+ + + +
+ ): (