From 9ffc67b5e7db0b033f2b60ce509e3050ea2e5e2e Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Mon, 2 Sep 2024 15:53:53 +0530 Subject: [PATCH] fix: ai menu build --- .../pages/editor/ai/ask-pi-menu.tsx | 103 ------ web/ce/components/pages/editor/ai/index.ts | 3 +- web/ce/components/pages/editor/ai/menu.tsx | 299 ------------------ 3 files changed, 1 insertion(+), 404 deletions(-) delete mode 100644 web/ce/components/pages/editor/ai/ask-pi-menu.tsx delete mode 100644 web/ce/components/pages/editor/ai/menu.tsx diff --git a/web/ce/components/pages/editor/ai/ask-pi-menu.tsx b/web/ce/components/pages/editor/ai/ask-pi-menu.tsx deleted file mode 100644 index d3440ea479..0000000000 --- a/web/ce/components/pages/editor/ai/ask-pi-menu.tsx +++ /dev/null @@ -1,103 +0,0 @@ -import { useState } from "react"; -import { CircleArrowUp, CornerDownRight, RefreshCcw, Sparkles } from "lucide-react"; -// ui -import { Tooltip } from "@plane/ui"; -// components -import { RichTextReadOnlyEditor } from "@/components/editor"; -// helpers -import { cn } from "@/helpers/common.helper"; - -type Props = { - handleInsertText: (insertOnNextLine: boolean) => void; - handleRegenerate: () => Promise; - isRegenerating: boolean; - response: string | undefined; -}; - -export const AskPiMenu: React.FC = (props) => { - const { handleInsertText, handleRegenerate, isRegenerating, response } = props; - // states - const [query, setQuery] = useState(""); - - return ( - <> -
- - - - {response ? ( -
- -
- - - - - - - -
-
- ) : ( -

Pi is answering...

- )} -
-
-
- - - - setQuery(e.target.value)} - placeholder="Tell Pi what to do..." - /> - - - -
-
- - ); -}; diff --git a/web/ce/components/pages/editor/ai/index.ts b/web/ce/components/pages/editor/ai/index.ts index d21eb63d70..06dbd42f3d 100644 --- a/web/ce/components/pages/editor/ai/index.ts +++ b/web/ce/components/pages/editor/ai/index.ts @@ -1,2 +1 @@ -export * from "./ask-pi-menu"; -export * from "./menu"; +export * from "ee/components/pages/editor/ai"; diff --git a/web/ce/components/pages/editor/ai/menu.tsx b/web/ce/components/pages/editor/ai/menu.tsx deleted file mode 100644 index 4159b65568..0000000000 --- a/web/ce/components/pages/editor/ai/menu.tsx +++ /dev/null @@ -1,299 +0,0 @@ -"use client"; - -import React, { RefObject, useEffect, useRef, useState } from "react"; -import { useParams } from "next/navigation"; -import { ChevronRight, CornerDownRight, LucideIcon, RefreshCcw, Sparkles, TriangleAlert } from "lucide-react"; -// plane editor -import { EditorRefApi } from "@plane/editor"; -// plane ui -import { Tooltip } from "@plane/ui"; -// plane web constants -import { AI_EDITOR_TASKS, LOADING_TEXTS } from "@/ce/constants/ai"; -// components -import { RichTextReadOnlyEditor } from "@/components/editor"; -// helpers -import { cn } from "@/helpers/common.helper"; -// plane web services -import { AIService, TTaskPayload } from "@/services/ai.service"; -import { AskPiMenu } from "./ask-pi-menu"; -const aiService = new AIService(); - -type Props = { - editorRef: RefObject; - isOpen: boolean; - onClose: () => void; -}; - -const MENU_ITEMS: { - icon: LucideIcon; - key: AI_EDITOR_TASKS; - label: string; -}[] = [ - { - key: AI_EDITOR_TASKS.ASK_ANYTHING, - icon: Sparkles, - label: "Ask Pi", - }, -]; - -const TONES_LIST = [ - { - key: "default", - label: "Default", - casual_score: 5, - formal_score: 5, - }, - { - key: "professional", - label: "💼 Professional", - casual_score: 0, - formal_score: 10, - }, - { - key: "casual", - label: "😃 Casual", - casual_score: 10, - formal_score: 0, - }, -]; - -export const EditorAIMenu: React.FC = (props) => { - const { editorRef, isOpen, onClose } = props; - // states - const [activeTask, setActiveTask] = useState(null); - const [response, setResponse] = useState(undefined); - const [isRegenerating, setIsRegenerating] = useState(false); - // refs - const responseContainerRef = useRef(null); - // params - const { workspaceSlug } = useParams(); - const handleGenerateResponse = async (payload: TTaskPayload) => { - if (!workspaceSlug) return; - await aiService.performEditorTask(workspaceSlug.toString(), payload).then((res) => setResponse(res.response)); - }; - // handle task click - const handleClick = async (key: AI_EDITOR_TASKS) => { - const selection = editorRef.current?.getSelectedText(); - if (!selection || activeTask === key) return; - setActiveTask(key); - if (key === AI_EDITOR_TASKS.ASK_ANYTHING) return; - setResponse(undefined); - setIsRegenerating(false); - await handleGenerateResponse({ - task: key, - text_input: selection, - }); - }; - // handle re-generate response - const handleRegenerate = async () => { - const selection = editorRef.current?.getSelectedText(); - if (!selection || !activeTask) return; - setIsRegenerating(true); - await handleGenerateResponse({ - task: activeTask, - text_input: selection, - }) - .then(() => - responseContainerRef.current?.scrollTo({ - top: 0, - behavior: "smooth", - }) - ) - .finally(() => setIsRegenerating(false)); - }; - // handle re-generate response - const handleToneChange = async (key: string) => { - const selectedTone = TONES_LIST.find((t) => t.key === key); - const selection = editorRef.current?.getSelectedText(); - if (!selectedTone || !selection || !activeTask) return; - setResponse(undefined); - setIsRegenerating(false); - await handleGenerateResponse({ - casual_score: selectedTone.casual_score, - formal_score: selectedTone.formal_score, - task: activeTask, - text_input: selection, - }).then(() => - responseContainerRef.current?.scrollTo({ - top: 0, - behavior: "smooth", - }) - ); - }; - // handle replace selected text with the response - const handleInsertText = (insertOnNextLine: boolean) => { - if (!response) return; - editorRef.current?.insertText(response, insertOnNextLine); - onClose(); - }; - - // reset on close - useEffect(() => { - if (!isOpen) { - setActiveTask(null); - setResponse(undefined); - } - }, [isOpen]); - - return ( -
-
-
- {MENU_ITEMS.map((item) => { - const isActiveTask = activeTask === item.key; - - return ( - - ); - })} -
-
- {activeTask === AI_EDITOR_TASKS.ASK_ANYTHING ? ( - - ) : ( - <> -
- - - - {response ? ( -
- -
- - - - - - - -
-
- ) : ( -

- {activeTask ? LOADING_TEXTS[activeTask] : "Pi is writing"}... -

- )} -
-
- {TONES_LIST.map((tone) => ( - - ))} -
- - )} -
-
- {activeTask && ( -
- - - -

- By using this feature, you consent to sharing the message with a 3rd party service. -

-
- )} -
- ); -};