Skip to content

Self-improving AI Employees for everyone

refactor(ui): MiddleSection + ErrorBoundary off theme-locked classes

trohitgae6864c0ea57
diff --git a/client/src/components/parameterPanel/MiddleSection.tsx b/client/src/components/parameterPanel/MiddleSection.tsx
index 024d5e6e..4953c77f 100644
--- a/client/src/components/parameterPanel/MiddleSection.tsx
+++ b/client/src/components/parameterPanel/MiddleSection.tsx
@@ -24,8 +24,9 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
-import { Zap, Pencil, Sparkles, TerminalSquare } from 'lucide-react';
+import { Zap, Pencil, Sparkles, TerminalSquare, Trash2, RotateCcw } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
+import { ActionButton } from '@/components/ui/action-button';
import ParameterRenderer from '../ParameterRenderer';
import ToolSchemaEditor from './ToolSchemaEditor';
import MasterSkillEditor from './MasterSkillEditor';
@@ -563,15 +564,11 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({
{isMemoryNode && (
<div className="mt-3 flex justify-end border-t border-border pt-3">
<Button
- variant="outline"
+ variant="destructive"
size="sm"
onClick={() => setShowClearMemoryDialog(true)}
- 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>
+ <Trash2 className="h-3.5 w-3.5" />
Clear Memory
</Button>
</div>
@@ -580,18 +577,14 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({
{/* Reset Skill Button - Only for built-in skill nodes */}
{isSkillNode && (
<div className="mt-3 flex justify-end border-t border-border pt-3">
- <Button
- variant="outline"
- size="sm"
+ <ActionButton
+ tone="orange"
onClick={() => setShowResetSkillDialog(true)}
- className="border-dracula-orange/50 bg-dracula-orange/15 text-dracula-orange hover:bg-dracula-orange/25"
+ className="h-8"
>
- <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>
+ <RotateCcw className="h-3.5 w-3.5" />
Reset to Default
- </Button>
+ </ActionButton>
</div>
)}
</div>
@@ -625,9 +618,9 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({
<AlertDialogFooter>
<AlertDialogCancel disabled={isProcessing}>Cancel</AlertDialogCancel>
<AlertDialogAction
+ variant="destructive"
disabled={isProcessing}
onClick={handleClearMemory}
- className="bg-dracula-red text-white hover:bg-dracula-red/90"
>
{isProcessing ? 'Clearing...' : 'Clear Memory'}
</AlertDialogAction>
@@ -652,7 +645,6 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({
<AlertDialogAction
disabled={isProcessing}
onClick={handleResetSkill}
- className="bg-dracula-orange text-white hover:bg-dracula-orange/90"
>
{isProcessing ? 'Resetting...' : 'Reset to Default'}
</AlertDialogAction>
@@ -811,7 +803,10 @@ const MiddleSection: React.FC<MiddleSectionProps> = ({
>
<div
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-md"
- style={{ backgroundColor: skill.color + '20' }}
+ // skill.color is per-skill metadata (SKILL.md frontmatter); the
+ // tinted icon background uses CSS color-mix so the math lives in
+ // CSS, not as JS string concat at the call site.
+ style={{ backgroundColor: `color-mix(in srgb, ${skill.color} 12%, transparent)` }}
>
{(() => {
const LibIcon = resolveLibraryIcon(skill.icon);
diff --git a/client/src/components/ui/ErrorBoundary.tsx b/client/src/components/ui/ErrorBoundary.tsx
index 458ba565..55e43018 100644
--- a/client/src/components/ui/ErrorBoundary.tsx
+++ b/client/src/components/ui/ErrorBoundary.tsx
@@ -1,5 +1,8 @@
import { Component, ErrorInfo, ReactNode } from 'react';
-import { theme } from '../../styles/theme';
+import { AlertTriangle, RotateCcw, RefreshCw, Bug } from 'lucide-react';
+import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert';
+import { Button } from '@/components/ui/button';
+import { Card, CardContent } from '@/components/ui/card';
interface Props {
children: ReactNode;
@@ -13,30 +16,19 @@ interface State {
}
class ErrorBoundary extends Component<Props, State> {
- public state: State = {
- hasError: false
- };
+ public state: State = { hasError: false };
public static getDerivedStateFromError(error: Error): State {
- // Update state so the next render will show the fallback UI
return { hasError: true, error };
}
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error('ErrorBoundary caught an error:', error, errorInfo);
-
- this.setState({
- error,
- errorInfo
- });
+ this.setState({ error, errorInfo });
}
private handleReset = () => {
- this.setState({
- hasError: false,
- error: undefined,
- errorInfo: undefined
- });
+ this.setState({ hasError: false, error: undefined, errorInfo: undefined });
};
private handleReload = () => {
@@ -44,153 +36,50 @@ class ErrorBoundary extends Component<Props, State> {
};
public render() {
- if (this.state.hasError) {
- // Custom fallback UI
- if (this.props.fallback) {
- return this.props.fallback;
- }
+ if (!this.state.hasError) return this.props.children;
+ if (this.props.fallback) return this.props.fallback;
- // Default fallback UI
- return (
- <div style={{
- width: '100%',
- height: '100%',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- backgroundColor: theme.colors.background,
- padding: theme.spacing.xl
- }}>
- <div style={{
- maxWidth: '600px',
- textAlign: 'center',
- backgroundColor: theme.colors.backgroundAlt,
- padding: theme.spacing.xl,
- borderRadius: theme.borderRadius.lg,
- border: `1px solid ${theme.colors.border}`
- }}>
- <div style={{
- fontSize: '64px',
- marginBottom: theme.spacing.lg
- }}>
- ⚠️
- </div>
-
- <h2 style={{
- margin: 0,
- marginBottom: theme.spacing.md,
- fontSize: theme.fontSize.xl,
- fontWeight: theme.fontWeight.semibold,
- color: theme.colors.text
- }}>
- Canvas Error Detected
- </h2>
-
- <p style={{
- margin: 0,
- marginBottom: theme.spacing.lg,
- fontSize: theme.fontSize.base,
- color: theme.colors.textSecondary,
- lineHeight: '1.6'
- }}>
- The workflow canvas encountered an error and needs to be reset.
- Your workflow data is safe and will be restored.
- </p>
+ return (
+ <div className="flex h-full w-full items-center justify-center bg-background p-8">
+ <Card className="w-full max-w-xl">
+ <CardContent className="space-y-4 p-6 text-center">
+ <Alert variant="destructive">
+ <AlertTriangle className="h-4 w-4" />
+ <AlertTitle>Canvas Error Detected</AlertTitle>
+ <AlertDescription>
+ The workflow canvas encountered an error and needs to be reset.
+ Your workflow data is safe and will be restored.
+ </AlertDescription>
+ </Alert>
- <div style={{
- display: 'flex',
- gap: theme.spacing.md,
- justifyContent: 'center',
- flexWrap: 'wrap'
- }}>
- <button
- onClick={this.handleReset}
- style={{
- padding: `${theme.spacing.sm} ${theme.spacing.lg}`,
- backgroundColor: theme.colors.focus,
- color: 'white',
- border: 'none',
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.base,
- fontWeight: theme.fontWeight.medium,
- cursor: 'pointer',
- transition: 'all 0.2s ease'
- }}
- onMouseEnter={(e) => {
- e.currentTarget.style.backgroundColor = '#2563eb';
- }}
- onMouseLeave={(e) => {
- e.currentTarget.style.backgroundColor = theme.colors.focus;
- }}
- >
- 🔄 Reset Canvas
- </button>
-
- <button
- onClick={this.handleReload}
- style={{
- padding: `${theme.spacing.sm} ${theme.spacing.lg}`,
- backgroundColor: 'transparent',
- color: theme.colors.text,
- border: `1px solid ${theme.colors.border}`,
- borderRadius: theme.borderRadius.sm,
- fontSize: theme.fontSize.base,
- fontWeight: theme.fontWeight.medium,
- cursor: 'pointer',
- transition: 'all 0.2s ease'
- }}
- onMouseEnter={(e) => {
- e.currentTarget.style.backgroundColor = theme.colors.backgroundAlt;
- e.currentTarget.style.borderColor = theme.colors.borderHover;
- }}
- onMouseLeave={(e) => {
- e.currentTarget.style.backgroundColor = 'transparent';
- e.currentTarget.style.borderColor = theme.colors.border;
- }}
- >
- 🔃 Reload Page
- </button>
+ <div className="flex flex-wrap justify-center gap-3">
+ <Button onClick={this.handleReset}>
+ <RotateCcw className="h-4 w-4" />
+ Reset Canvas
+ </Button>
+ <Button variant="outline" onClick={this.handleReload}>
+ <RefreshCw className="h-4 w-4" />
+ Reload Page
+ </Button>
</div>
{process.env.NODE_ENV === 'development' && this.state.error && (
- <details style={{
- marginTop: theme.spacing.lg,
- textAlign: 'left',
- backgroundColor: theme.colors.backgroundPanel,
- padding: theme.spacing.md,
- borderRadius: theme.borderRadius.sm,
- border: `1px solid ${theme.colors.border}`
- }}>
- <summary style={{
- cursor: 'pointer',
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- marginBottom: theme.spacing.sm
- }}>
- 🐛 Debug Information
+ <details className="rounded-sm border border-border bg-muted p-3 text-left">
+ <summary className="mb-2 flex cursor-pointer items-center gap-2 font-medium text-foreground">
+ <Bug className="h-3.5 w-3.5" />
+ Debug Information
</summary>
- <pre style={{
- margin: 0,
- fontSize: theme.fontSize.xs,
- color: theme.colors.textSecondary,
- fontFamily: 'Monaco, Menlo, "Ubuntu Mono", monospace',
- whiteSpace: 'pre-wrap',
- wordBreak: 'break-word',
- maxHeight: '200px',
- overflowY: 'auto'
- }}>
+ <pre className="m-0 max-h-[200px] overflow-y-auto font-mono text-xs whitespace-pre-wrap break-words text-muted-foreground">
{this.state.error.toString()}
{this.state.errorInfo && this.state.errorInfo.componentStack}
</pre>
</details>
)}
- </div>
- </div>
- );
- }
-
- return this.props.children;
+ </CardContent>
+ </Card>
+ </div>
+ );
}
}
-export default ErrorBoundary;
\ No newline at end of file
+export default ErrorBoundary;