diff --git a/ui/src/app/jobs/[jobID]/page.tsx b/ui/src/app/jobs/[jobID]/page.tsx index f8efced3..5a6d5d59 100644 --- a/ui/src/app/jobs/[jobID]/page.tsx +++ b/ui/src/app/jobs/[jobID]/page.tsx @@ -9,6 +9,8 @@ import { startJob, stopJob } from '@/utils/jobs'; import SampleImages from '@/components/SampleImages'; import JobOverview from '@/components/JobOverview'; import { JobConfig } from '@/types'; +import { redirect } from 'next/navigation'; +import JobActionBar from '@/components/JobActionBar'; type PageKey = 'overview' | 'samples'; @@ -28,21 +30,12 @@ export default function JobPage({ params }: { params: { jobID: string } }) { const { job, status, refreshJob } = useJob(jobID, 5000); const [pageKey, setPageKey] = useState('overview'); - const numSamples = useMemo(() => { - if (job?.job_config) { - const jobConfig = JSON.parse(job.job_config) as JobConfig; - const sampleConfig = jobConfig.config.process[0].sample; - return sampleConfig.prompts.length; - } - return 10; - }, [job]); - return ( <> {/* Fixed top bar */}
-
@@ -50,27 +43,15 @@ export default function JobPage({ params }: { params: { jobID: string } }) {

Job: {job?.name}

- {job?.status === 'running' && ( - - )} - {(job?.status === 'stopped' || job?.status === 'error') && ( - + /> )}
diff --git a/ui/src/components/JobActionBar.tsx b/ui/src/components/JobActionBar.tsx new file mode 100644 index 00000000..3aac3da0 --- /dev/null +++ b/ui/src/components/JobActionBar.tsx @@ -0,0 +1,87 @@ +import Link from 'next/link'; +import { Eye, Trash2, Pen, Play, Pause } from 'lucide-react'; +import { Button } from '@headlessui/react'; +import { openConfirm } from '@/components/ConfirmModal'; +import { Job } from '@prisma/client'; +import { startJob, stopJob, deleteJob, getAvaliableJobActions } from '@/utils/jobs'; + +interface JobActionBarProps { + job: Job; + onRefresh?: () => void; + afterDelete?: () => void; + hideView?: boolean; + className?: string; +} + +export default function JobActionBar({ job, onRefresh, afterDelete, className, hideView }: JobActionBarProps) { + const { canStart, canStop, canDelete, canEdit } = getAvaliableJobActions(job); + + if (!afterDelete) afterDelete = onRefresh; + + return ( +
+ {canStart && ( + + )} + {canStop && ( + + )} + {!hideView && ( + + + + )} + {canEdit && ( + + + + )} + {canDelete && ( + + )} +
+ ); +} diff --git a/ui/src/components/JobsTable.tsx b/ui/src/components/JobsTable.tsx index 5f3b4dc6..9ad755d1 100644 --- a/ui/src/components/JobsTable.tsx +++ b/ui/src/components/JobsTable.tsx @@ -6,6 +6,7 @@ import { Eye, Trash2, Pen, Play, Pause } from 'lucide-react'; import { Button } from '@headlessui/react'; import { openConfirm } from '@/components/ConfirmModal'; import { startJob, stopJob, deleteJob, getAvaliableJobActions } from '@/utils/jobs'; +import JobActionBar from './JobActionBar'; interface JobsTableProps {} @@ -71,71 +72,7 @@ export default function JobsTable(props: JobsTableProps) { key: 'actions', className: 'text-right', render: row => { - const { canDelete, canEdit, canStop, canStart } = getAvaliableJobActions(row); - return ( -
- {canStart && ( - - )} - {canStop && ( - - )} - - - - {canEdit && ( - - - - )} - {canDelete && ( - - )} -
- ); + return ; }, }, ]; diff --git a/ui/src/utils/jobs.ts b/ui/src/utils/jobs.ts index 1e30da1d..93624d12 100644 --- a/ui/src/utils/jobs.ts +++ b/ui/src/utils/jobs.ts @@ -63,3 +63,13 @@ export const getAvaliableJobActions = (job: Job) => { } return { canDelete, canEdit, canStop, canStart }; }; + +export const getNumberOfSamples = (job: Job) => { + const jobConfig = getJobConfig(job); + return jobConfig.config.process[0].sample?.prompts?.length || 0; +} + +export const getTotalSteps = (job: Job) => { + const jobConfig = getJobConfig(job); + return jobConfig.config.process[0].train.steps; +}