From cea789b99437553655b2994bf4181d422a759e54 Mon Sep 17 00:00:00 2001 From: Marc McIntosh Date: Mon, 9 Dec 2024 14:25:47 +0100 Subject: [PATCH] fix(chat links): handle go to actions. --- src/components/ChatLinks/ChatLinks.tsx | 62 ++++++++++++++++---------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/components/ChatLinks/ChatLinks.tsx b/src/components/ChatLinks/ChatLinks.tsx index 025fbab5..1218eb96 100644 --- a/src/components/ChatLinks/ChatLinks.tsx +++ b/src/components/ChatLinks/ChatLinks.tsx @@ -1,5 +1,5 @@ import React, { useEffect } from "react"; -import { Flex, Button, Heading, Container, Box } from "@radix-ui/themes"; +import { Flex, Button, Container, Box } from "@radix-ui/themes"; import { linksApi, type ChatLink } from "../../services/refact/links"; import { diffApi, isUserMessage } from "../../services/refact"; import { @@ -20,6 +20,7 @@ import { setIntegrationData, } from "../../features/Chat"; import { popBackTo } from "../../features/Pages/pagesSlice"; +import { TruncateRight } from "../Text/TruncateRight"; function maybeConcatActionAndGoToStrings(link: ChatLink): string | undefined { const hasAction = "action" in link; @@ -82,8 +83,12 @@ export const ChatLinks: React.FC = () => { popBackTo({ name: "integrations page", // projectPath: isFile ? payload : "", - integrationName: !isFile ? payload : "", - integrationPath: isFile ? payload : "", + integrationName: + !isFile && payload !== "DEFAULT" + ? payload + : maybeIntegration?.name, + integrationPath: isFile ? payload : maybeIntegration?.path, + projectPath: maybeIntegration?.project, }), ); // TODO: open in the integrations @@ -99,8 +104,17 @@ export const ChatLinks: React.FC = () => { const handleLinkAction = (link: ChatLink) => { if (!("action" in link)) return; + if (link.action === "goto" && "goto" in link) { + handleGoTo(link.goto); + return; + } + if (link.action === "patch-all") { - void applyPatches(messages); + void applyPatches(messages).then(() => { + if ("goto" in link) { + handleGoTo(link.goto); + } + }); return; } @@ -118,26 +132,22 @@ export const ChatLinks: React.FC = () => { return; } - if (link.action === "commit") { - // TODO: there should be an endpoint for this - void applyPatches(messages).then(() => { - if ("goto" in link && link.goto) { - handleGoTo(link.goto); - } - }); + // if (link.action === "commit") { + // // TODO: there should be an endpoint for this + // void applyPatches(messages).then(() => { + // if ("goto" in link && link.goto) { + // handleGoTo(link.goto); + // } + // }); - return; - } + // return; + // } // eslint-disable-next-line no-console console.warn(`unknown action: ${JSON.stringify(link)}`); }; const handleClick = (link: ChatLink) => { - if (!("action" in link) && "goto" in link) { - handleGoTo(link.goto); - } else { - handleLinkAction(link); - } + handleLinkAction(link); }; const [linksRequest, linksResult] = linksApi.useGetLinksForChatMutation(); @@ -176,17 +186,19 @@ export const ChatLinks: React.FC = () => { // TODO: waiting, errors, maybe add a title - if (!linksResult.data || isStreaming || isWaiting || unCalledTools) { + if ( + !linksResult.data || + isStreaming || + isWaiting || + unCalledTools || + linksResult.data.links.length === 0 + ) { return null; } const Wrapper = messages.length === 0 ? Box : Container; return ( - - Available Actions:{" "} - - {linksResult.data.links.map((link, index) => { const key = `chat-link-${index}`; @@ -211,11 +223,13 @@ const ChatLinkButton: React.FC<{ // variant="outline" // variant="soft" // variant="ghost" + variant="surface" title={title} onClick={handleClick} + style={{ maxWidth: "100%" }} > - {link.text} + {link.text} ); };