From 281ad7f2cd1863d8ae3b995682603847484dd17a Mon Sep 17 00:00:00 2001 From: ramnique <30795890+ramnique@users.noreply.github.com> Date: Tue, 21 Jan 2025 10:09:19 +0530 Subject: [PATCH] improve copilot response styling --- .../[projectId]/workflow/copilot_actions.tsx | 133 ++++++++---------- 1 file changed, 62 insertions(+), 71 deletions(-) diff --git a/apps/rowboat/app/projects/[projectId]/workflow/copilot_actions.tsx b/apps/rowboat/app/projects/[projectId]/workflow/copilot_actions.tsx index 54e0e3b1..43d935c0 100644 --- a/apps/rowboat/app/projects/[projectId]/workflow/copilot_actions.tsx +++ b/apps/rowboat/app/projects/[projectId]/workflow/copilot_actions.tsx @@ -5,6 +5,7 @@ import { z } from "zod"; import { Workflow, CopilotAssistantMessage, CopilotAssistantMessageActionPart } from "@/app/lib/types"; import { PreviewModalProvider, usePreviewModal } from './preview-modal'; import { getAppliedChangeKey } from "./copilot"; +import { CheckCheckIcon, CheckIcon, ChevronsDownIcon, ChevronsUpIcon, EyeIcon, PencilIcon, PlusIcon } from "lucide-react"; const ActionContext = createContext<{ msgIndex: number; @@ -14,7 +15,7 @@ const ActionContext = createContext<{ handleApplyChange: (messageIndex: number, actionIndex: number, field?: string) => void; appliedFields: string[]; stale: boolean; -}>({ msgIndex: 0, actionIndex: 0, action: null, workflow: null, handleApplyChange: () => {}, appliedFields: [], stale: false }); +}>({ msgIndex: 0, actionIndex: 0, action: null, workflow: null, handleApplyChange: () => { }, appliedFields: [], stale: false }); export function Action({ msgIndex, @@ -33,42 +34,73 @@ export function Action({ appliedChanges: Record; stale: boolean; }) { - const [expanded, setExpanded] = useState(Object.entries(action.config_changes).length <= 2); - const changes = Object.entries(action.config_changes).slice(0, expanded ? undefined : 2); + const [expanded, setExpanded] = useState(false); // determine whether all changes contained in this action are applied const appliedFields = Object.keys(action.config_changes).filter(key => appliedChanges[getAppliedChangeKey(msgIndex, actionIndex, key)]); console.log('appliedFields', appliedFields); - return
appliedFields.includes(key)); + + // generate apply change function + const applyChangeHandler = () => { + handleApplyChange(msgIndex, actionIndex); + } + + return
- - - {changes.map(([key, value]) => { + + {expanded && +
+ {Object.entries(action.config_changes).map(([key, value]) => { return })} - - - {Object.entries(action.config_changes).length > 2 && } +
+
} +
+ + +
; } +export function ActionSummary() { + const { msgIndex, actionIndex, action, workflow, handleApplyChange, appliedFields, stale } = useContext(ActionContext); + if (!action || !workflow) return null; + + return
+
+ {action.change_description} +
+
; +} + export function ActionHeader() { const { msgIndex, actionIndex, action, workflow, handleApplyChange, appliedFields, stale } = useContext(ActionContext); if (!action || !workflow) return null; @@ -76,47 +108,13 @@ export function ActionHeader() { const targetType = action.config_type === 'tool' ? 'tool' : action.config_type === 'agent' ? 'agent' : 'prompt'; const change = action.action === 'create_new' ? 'Create' : 'Edit'; - // determine whether all changes contained in this action are applied - const allApplied = Object.keys(action.config_changes).every(key => appliedFields.includes(key)); - - // generate apply change function - const applyChangeHandler = () => { - handleApplyChange(msgIndex, actionIndex); - } - - return
-
{`${change} ${targetType}`}: {action.name}
- + return
+ {action.action == 'create_new' && } + {action.action == 'edit' && } +
{`${change} ${targetType}`}: {action.name}
; } -export function ActionBody({ - children, -}: { - children: React.ReactNode; -}) { - return
{children}
; -} - export function ActionField({ field, }: { @@ -183,20 +181,13 @@ export function ActionField({ return
-
{field}
+
{field}
{previewCondition &&
{action.action === 'edit' && }
}