Skip to content

Commit 6718758

Browse files
add jsfunction resp viz
1 parent dddc6f1 commit 6718758

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

app/client/src/PluginActionEditor/components/PluginActionResponse/components/Visualization/Visualization.tsx

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
import { Button, Flex } from "@appsmith/ads";
2-
import type { ActionResponse } from "api/ActionAPI";
3-
import { type Action } from "entities/Action";
2+
import { ErrorBoundary } from "@sentry/react";
3+
import { type VisualizationElements } from "entities/Action";
44
import React, { useState } from "react";
5-
import { parseActionResponse } from "../Response/utils";
65
import { EmptyVisualization } from "./components/EmptyVisualization";
76
import { LoadingOverlay } from "./components/LoadingOverlay";
87
import { PromptInput } from "./components/PromptInput";
98
import { Result } from "./components/Result";
109
import { SuggestionButtons } from "./components/SuggestionButtons";
1110
import { useGenerateVisualization } from "./useGenerateVisualization";
1211
import { useSaveVisualization } from "./useSaveVisualization";
13-
import { ErrorBoundary } from "@sentry/react";
1412

1513
interface VisualizationProps {
16-
action: Action;
17-
actionResponse?: ActionResponse;
14+
entityId: string;
15+
visualizationElements?: VisualizationElements;
16+
response?: string | Record<string, unknown>[];
1817
}
1918

2019
const BOTTOM_BAR_HEIGHT = 37;
2120

2221
export const Visualization = (props: VisualizationProps) => {
23-
const { action, actionResponse } = props;
22+
const { entityId, response, visualizationElements } = props;
2423
const [prompt, setPrompt] = useState("");
25-
const { response } = parseActionResponse(actionResponse);
2624
const generateVisualization = useGenerateVisualization(
27-
action.id,
28-
action.visualization?.result,
25+
entityId,
26+
visualizationElements,
2927
);
30-
const saveVisualization = useSaveVisualization(action.id);
28+
const saveVisualization = useSaveVisualization(entityId);
3129

3230
return (
3331
// TODO: Remove the hardcoded height
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Button, Input } from "@appsmith/ads";
1+
import { Button, Flex, Input } from "@appsmith/ads";
22
import React from "react";
3-
import styled from "styled-components";
43

54
interface PromptInputProps {
65
value: string;
@@ -10,25 +9,20 @@ interface PromptInputProps {
109
isDisabled: boolean;
1110
}
1211

13-
const PromptForm = styled.form`
14-
display: flex;
15-
flex: 1;
16-
gap: var(--ads-v2-spaces-3);
17-
`;
18-
1912
export const PromptInput = (props: PromptInputProps) => {
2013
const { isDisabled, isLoading, onChange, onSubmit, value } = props;
2114

2215
return (
23-
<PromptForm
24-
onSubmit={(e) => {
25-
e.preventDefault();
26-
onSubmit();
27-
}}
28-
>
16+
// We can't use a form here because editor already wrapped in a form
17+
<Flex flex="1" gap="spaces-3">
2918
<Input
3019
isDisabled={isDisabled}
3120
onChange={onChange}
21+
onKeyDown={(e) => {
22+
if (e.key === "Enter") {
23+
onSubmit();
24+
}
25+
}}
3226
placeholder="Describe the data visualisation you want"
3327
size="md"
3428
value={value}
@@ -38,10 +32,10 @@ export const PromptInput = (props: PromptInputProps) => {
3832
isIconButton
3933
isLoading={isLoading}
4034
kind="primary"
35+
onClick={onSubmit}
4136
size="md"
4237
startIcon="arrow-up-line"
43-
type="submit"
4438
/>
45-
</PromptForm>
39+
</Flex>
4640
);
4741
};

app/client/src/components/editorComponents/JSResponseView.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import { StateInspector } from "./Debugger/StateInspector";
4242
import { getErrorCount } from "selectors/debuggerSelectors";
4343
import { getIDETypeByUrl } from "ee/entities/IDE/utils";
4444
import { useLocation } from "react-router";
45+
import { getReleaseFnCallingEnabled } from "layoutSystems/anvil/integrations/selectors";
46+
import { Visualization } from "../../PluginActionEditor/components/PluginActionResponse/components/Visualization";
4547

4648
const ResponseTabWrapper = styled.div`
4749
display: flex;
@@ -212,16 +214,35 @@ function JSResponseView(props: Props) {
212214

213215
const ideViewMode = useSelector(getIDEViewMode);
214216
const location = useLocation();
217+
const isFnCallingEnabled = useSelector(getReleaseFnCallingEnabled);
215218

216219
const ideType = getIDETypeByUrl(location.pathname);
217220

218221
const tabs = useMemo(() => {
219-
const jsTabs: BottomTab[] = [
222+
const responseTabs: BottomTab[] = [
220223
{
221224
key: DEBUGGER_TAB_KEYS.RESPONSE_TAB,
222225
title: createMessage(DEBUGGER_RESPONSE),
223226
panelComponent: JSResponseTab,
224227
},
228+
];
229+
230+
if (isFnCallingEnabled) {
231+
responseTabs.push({
232+
key: DEBUGGER_TAB_KEYS.VISUALIZATION_TAB,
233+
title: "AI Response Visualizer",
234+
panelComponent: currentFunction && (
235+
<Visualization
236+
entityId={currentFunction.id}
237+
response={response.value}
238+
visualizationElements={currentFunction.visualization?.result}
239+
/>
240+
),
241+
});
242+
}
243+
244+
const jsTabs: BottomTab[] = [
245+
...responseTabs,
225246
{
226247
key: DEBUGGER_TAB_KEYS.LOGS_TAB,
227248
title: createMessage(DEBUGGER_LOGS),

0 commit comments

Comments
 (0)