Skip to content

Self-improving AI Employees for everyone

refactor(client): MiddleSection - hand-rolled modals -> shadcn AlertDialog

trohitg61bf23c4f8d2
diff --git a/client/src/components/parameterPanel/MiddleSection.tsx b/client/src/components/parameterPanel/MiddleSection.tsx
index 17bc689b..c513d527 100644
--- a/client/src/components/parameterPanel/MiddleSection.tsx
+++ b/client/src/components/parameterPanel/MiddleSection.tsx
@@ -6,6 +6,7 @@ import { useMutation } from '@tanstack/react-query';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Progress } from '@/components/ui/progress';
+import { Checkbox } from '@/components/ui/checkbox';
import { cn } from '@/lib/utils';
import {
Accordion,
@@ -13,6 +14,16 @@ import {
AccordionTrigger,
AccordionContent,
} from '@/components/ui/accordion';
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from '@/components/ui/alert-dialog';
import { Zap, Pencil } from 'lucide-react';
import ParameterRenderer from '../ParameterRenderer';
import ToolSchemaEditor from './ToolSchemaEditor';
@@ -563,256 +574,104 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({
{/* Clear Memory Button - Only for memory nodes */}
{isMemoryNode && (
- <div style={{
- display: 'flex',
- justifyContent: 'flex-end',
- paddingTop: theme.spacing.md,
- marginTop: theme.spacing.md,
- borderTop: `1px solid ${theme.colors.border}`
- }}>
- <button
+ <div className="mt-3 flex justify-end border-t border-border pt-3">
+ <Button
+ variant="outline"
+ size="sm"
onClick={() => setShowClearMemoryDialog(true)}
- style={{
- display: 'flex',
- alignItems: 'center',
- gap: '6px',
- padding: '6px 12px',
- backgroundColor: `${theme.dracula.red}20`,
- color: theme.dracula.red,
- border: `1px solid ${theme.dracula.red}50`,
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- cursor: 'pointer',
- transition: 'all 0.15s ease'
- }}
+ className="border-dracula-red/50 bg-dracula-red/15 text-dracula-red hover:bg-dracula-red/25"
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<polyline points="3 6 5 6 21 6" />
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
</svg>
Clear Memory
- </button>
+ </Button>
</div>
)}
{/* Reset Skill Button - Only for built-in skill nodes */}
{isSkillNode && (
- <div style={{
- display: 'flex',
- justifyContent: 'flex-end',
- paddingTop: theme.spacing.md,
- marginTop: theme.spacing.md,
- borderTop: `1px solid ${theme.colors.border}`
- }}>
- <button
+ <div className="mt-3 flex justify-end border-t border-border pt-3">
+ <Button
+ variant="outline"
+ size="sm"
onClick={() => setShowResetSkillDialog(true)}
- style={{
- display: 'flex',
- alignItems: 'center',
- gap: '6px',
- padding: '6px 12px',
- backgroundColor: `${theme.dracula.orange}20`,
- color: theme.dracula.orange,
- border: `1px solid ${theme.dracula.orange}50`,
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- cursor: 'pointer',
- transition: 'all 0.15s ease'
- }}
+ className="border-dracula-orange/50 bg-dracula-orange/15 text-dracula-orange hover:bg-dracula-orange/25"
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<polyline points="1 4 1 10 7 10" />
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10" />
</svg>
Reset to Default
- </button>
+ </Button>
</div>
)}
</div>
- {/* Clear Memory Confirmation Dialog */}
- {showClearMemoryDialog && (
- <div style={{
- position: 'fixed',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- zIndex: 9999
- }}>
- <div style={{
- backgroundColor: theme.colors.background,
- borderRadius: theme.borderRadius.lg,
- border: `1px solid ${theme.colors.border}`,
- padding: theme.spacing.xl,
- maxWidth: '400px',
- width: '90%',
- boxShadow: '0 10px 40px rgba(0, 0, 0, 0.3)'
- }}>
- <h3 style={{
- margin: `0 0 ${theme.spacing.md}`,
- fontSize: theme.fontSize.lg,
- fontWeight: theme.fontWeight.semibold,
- color: theme.colors.text
- }}>
- Clear Conversation Memory
- </h3>
- <p style={{
- margin: `0 0 ${theme.spacing.lg}`,
- fontSize: theme.fontSize.sm,
- color: theme.colors.textSecondary,
- lineHeight: 1.5
- }}>
+ {/* Clear Memory Confirmation Dialog (shadcn AlertDialog) */}
+ <AlertDialog
+ open={showClearMemoryDialog}
+ onOpenChange={(open) => {
+ if (!open) {
+ setShowClearMemoryDialog(false);
+ setClearLongTermMemory(false);
+ }
+ }}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Clear Conversation Memory</AlertDialogTitle>
+ <AlertDialogDescription>
This will reset the conversation history to its initial state. This action cannot be undone.
- </p>
-
- {/* Long-term memory checkbox */}
- {parameters.longTermEnabled && (
- <label style={{
- display: 'flex',
- alignItems: 'center',
- gap: '8px',
- marginBottom: theme.spacing.lg,
- fontSize: theme.fontSize.sm,
- color: theme.colors.text,
- cursor: 'pointer'
- }}>
- <input
- type="checkbox"
- checked={clearLongTermMemory}
- onChange={(e) => setClearLongTermMemory(e.target.checked)}
- style={{ width: 16, height: 16 }}
- />
- Also clear long-term memory (vector store)
- </label>
- )}
-
- <div style={{ display: 'flex', justifyContent: 'flex-end', gap: theme.spacing.sm }}>
- <button
- onClick={() => {
- setShowClearMemoryDialog(false);
- setClearLongTermMemory(false);
- }}
- disabled={isProcessing}
- style={{
- padding: '8px 16px',
- backgroundColor: theme.colors.backgroundAlt,
- color: theme.colors.text,
- border: `1px solid ${theme.colors.border}`,
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- cursor: isProcessing ? 'not-allowed' : 'pointer'
- }}
- >
- Cancel
- </button>
- <button
- onClick={handleClearMemory}
- disabled={isProcessing}
- style={{
- padding: '8px 16px',
- backgroundColor: theme.dracula.red,
- color: '#fff',
- border: 'none',
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- cursor: isProcessing ? 'not-allowed' : 'pointer',
- opacity: isProcessing ? 0.7 : 1
- }}
- >
- {isProcessing ? 'Clearing...' : 'Clear Memory'}
- </button>
- </div>
- </div>
- </div>
- )}
-
- {/* Reset Skill Confirmation Dialog */}
- {showResetSkillDialog && (
- <div style={{
- position: 'fixed',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- zIndex: 9999
- }}>
- <div style={{
- backgroundColor: theme.colors.background,
- borderRadius: theme.borderRadius.lg,
- border: `1px solid ${theme.colors.border}`,
- padding: theme.spacing.xl,
- maxWidth: '400px',
- width: '90%',
- boxShadow: '0 10px 40px rgba(0, 0, 0, 0.3)'
- }}>
- <h3 style={{
- margin: `0 0 ${theme.spacing.md}`,
- fontSize: theme.fontSize.lg,
- fontWeight: theme.fontWeight.semibold,
- color: theme.colors.text
- }}>
- Reset Skill to Default
- </h3>
- <p style={{
- margin: `0 0 ${theme.spacing.lg}`,
- fontSize: theme.fontSize.sm,
- color: theme.colors.textSecondary,
- lineHeight: 1.5
- }}>
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ {parameters.longTermEnabled && (
+ <label className="flex cursor-pointer items-center gap-2 text-sm text-foreground">
+ <Checkbox
+ checked={clearLongTermMemory}
+ onCheckedChange={(checked) => setClearLongTermMemory(checked === true)}
+ />
+ Also clear long-term memory (vector store)
+ </label>
+ )}
+ <AlertDialogFooter>
+ <AlertDialogCancel disabled={isProcessing}>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ disabled={isProcessing}
+ onClick={handleClearMemory}
+ className="bg-dracula-red text-white hover:bg-dracula-red/90"
+ >
+ {isProcessing ? 'Clearing...' : 'Clear Memory'}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+
+ {/* Reset Skill Confirmation Dialog (shadcn AlertDialog) */}
+ <AlertDialog
+ open={showResetSkillDialog}
+ onOpenChange={(open) => !open && setShowResetSkillDialog(false)}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Reset Skill to Default</AlertDialogTitle>
+ <AlertDialogDescription>
This will restore the skill instructions to their original content. Any customizations will be lost.
- </p>
-
- <div style={{ display: 'flex', justifyContent: 'flex-end', gap: theme.spacing.sm }}>
- <button
- onClick={() => setShowResetSkillDialog(false)}
- disabled={isProcessing}
- style={{
- padding: '8px 16px',
- backgroundColor: theme.colors.backgroundAlt,
- color: theme.colors.text,
- border: `1px solid ${theme.colors.border}`,
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- cursor: isProcessing ? 'not-allowed' : 'pointer'
- }}
- >
- Cancel
- </button>
- <button
- onClick={handleResetSkill}
- disabled={isProcessing}
- style={{
- padding: '8px 16px',
- backgroundColor: theme.dracula.orange,
- color: '#fff',
- border: 'none',
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- cursor: isProcessing ? 'not-allowed' : 'pointer',
- opacity: isProcessing ? 0.7 : 1
- }}
- >
- {isProcessing ? 'Resetting...' : 'Reset to Default'}
- </button>
- </div>
- </div>
- </div>
- )}
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel disabled={isProcessing}>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ disabled={isProcessing}
+ onClick={handleResetSkill}
+ className="bg-dracula-orange text-white hover:bg-dracula-orange/90"
+ >
+ {isProcessing ? 'Resetting...' : 'Reset to Default'}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
{/* Token Usage Section - Only for agent nodes with memory connected */}
{isAgentWithSkills && connectedMemorySessionId && (