mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-01-26 16:39:47 +00:00
Have error boundary if simple job cannot be displayed due to the job being advanced
This commit is contained in:
@@ -19,6 +19,7 @@ import { Button } from '@headlessui/react';
|
||||
import { FaChevronLeft } from 'react-icons/fa';
|
||||
import SimpleJob from './SimpleJob';
|
||||
import AdvancedJob from './AdvancedJob';
|
||||
import ErrorBoundary from '@/components/ErrorBoundary';
|
||||
import { apiClient } from '@/utils/api';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
@@ -179,21 +180,27 @@ export default function TrainingForm() {
|
||||
</div>
|
||||
) : (
|
||||
<MainContent>
|
||||
<SimpleJob
|
||||
jobConfig={jobConfig}
|
||||
setJobConfig={setJobConfig}
|
||||
status={status}
|
||||
handleSubmit={handleSubmit}
|
||||
runId={runId}
|
||||
gpuIDs={gpuIDs}
|
||||
setGpuIDs={setGpuIDs}
|
||||
gpuList={gpuList}
|
||||
datasetOptions={datasetOptions}
|
||||
/>
|
||||
<ErrorBoundary fallback={
|
||||
<div className="flex items-center justify-center h-64 text-lg text-red-600 font-medium bg-red-100 dark:bg-red-900/20 dark:text-red-400 border border-red-300 dark:border-red-700 rounded-lg">
|
||||
Advanced job detected. Please switch to advanced view to continue.
|
||||
</div>
|
||||
}>
|
||||
<SimpleJob
|
||||
jobConfig={jobConfig}
|
||||
setJobConfig={setJobConfig}
|
||||
status={status}
|
||||
handleSubmit={handleSubmit}
|
||||
runId={runId}
|
||||
gpuIDs={gpuIDs}
|
||||
setGpuIDs={setGpuIDs}
|
||||
gpuList={gpuList}
|
||||
datasetOptions={datasetOptions}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
|
||||
<div className="pt-20"></div>
|
||||
</MainContent>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
41
ui/src/components/ErrorBoundary.tsx
Normal file
41
ui/src/components/ErrorBoundary.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
// ErrorBoundary.tsx
|
||||
'use client';
|
||||
|
||||
import React, { ReactNode, ErrorInfo, Component } from 'react';
|
||||
|
||||
interface ErrorBoundaryProps {
|
||||
children: ReactNode;
|
||||
fallback?: ReactNode;
|
||||
}
|
||||
|
||||
interface ErrorBoundaryState {
|
||||
hasError: boolean;
|
||||
}
|
||||
|
||||
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
constructor(props: ErrorBoundaryProps) {
|
||||
super(props);
|
||||
this.state = { hasError: false };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(_: Error): ErrorBoundaryState {
|
||||
// Update state so the next render will show the fallback UI
|
||||
return { hasError: true };
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
||||
// You can log the error to an error reporting service
|
||||
console.error("Error caught by ErrorBoundary:", error, errorInfo);
|
||||
}
|
||||
|
||||
render(): ReactNode {
|
||||
if (this.state.hasError) {
|
||||
// You can render any custom fallback UI
|
||||
return this.props.fallback || <div>Something went wrong.</div>;
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorBoundary;
|
||||
Reference in New Issue
Block a user