From b6834a9efe98e89d97369420ef1065cf404889cb Mon Sep 17 00:00:00 2001 From: Myles Scolnick Date: Sat, 4 Jan 2025 15:15:06 -0500 Subject: [PATCH] fix: better component memozation (#3341) --- frontend/src/components/editor/Cell.tsx | 9 +- .../editor/output/ConsoleOutput.tsx | 83 +++++++++++++------ 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/frontend/src/components/editor/Cell.tsx b/frontend/src/components/editor/Cell.tsx index cd499714ad9..61fcac7350c 100644 --- a/frontend/src/components/editor/Cell.tsx +++ b/frontend/src/components/editor/Cell.tsx @@ -11,7 +11,6 @@ import { useRef, useState, } from "react"; - import { saveCellConfig, sendRun, sendStdin } from "@/core/network/requests"; import { autocompletionKeymap } from "@/core/codemirror/cm"; import type { UserConfig } from "../../core/config/config-schema"; @@ -520,6 +519,10 @@ const CellComponent = ( : {}), }); + const handleRefactorWithAI = useEvent((opts: { prompt: string }) => { + setAiCompletionCell({ cellId, initialPrompt: opts.prompt }); + }); + if (!editing) { const outputIsError = isErrorMime(output?.mimetype); const hidden = errored || interrupted || stopped || outputIsError; @@ -546,10 +549,6 @@ const CellComponent = ( return undefined; }; - const handleRefactorWithAI = (opts: { prompt: string }) => { - setAiCompletionCell({ cellId, initialPrompt: opts.prompt }); - }; - const cellStatusComponent = ( { return null; } - const renderText = (text: string) => { - return ( - - ); - }; - const reversedOutputs = [...consoleOutputs].reverse(); return ( @@ -99,7 +93,6 @@ export const ConsoleOutput = (props: Props): React.ReactNode => { if (output.channel === "pdb") { return null; } - const originalIdx = consoleOutputs.length - idx - 1; if (output.channel === "stdin") { invariant( @@ -107,31 +100,24 @@ export const ConsoleOutput = (props: Props): React.ReactNode => { "Expected data to be a string", ); + const originalIdx = consoleOutputs.length - idx - 1; + if (output.response == null) { return ( -
- {renderText(output.data)} - { - if (e.key === "Enter" && !e.shiftKey) { - onSubmitDebugger(e.currentTarget.value, originalIdx); - } - }} - /> -
+ onSubmitDebugger(text, originalIdx)} + /> ); } + return ( -
- {renderText(output.data)} - {output.response} -
+ ); } @@ -152,3 +138,46 @@ export const ConsoleOutput = (props: Props): React.ReactNode => { ); }; + +const StdInput = (props: { + onSubmit: (text: string) => void; + output: string; + response?: string; +}) => { + return ( +
+ {renderText(props.output)} + { + if (e.key === "Enter" && !e.shiftKey) { + props.onSubmit(e.currentTarget.value); + } + }} + /> +
+ ); +}; + +const StdInputWithResponse = (props: { + output: string; + response?: string; +}) => { + return ( +
+ {renderText(props.output)} + {props.response} +
+ ); +}; + +const renderText = (text: string) => { + return ( + + ); +};