Skip to content

Commit

Permalink
add button to navigate to view rather than doing so automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
xinaesthete committed Feb 12, 2025
1 parent b7e3d4a commit a0da73b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/charts/dialogs/ChatAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type ChatResponse = z.infer<typeof completedChatResponseSchema>;

export type ChatMessage = {
text: string;
view?: string; //maybe this type should be more assocated with ChatResponse
sender: 'user' | 'bot' | 'system';
id: string;
};
Expand Down Expand Up @@ -155,9 +156,10 @@ const useChat = () => {
}
}, [isSending, isInit, routeInit, progressRoute, route, progressListener]);

const appendMessage = (message: string, sender: 'bot' | 'user') => {
//we should be using an id passed as part of the message, not generating one here
const msg = { text: message, sender, id: generateId() };
const appendMessage = (message: string, sender: 'bot' | 'user', view?: string) => {
//we should be using an id passed as part of the message, not generating one here.
//also - id as react key if we have an id shared between query and response may be a conflict
const msg = { text: message, sender, id: generateId(), view };
setMessages((prevMessages) => [...prevMessages, msg]);
};

Expand All @@ -172,9 +174,12 @@ const useChat = () => {
setIsSending(true);
setCurrentRequestId(id);
const response = await sendMessage(input, id, route);
appendMessage(response.message, 'bot');
//todo - navigating via button rather than automatically
if (response.view) navigateToView(response.view);
// we should be appending more stuff, and then rendering appropriately,
// with things like a button to navigate to the view if view property is present.
appendMessage(response.message, 'bot', response.view);
//todo - navigating via button rather than automatically.

// if (response.view) navigateToView(response.view);
} catch (error) {
appendMessage(`Error: ${error}`, 'bot');
}
Expand All @@ -190,7 +195,7 @@ const useChat = () => {
*
* ! doesn't belong in this file, I intend to refactor soon, but for quick prototyping it's here
*/
async function navigateToView(view: string) {
export async function navigateToView(view: string) {
//todo - use this, but make sure it works with updated datasources etc...
//window.mdv.chartManager.changeView(view);

Expand Down
6 changes: 4 additions & 2 deletions src/charts/dialogs/ChatDialogComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { BotMessageSquare, SquareTerminal } from 'lucide-react';
import { MessageCircleQuestion, ThumbsUp, ThumbsDown, Star, NotebookPen } from 'lucide-react';
import useChat, { type ChatProgress, type ChatMessage } from './ChatAPI';
import useChat, { type ChatProgress, type ChatMessage, navigateToView } from './ChatAPI';
import { useCallback, useEffect, useRef, useState } from 'react';
import JsonView from 'react18-json-view';
import ReactMarkdown from 'react-markdown';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { dracula } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import RobotPandaSVG from './PandaSVG';
import LinearProgress from '@mui/material/LinearProgress';
import { Button } from '@mui/material';

const Message = ({ text, sender }: ChatMessage) => {
const Message = ({ text, sender, view }: ChatMessage) => {
const isUser = sender === 'user';
const pythonSections = extractPythonSections(text);
try {
Expand All @@ -29,6 +30,7 @@ const Message = ({ text, sender }: ChatMessage) => {
<PythonCode key={index} code={section} />
))} */}
{(sender === 'bot') && <MessageFeedback />}
{view && <Button variant="contained" color="primary" onClick={() => navigateToView(view)}>Load view...</Button>}
</div>
);
}
Expand Down

0 comments on commit a0da73b

Please sign in to comment.