Have error boundary if simple job cannot be displayed due to the job being advanced
This commit is contained in:
1 parent
3c95f87a90
commit
b94d7aafea
2 files changed
+59
-11
No files matched your search
@@ -19,6 +19,7 @@ import { Button } from '@headlessui/react';
|
|||||||
import { FaChevronLeft } from 'react-icons/fa';
|
import { FaChevronLeft } from 'react-icons/fa';
|
||||||
import SimpleJob from './SimpleJob';
|
import SimpleJob from './SimpleJob';
|
||||||
import AdvancedJob from './AdvancedJob';
|
import AdvancedJob from './AdvancedJob';
|
||||||
|
import ErrorBoundary from '@/components/ErrorBoundary';
|
||||||
import { apiClient } from '@/utils/api';
|
import { apiClient } from '@/utils/api';
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const isDev = process.env.NODE_ENV === 'development';
|
||||||
@@ -179,17 +180,23 @@ export default function TrainingForm() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<MainContent>
|
<MainContent>
|
||||||
<SimpleJob
|
<ErrorBoundary fallback={
|
||||||
jobConfig={jobConfig}
|
<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">
|
||||||
setJobConfig={setJobConfig}
|
Advanced job detected. Please switch to advanced view to continue.
|
||||||
status={status}
|
</div>
|
||||||
handleSubmit={handleSubmit}
|
}>
|
||||||
runId={runId}
|
<SimpleJob
|
||||||
gpuIDs={gpuIDs}
|
jobConfig={jobConfig}
|
||||||
setGpuIDs={setGpuIDs}
|
setJobConfig={setJobConfig}
|
||||||
gpuList={gpuList}
|
status={status}
|
||||||
datasetOptions={datasetOptions}
|
handleSubmit={handleSubmit}
|
||||||
/>
|
runId={runId}
|
||||||
|
gpuIDs={gpuIDs}
|
||||||
|
setGpuIDs={setGpuIDs}
|
||||||
|
gpuList={gpuList}
|
||||||
|
datasetOptions={datasetOptions}
|
||||||
|
/>
|
||||||
|
</ErrorBoundary>
|
||||||
|
|
||||||
<div className="pt-20"></div>
|
<div className="pt-20"></div>
|
||||||
</MainContent>
|
</MainContent>
|
||||||
|
|||||||
@@ -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