From b72f50cc4a09bc074ebb72508655374b87556cf9 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 26 Dec 2024 18:02:38 -0500 Subject: [PATCH] Remove file editing functionality from UI (#5823) Co-authored-by: openhands --- .../features/editor/code-editor-component.tsx | 115 -------------- .../features/editor/editor-actions.tsx | 33 ---- .../features/file-explorer/dropzone.tsx | 27 ---- .../file-explorer/file-explorer-actions.tsx | 10 +- .../file-explorer/file-explorer-header.tsx | 3 - .../features/file-explorer/file-explorer.tsx | 87 +--------- .../features/file-explorer/tree-node.tsx | 15 +- .../shared/buttons/upload-icon-button.tsx | 22 --- frontend/src/context/files.tsx | 58 +------ frontend/src/hooks/mutation/use-save-file.ts | 20 --- .../src/hooks/mutation/use-upload-files.ts | 15 -- frontend/src/routes/_oh.app._index/route.tsx | 148 +++++++++--------- .../hooks/use-handle-runtime-active.ts | 35 +---- 13 files changed, 78 insertions(+), 510 deletions(-) delete mode 100644 frontend/src/components/features/editor/code-editor-component.tsx delete mode 100644 frontend/src/components/features/editor/editor-actions.tsx delete mode 100644 frontend/src/components/features/file-explorer/dropzone.tsx delete mode 100644 frontend/src/components/shared/buttons/upload-icon-button.tsx delete mode 100644 frontend/src/hooks/mutation/use-save-file.ts delete mode 100644 frontend/src/hooks/mutation/use-upload-files.ts diff --git a/frontend/src/components/features/editor/code-editor-component.tsx b/frontend/src/components/features/editor/code-editor-component.tsx deleted file mode 100644 index 673010b8b1..0000000000 --- a/frontend/src/components/features/editor/code-editor-component.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import { Editor, EditorProps } from "@monaco-editor/react"; -import React from "react"; -import { useTranslation } from "react-i18next"; -import { VscCode } from "react-icons/vsc"; -import { I18nKey } from "#/i18n/declaration"; -import { useFiles } from "#/context/files"; -import { useSaveFile } from "#/hooks/mutation/use-save-file"; - -interface CodeEditorComponentProps { - onMount: EditorProps["onMount"]; - isReadOnly: boolean; -} - -function CodeEditorComponent({ - onMount, - isReadOnly, -}: CodeEditorComponentProps) { - const { t } = useTranslation(); - const { - files, - selectedPath, - modifiedFiles, - modifyFileContent, - saveFileContent: saveNewFileContent, - } = useFiles(); - - const { mutate: saveFile } = useSaveFile(); - - const handleEditorChange = (value: string | undefined) => { - if (selectedPath && value) modifyFileContent(selectedPath, value); - }; - - const isBase64Image = (content: string) => content.startsWith("data:image/"); - const isPDF = (content: string) => content.startsWith("data:application/pdf"); - const isVideo = (content: string) => content.startsWith("data:video/"); - - React.useEffect(() => { - const handleSave = async (event: KeyboardEvent) => { - if (selectedPath && event.metaKey && event.key === "s") { - const content = saveNewFileContent(selectedPath); - - if (content) { - saveFile({ path: selectedPath, content }); - } - } - }; - - document.addEventListener("keydown", handleSave); - return () => { - document.removeEventListener("keydown", handleSave); - }; - }, [saveNewFileContent]); - - if (!selectedPath) { - return ( -
- - {t(I18nKey.CODE_EDITOR$EMPTY_MESSAGE)} -
- ); - } - - const fileContent: string | undefined = - modifiedFiles[selectedPath] || files[selectedPath]; - - if (fileContent) { - if (isBase64Image(fileContent)) { - return ( -
- {selectedPath} -
- ); - } - - if (isPDF(fileContent)) { - return ( -